]>
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" |
f08b6170 | 25 | #include "exec/cpu_ldst.h" |
79aceca5 | 26 | |
2ef6175a RH |
27 | #include "exec/helper-proto.h" |
28 | #include "exec/helper-gen.h" | |
a7812ae4 | 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); | |
a737d3eb TM |
390 | /* Update Cr6 flags (Altivec) */ |
391 | EXTRACT_HELPER(Rc21, 10, 1); | |
79aceca5 FB |
392 | /* Destination */ |
393 | EXTRACT_HELPER(rD, 21, 5); | |
394 | /* Source */ | |
395 | EXTRACT_HELPER(rS, 21, 5); | |
396 | /* First operand */ | |
397 | EXTRACT_HELPER(rA, 16, 5); | |
398 | /* Second operand */ | |
399 | EXTRACT_HELPER(rB, 11, 5); | |
400 | /* Third operand */ | |
401 | EXTRACT_HELPER(rC, 6, 5); | |
402 | /*** Get CRn ***/ | |
403 | EXTRACT_HELPER(crfD, 23, 3); | |
404 | EXTRACT_HELPER(crfS, 18, 3); | |
405 | EXTRACT_HELPER(crbD, 21, 5); | |
406 | EXTRACT_HELPER(crbA, 16, 5); | |
407 | EXTRACT_HELPER(crbB, 11, 5); | |
408 | /* SPR / TBL */ | |
3fc6c082 | 409 | EXTRACT_HELPER(_SPR, 11, 10); |
636aa200 | 410 | static inline uint32_t SPR(uint32_t opcode) |
3fc6c082 FB |
411 | { |
412 | uint32_t sprn = _SPR(opcode); | |
413 | ||
414 | return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); | |
415 | } | |
79aceca5 FB |
416 | /*** Get constants ***/ |
417 | EXTRACT_HELPER(IMM, 12, 8); | |
418 | /* 16 bits signed immediate value */ | |
419 | EXTRACT_SHELPER(SIMM, 0, 16); | |
420 | /* 16 bits unsigned immediate value */ | |
421 | EXTRACT_HELPER(UIMM, 0, 16); | |
21d21583 AJ |
422 | /* 5 bits signed immediate value */ |
423 | EXTRACT_HELPER(SIMM5, 16, 5); | |
27a4edb3 AJ |
424 | /* 5 bits signed immediate value */ |
425 | EXTRACT_HELPER(UIMM5, 16, 5); | |
79aceca5 FB |
426 | /* Bit count */ |
427 | EXTRACT_HELPER(NB, 11, 5); | |
428 | /* Shift count */ | |
429 | EXTRACT_HELPER(SH, 11, 5); | |
cd633b10 AJ |
430 | /* Vector shift count */ |
431 | EXTRACT_HELPER(VSH, 6, 4); | |
79aceca5 FB |
432 | /* Mask start */ |
433 | EXTRACT_HELPER(MB, 6, 5); | |
434 | /* Mask end */ | |
435 | EXTRACT_HELPER(ME, 1, 5); | |
fb0eaffc FB |
436 | /* Trap operand */ |
437 | EXTRACT_HELPER(TO, 21, 5); | |
79aceca5 FB |
438 | |
439 | EXTRACT_HELPER(CRM, 12, 8); | |
79aceca5 | 440 | EXTRACT_HELPER(SR, 16, 4); |
7d08d856 AJ |
441 | |
442 | /* mtfsf/mtfsfi */ | |
779f6590 | 443 | EXTRACT_HELPER(FPBF, 23, 3); |
e4bb997e | 444 | EXTRACT_HELPER(FPIMM, 12, 4); |
779f6590 | 445 | EXTRACT_HELPER(FPL, 25, 1); |
7d08d856 AJ |
446 | EXTRACT_HELPER(FPFLM, 17, 8); |
447 | EXTRACT_HELPER(FPW, 16, 1); | |
fb0eaffc | 448 | |
79aceca5 FB |
449 | /*** Jump target decoding ***/ |
450 | /* Displacement */ | |
451 | EXTRACT_SHELPER(d, 0, 16); | |
452 | /* Immediate address */ | |
636aa200 | 453 | static inline target_ulong LI(uint32_t opcode) |
79aceca5 FB |
454 | { |
455 | return (opcode >> 0) & 0x03FFFFFC; | |
456 | } | |
457 | ||
636aa200 | 458 | static inline uint32_t BD(uint32_t opcode) |
79aceca5 FB |
459 | { |
460 | return (opcode >> 0) & 0xFFFC; | |
461 | } | |
462 | ||
463 | EXTRACT_HELPER(BO, 21, 5); | |
464 | EXTRACT_HELPER(BI, 16, 5); | |
465 | /* Absolute/relative address */ | |
466 | EXTRACT_HELPER(AA, 1, 1); | |
467 | /* Link */ | |
468 | EXTRACT_HELPER(LK, 0, 1); | |
469 | ||
f0b01f02 TM |
470 | /* DFP Z22-form */ |
471 | EXTRACT_HELPER(DCM, 10, 6) | |
472 | ||
473 | /* DFP Z23-form */ | |
474 | EXTRACT_HELPER(RMC, 9, 2) | |
475 | ||
79aceca5 | 476 | /* Create a mask between <start> and <end> bits */ |
636aa200 | 477 | static inline target_ulong MASK(uint32_t start, uint32_t end) |
79aceca5 | 478 | { |
76a66253 | 479 | target_ulong ret; |
79aceca5 | 480 | |
76a66253 JM |
481 | #if defined(TARGET_PPC64) |
482 | if (likely(start == 0)) { | |
6f2d8978 | 483 | ret = UINT64_MAX << (63 - end); |
76a66253 | 484 | } else if (likely(end == 63)) { |
6f2d8978 | 485 | ret = UINT64_MAX >> start; |
76a66253 JM |
486 | } |
487 | #else | |
488 | if (likely(start == 0)) { | |
6f2d8978 | 489 | ret = UINT32_MAX << (31 - end); |
76a66253 | 490 | } else if (likely(end == 31)) { |
6f2d8978 | 491 | ret = UINT32_MAX >> start; |
76a66253 JM |
492 | } |
493 | #endif | |
494 | else { | |
495 | ret = (((target_ulong)(-1ULL)) >> (start)) ^ | |
496 | (((target_ulong)(-1ULL) >> (end)) >> 1); | |
497 | if (unlikely(start > end)) | |
498 | return ~ret; | |
499 | } | |
79aceca5 FB |
500 | |
501 | return ret; | |
502 | } | |
503 | ||
f9fc6d81 TM |
504 | EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5); |
505 | EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5); | |
506 | EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5); | |
507 | EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5); | |
551e3ef7 | 508 | EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5); |
f9fc6d81 | 509 | EXTRACT_HELPER(DM, 8, 2); |
76c15fe0 | 510 | EXTRACT_HELPER(UIM, 16, 2); |
acc42968 | 511 | EXTRACT_HELPER(SHW, 8, 2); |
f0b01f02 | 512 | EXTRACT_HELPER(SP, 19, 2); |
a750fc0b | 513 | /*****************************************************************************/ |
a750fc0b | 514 | /* PowerPC instructions table */ |
933dc6eb | 515 | |
76a66253 | 516 | #if defined(DO_PPC_STATISTICS) |
a5858d7a | 517 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 518 | { \ |
79aceca5 FB |
519 | .opc1 = op1, \ |
520 | .opc2 = op2, \ | |
521 | .opc3 = op3, \ | |
18fba28c | 522 | .pad = { 0, }, \ |
79aceca5 | 523 | .handler = { \ |
70560da7 FC |
524 | .inval1 = invl, \ |
525 | .type = _typ, \ | |
526 | .type2 = _typ2, \ | |
527 | .handler = &gen_##name, \ | |
528 | .oname = stringify(name), \ | |
529 | }, \ | |
530 | .oname = stringify(name), \ | |
531 | } | |
532 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
533 | { \ | |
534 | .opc1 = op1, \ | |
535 | .opc2 = op2, \ | |
536 | .opc3 = op3, \ | |
537 | .pad = { 0, }, \ | |
538 | .handler = { \ | |
539 | .inval1 = invl1, \ | |
540 | .inval2 = invl2, \ | |
9a64fbe4 | 541 | .type = _typ, \ |
a5858d7a | 542 | .type2 = _typ2, \ |
79aceca5 | 543 | .handler = &gen_##name, \ |
76a66253 | 544 | .oname = stringify(name), \ |
79aceca5 | 545 | }, \ |
3fc6c082 | 546 | .oname = stringify(name), \ |
79aceca5 | 547 | } |
a5858d7a | 548 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 549 | { \ |
c7697e1f JM |
550 | .opc1 = op1, \ |
551 | .opc2 = op2, \ | |
552 | .opc3 = op3, \ | |
553 | .pad = { 0, }, \ | |
554 | .handler = { \ | |
70560da7 | 555 | .inval1 = invl, \ |
c7697e1f | 556 | .type = _typ, \ |
a5858d7a | 557 | .type2 = _typ2, \ |
c7697e1f JM |
558 | .handler = &gen_##name, \ |
559 | .oname = onam, \ | |
560 | }, \ | |
561 | .oname = onam, \ | |
562 | } | |
76a66253 | 563 | #else |
a5858d7a | 564 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 565 | { \ |
c7697e1f JM |
566 | .opc1 = op1, \ |
567 | .opc2 = op2, \ | |
568 | .opc3 = op3, \ | |
569 | .pad = { 0, }, \ | |
570 | .handler = { \ | |
70560da7 FC |
571 | .inval1 = invl, \ |
572 | .type = _typ, \ | |
573 | .type2 = _typ2, \ | |
574 | .handler = &gen_##name, \ | |
575 | }, \ | |
576 | .oname = stringify(name), \ | |
577 | } | |
578 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
579 | { \ | |
580 | .opc1 = op1, \ | |
581 | .opc2 = op2, \ | |
582 | .opc3 = op3, \ | |
583 | .pad = { 0, }, \ | |
584 | .handler = { \ | |
585 | .inval1 = invl1, \ | |
586 | .inval2 = invl2, \ | |
c7697e1f | 587 | .type = _typ, \ |
a5858d7a | 588 | .type2 = _typ2, \ |
c7697e1f | 589 | .handler = &gen_##name, \ |
5c55ff99 BS |
590 | }, \ |
591 | .oname = stringify(name), \ | |
592 | } | |
a5858d7a | 593 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 BS |
594 | { \ |
595 | .opc1 = op1, \ | |
596 | .opc2 = op2, \ | |
597 | .opc3 = op3, \ | |
598 | .pad = { 0, }, \ | |
599 | .handler = { \ | |
70560da7 | 600 | .inval1 = invl, \ |
5c55ff99 | 601 | .type = _typ, \ |
a5858d7a | 602 | .type2 = _typ2, \ |
5c55ff99 BS |
603 | .handler = &gen_##name, \ |
604 | }, \ | |
605 | .oname = onam, \ | |
606 | } | |
607 | #endif | |
2e610050 | 608 | |
5c55ff99 | 609 | /* SPR load/store helpers */ |
636aa200 | 610 | static inline void gen_load_spr(TCGv t, int reg) |
5c55ff99 | 611 | { |
1328c2bf | 612 | tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 613 | } |
2e610050 | 614 | |
636aa200 | 615 | static inline void gen_store_spr(int reg, TCGv t) |
5c55ff99 | 616 | { |
1328c2bf | 617 | tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 618 | } |
2e610050 | 619 | |
54623277 | 620 | /* Invalid instruction */ |
99e300ef | 621 | static void gen_invalid(DisasContext *ctx) |
9a64fbe4 | 622 | { |
e06fcd75 | 623 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
9a64fbe4 FB |
624 | } |
625 | ||
c227f099 | 626 | static opc_handler_t invalid_handler = { |
70560da7 FC |
627 | .inval1 = 0xFFFFFFFF, |
628 | .inval2 = 0xFFFFFFFF, | |
9a64fbe4 | 629 | .type = PPC_NONE, |
a5858d7a | 630 | .type2 = PPC_NONE, |
79aceca5 FB |
631 | .handler = gen_invalid, |
632 | }; | |
633 | ||
71a8c019 TM |
634 | #if defined(TARGET_PPC64) |
635 | /* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */ | |
636 | /* so the function is wrapped in the standard 64-bit ifdef in order to */ | |
637 | /* avoid compiler warnings in 32-bit implementations. */ | |
638 | static bool is_user_mode(DisasContext *ctx) | |
639 | { | |
640 | #if defined(CONFIG_USER_ONLY) | |
641 | return true; | |
642 | #else | |
643 | return ctx->mem_idx == 0; | |
644 | #endif | |
645 | } | |
646 | #endif | |
647 | ||
e1571908 AJ |
648 | /*** Integer comparison ***/ |
649 | ||
636aa200 | 650 | static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 651 | { |
2fdcb629 RH |
652 | TCGv t0 = tcg_temp_new(); |
653 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
e1571908 | 654 | |
da91a00f | 655 | tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so); |
e1571908 | 656 | |
2fdcb629 RH |
657 | tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1); |
658 | tcg_gen_trunc_tl_i32(t1, t0); | |
659 | tcg_gen_shli_i32(t1, t1, CRF_LT); | |
660 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
661 | ||
662 | tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1); | |
663 | tcg_gen_trunc_tl_i32(t1, t0); | |
664 | tcg_gen_shli_i32(t1, t1, CRF_GT); | |
665 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
666 | ||
667 | tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1); | |
668 | tcg_gen_trunc_tl_i32(t1, t0); | |
669 | tcg_gen_shli_i32(t1, t1, CRF_EQ); | |
670 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
671 | ||
672 | tcg_temp_free(t0); | |
673 | tcg_temp_free_i32(t1); | |
e1571908 AJ |
674 | } |
675 | ||
636aa200 | 676 | static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 677 | { |
2fdcb629 | 678 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
679 | gen_op_cmp(arg0, t0, s, crf); |
680 | tcg_temp_free(t0); | |
e1571908 AJ |
681 | } |
682 | ||
636aa200 | 683 | static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 684 | { |
ea363694 | 685 | TCGv t0, t1; |
2fdcb629 RH |
686 | t0 = tcg_temp_new(); |
687 | t1 = tcg_temp_new(); | |
e1571908 | 688 | if (s) { |
ea363694 AJ |
689 | tcg_gen_ext32s_tl(t0, arg0); |
690 | tcg_gen_ext32s_tl(t1, arg1); | |
e1571908 | 691 | } else { |
ea363694 AJ |
692 | tcg_gen_ext32u_tl(t0, arg0); |
693 | tcg_gen_ext32u_tl(t1, arg1); | |
e1571908 | 694 | } |
ea363694 AJ |
695 | gen_op_cmp(t0, t1, s, crf); |
696 | tcg_temp_free(t1); | |
697 | tcg_temp_free(t0); | |
e1571908 AJ |
698 | } |
699 | ||
636aa200 | 700 | static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 701 | { |
2fdcb629 | 702 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
703 | gen_op_cmp32(arg0, t0, s, crf); |
704 | tcg_temp_free(t0); | |
e1571908 | 705 | } |
e1571908 | 706 | |
636aa200 | 707 | static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg) |
e1571908 | 708 | { |
02765534 | 709 | if (NARROW_MODE(ctx)) { |
e1571908 | 710 | gen_op_cmpi32(reg, 0, 1, 0); |
02765534 | 711 | } else { |
e1571908 | 712 | gen_op_cmpi(reg, 0, 1, 0); |
02765534 | 713 | } |
e1571908 AJ |
714 | } |
715 | ||
716 | /* cmp */ | |
99e300ef | 717 | static void gen_cmp(DisasContext *ctx) |
e1571908 | 718 | { |
36f48d9c | 719 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
720 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
721 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
722 | } else { |
723 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
724 | 1, crfD(ctx->opcode)); | |
02765534 | 725 | } |
e1571908 AJ |
726 | } |
727 | ||
728 | /* cmpi */ | |
99e300ef | 729 | static void gen_cmpi(DisasContext *ctx) |
e1571908 | 730 | { |
36f48d9c | 731 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
732 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), |
733 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
734 | } else { |
735 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
736 | 1, crfD(ctx->opcode)); | |
02765534 | 737 | } |
e1571908 AJ |
738 | } |
739 | ||
740 | /* cmpl */ | |
99e300ef | 741 | static void gen_cmpl(DisasContext *ctx) |
e1571908 | 742 | { |
36f48d9c | 743 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
744 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
745 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
746 | } else { |
747 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
748 | 0, crfD(ctx->opcode)); | |
02765534 | 749 | } |
e1571908 AJ |
750 | } |
751 | ||
752 | /* cmpli */ | |
99e300ef | 753 | static void gen_cmpli(DisasContext *ctx) |
e1571908 | 754 | { |
36f48d9c | 755 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
756 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), |
757 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
758 | } else { |
759 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
760 | 0, crfD(ctx->opcode)); | |
02765534 | 761 | } |
e1571908 AJ |
762 | } |
763 | ||
764 | /* isel (PowerPC 2.03 specification) */ | |
99e300ef | 765 | static void gen_isel(DisasContext *ctx) |
e1571908 AJ |
766 | { |
767 | int l1, l2; | |
768 | uint32_t bi = rC(ctx->opcode); | |
769 | uint32_t mask; | |
a7812ae4 | 770 | TCGv_i32 t0; |
e1571908 AJ |
771 | |
772 | l1 = gen_new_label(); | |
773 | l2 = gen_new_label(); | |
774 | ||
775 | mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 776 | t0 = tcg_temp_new_i32(); |
fea0c503 AJ |
777 | tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask); |
778 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
e1571908 AJ |
779 | if (rA(ctx->opcode) == 0) |
780 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
781 | else | |
782 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
783 | tcg_gen_br(l2); | |
784 | gen_set_label(l1); | |
785 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
786 | gen_set_label(l2); | |
a7812ae4 | 787 | tcg_temp_free_i32(t0); |
e1571908 AJ |
788 | } |
789 | ||
fcfda20f AJ |
790 | /* cmpb: PowerPC 2.05 specification */ |
791 | static void gen_cmpb(DisasContext *ctx) | |
792 | { | |
793 | gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], | |
794 | cpu_gpr[rB(ctx->opcode)]); | |
795 | } | |
796 | ||
79aceca5 | 797 | /*** Integer arithmetic ***/ |
79aceca5 | 798 | |
636aa200 BS |
799 | static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, |
800 | TCGv arg1, TCGv arg2, int sub) | |
74637406 | 801 | { |
ffe30937 | 802 | TCGv t0 = tcg_temp_new(); |
79aceca5 | 803 | |
8e7a6db9 | 804 | tcg_gen_xor_tl(cpu_ov, arg0, arg2); |
74637406 | 805 | tcg_gen_xor_tl(t0, arg1, arg2); |
ffe30937 RH |
806 | if (sub) { |
807 | tcg_gen_and_tl(cpu_ov, cpu_ov, t0); | |
808 | } else { | |
809 | tcg_gen_andc_tl(cpu_ov, cpu_ov, t0); | |
810 | } | |
811 | tcg_temp_free(t0); | |
02765534 | 812 | if (NARROW_MODE(ctx)) { |
ffe30937 RH |
813 | tcg_gen_ext32s_tl(cpu_ov, cpu_ov); |
814 | } | |
ffe30937 RH |
815 | tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1); |
816 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); | |
79aceca5 FB |
817 | } |
818 | ||
74637406 | 819 | /* Common add function */ |
636aa200 | 820 | static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
b5a73f8d RH |
821 | TCGv arg2, bool add_ca, bool compute_ca, |
822 | bool compute_ov, bool compute_rc0) | |
74637406 | 823 | { |
b5a73f8d | 824 | TCGv t0 = ret; |
d9bce9d9 | 825 | |
752d634e | 826 | if (compute_ca || compute_ov) { |
146de60d | 827 | t0 = tcg_temp_new(); |
74637406 | 828 | } |
79aceca5 | 829 | |
da91a00f | 830 | if (compute_ca) { |
79482e5a | 831 | if (NARROW_MODE(ctx)) { |
752d634e RH |
832 | /* Caution: a non-obvious corner case of the spec is that we |
833 | must produce the *entire* 64-bit addition, but produce the | |
834 | carry into bit 32. */ | |
79482e5a | 835 | TCGv t1 = tcg_temp_new(); |
752d634e RH |
836 | tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */ |
837 | tcg_gen_add_tl(t0, arg1, arg2); | |
79482e5a RH |
838 | if (add_ca) { |
839 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
840 | } | |
752d634e RH |
841 | tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */ |
842 | tcg_temp_free(t1); | |
843 | tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ | |
844 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
b5a73f8d | 845 | } else { |
79482e5a RH |
846 | TCGv zero = tcg_const_tl(0); |
847 | if (add_ca) { | |
848 | tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero); | |
849 | tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero); | |
850 | } else { | |
851 | tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero); | |
852 | } | |
853 | tcg_temp_free(zero); | |
b5a73f8d | 854 | } |
b5a73f8d RH |
855 | } else { |
856 | tcg_gen_add_tl(t0, arg1, arg2); | |
857 | if (add_ca) { | |
858 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
859 | } | |
da91a00f | 860 | } |
79aceca5 | 861 | |
74637406 AJ |
862 | if (compute_ov) { |
863 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0); | |
864 | } | |
b5a73f8d | 865 | if (unlikely(compute_rc0)) { |
74637406 | 866 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 867 | } |
74637406 | 868 | |
a7812ae4 | 869 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
870 | tcg_gen_mov_tl(ret, t0); |
871 | tcg_temp_free(t0); | |
872 | } | |
39dd32ee | 873 | } |
74637406 AJ |
874 | /* Add functions with two operands */ |
875 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 876 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
877 | { \ |
878 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
879 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
b5a73f8d | 880 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
881 | } |
882 | /* Add functions with one operand and one immediate */ | |
883 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
884 | add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 885 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 886 | { \ |
b5a73f8d | 887 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
888 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ |
889 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
b5a73f8d | 890 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
891 | tcg_temp_free(t0); \ |
892 | } | |
893 | ||
894 | /* add add. addo addo. */ | |
895 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
896 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
897 | /* addc addc. addco addco. */ | |
898 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
899 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
900 | /* adde adde. addeo addeo. */ | |
901 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
902 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
903 | /* addme addme. addmeo addmeo. */ | |
904 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
905 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
906 | /* addze addze. addzeo addzeo.*/ | |
907 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
908 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
909 | /* addi */ | |
99e300ef | 910 | static void gen_addi(DisasContext *ctx) |
d9bce9d9 | 911 | { |
74637406 AJ |
912 | target_long simm = SIMM(ctx->opcode); |
913 | ||
914 | if (rA(ctx->opcode) == 0) { | |
915 | /* li case */ | |
916 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm); | |
917 | } else { | |
b5a73f8d RH |
918 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
919 | cpu_gpr[rA(ctx->opcode)], simm); | |
74637406 | 920 | } |
d9bce9d9 | 921 | } |
74637406 | 922 | /* addic addic.*/ |
b5a73f8d | 923 | static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0) |
d9bce9d9 | 924 | { |
b5a73f8d RH |
925 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
926 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
927 | c, 0, 1, 0, compute_rc0); | |
928 | tcg_temp_free(c); | |
d9bce9d9 | 929 | } |
99e300ef BS |
930 | |
931 | static void gen_addic(DisasContext *ctx) | |
d9bce9d9 | 932 | { |
b5a73f8d | 933 | gen_op_addic(ctx, 0); |
d9bce9d9 | 934 | } |
e8eaa2c0 BS |
935 | |
936 | static void gen_addic_(DisasContext *ctx) | |
d9bce9d9 | 937 | { |
b5a73f8d | 938 | gen_op_addic(ctx, 1); |
d9bce9d9 | 939 | } |
99e300ef | 940 | |
54623277 | 941 | /* addis */ |
99e300ef | 942 | static void gen_addis(DisasContext *ctx) |
d9bce9d9 | 943 | { |
74637406 AJ |
944 | target_long simm = SIMM(ctx->opcode); |
945 | ||
946 | if (rA(ctx->opcode) == 0) { | |
947 | /* lis case */ | |
948 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16); | |
949 | } else { | |
b5a73f8d RH |
950 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
951 | cpu_gpr[rA(ctx->opcode)], simm << 16); | |
74637406 | 952 | } |
d9bce9d9 | 953 | } |
74637406 | 954 | |
636aa200 BS |
955 | static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1, |
956 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 957 | { |
2ef1b120 AJ |
958 | int l1 = gen_new_label(); |
959 | int l2 = gen_new_label(); | |
a7812ae4 PB |
960 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
961 | TCGv_i32 t1 = tcg_temp_local_new_i32(); | |
74637406 | 962 | |
2ef1b120 AJ |
963 | tcg_gen_trunc_tl_i32(t0, arg1); |
964 | tcg_gen_trunc_tl_i32(t1, arg2); | |
965 | tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1); | |
74637406 | 966 | if (sign) { |
2ef1b120 AJ |
967 | int l3 = gen_new_label(); |
968 | tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3); | |
969 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1); | |
74637406 | 970 | gen_set_label(l3); |
2ef1b120 | 971 | tcg_gen_div_i32(t0, t0, t1); |
74637406 | 972 | } else { |
2ef1b120 | 973 | tcg_gen_divu_i32(t0, t0, t1); |
74637406 AJ |
974 | } |
975 | if (compute_ov) { | |
da91a00f | 976 | tcg_gen_movi_tl(cpu_ov, 0); |
74637406 AJ |
977 | } |
978 | tcg_gen_br(l2); | |
979 | gen_set_label(l1); | |
980 | if (sign) { | |
2ef1b120 | 981 | tcg_gen_sari_i32(t0, t0, 31); |
74637406 AJ |
982 | } else { |
983 | tcg_gen_movi_i32(t0, 0); | |
984 | } | |
985 | if (compute_ov) { | |
da91a00f RH |
986 | tcg_gen_movi_tl(cpu_ov, 1); |
987 | tcg_gen_movi_tl(cpu_so, 1); | |
74637406 AJ |
988 | } |
989 | gen_set_label(l2); | |
2ef1b120 | 990 | tcg_gen_extu_i32_tl(ret, t0); |
a7812ae4 PB |
991 | tcg_temp_free_i32(t0); |
992 | tcg_temp_free_i32(t1); | |
74637406 AJ |
993 | if (unlikely(Rc(ctx->opcode) != 0)) |
994 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 995 | } |
74637406 AJ |
996 | /* Div functions */ |
997 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
99e300ef | 998 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
999 | { \ |
1000 | gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1001 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1002 | sign, compute_ov); \ | |
1003 | } | |
1004 | /* divwu divwu. divwuo divwuo. */ | |
1005 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0); | |
1006 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1); | |
1007 | /* divw divw. divwo divwo. */ | |
1008 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0); | |
1009 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1); | |
98d1eb27 TM |
1010 | |
1011 | /* div[wd]eu[o][.] */ | |
1012 | #define GEN_DIVE(name, hlpr, compute_ov) \ | |
1013 | static void gen_##name(DisasContext *ctx) \ | |
1014 | { \ | |
1015 | TCGv_i32 t0 = tcg_const_i32(compute_ov); \ | |
1016 | gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \ | |
1017 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \ | |
1018 | tcg_temp_free_i32(t0); \ | |
1019 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
1020 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \ | |
1021 | } \ | |
1022 | } | |
1023 | ||
6a4fda33 TM |
1024 | GEN_DIVE(divweu, divweu, 0); |
1025 | GEN_DIVE(divweuo, divweu, 1); | |
a98eb9e9 TM |
1026 | GEN_DIVE(divwe, divwe, 0); |
1027 | GEN_DIVE(divweo, divwe, 1); | |
6a4fda33 | 1028 | |
d9bce9d9 | 1029 | #if defined(TARGET_PPC64) |
636aa200 BS |
1030 | static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1, |
1031 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 1032 | { |
2ef1b120 AJ |
1033 | int l1 = gen_new_label(); |
1034 | int l2 = gen_new_label(); | |
74637406 AJ |
1035 | |
1036 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1); | |
1037 | if (sign) { | |
2ef1b120 | 1038 | int l3 = gen_new_label(); |
74637406 AJ |
1039 | tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3); |
1040 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1); | |
1041 | gen_set_label(l3); | |
74637406 AJ |
1042 | tcg_gen_div_i64(ret, arg1, arg2); |
1043 | } else { | |
1044 | tcg_gen_divu_i64(ret, arg1, arg2); | |
1045 | } | |
1046 | if (compute_ov) { | |
da91a00f | 1047 | tcg_gen_movi_tl(cpu_ov, 0); |
74637406 AJ |
1048 | } |
1049 | tcg_gen_br(l2); | |
1050 | gen_set_label(l1); | |
1051 | if (sign) { | |
1052 | tcg_gen_sari_i64(ret, arg1, 63); | |
1053 | } else { | |
1054 | tcg_gen_movi_i64(ret, 0); | |
1055 | } | |
1056 | if (compute_ov) { | |
da91a00f RH |
1057 | tcg_gen_movi_tl(cpu_ov, 1); |
1058 | tcg_gen_movi_tl(cpu_so, 1); | |
74637406 AJ |
1059 | } |
1060 | gen_set_label(l2); | |
1061 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1062 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1063 | } |
74637406 | 1064 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ |
99e300ef | 1065 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1066 | { \ |
2ef1b120 AJ |
1067 | gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1068 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1069 | sign, compute_ov); \ | |
74637406 AJ |
1070 | } |
1071 | /* divwu divwu. divwuo divwuo. */ | |
1072 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0); | |
1073 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1); | |
1074 | /* divw divw. divwo divwo. */ | |
1075 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0); | |
1076 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1); | |
98d1eb27 TM |
1077 | |
1078 | GEN_DIVE(divdeu, divdeu, 0); | |
1079 | GEN_DIVE(divdeuo, divdeu, 1); | |
e44259b6 TM |
1080 | GEN_DIVE(divde, divde, 0); |
1081 | GEN_DIVE(divdeo, divde, 1); | |
d9bce9d9 | 1082 | #endif |
74637406 AJ |
1083 | |
1084 | /* mulhw mulhw. */ | |
99e300ef | 1085 | static void gen_mulhw(DisasContext *ctx) |
d9bce9d9 | 1086 | { |
23ad1d5d RH |
1087 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1088 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1089 | |
23ad1d5d RH |
1090 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1091 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1092 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1093 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1094 | tcg_temp_free_i32(t0); | |
1095 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1096 | if (unlikely(Rc(ctx->opcode) != 0)) |
1097 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1098 | } |
99e300ef | 1099 | |
54623277 | 1100 | /* mulhwu mulhwu. */ |
99e300ef | 1101 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1102 | { |
23ad1d5d RH |
1103 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1104 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1105 | |
23ad1d5d RH |
1106 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1107 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1108 | tcg_gen_mulu2_i32(t0, t1, t0, t1); | |
1109 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1110 | tcg_temp_free_i32(t0); | |
1111 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1112 | if (unlikely(Rc(ctx->opcode) != 0)) |
1113 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1114 | } |
99e300ef | 1115 | |
54623277 | 1116 | /* mullw mullw. */ |
99e300ef | 1117 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1118 | { |
74637406 AJ |
1119 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1120 | cpu_gpr[rB(ctx->opcode)]); | |
1e4c090f | 1121 | tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]); |
74637406 AJ |
1122 | if (unlikely(Rc(ctx->opcode) != 0)) |
1123 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1124 | } |
99e300ef | 1125 | |
54623277 | 1126 | /* mullwo mullwo. */ |
99e300ef | 1127 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1128 | { |
e4a2c846 RH |
1129 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1130 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1131 | |
e4a2c846 RH |
1132 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1133 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1134 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1135 | tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1136 | ||
1137 | tcg_gen_sari_i32(t0, t0, 31); | |
1138 | tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1); | |
1139 | tcg_gen_extu_i32_tl(cpu_ov, t0); | |
1140 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); | |
1141 | ||
1142 | tcg_temp_free_i32(t0); | |
1143 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1144 | if (unlikely(Rc(ctx->opcode) != 0)) |
1145 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1146 | } |
99e300ef | 1147 | |
54623277 | 1148 | /* mulli */ |
99e300ef | 1149 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1150 | { |
74637406 AJ |
1151 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1152 | SIMM(ctx->opcode)); | |
d9bce9d9 | 1153 | } |
23ad1d5d | 1154 | |
d9bce9d9 | 1155 | #if defined(TARGET_PPC64) |
74637406 | 1156 | /* mulhd mulhd. */ |
23ad1d5d RH |
1157 | static void gen_mulhd(DisasContext *ctx) |
1158 | { | |
1159 | TCGv lo = tcg_temp_new(); | |
1160 | tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1161 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1162 | tcg_temp_free(lo); | |
1163 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1164 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1165 | } | |
1166 | } | |
1167 | ||
74637406 | 1168 | /* mulhdu mulhdu. */ |
23ad1d5d RH |
1169 | static void gen_mulhdu(DisasContext *ctx) |
1170 | { | |
1171 | TCGv lo = tcg_temp_new(); | |
1172 | tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1173 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1174 | tcg_temp_free(lo); | |
1175 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1176 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1177 | } | |
1178 | } | |
99e300ef | 1179 | |
54623277 | 1180 | /* mulld mulld. */ |
99e300ef | 1181 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1182 | { |
74637406 AJ |
1183 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1184 | cpu_gpr[rB(ctx->opcode)]); | |
1185 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1186 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1187 | } |
d15f74fb | 1188 | |
74637406 | 1189 | /* mulldo mulldo. */ |
d15f74fb BS |
1190 | static void gen_mulldo(DisasContext *ctx) |
1191 | { | |
1192 | gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env, | |
1193 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1194 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1195 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1196 | } | |
1197 | } | |
d9bce9d9 | 1198 | #endif |
74637406 | 1199 | |
74637406 | 1200 | /* Common subf function */ |
636aa200 | 1201 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
b5a73f8d RH |
1202 | TCGv arg2, bool add_ca, bool compute_ca, |
1203 | bool compute_ov, bool compute_rc0) | |
79aceca5 | 1204 | { |
b5a73f8d | 1205 | TCGv t0 = ret; |
79aceca5 | 1206 | |
752d634e | 1207 | if (compute_ca || compute_ov) { |
b5a73f8d | 1208 | t0 = tcg_temp_new(); |
da91a00f | 1209 | } |
74637406 | 1210 | |
79482e5a RH |
1211 | if (compute_ca) { |
1212 | /* dest = ~arg1 + arg2 [+ ca]. */ | |
1213 | if (NARROW_MODE(ctx)) { | |
752d634e RH |
1214 | /* Caution: a non-obvious corner case of the spec is that we |
1215 | must produce the *entire* 64-bit addition, but produce the | |
1216 | carry into bit 32. */ | |
79482e5a | 1217 | TCGv inv1 = tcg_temp_new(); |
752d634e | 1218 | TCGv t1 = tcg_temp_new(); |
79482e5a | 1219 | tcg_gen_not_tl(inv1, arg1); |
79482e5a | 1220 | if (add_ca) { |
752d634e | 1221 | tcg_gen_add_tl(t0, arg2, cpu_ca); |
79482e5a | 1222 | } else { |
752d634e | 1223 | tcg_gen_addi_tl(t0, arg2, 1); |
79482e5a | 1224 | } |
752d634e | 1225 | tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */ |
79482e5a | 1226 | tcg_gen_add_tl(t0, t0, inv1); |
752d634e RH |
1227 | tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */ |
1228 | tcg_temp_free(t1); | |
1229 | tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ | |
1230 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
79482e5a | 1231 | } else if (add_ca) { |
08f4a0f7 RH |
1232 | TCGv zero, inv1 = tcg_temp_new(); |
1233 | tcg_gen_not_tl(inv1, arg1); | |
b5a73f8d RH |
1234 | zero = tcg_const_tl(0); |
1235 | tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero); | |
08f4a0f7 | 1236 | tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero); |
b5a73f8d | 1237 | tcg_temp_free(zero); |
08f4a0f7 | 1238 | tcg_temp_free(inv1); |
b5a73f8d | 1239 | } else { |
79482e5a | 1240 | tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1); |
b5a73f8d | 1241 | tcg_gen_sub_tl(t0, arg2, arg1); |
b5a73f8d | 1242 | } |
79482e5a RH |
1243 | } else if (add_ca) { |
1244 | /* Since we're ignoring carry-out, we can simplify the | |
1245 | standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */ | |
1246 | tcg_gen_sub_tl(t0, arg2, arg1); | |
1247 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
1248 | tcg_gen_subi_tl(t0, t0, 1); | |
79aceca5 | 1249 | } else { |
b5a73f8d | 1250 | tcg_gen_sub_tl(t0, arg2, arg1); |
74637406 | 1251 | } |
b5a73f8d | 1252 | |
74637406 AJ |
1253 | if (compute_ov) { |
1254 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1255 | } | |
b5a73f8d | 1256 | if (unlikely(compute_rc0)) { |
74637406 | 1257 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 1258 | } |
74637406 | 1259 | |
a7812ae4 | 1260 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
1261 | tcg_gen_mov_tl(ret, t0); |
1262 | tcg_temp_free(t0); | |
79aceca5 | 1263 | } |
79aceca5 | 1264 | } |
74637406 AJ |
1265 | /* Sub functions with Two operands functions */ |
1266 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1267 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1268 | { \ |
1269 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1270 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
b5a73f8d | 1271 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1272 | } |
1273 | /* Sub functions with one operand and one immediate */ | |
1274 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1275 | add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1276 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1277 | { \ |
b5a73f8d | 1278 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
1279 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1280 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
b5a73f8d | 1281 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1282 | tcg_temp_free(t0); \ |
1283 | } | |
1284 | /* subf subf. subfo subfo. */ | |
1285 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1286 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1287 | /* subfc subfc. subfco subfco. */ | |
1288 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1289 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1290 | /* subfe subfe. subfeo subfo. */ | |
1291 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1292 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1293 | /* subfme subfme. subfmeo subfmeo. */ | |
1294 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1295 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1296 | /* subfze subfze. subfzeo subfzeo.*/ | |
1297 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1298 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1299 | |
54623277 | 1300 | /* subfic */ |
99e300ef | 1301 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1302 | { |
b5a73f8d RH |
1303 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
1304 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1305 | c, 0, 1, 0, 0); | |
1306 | tcg_temp_free(c); | |
79aceca5 FB |
1307 | } |
1308 | ||
fd3f0081 RH |
1309 | /* neg neg. nego nego. */ |
1310 | static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov) | |
1311 | { | |
1312 | TCGv zero = tcg_const_tl(0); | |
1313 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1314 | zero, 0, 0, compute_ov, Rc(ctx->opcode)); | |
1315 | tcg_temp_free(zero); | |
1316 | } | |
1317 | ||
1318 | static void gen_neg(DisasContext *ctx) | |
1319 | { | |
1320 | gen_op_arith_neg(ctx, 0); | |
1321 | } | |
1322 | ||
1323 | static void gen_nego(DisasContext *ctx) | |
1324 | { | |
1325 | gen_op_arith_neg(ctx, 1); | |
1326 | } | |
1327 | ||
79aceca5 | 1328 | /*** Integer logical ***/ |
26d67362 | 1329 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1330 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1331 | { \ |
26d67362 AJ |
1332 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1333 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1334 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1335 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1336 | } |
79aceca5 | 1337 | |
26d67362 | 1338 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1339 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1340 | { \ |
26d67362 | 1341 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1342 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1343 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1344 | } |
1345 | ||
1346 | /* and & and. */ | |
26d67362 | 1347 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1348 | /* andc & andc. */ |
26d67362 | 1349 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1350 | |
54623277 | 1351 | /* andi. */ |
e8eaa2c0 | 1352 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1353 | { |
26d67362 AJ |
1354 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1355 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1356 | } |
e8eaa2c0 | 1357 | |
54623277 | 1358 | /* andis. */ |
e8eaa2c0 | 1359 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1360 | { |
26d67362 AJ |
1361 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1362 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1363 | } |
99e300ef | 1364 | |
54623277 | 1365 | /* cntlzw */ |
99e300ef | 1366 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1367 | { |
a7812ae4 | 1368 | gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 | 1369 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1370 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1371 | } |
79aceca5 | 1372 | /* eqv & eqv. */ |
26d67362 | 1373 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1374 | /* extsb & extsb. */ |
26d67362 | 1375 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1376 | /* extsh & extsh. */ |
26d67362 | 1377 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1378 | /* nand & nand. */ |
26d67362 | 1379 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1380 | /* nor & nor. */ |
26d67362 | 1381 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1382 | |
54623277 | 1383 | /* or & or. */ |
99e300ef | 1384 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1385 | { |
76a66253 JM |
1386 | int rs, ra, rb; |
1387 | ||
1388 | rs = rS(ctx->opcode); | |
1389 | ra = rA(ctx->opcode); | |
1390 | rb = rB(ctx->opcode); | |
1391 | /* Optimisation for mr. ri case */ | |
1392 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1393 | if (rs != rb) |
1394 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1395 | else | |
1396 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1397 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1398 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1399 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1400 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 JM |
1401 | #if defined(TARGET_PPC64) |
1402 | } else { | |
26d67362 AJ |
1403 | int prio = 0; |
1404 | ||
c80f84e3 JM |
1405 | switch (rs) { |
1406 | case 1: | |
1407 | /* Set process priority to low */ | |
26d67362 | 1408 | prio = 2; |
c80f84e3 JM |
1409 | break; |
1410 | case 6: | |
1411 | /* Set process priority to medium-low */ | |
26d67362 | 1412 | prio = 3; |
c80f84e3 JM |
1413 | break; |
1414 | case 2: | |
1415 | /* Set process priority to normal */ | |
26d67362 | 1416 | prio = 4; |
c80f84e3 | 1417 | break; |
be147d08 JM |
1418 | #if !defined(CONFIG_USER_ONLY) |
1419 | case 31: | |
76db3ba4 | 1420 | if (ctx->mem_idx > 0) { |
be147d08 | 1421 | /* Set process priority to very low */ |
26d67362 | 1422 | prio = 1; |
be147d08 JM |
1423 | } |
1424 | break; | |
1425 | case 5: | |
76db3ba4 | 1426 | if (ctx->mem_idx > 0) { |
be147d08 | 1427 | /* Set process priority to medium-hight */ |
26d67362 | 1428 | prio = 5; |
be147d08 JM |
1429 | } |
1430 | break; | |
1431 | case 3: | |
76db3ba4 | 1432 | if (ctx->mem_idx > 0) { |
be147d08 | 1433 | /* Set process priority to high */ |
26d67362 | 1434 | prio = 6; |
be147d08 JM |
1435 | } |
1436 | break; | |
be147d08 | 1437 | case 7: |
76db3ba4 | 1438 | if (ctx->mem_idx > 1) { |
be147d08 | 1439 | /* Set process priority to very high */ |
26d67362 | 1440 | prio = 7; |
be147d08 JM |
1441 | } |
1442 | break; | |
be147d08 | 1443 | #endif |
c80f84e3 JM |
1444 | default: |
1445 | /* nop */ | |
1446 | break; | |
1447 | } | |
26d67362 | 1448 | if (prio) { |
a7812ae4 | 1449 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1450 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1451 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1452 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1453 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1454 | tcg_temp_free(t0); |
26d67362 | 1455 | } |
c80f84e3 | 1456 | #endif |
9a64fbe4 | 1457 | } |
9a64fbe4 | 1458 | } |
79aceca5 | 1459 | /* orc & orc. */ |
26d67362 | 1460 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1461 | |
54623277 | 1462 | /* xor & xor. */ |
99e300ef | 1463 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1464 | { |
9a64fbe4 | 1465 | /* Optimisation for "set to zero" case */ |
26d67362 | 1466 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1467 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1468 | else |
1469 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1470 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1471 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1472 | } |
99e300ef | 1473 | |
54623277 | 1474 | /* ori */ |
99e300ef | 1475 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1476 | { |
76a66253 | 1477 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1478 | |
9a64fbe4 FB |
1479 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1480 | /* NOP */ | |
76a66253 | 1481 | /* XXX: should handle special NOPs for POWER series */ |
9a64fbe4 | 1482 | return; |
76a66253 | 1483 | } |
26d67362 | 1484 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1485 | } |
99e300ef | 1486 | |
54623277 | 1487 | /* oris */ |
99e300ef | 1488 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1489 | { |
76a66253 | 1490 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1491 | |
9a64fbe4 FB |
1492 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1493 | /* NOP */ | |
1494 | return; | |
76a66253 | 1495 | } |
26d67362 | 1496 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1497 | } |
99e300ef | 1498 | |
54623277 | 1499 | /* xori */ |
99e300ef | 1500 | static void gen_xori(DisasContext *ctx) |
79aceca5 | 1501 | { |
76a66253 | 1502 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1503 | |
1504 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1505 | /* NOP */ | |
1506 | return; | |
1507 | } | |
26d67362 | 1508 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1509 | } |
99e300ef | 1510 | |
54623277 | 1511 | /* xoris */ |
99e300ef | 1512 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1513 | { |
76a66253 | 1514 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1515 | |
1516 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1517 | /* NOP */ | |
1518 | return; | |
1519 | } | |
26d67362 | 1520 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1521 | } |
99e300ef | 1522 | |
54623277 | 1523 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1524 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1525 | { |
eaabeef2 DG |
1526 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1527 | } | |
1528 | ||
1529 | static void gen_popcntw(DisasContext *ctx) | |
1530 | { | |
1531 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1532 | } | |
1533 | ||
d9bce9d9 | 1534 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1535 | /* popcntd: PowerPC 2.06 specification */ |
1536 | static void gen_popcntd(DisasContext *ctx) | |
1537 | { | |
1538 | gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 1539 | } |
eaabeef2 | 1540 | #endif |
d9bce9d9 | 1541 | |
725bcec2 AJ |
1542 | /* prtyw: PowerPC 2.05 specification */ |
1543 | static void gen_prtyw(DisasContext *ctx) | |
1544 | { | |
1545 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1546 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1547 | TCGv t0 = tcg_temp_new(); | |
1548 | tcg_gen_shri_tl(t0, rs, 16); | |
1549 | tcg_gen_xor_tl(ra, rs, t0); | |
1550 | tcg_gen_shri_tl(t0, ra, 8); | |
1551 | tcg_gen_xor_tl(ra, ra, t0); | |
1552 | tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL); | |
1553 | tcg_temp_free(t0); | |
1554 | } | |
1555 | ||
1556 | #if defined(TARGET_PPC64) | |
1557 | /* prtyd: PowerPC 2.05 specification */ | |
1558 | static void gen_prtyd(DisasContext *ctx) | |
1559 | { | |
1560 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1561 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1562 | TCGv t0 = tcg_temp_new(); | |
1563 | tcg_gen_shri_tl(t0, rs, 32); | |
1564 | tcg_gen_xor_tl(ra, rs, t0); | |
1565 | tcg_gen_shri_tl(t0, ra, 16); | |
1566 | tcg_gen_xor_tl(ra, ra, t0); | |
1567 | tcg_gen_shri_tl(t0, ra, 8); | |
1568 | tcg_gen_xor_tl(ra, ra, t0); | |
1569 | tcg_gen_andi_tl(ra, ra, 1); | |
1570 | tcg_temp_free(t0); | |
1571 | } | |
1572 | #endif | |
1573 | ||
86ba37ed TM |
1574 | #if defined(TARGET_PPC64) |
1575 | /* bpermd */ | |
1576 | static void gen_bpermd(DisasContext *ctx) | |
1577 | { | |
1578 | gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)], | |
1579 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1580 | } | |
1581 | #endif | |
1582 | ||
d9bce9d9 JM |
1583 | #if defined(TARGET_PPC64) |
1584 | /* extsw & extsw. */ | |
26d67362 | 1585 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1586 | |
54623277 | 1587 | /* cntlzd */ |
99e300ef | 1588 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1589 | { |
a7812ae4 | 1590 | gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 AJ |
1591 | if (unlikely(Rc(ctx->opcode) != 0)) |
1592 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1593 | } | |
d9bce9d9 JM |
1594 | #endif |
1595 | ||
79aceca5 | 1596 | /*** Integer rotate ***/ |
99e300ef | 1597 | |
54623277 | 1598 | /* rlwimi & rlwimi. */ |
99e300ef | 1599 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1600 | { |
76a66253 | 1601 | uint32_t mb, me, sh; |
79aceca5 FB |
1602 | |
1603 | mb = MB(ctx->opcode); | |
1604 | me = ME(ctx->opcode); | |
76a66253 | 1605 | sh = SH(ctx->opcode); |
d03ef511 AJ |
1606 | if (likely(sh == 0 && mb == 0 && me == 31)) { |
1607 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1608 | } else { | |
d03ef511 | 1609 | target_ulong mask; |
a7812ae4 PB |
1610 | TCGv t1; |
1611 | TCGv t0 = tcg_temp_new(); | |
54843a58 | 1612 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1613 | TCGv_i32 t2 = tcg_temp_new_i32(); |
1614 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]); | |
1615 | tcg_gen_rotli_i32(t2, t2, sh); | |
1616 | tcg_gen_extu_i32_i64(t0, t2); | |
1617 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1618 | #else |
1619 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1620 | #endif | |
76a66253 | 1621 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1622 | mb += 32; |
1623 | me += 32; | |
76a66253 | 1624 | #endif |
d03ef511 | 1625 | mask = MASK(mb, me); |
a7812ae4 | 1626 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1627 | tcg_gen_andi_tl(t0, t0, mask); |
1628 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1629 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1630 | tcg_temp_free(t0); | |
1631 | tcg_temp_free(t1); | |
1632 | } | |
76a66253 | 1633 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1634 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1635 | } |
99e300ef | 1636 | |
54623277 | 1637 | /* rlwinm & rlwinm. */ |
99e300ef | 1638 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 FB |
1639 | { |
1640 | uint32_t mb, me, sh; | |
3b46e624 | 1641 | |
79aceca5 FB |
1642 | sh = SH(ctx->opcode); |
1643 | mb = MB(ctx->opcode); | |
1644 | me = ME(ctx->opcode); | |
d03ef511 AJ |
1645 | |
1646 | if (likely(mb == 0 && me == (31 - sh))) { | |
1647 | if (likely(sh == 0)) { | |
1648 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1649 | } else { | |
a7812ae4 | 1650 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1651 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1652 | tcg_gen_shli_tl(t0, t0, sh); | |
1653 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1654 | tcg_temp_free(t0); | |
79aceca5 | 1655 | } |
d03ef511 | 1656 | } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) { |
a7812ae4 | 1657 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1658 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1659 | tcg_gen_shri_tl(t0, t0, mb); | |
1660 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1661 | tcg_temp_free(t0); | |
1662 | } else { | |
a7812ae4 | 1663 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1664 | #if defined(TARGET_PPC64) |
a7812ae4 | 1665 | TCGv_i32 t1 = tcg_temp_new_i32(); |
54843a58 AJ |
1666 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1667 | tcg_gen_rotli_i32(t1, t1, sh); | |
1668 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 | 1669 | tcg_temp_free_i32(t1); |
54843a58 AJ |
1670 | #else |
1671 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1672 | #endif | |
76a66253 | 1673 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1674 | mb += 32; |
1675 | me += 32; | |
76a66253 | 1676 | #endif |
d03ef511 AJ |
1677 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1678 | tcg_temp_free(t0); | |
1679 | } | |
76a66253 | 1680 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1681 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1682 | } |
99e300ef | 1683 | |
54623277 | 1684 | /* rlwnm & rlwnm. */ |
99e300ef | 1685 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 FB |
1686 | { |
1687 | uint32_t mb, me; | |
54843a58 AJ |
1688 | TCGv t0; |
1689 | #if defined(TARGET_PPC64) | |
a7812ae4 | 1690 | TCGv_i32 t1, t2; |
54843a58 | 1691 | #endif |
79aceca5 FB |
1692 | |
1693 | mb = MB(ctx->opcode); | |
1694 | me = ME(ctx->opcode); | |
a7812ae4 | 1695 | t0 = tcg_temp_new(); |
d03ef511 | 1696 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f); |
54843a58 | 1697 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1698 | t1 = tcg_temp_new_i32(); |
1699 | t2 = tcg_temp_new_i32(); | |
54843a58 AJ |
1700 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1701 | tcg_gen_trunc_i64_i32(t2, t0); | |
1702 | tcg_gen_rotl_i32(t1, t1, t2); | |
1703 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 PB |
1704 | tcg_temp_free_i32(t1); |
1705 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1706 | #else |
1707 | tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1708 | #endif | |
76a66253 JM |
1709 | if (unlikely(mb != 0 || me != 31)) { |
1710 | #if defined(TARGET_PPC64) | |
1711 | mb += 32; | |
1712 | me += 32; | |
1713 | #endif | |
54843a58 | 1714 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
d03ef511 | 1715 | } else { |
54843a58 | 1716 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
79aceca5 | 1717 | } |
54843a58 | 1718 | tcg_temp_free(t0); |
76a66253 | 1719 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1720 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 FB |
1721 | } |
1722 | ||
d9bce9d9 JM |
1723 | #if defined(TARGET_PPC64) |
1724 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1725 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1726 | { \ |
1727 | gen_##name(ctx, 0); \ | |
1728 | } \ | |
e8eaa2c0 BS |
1729 | \ |
1730 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1731 | { \ |
1732 | gen_##name(ctx, 1); \ | |
1733 | } | |
1734 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1735 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1736 | { \ |
1737 | gen_##name(ctx, 0, 0); \ | |
1738 | } \ | |
e8eaa2c0 BS |
1739 | \ |
1740 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1741 | { \ |
1742 | gen_##name(ctx, 0, 1); \ | |
1743 | } \ | |
e8eaa2c0 BS |
1744 | \ |
1745 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1746 | { \ |
1747 | gen_##name(ctx, 1, 0); \ | |
1748 | } \ | |
e8eaa2c0 BS |
1749 | \ |
1750 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1751 | { \ |
1752 | gen_##name(ctx, 1, 1); \ | |
1753 | } | |
51789c41 | 1754 | |
636aa200 BS |
1755 | static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me, |
1756 | uint32_t sh) | |
51789c41 | 1757 | { |
d03ef511 AJ |
1758 | if (likely(sh != 0 && mb == 0 && me == (63 - sh))) { |
1759 | tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
1760 | } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) { | |
1761 | tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb); | |
1762 | } else { | |
a7812ae4 | 1763 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1764 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
d03ef511 | 1765 | if (likely(mb == 0 && me == 63)) { |
54843a58 | 1766 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
d03ef511 AJ |
1767 | } else { |
1768 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); | |
51789c41 | 1769 | } |
d03ef511 | 1770 | tcg_temp_free(t0); |
51789c41 | 1771 | } |
51789c41 | 1772 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1773 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
51789c41 | 1774 | } |
d9bce9d9 | 1775 | /* rldicl - rldicl. */ |
636aa200 | 1776 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1777 | { |
51789c41 | 1778 | uint32_t sh, mb; |
d9bce9d9 | 1779 | |
9d53c753 JM |
1780 | sh = SH(ctx->opcode) | (shn << 5); |
1781 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 1782 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 1783 | } |
51789c41 | 1784 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
d9bce9d9 | 1785 | /* rldicr - rldicr. */ |
636aa200 | 1786 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 1787 | { |
51789c41 | 1788 | uint32_t sh, me; |
d9bce9d9 | 1789 | |
9d53c753 JM |
1790 | sh = SH(ctx->opcode) | (shn << 5); |
1791 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 1792 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 1793 | } |
51789c41 | 1794 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
d9bce9d9 | 1795 | /* rldic - rldic. */ |
636aa200 | 1796 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1797 | { |
51789c41 | 1798 | uint32_t sh, mb; |
d9bce9d9 | 1799 | |
9d53c753 JM |
1800 | sh = SH(ctx->opcode) | (shn << 5); |
1801 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
1802 | gen_rldinm(ctx, mb, 63 - sh, sh); |
1803 | } | |
1804 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
1805 | ||
636aa200 | 1806 | static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me) |
51789c41 | 1807 | { |
54843a58 | 1808 | TCGv t0; |
d03ef511 | 1809 | |
a7812ae4 | 1810 | t0 = tcg_temp_new(); |
d03ef511 | 1811 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f); |
54843a58 | 1812 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); |
51789c41 | 1813 | if (unlikely(mb != 0 || me != 63)) { |
54843a58 AJ |
1814 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1815 | } else { | |
1816 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1817 | } | |
1818 | tcg_temp_free(t0); | |
51789c41 | 1819 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1820 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1821 | } |
51789c41 | 1822 | |
d9bce9d9 | 1823 | /* rldcl - rldcl. */ |
636aa200 | 1824 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 1825 | { |
51789c41 | 1826 | uint32_t mb; |
d9bce9d9 | 1827 | |
9d53c753 | 1828 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 1829 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 1830 | } |
36081602 | 1831 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
d9bce9d9 | 1832 | /* rldcr - rldcr. */ |
636aa200 | 1833 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 1834 | { |
51789c41 | 1835 | uint32_t me; |
d9bce9d9 | 1836 | |
9d53c753 | 1837 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 1838 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 1839 | } |
36081602 | 1840 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
d9bce9d9 | 1841 | /* rldimi - rldimi. */ |
636aa200 | 1842 | static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1843 | { |
271a916e | 1844 | uint32_t sh, mb, me; |
d9bce9d9 | 1845 | |
9d53c753 JM |
1846 | sh = SH(ctx->opcode) | (shn << 5); |
1847 | mb = MB(ctx->opcode) | (mbn << 5); | |
271a916e | 1848 | me = 63 - sh; |
d03ef511 AJ |
1849 | if (unlikely(sh == 0 && mb == 0)) { |
1850 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1851 | } else { | |
1852 | TCGv t0, t1; | |
1853 | target_ulong mask; | |
1854 | ||
a7812ae4 | 1855 | t0 = tcg_temp_new(); |
54843a58 | 1856 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
a7812ae4 | 1857 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1858 | mask = MASK(mb, me); |
1859 | tcg_gen_andi_tl(t0, t0, mask); | |
1860 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1861 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1862 | tcg_temp_free(t0); | |
1863 | tcg_temp_free(t1); | |
51789c41 | 1864 | } |
51789c41 | 1865 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1866 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1867 | } |
36081602 | 1868 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
1869 | #endif |
1870 | ||
79aceca5 | 1871 | /*** Integer shift ***/ |
99e300ef | 1872 | |
54623277 | 1873 | /* slw & slw. */ |
99e300ef | 1874 | static void gen_slw(DisasContext *ctx) |
26d67362 | 1875 | { |
7fd6bf7d | 1876 | TCGv t0, t1; |
26d67362 | 1877 | |
7fd6bf7d AJ |
1878 | t0 = tcg_temp_new(); |
1879 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1880 | #if defined(TARGET_PPC64) | |
1881 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1882 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1883 | #else | |
1884 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1885 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1886 | #endif | |
1887 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1888 | t1 = tcg_temp_new(); | |
1889 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
1890 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1891 | tcg_temp_free(t1); | |
fea0c503 | 1892 | tcg_temp_free(t0); |
7fd6bf7d | 1893 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
1894 | if (unlikely(Rc(ctx->opcode) != 0)) |
1895 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1896 | } | |
99e300ef | 1897 | |
54623277 | 1898 | /* sraw & sraw. */ |
99e300ef | 1899 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 1900 | { |
d15f74fb | 1901 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1902 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1903 | if (unlikely(Rc(ctx->opcode) != 0)) |
1904 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1905 | } | |
99e300ef | 1906 | |
54623277 | 1907 | /* srawi & srawi. */ |
99e300ef | 1908 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 1909 | { |
26d67362 | 1910 | int sh = SH(ctx->opcode); |
ba4af3e4 RH |
1911 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
1912 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
1913 | if (sh == 0) { | |
1914 | tcg_gen_mov_tl(dst, src); | |
da91a00f | 1915 | tcg_gen_movi_tl(cpu_ca, 0); |
26d67362 | 1916 | } else { |
ba4af3e4 RH |
1917 | TCGv t0; |
1918 | tcg_gen_ext32s_tl(dst, src); | |
1919 | tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1); | |
1920 | t0 = tcg_temp_new(); | |
1921 | tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1); | |
1922 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
1923 | tcg_temp_free(t0); | |
1924 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
1925 | tcg_gen_sari_tl(dst, dst, sh); | |
1926 | } | |
1927 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1928 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 1929 | } |
79aceca5 | 1930 | } |
99e300ef | 1931 | |
54623277 | 1932 | /* srw & srw. */ |
99e300ef | 1933 | static void gen_srw(DisasContext *ctx) |
26d67362 | 1934 | { |
fea0c503 | 1935 | TCGv t0, t1; |
d9bce9d9 | 1936 | |
7fd6bf7d AJ |
1937 | t0 = tcg_temp_new(); |
1938 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1939 | #if defined(TARGET_PPC64) | |
1940 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1941 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1942 | #else | |
1943 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1944 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1945 | #endif | |
1946 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1947 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 1948 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
1949 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
1950 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 1951 | tcg_temp_free(t1); |
fea0c503 | 1952 | tcg_temp_free(t0); |
26d67362 AJ |
1953 | if (unlikely(Rc(ctx->opcode) != 0)) |
1954 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1955 | } | |
54623277 | 1956 | |
d9bce9d9 JM |
1957 | #if defined(TARGET_PPC64) |
1958 | /* sld & sld. */ | |
99e300ef | 1959 | static void gen_sld(DisasContext *ctx) |
26d67362 | 1960 | { |
7fd6bf7d | 1961 | TCGv t0, t1; |
26d67362 | 1962 | |
7fd6bf7d AJ |
1963 | t0 = tcg_temp_new(); |
1964 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
1965 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
1966 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1967 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1968 | t1 = tcg_temp_new(); | |
1969 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
1970 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1971 | tcg_temp_free(t1); | |
fea0c503 | 1972 | tcg_temp_free(t0); |
26d67362 AJ |
1973 | if (unlikely(Rc(ctx->opcode) != 0)) |
1974 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1975 | } | |
99e300ef | 1976 | |
54623277 | 1977 | /* srad & srad. */ |
99e300ef | 1978 | static void gen_srad(DisasContext *ctx) |
26d67362 | 1979 | { |
d15f74fb | 1980 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1981 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1982 | if (unlikely(Rc(ctx->opcode) != 0)) |
1983 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1984 | } | |
d9bce9d9 | 1985 | /* sradi & sradi. */ |
636aa200 | 1986 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 1987 | { |
26d67362 | 1988 | int sh = SH(ctx->opcode) + (n << 5); |
ba4af3e4 RH |
1989 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
1990 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
1991 | if (sh == 0) { | |
1992 | tcg_gen_mov_tl(dst, src); | |
da91a00f | 1993 | tcg_gen_movi_tl(cpu_ca, 0); |
26d67362 | 1994 | } else { |
ba4af3e4 RH |
1995 | TCGv t0; |
1996 | tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1); | |
1997 | t0 = tcg_temp_new(); | |
1998 | tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1); | |
1999 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
2000 | tcg_temp_free(t0); | |
2001 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
2002 | tcg_gen_sari_tl(dst, src, sh); | |
2003 | } | |
2004 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2005 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 2006 | } |
d9bce9d9 | 2007 | } |
e8eaa2c0 BS |
2008 | |
2009 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
2010 | { |
2011 | gen_sradi(ctx, 0); | |
2012 | } | |
e8eaa2c0 BS |
2013 | |
2014 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
2015 | { |
2016 | gen_sradi(ctx, 1); | |
2017 | } | |
99e300ef | 2018 | |
54623277 | 2019 | /* srd & srd. */ |
99e300ef | 2020 | static void gen_srd(DisasContext *ctx) |
26d67362 | 2021 | { |
7fd6bf7d | 2022 | TCGv t0, t1; |
26d67362 | 2023 | |
7fd6bf7d AJ |
2024 | t0 = tcg_temp_new(); |
2025 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2026 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2027 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2028 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2029 | t1 = tcg_temp_new(); | |
2030 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2031 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2032 | tcg_temp_free(t1); | |
fea0c503 | 2033 | tcg_temp_free(t0); |
26d67362 AJ |
2034 | if (unlikely(Rc(ctx->opcode) != 0)) |
2035 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2036 | } | |
d9bce9d9 | 2037 | #endif |
79aceca5 FB |
2038 | |
2039 | /*** Floating-Point arithmetic ***/ | |
7c58044c | 2040 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ |
99e300ef | 2041 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2042 | { \ |
76a66253 | 2043 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2044 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2045 | return; \ |
2046 | } \ | |
eb44b959 AJ |
2047 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2048 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2049 | gen_reset_fpstatus(); \ |
8e703949 BS |
2050 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2051 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2052 | cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2053 | if (isfloat) { \ |
8e703949 BS |
2054 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2055 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2056 | } \ |
af12906f AJ |
2057 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \ |
2058 | Rc(ctx->opcode) != 0); \ | |
9a64fbe4 FB |
2059 | } |
2060 | ||
7c58044c JM |
2061 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ |
2062 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \ | |
2063 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type); | |
9a64fbe4 | 2064 | |
7c58044c | 2065 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2066 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2067 | { \ |
76a66253 | 2068 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2069 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2070 | return; \ |
2071 | } \ | |
eb44b959 AJ |
2072 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2073 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2074 | gen_reset_fpstatus(); \ |
8e703949 BS |
2075 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2076 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2077 | cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2078 | if (isfloat) { \ |
8e703949 BS |
2079 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2080 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2081 | } \ |
af12906f AJ |
2082 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2083 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2084 | } |
7c58044c JM |
2085 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ |
2086 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2087 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2088 | |
7c58044c | 2089 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2090 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2091 | { \ |
76a66253 | 2092 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2093 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2094 | return; \ |
2095 | } \ | |
eb44b959 AJ |
2096 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2097 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2098 | gen_reset_fpstatus(); \ |
8e703949 BS |
2099 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2100 | cpu_fpr[rA(ctx->opcode)], \ | |
2101 | cpu_fpr[rC(ctx->opcode)]); \ | |
4ecc3190 | 2102 | if (isfloat) { \ |
8e703949 BS |
2103 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2104 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2105 | } \ |
af12906f AJ |
2106 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2107 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2108 | } |
7c58044c JM |
2109 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ |
2110 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2111 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2112 | |
7c58044c | 2113 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ |
99e300ef | 2114 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2115 | { \ |
76a66253 | 2116 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2117 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2118 | return; \ |
2119 | } \ | |
eb44b959 AJ |
2120 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2121 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2122 | gen_reset_fpstatus(); \ |
8e703949 BS |
2123 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2124 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2125 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2126 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2127 | } |
2128 | ||
7c58044c | 2129 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ |
99e300ef | 2130 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2131 | { \ |
76a66253 | 2132 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2133 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2134 | return; \ |
2135 | } \ | |
eb44b959 AJ |
2136 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2137 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2138 | gen_reset_fpstatus(); \ |
8e703949 BS |
2139 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2140 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2141 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2142 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2143 | } |
2144 | ||
9a64fbe4 | 2145 | /* fadd - fadds */ |
7c58044c | 2146 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2147 | /* fdiv - fdivs */ |
7c58044c | 2148 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2149 | /* fmul - fmuls */ |
7c58044c | 2150 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT); |
79aceca5 | 2151 | |
d7e4b87e | 2152 | /* fre */ |
7c58044c | 2153 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2154 | |
a750fc0b | 2155 | /* fres */ |
7c58044c | 2156 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES); |
79aceca5 | 2157 | |
a750fc0b | 2158 | /* frsqrte */ |
7c58044c JM |
2159 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE); |
2160 | ||
2161 | /* frsqrtes */ | |
99e300ef | 2162 | static void gen_frsqrtes(DisasContext *ctx) |
7c58044c | 2163 | { |
af12906f | 2164 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2165 | gen_exception(ctx, POWERPC_EXCP_FPU); |
af12906f AJ |
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); | |
af12906f | 2170 | gen_reset_fpstatus(); |
8e703949 BS |
2171 | gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2172 | cpu_fpr[rB(ctx->opcode)]); | |
2173 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2174 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2175 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
7c58044c | 2176 | } |
79aceca5 | 2177 | |
a750fc0b | 2178 | /* fsel */ |
7c58044c | 2179 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL); |
4ecc3190 | 2180 | /* fsub - fsubs */ |
7c58044c | 2181 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT); |
79aceca5 | 2182 | /* Optional: */ |
99e300ef | 2183 | |
54623277 | 2184 | /* fsqrt */ |
99e300ef | 2185 | static void gen_fsqrt(DisasContext *ctx) |
c7d344af | 2186 | { |
76a66253 | 2187 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2188 | gen_exception(ctx, POWERPC_EXCP_FPU); |
c7d344af FB |
2189 | return; |
2190 | } | |
eb44b959 AJ |
2191 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2192 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2193 | gen_reset_fpstatus(); |
8e703949 BS |
2194 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2195 | cpu_fpr[rB(ctx->opcode)]); | |
af12906f | 2196 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
c7d344af | 2197 | } |
79aceca5 | 2198 | |
99e300ef | 2199 | static void gen_fsqrts(DisasContext *ctx) |
79aceca5 | 2200 | { |
76a66253 | 2201 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2202 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2203 | return; |
2204 | } | |
eb44b959 AJ |
2205 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2206 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2207 | gen_reset_fpstatus(); |
8e703949 BS |
2208 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2209 | cpu_fpr[rB(ctx->opcode)]); | |
2210 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2211 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2212 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2213 | } |
2214 | ||
2215 | /*** Floating-Point multiply-and-add ***/ | |
4ecc3190 | 2216 | /* fmadd - fmadds */ |
7c58044c | 2217 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT); |
4ecc3190 | 2218 | /* fmsub - fmsubs */ |
7c58044c | 2219 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT); |
4ecc3190 | 2220 | /* fnmadd - fnmadds */ |
7c58044c | 2221 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT); |
4ecc3190 | 2222 | /* fnmsub - fnmsubs */ |
7c58044c | 2223 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT); |
79aceca5 FB |
2224 | |
2225 | /*** Floating-Point round & convert ***/ | |
2226 | /* fctiw */ | |
7c58044c | 2227 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT); |
fab7fe42 TM |
2228 | /* fctiwu */ |
2229 | GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206); | |
79aceca5 | 2230 | /* fctiwz */ |
7c58044c | 2231 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT); |
fab7fe42 TM |
2232 | /* fctiwuz */ |
2233 | GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206); | |
79aceca5 | 2234 | /* frsp */ |
7c58044c | 2235 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT); |
426613db JM |
2236 | #if defined(TARGET_PPC64) |
2237 | /* fcfid */ | |
7c58044c | 2238 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B); |
28288b48 TM |
2239 | /* fcfids */ |
2240 | GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206); | |
2241 | /* fcfidu */ | |
2242 | GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206); | |
2243 | /* fcfidus */ | |
2244 | GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2245 | /* fctid */ |
7c58044c | 2246 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B); |
fab7fe42 TM |
2247 | /* fctidu */ |
2248 | GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2249 | /* fctidz */ |
7c58044c | 2250 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B); |
fab7fe42 TM |
2251 | /* fctidu */ |
2252 | GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2253 | #endif |
79aceca5 | 2254 | |
d7e4b87e | 2255 | /* frin */ |
7c58044c | 2256 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2257 | /* friz */ |
7c58044c | 2258 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2259 | /* frip */ |
7c58044c | 2260 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2261 | /* frim */ |
7c58044c | 2262 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2263 | |
da29cb7b TM |
2264 | static void gen_ftdiv(DisasContext *ctx) |
2265 | { | |
2266 | if (unlikely(!ctx->fpu_enabled)) { | |
2267 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2268 | return; | |
2269 | } | |
2270 | gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2271 | cpu_fpr[rB(ctx->opcode)]); | |
2272 | } | |
2273 | ||
6d41d146 TM |
2274 | static void gen_ftsqrt(DisasContext *ctx) |
2275 | { | |
2276 | if (unlikely(!ctx->fpu_enabled)) { | |
2277 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2278 | return; | |
2279 | } | |
2280 | gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); | |
2281 | } | |
2282 | ||
da29cb7b TM |
2283 | |
2284 | ||
79aceca5 | 2285 | /*** Floating-Point compare ***/ |
99e300ef | 2286 | |
54623277 | 2287 | /* fcmpo */ |
99e300ef | 2288 | static void gen_fcmpo(DisasContext *ctx) |
79aceca5 | 2289 | { |
330c483b | 2290 | TCGv_i32 crf; |
76a66253 | 2291 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2292 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2293 | return; |
2294 | } | |
eb44b959 AJ |
2295 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2296 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2297 | gen_reset_fpstatus(); |
9a819377 | 2298 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2299 | gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2300 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2301 | tcg_temp_free_i32(crf); |
8e703949 | 2302 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2303 | } |
2304 | ||
2305 | /* fcmpu */ | |
99e300ef | 2306 | static void gen_fcmpu(DisasContext *ctx) |
79aceca5 | 2307 | { |
330c483b | 2308 | TCGv_i32 crf; |
76a66253 | 2309 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2310 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2311 | return; |
2312 | } | |
eb44b959 AJ |
2313 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2314 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2315 | gen_reset_fpstatus(); |
9a819377 | 2316 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2317 | gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2318 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2319 | tcg_temp_free_i32(crf); |
8e703949 | 2320 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2321 | } |
2322 | ||
9a64fbe4 FB |
2323 | /*** Floating-point move ***/ |
2324 | /* fabs */ | |
7c58044c | 2325 | /* XXX: beware that fabs never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2326 | static void gen_fabs(DisasContext *ctx) |
2327 | { | |
2328 | if (unlikely(!ctx->fpu_enabled)) { | |
2329 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2330 | return; | |
2331 | } | |
2332 | tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2333 | ~(1ULL << 63)); | |
2334 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2335 | } | |
9a64fbe4 FB |
2336 | |
2337 | /* fmr - fmr. */ | |
7c58044c | 2338 | /* XXX: beware that fmr never checks for NaNs nor update FPSCR */ |
99e300ef | 2339 | static void gen_fmr(DisasContext *ctx) |
9a64fbe4 | 2340 | { |
76a66253 | 2341 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2342 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2343 | return; |
2344 | } | |
af12906f AJ |
2345 | tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2346 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
9a64fbe4 FB |
2347 | } |
2348 | ||
2349 | /* fnabs */ | |
7c58044c | 2350 | /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2351 | static void gen_fnabs(DisasContext *ctx) |
2352 | { | |
2353 | if (unlikely(!ctx->fpu_enabled)) { | |
2354 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2355 | return; | |
2356 | } | |
2357 | tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2358 | 1ULL << 63); | |
2359 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2360 | } | |
2361 | ||
9a64fbe4 | 2362 | /* fneg */ |
7c58044c | 2363 | /* XXX: beware that fneg never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2364 | static void gen_fneg(DisasContext *ctx) |
2365 | { | |
2366 | if (unlikely(!ctx->fpu_enabled)) { | |
2367 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2368 | return; | |
2369 | } | |
2370 | tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2371 | 1ULL << 63); | |
2372 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2373 | } | |
9a64fbe4 | 2374 | |
f0332888 AJ |
2375 | /* fcpsgn: PowerPC 2.05 specification */ |
2376 | /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */ | |
2377 | static void gen_fcpsgn(DisasContext *ctx) | |
2378 | { | |
2379 | if (unlikely(!ctx->fpu_enabled)) { | |
2380 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2381 | return; | |
2382 | } | |
2383 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2384 | cpu_fpr[rB(ctx->opcode)], 0, 63); | |
2385 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2386 | } | |
2387 | ||
097ec5d8 TM |
2388 | static void gen_fmrgew(DisasContext *ctx) |
2389 | { | |
2390 | TCGv_i64 b0; | |
2391 | if (unlikely(!ctx->fpu_enabled)) { | |
2392 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2393 | return; | |
2394 | } | |
2395 | b0 = tcg_temp_new_i64(); | |
2396 | tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32); | |
2397 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2398 | b0, 0, 32); | |
2399 | tcg_temp_free_i64(b0); | |
2400 | } | |
2401 | ||
2402 | static void gen_fmrgow(DisasContext *ctx) | |
2403 | { | |
2404 | if (unlikely(!ctx->fpu_enabled)) { | |
2405 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2406 | return; | |
2407 | } | |
2408 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], | |
2409 | cpu_fpr[rB(ctx->opcode)], | |
2410 | cpu_fpr[rA(ctx->opcode)], | |
2411 | 32, 32); | |
2412 | } | |
2413 | ||
79aceca5 | 2414 | /*** Floating-Point status & ctrl register ***/ |
99e300ef | 2415 | |
54623277 | 2416 | /* mcrfs */ |
99e300ef | 2417 | static void gen_mcrfs(DisasContext *ctx) |
79aceca5 | 2418 | { |
30304420 | 2419 | TCGv tmp = tcg_temp_new(); |
7c58044c JM |
2420 | int bfa; |
2421 | ||
76a66253 | 2422 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2423 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2424 | return; |
2425 | } | |
7c58044c | 2426 | bfa = 4 * (7 - crfS(ctx->opcode)); |
30304420 DG |
2427 | tcg_gen_shri_tl(tmp, cpu_fpscr, bfa); |
2428 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp); | |
2429 | tcg_temp_free(tmp); | |
e1571908 | 2430 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf); |
30304420 | 2431 | tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); |
79aceca5 FB |
2432 | } |
2433 | ||
2434 | /* mffs */ | |
99e300ef | 2435 | static void gen_mffs(DisasContext *ctx) |
79aceca5 | 2436 | { |
76a66253 | 2437 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2438 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2439 | return; |
2440 | } | |
7c58044c | 2441 | gen_reset_fpstatus(); |
30304420 | 2442 | tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr); |
af12906f | 2443 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2444 | } |
2445 | ||
2446 | /* mtfsb0 */ | |
99e300ef | 2447 | static void gen_mtfsb0(DisasContext *ctx) |
79aceca5 | 2448 | { |
fb0eaffc | 2449 | uint8_t crb; |
3b46e624 | 2450 | |
76a66253 | 2451 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2452 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2453 | return; |
2454 | } | |
6e35d524 | 2455 | crb = 31 - crbD(ctx->opcode); |
7c58044c | 2456 | gen_reset_fpstatus(); |
6e35d524 | 2457 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) { |
eb44b959 AJ |
2458 | TCGv_i32 t0; |
2459 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2460 | gen_update_nip(ctx, ctx->nip - 4); | |
2461 | t0 = tcg_const_i32(crb); | |
8e703949 | 2462 | gen_helper_fpscr_clrbit(cpu_env, t0); |
6e35d524 AJ |
2463 | tcg_temp_free_i32(t0); |
2464 | } | |
7c58044c | 2465 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2466 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2467 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c | 2468 | } |
79aceca5 FB |
2469 | } |
2470 | ||
2471 | /* mtfsb1 */ | |
99e300ef | 2472 | static void gen_mtfsb1(DisasContext *ctx) |
79aceca5 | 2473 | { |
fb0eaffc | 2474 | uint8_t crb; |
3b46e624 | 2475 | |
76a66253 | 2476 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2477 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2478 | return; |
2479 | } | |
6e35d524 | 2480 | crb = 31 - crbD(ctx->opcode); |
7c58044c JM |
2481 | gen_reset_fpstatus(); |
2482 | /* XXX: we pretend we can only do IEEE floating-point computations */ | |
af12906f | 2483 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) { |
eb44b959 AJ |
2484 | TCGv_i32 t0; |
2485 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2486 | gen_update_nip(ctx, ctx->nip - 4); | |
2487 | t0 = tcg_const_i32(crb); | |
8e703949 | 2488 | gen_helper_fpscr_setbit(cpu_env, t0); |
0f2f39c2 | 2489 | tcg_temp_free_i32(t0); |
af12906f | 2490 | } |
7c58044c | 2491 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2492 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2493 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2494 | } |
2495 | /* We can raise a differed exception */ | |
8e703949 | 2496 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2497 | } |
2498 | ||
2499 | /* mtfsf */ | |
99e300ef | 2500 | static void gen_mtfsf(DisasContext *ctx) |
79aceca5 | 2501 | { |
0f2f39c2 | 2502 | TCGv_i32 t0; |
7d08d856 | 2503 | int flm, l, w; |
af12906f | 2504 | |
76a66253 | 2505 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2506 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2507 | return; |
2508 | } | |
7d08d856 AJ |
2509 | flm = FPFLM(ctx->opcode); |
2510 | l = FPL(ctx->opcode); | |
2511 | w = FPW(ctx->opcode); | |
2512 | if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) { | |
2513 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
2514 | return; | |
2515 | } | |
eb44b959 AJ |
2516 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2517 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2518 | gen_reset_fpstatus(); |
7d08d856 AJ |
2519 | if (l) { |
2520 | t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff); | |
2521 | } else { | |
2522 | t0 = tcg_const_i32(flm << (w * 8)); | |
2523 | } | |
8e703949 | 2524 | gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0); |
0f2f39c2 | 2525 | tcg_temp_free_i32(t0); |
7c58044c | 2526 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2527 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2528 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2529 | } |
2530 | /* We can raise a differed exception */ | |
8e703949 | 2531 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2532 | } |
2533 | ||
2534 | /* mtfsfi */ | |
99e300ef | 2535 | static void gen_mtfsfi(DisasContext *ctx) |
79aceca5 | 2536 | { |
7d08d856 | 2537 | int bf, sh, w; |
0f2f39c2 AJ |
2538 | TCGv_i64 t0; |
2539 | TCGv_i32 t1; | |
7c58044c | 2540 | |
76a66253 | 2541 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2542 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2543 | return; |
2544 | } | |
7d08d856 AJ |
2545 | w = FPW(ctx->opcode); |
2546 | bf = FPBF(ctx->opcode); | |
2547 | if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) { | |
2548 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
2549 | return; | |
2550 | } | |
2551 | sh = (8 * w) + 7 - bf; | |
eb44b959 AJ |
2552 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2553 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2554 | gen_reset_fpstatus(); |
7d08d856 | 2555 | t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh)); |
af12906f | 2556 | t1 = tcg_const_i32(1 << sh); |
8e703949 | 2557 | gen_helper_store_fpscr(cpu_env, t0, t1); |
0f2f39c2 AJ |
2558 | tcg_temp_free_i64(t0); |
2559 | tcg_temp_free_i32(t1); | |
7c58044c | 2560 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2561 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2562 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2563 | } |
2564 | /* We can raise a differed exception */ | |
8e703949 | 2565 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2566 | } |
2567 | ||
76a66253 JM |
2568 | /*** Addressing modes ***/ |
2569 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2570 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2571 | target_long maskl) | |
76a66253 JM |
2572 | { |
2573 | target_long simm = SIMM(ctx->opcode); | |
2574 | ||
be147d08 | 2575 | simm &= ~maskl; |
76db3ba4 | 2576 | if (rA(ctx->opcode) == 0) { |
c791fe84 RH |
2577 | if (NARROW_MODE(ctx)) { |
2578 | simm = (uint32_t)simm; | |
2579 | } | |
e2be8d8d | 2580 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2581 | } else if (likely(simm != 0)) { |
e2be8d8d | 2582 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
c791fe84 | 2583 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2584 | tcg_gen_ext32u_tl(EA, EA); |
2585 | } | |
76db3ba4 | 2586 | } else { |
c791fe84 | 2587 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2588 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
c791fe84 RH |
2589 | } else { |
2590 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2591 | } | |
76db3ba4 | 2592 | } |
76a66253 JM |
2593 | } |
2594 | ||
636aa200 | 2595 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2596 | { |
76db3ba4 | 2597 | if (rA(ctx->opcode) == 0) { |
c791fe84 | 2598 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2599 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
c791fe84 RH |
2600 | } else { |
2601 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2602 | } | |
76db3ba4 | 2603 | } else { |
e2be8d8d | 2604 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
c791fe84 | 2605 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2606 | tcg_gen_ext32u_tl(EA, EA); |
2607 | } | |
76db3ba4 | 2608 | } |
76a66253 JM |
2609 | } |
2610 | ||
636aa200 | 2611 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2612 | { |
76db3ba4 | 2613 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2614 | tcg_gen_movi_tl(EA, 0); |
c791fe84 RH |
2615 | } else if (NARROW_MODE(ctx)) { |
2616 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
76db3ba4 | 2617 | } else { |
c791fe84 | 2618 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 AJ |
2619 | } |
2620 | } | |
2621 | ||
636aa200 BS |
2622 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2623 | target_long val) | |
76db3ba4 AJ |
2624 | { |
2625 | tcg_gen_addi_tl(ret, arg1, val); | |
c791fe84 | 2626 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2627 | tcg_gen_ext32u_tl(ret, ret); |
2628 | } | |
76a66253 JM |
2629 | } |
2630 | ||
636aa200 | 2631 | static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask) |
cf360a32 AJ |
2632 | { |
2633 | int l1 = gen_new_label(); | |
2634 | TCGv t0 = tcg_temp_new(); | |
2635 | TCGv_i32 t1, t2; | |
2636 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2637 | gen_update_nip(ctx, ctx->nip - 4); | |
2638 | tcg_gen_andi_tl(t0, EA, mask); | |
2639 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
2640 | t1 = tcg_const_i32(POWERPC_EXCP_ALIGN); | |
2641 | t2 = tcg_const_i32(0); | |
e5f17ac6 | 2642 | gen_helper_raise_exception_err(cpu_env, t1, t2); |
cf360a32 AJ |
2643 | tcg_temp_free_i32(t1); |
2644 | tcg_temp_free_i32(t2); | |
2645 | gen_set_label(l1); | |
2646 | tcg_temp_free(t0); | |
2647 | } | |
2648 | ||
7863667f | 2649 | /*** Integer load ***/ |
636aa200 | 2650 | static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2651 | { |
2652 | tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx); | |
2653 | } | |
2654 | ||
636aa200 | 2655 | static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2656 | { |
2657 | tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx); | |
2658 | } | |
2659 | ||
636aa200 | 2660 | static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2661 | { |
2662 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); | |
2663 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2664 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2665 | } |
b61f2753 AJ |
2666 | } |
2667 | ||
636aa200 | 2668 | static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2669 | { |
76db3ba4 | 2670 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2671 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
fa3966a3 | 2672 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2673 | tcg_gen_ext16s_tl(arg1, arg1); |
76db3ba4 AJ |
2674 | } else { |
2675 | tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx); | |
2676 | } | |
b61f2753 AJ |
2677 | } |
2678 | ||
636aa200 | 2679 | static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2680 | { |
76db3ba4 AJ |
2681 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2682 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2683 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2684 | } |
b61f2753 AJ |
2685 | } |
2686 | ||
f976b09e AG |
2687 | static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2688 | { | |
2689 | TCGv tmp = tcg_temp_new(); | |
2690 | gen_qemu_ld32u(ctx, tmp, addr); | |
2691 | tcg_gen_extu_tl_i64(val, tmp); | |
2692 | tcg_temp_free(tmp); | |
2693 | } | |
2694 | ||
636aa200 | 2695 | static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2696 | { |
a457e7ee | 2697 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2698 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
fa3966a3 AJ |
2699 | tcg_gen_bswap32_tl(arg1, arg1); |
2700 | tcg_gen_ext32s_tl(arg1, arg1); | |
b61f2753 | 2701 | } else |
76db3ba4 | 2702 | tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2703 | } |
2704 | ||
cac7f0ba TM |
2705 | static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2706 | { | |
2707 | TCGv tmp = tcg_temp_new(); | |
2708 | gen_qemu_ld32s(ctx, tmp, addr); | |
2709 | tcg_gen_ext_tl_i64(val, tmp); | |
2710 | tcg_temp_free(tmp); | |
2711 | } | |
2712 | ||
636aa200 | 2713 | static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2714 | { |
76db3ba4 AJ |
2715 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); |
2716 | if (unlikely(ctx->le_mode)) { | |
66896cb8 | 2717 | tcg_gen_bswap64_i64(arg1, arg1); |
76db3ba4 | 2718 | } |
b61f2753 AJ |
2719 | } |
2720 | ||
636aa200 | 2721 | static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2722 | { |
76db3ba4 | 2723 | tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2724 | } |
2725 | ||
636aa200 | 2726 | static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2727 | { |
76db3ba4 | 2728 | if (unlikely(ctx->le_mode)) { |
76db3ba4 AJ |
2729 | TCGv t0 = tcg_temp_new(); |
2730 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2731 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2732 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2733 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2734 | } else { |
2735 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2736 | } | |
b61f2753 AJ |
2737 | } |
2738 | ||
636aa200 | 2739 | static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2740 | { |
76db3ba4 | 2741 | if (unlikely(ctx->le_mode)) { |
fa3966a3 AJ |
2742 | TCGv t0 = tcg_temp_new(); |
2743 | tcg_gen_ext32u_tl(t0, arg1); | |
2744 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2745 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2746 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2747 | } else { |
2748 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2749 | } | |
b61f2753 AJ |
2750 | } |
2751 | ||
f976b09e AG |
2752 | static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2753 | { | |
2754 | TCGv tmp = tcg_temp_new(); | |
2755 | tcg_gen_trunc_i64_tl(tmp, val); | |
2756 | gen_qemu_st32(ctx, tmp, addr); | |
2757 | tcg_temp_free(tmp); | |
2758 | } | |
2759 | ||
636aa200 | 2760 | static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2761 | { |
76db3ba4 | 2762 | if (unlikely(ctx->le_mode)) { |
a7812ae4 | 2763 | TCGv_i64 t0 = tcg_temp_new_i64(); |
66896cb8 | 2764 | tcg_gen_bswap64_i64(t0, arg1); |
76db3ba4 | 2765 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); |
a7812ae4 | 2766 | tcg_temp_free_i64(t0); |
b61f2753 | 2767 | } else |
76db3ba4 | 2768 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2769 | } |
2770 | ||
0c8aacd4 | 2771 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2772 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2773 | { \ |
76db3ba4 AJ |
2774 | TCGv EA; \ |
2775 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2776 | EA = tcg_temp_new(); \ | |
2777 | gen_addr_imm_index(ctx, EA, 0); \ | |
2778 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2779 | tcg_temp_free(EA); \ |
79aceca5 FB |
2780 | } |
2781 | ||
0c8aacd4 | 2782 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2783 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2784 | { \ |
b61f2753 | 2785 | TCGv EA; \ |
76a66253 JM |
2786 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2787 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2788 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2789 | return; \ |
9a64fbe4 | 2790 | } \ |
76db3ba4 | 2791 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2792 | EA = tcg_temp_new(); \ |
9d53c753 | 2793 | if (type == PPC_64B) \ |
76db3ba4 | 2794 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2795 | else \ |
76db3ba4 AJ |
2796 | gen_addr_imm_index(ctx, EA, 0); \ |
2797 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2798 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2799 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2800 | } |
2801 | ||
0c8aacd4 | 2802 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2803 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2804 | { \ |
b61f2753 | 2805 | TCGv EA; \ |
76a66253 JM |
2806 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2807 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2808 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2809 | return; \ |
9a64fbe4 | 2810 | } \ |
76db3ba4 | 2811 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2812 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2813 | gen_addr_reg_index(ctx, EA); \ |
2814 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2815 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2816 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2817 | } |
2818 | ||
cd6e9320 | 2819 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
99e300ef | 2820 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2821 | { \ |
76db3ba4 AJ |
2822 | TCGv EA; \ |
2823 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2824 | EA = tcg_temp_new(); \ | |
2825 | gen_addr_reg_index(ctx, EA); \ | |
2826 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2827 | tcg_temp_free(EA); \ |
79aceca5 | 2828 | } |
cd6e9320 TH |
2829 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
2830 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2831 | |
0c8aacd4 AJ |
2832 | #define GEN_LDS(name, ldop, op, type) \ |
2833 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2834 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2835 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2836 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2837 | |
2838 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2839 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2840 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2841 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2842 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2843 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2844 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2845 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
d9bce9d9 | 2846 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2847 | /* lwaux */ |
0c8aacd4 | 2848 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2849 | /* lwax */ |
0c8aacd4 | 2850 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2851 | /* ldux */ |
0c8aacd4 | 2852 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2853 | /* ldx */ |
0c8aacd4 | 2854 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B); |
99e300ef BS |
2855 | |
2856 | static void gen_ld(DisasContext *ctx) | |
d9bce9d9 | 2857 | { |
b61f2753 | 2858 | TCGv EA; |
d9bce9d9 JM |
2859 | if (Rc(ctx->opcode)) { |
2860 | if (unlikely(rA(ctx->opcode) == 0 || | |
2861 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2862 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2863 | return; |
2864 | } | |
2865 | } | |
76db3ba4 | 2866 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2867 | EA = tcg_temp_new(); |
76db3ba4 | 2868 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2869 | if (ctx->opcode & 0x02) { |
2870 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2871 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2872 | } else { |
2873 | /* ld - ldu */ | |
76db3ba4 | 2874 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2875 | } |
d9bce9d9 | 2876 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2877 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2878 | tcg_temp_free(EA); | |
d9bce9d9 | 2879 | } |
99e300ef | 2880 | |
54623277 | 2881 | /* lq */ |
99e300ef | 2882 | static void gen_lq(DisasContext *ctx) |
be147d08 | 2883 | { |
be147d08 | 2884 | int ra, rd; |
b61f2753 | 2885 | TCGv EA; |
be147d08 | 2886 | |
e0498daa TM |
2887 | /* lq is a legal user mode instruction starting in ISA 2.07 */ |
2888 | bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
2889 | bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
2890 | ||
2891 | if (!legal_in_user_mode && is_user_mode(ctx)) { | |
e06fcd75 | 2892 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2893 | return; |
2894 | } | |
e0498daa TM |
2895 | |
2896 | if (!le_is_supported && ctx->le_mode) { | |
2897 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); | |
2898 | return; | |
2899 | } | |
2900 | ||
be147d08 JM |
2901 | ra = rA(ctx->opcode); |
2902 | rd = rD(ctx->opcode); | |
2903 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2904 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2905 | return; |
2906 | } | |
e0498daa | 2907 | |
76db3ba4 | 2908 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2909 | EA = tcg_temp_new(); |
76db3ba4 | 2910 | gen_addr_imm_index(ctx, EA, 0x0F); |
e0498daa TM |
2911 | |
2912 | if (unlikely(ctx->le_mode)) { | |
2913 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
2914 | gen_addr_add(ctx, EA, EA, 8); | |
2915 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2916 | } else { | |
2917 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2918 | gen_addr_add(ctx, EA, EA, 8); | |
2919 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
2920 | } | |
b61f2753 | 2921 | tcg_temp_free(EA); |
be147d08 | 2922 | } |
d9bce9d9 | 2923 | #endif |
79aceca5 FB |
2924 | |
2925 | /*** Integer store ***/ | |
0c8aacd4 | 2926 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2927 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2928 | { \ |
76db3ba4 AJ |
2929 | TCGv EA; \ |
2930 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2931 | EA = tcg_temp_new(); \ | |
2932 | gen_addr_imm_index(ctx, EA, 0); \ | |
2933 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2934 | tcg_temp_free(EA); \ |
79aceca5 FB |
2935 | } |
2936 | ||
0c8aacd4 | 2937 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2938 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2939 | { \ |
b61f2753 | 2940 | TCGv EA; \ |
76a66253 | 2941 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2942 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2943 | return; \ |
9a64fbe4 | 2944 | } \ |
76db3ba4 | 2945 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2946 | EA = tcg_temp_new(); \ |
9d53c753 | 2947 | if (type == PPC_64B) \ |
76db3ba4 | 2948 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2949 | else \ |
76db3ba4 AJ |
2950 | gen_addr_imm_index(ctx, EA, 0); \ |
2951 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2952 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2953 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2954 | } |
2955 | ||
0c8aacd4 | 2956 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2957 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2958 | { \ |
b61f2753 | 2959 | TCGv EA; \ |
76a66253 | 2960 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2961 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2962 | return; \ |
9a64fbe4 | 2963 | } \ |
76db3ba4 | 2964 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2965 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2966 | gen_addr_reg_index(ctx, EA); \ |
2967 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2968 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2969 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2970 | } |
2971 | ||
cd6e9320 TH |
2972 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
2973 | static void glue(gen_, name##x)(DisasContext *ctx) \ | |
79aceca5 | 2974 | { \ |
76db3ba4 AJ |
2975 | TCGv EA; \ |
2976 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2977 | EA = tcg_temp_new(); \ | |
2978 | gen_addr_reg_index(ctx, EA); \ | |
2979 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2980 | tcg_temp_free(EA); \ |
79aceca5 | 2981 | } |
cd6e9320 TH |
2982 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
2983 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2984 | |
0c8aacd4 AJ |
2985 | #define GEN_STS(name, stop, op, type) \ |
2986 | GEN_ST(name, stop, op | 0x20, type); \ | |
2987 | GEN_STU(name, stop, op | 0x21, type); \ | |
2988 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2989 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2990 | |
2991 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2992 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2993 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2994 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2995 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2996 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
d9bce9d9 | 2997 | #if defined(TARGET_PPC64) |
0c8aacd4 AJ |
2998 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B); |
2999 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B); | |
99e300ef BS |
3000 | |
3001 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 3002 | { |
be147d08 | 3003 | int rs; |
b61f2753 | 3004 | TCGv EA; |
be147d08 JM |
3005 | |
3006 | rs = rS(ctx->opcode); | |
84cab1e2 TM |
3007 | if ((ctx->opcode & 0x3) == 0x2) { /* stq */ |
3008 | ||
3009 | bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
3010 | bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
3011 | ||
3012 | if (!legal_in_user_mode && is_user_mode(ctx)) { | |
e06fcd75 | 3013 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3014 | return; |
3015 | } | |
84cab1e2 TM |
3016 | |
3017 | if (!le_is_supported && ctx->le_mode) { | |
3018 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); | |
d9bce9d9 JM |
3019 | return; |
3020 | } | |
84cab1e2 TM |
3021 | |
3022 | if (unlikely(rs & 1)) { | |
3023 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
be147d08 JM |
3024 | return; |
3025 | } | |
76db3ba4 | 3026 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 3027 | EA = tcg_temp_new(); |
76db3ba4 | 3028 | gen_addr_imm_index(ctx, EA, 0x03); |
84cab1e2 TM |
3029 | |
3030 | if (unlikely(ctx->le_mode)) { | |
3031 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
3032 | gen_addr_add(ctx, EA, EA, 8); | |
3033 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
3034 | } else { | |
3035 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
3036 | gen_addr_add(ctx, EA, EA, 8); | |
3037 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
3038 | } | |
b61f2753 | 3039 | tcg_temp_free(EA); |
be147d08 | 3040 | } else { |
84cab1e2 | 3041 | /* std / stdu*/ |
be147d08 JM |
3042 | if (Rc(ctx->opcode)) { |
3043 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 3044 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
3045 | return; |
3046 | } | |
3047 | } | |
76db3ba4 | 3048 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 3049 | EA = tcg_temp_new(); |
76db3ba4 AJ |
3050 | gen_addr_imm_index(ctx, EA, 0x03); |
3051 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
be147d08 | 3052 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
3053 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
3054 | tcg_temp_free(EA); | |
d9bce9d9 | 3055 | } |
d9bce9d9 JM |
3056 | } |
3057 | #endif | |
79aceca5 FB |
3058 | /*** Integer load and store with byte reverse ***/ |
3059 | /* lhbrx */ | |
86178a57 | 3060 | static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3061 | { |
76db3ba4 AJ |
3062 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
3063 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 3064 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 3065 | } |
b61f2753 | 3066 | } |
0c8aacd4 | 3067 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 3068 | |
79aceca5 | 3069 | /* lwbrx */ |
86178a57 | 3070 | static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3071 | { |
76db3ba4 AJ |
3072 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
3073 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 3074 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 3075 | } |
b61f2753 | 3076 | } |
0c8aacd4 | 3077 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 3078 | |
cd6e9320 TH |
3079 | #if defined(TARGET_PPC64) |
3080 | /* ldbrx */ | |
3081 | static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
3082 | { | |
3083 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); | |
3084 | if (likely(!ctx->le_mode)) { | |
3085 | tcg_gen_bswap64_tl(arg1, arg1); | |
3086 | } | |
3087 | } | |
3088 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX); | |
3089 | #endif /* TARGET_PPC64 */ | |
3090 | ||
79aceca5 | 3091 | /* sthbrx */ |
86178a57 | 3092 | static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3093 | { |
76db3ba4 | 3094 | if (likely(!ctx->le_mode)) { |
76db3ba4 AJ |
3095 | TCGv t0 = tcg_temp_new(); |
3096 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 3097 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
3098 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
3099 | tcg_temp_free(t0); | |
76db3ba4 AJ |
3100 | } else { |
3101 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
3102 | } | |
b61f2753 | 3103 | } |
0c8aacd4 | 3104 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
b61f2753 | 3105 | |
79aceca5 | 3106 | /* stwbrx */ |
86178a57 | 3107 | static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3108 | { |
76db3ba4 | 3109 | if (likely(!ctx->le_mode)) { |
fa3966a3 AJ |
3110 | TCGv t0 = tcg_temp_new(); |
3111 | tcg_gen_ext32u_tl(t0, arg1); | |
3112 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
3113 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
3114 | tcg_temp_free(t0); | |
76db3ba4 AJ |
3115 | } else { |
3116 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
3117 | } | |
b61f2753 | 3118 | } |
0c8aacd4 | 3119 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 | 3120 | |
cd6e9320 TH |
3121 | #if defined(TARGET_PPC64) |
3122 | /* stdbrx */ | |
3123 | static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
3124 | { | |
3125 | if (likely(!ctx->le_mode)) { | |
3126 | TCGv t0 = tcg_temp_new(); | |
3127 | tcg_gen_bswap64_tl(t0, arg1); | |
3128 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); | |
3129 | tcg_temp_free(t0); | |
3130 | } else { | |
3131 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); | |
3132 | } | |
3133 | } | |
3134 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX); | |
3135 | #endif /* TARGET_PPC64 */ | |
3136 | ||
79aceca5 | 3137 | /*** Integer load and store multiple ***/ |
99e300ef | 3138 | |
54623277 | 3139 | /* lmw */ |
99e300ef | 3140 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 3141 | { |
76db3ba4 AJ |
3142 | TCGv t0; |
3143 | TCGv_i32 t1; | |
3144 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3145 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3146 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3147 | t0 = tcg_temp_new(); |
3148 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3149 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3150 | gen_helper_lmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3151 | tcg_temp_free(t0); |
3152 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3153 | } |
3154 | ||
3155 | /* stmw */ | |
99e300ef | 3156 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 3157 | { |
76db3ba4 AJ |
3158 | TCGv t0; |
3159 | TCGv_i32 t1; | |
3160 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3161 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3162 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3163 | t0 = tcg_temp_new(); |
3164 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
3165 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3166 | gen_helper_stmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3167 | tcg_temp_free(t0); |
3168 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3169 | } |
3170 | ||
3171 | /*** Integer load and store strings ***/ | |
54623277 | 3172 | |
79aceca5 | 3173 | /* lswi */ |
3fc6c082 | 3174 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
3175 | * rA is in the range of registers to be loaded. |
3176 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
3177 | * For now, I'll follow the spec... | |
3178 | */ | |
99e300ef | 3179 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 3180 | { |
dfbc799d AJ |
3181 | TCGv t0; |
3182 | TCGv_i32 t1, t2; | |
79aceca5 FB |
3183 | int nb = NB(ctx->opcode); |
3184 | int start = rD(ctx->opcode); | |
9a64fbe4 | 3185 | int ra = rA(ctx->opcode); |
79aceca5 FB |
3186 | int nr; |
3187 | ||
3188 | if (nb == 0) | |
3189 | nb = 32; | |
3190 | nr = nb / 4; | |
76a66253 JM |
3191 | if (unlikely(((start + nr) > 32 && |
3192 | start <= ra && (start + nr - 32) > ra) || | |
3193 | ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) { | |
e06fcd75 | 3194 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 3195 | return; |
297d8e62 | 3196 | } |
76db3ba4 | 3197 | gen_set_access_type(ctx, ACCESS_INT); |
8dd4983c | 3198 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3199 | gen_update_nip(ctx, ctx->nip - 4); |
dfbc799d | 3200 | t0 = tcg_temp_new(); |
76db3ba4 | 3201 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
3202 | t1 = tcg_const_i32(nb); |
3203 | t2 = tcg_const_i32(start); | |
2f5a189c | 3204 | gen_helper_lsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3205 | tcg_temp_free(t0); |
3206 | tcg_temp_free_i32(t1); | |
3207 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3208 | } |
3209 | ||
3210 | /* lswx */ | |
99e300ef | 3211 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 3212 | { |
76db3ba4 AJ |
3213 | TCGv t0; |
3214 | TCGv_i32 t1, t2, t3; | |
3215 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3216 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3217 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3218 | t0 = tcg_temp_new(); |
3219 | gen_addr_reg_index(ctx, t0); | |
3220 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3221 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
3222 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
2f5a189c | 3223 | gen_helper_lswx(cpu_env, t0, t1, t2, t3); |
dfbc799d AJ |
3224 | tcg_temp_free(t0); |
3225 | tcg_temp_free_i32(t1); | |
3226 | tcg_temp_free_i32(t2); | |
3227 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
3228 | } |
3229 | ||
3230 | /* stswi */ | |
99e300ef | 3231 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 3232 | { |
76db3ba4 AJ |
3233 | TCGv t0; |
3234 | TCGv_i32 t1, t2; | |
4b3686fa | 3235 | int nb = NB(ctx->opcode); |
76db3ba4 | 3236 | gen_set_access_type(ctx, ACCESS_INT); |
76a66253 | 3237 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3238 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3239 | t0 = tcg_temp_new(); |
3240 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
3241 | if (nb == 0) |
3242 | nb = 32; | |
dfbc799d | 3243 | t1 = tcg_const_i32(nb); |
76db3ba4 | 3244 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3245 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3246 | tcg_temp_free(t0); |
3247 | tcg_temp_free_i32(t1); | |
3248 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3249 | } |
3250 | ||
3251 | /* stswx */ | |
99e300ef | 3252 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3253 | { |
76db3ba4 AJ |
3254 | TCGv t0; |
3255 | TCGv_i32 t1, t2; | |
3256 | gen_set_access_type(ctx, ACCESS_INT); | |
8dd4983c | 3257 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5fafdf24 | 3258 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3259 | t0 = tcg_temp_new(); |
3260 | gen_addr_reg_index(ctx, t0); | |
3261 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3262 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3263 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3264 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3265 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3266 | tcg_temp_free(t0); |
3267 | tcg_temp_free_i32(t1); | |
3268 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3269 | } |
3270 | ||
3271 | /*** Memory synchronisation ***/ | |
3272 | /* eieio */ | |
99e300ef | 3273 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3274 | { |
79aceca5 FB |
3275 | } |
3276 | ||
3277 | /* isync */ | |
99e300ef | 3278 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3279 | { |
e06fcd75 | 3280 | gen_stop_exception(ctx); |
79aceca5 FB |
3281 | } |
3282 | ||
5c77a786 TM |
3283 | #define LARX(name, len, loadop) \ |
3284 | static void gen_##name(DisasContext *ctx) \ | |
3285 | { \ | |
3286 | TCGv t0; \ | |
3287 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \ | |
3288 | gen_set_access_type(ctx, ACCESS_RES); \ | |
3289 | t0 = tcg_temp_local_new(); \ | |
3290 | gen_addr_reg_index(ctx, t0); \ | |
3291 | if ((len) > 1) { \ | |
3292 | gen_check_align(ctx, t0, (len)-1); \ | |
3293 | } \ | |
3294 | gen_qemu_##loadop(ctx, gpr, t0); \ | |
3295 | tcg_gen_mov_tl(cpu_reserve, t0); \ | |
3296 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \ | |
3297 | tcg_temp_free(t0); \ | |
79aceca5 FB |
3298 | } |
3299 | ||
5c77a786 TM |
3300 | /* lwarx */ |
3301 | LARX(lbarx, 1, ld8u); | |
3302 | LARX(lharx, 2, ld16u); | |
3303 | LARX(lwarx, 4, ld32u); | |
3304 | ||
3305 | ||
4425265b | 3306 | #if defined(CONFIG_USER_ONLY) |
587c51f7 TM |
3307 | static void gen_conditional_store(DisasContext *ctx, TCGv EA, |
3308 | int reg, int size) | |
4425265b NF |
3309 | { |
3310 | TCGv t0 = tcg_temp_new(); | |
3311 | uint32_t save_exception = ctx->exception; | |
3312 | ||
1328c2bf | 3313 | tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea)); |
4425265b | 3314 | tcg_gen_movi_tl(t0, (size << 5) | reg); |
1328c2bf | 3315 | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info)); |
4425265b NF |
3316 | tcg_temp_free(t0); |
3317 | gen_update_nip(ctx, ctx->nip-4); | |
3318 | ctx->exception = POWERPC_EXCP_BRANCH; | |
3319 | gen_exception(ctx, POWERPC_EXCP_STCX); | |
3320 | ctx->exception = save_exception; | |
3321 | } | |
4425265b | 3322 | #else |
587c51f7 TM |
3323 | static void gen_conditional_store(DisasContext *ctx, TCGv EA, |
3324 | int reg, int size) | |
3325 | { | |
3326 | int l1; | |
4425265b | 3327 | |
587c51f7 TM |
3328 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
3329 | l1 = gen_new_label(); | |
3330 | tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1); | |
3331 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3332 | #if defined(TARGET_PPC64) | |
3333 | if (size == 8) { | |
3334 | gen_qemu_st64(ctx, cpu_gpr[reg], EA); | |
3335 | } else | |
3336 | #endif | |
3337 | if (size == 4) { | |
3338 | gen_qemu_st32(ctx, cpu_gpr[reg], EA); | |
3339 | } else if (size == 2) { | |
3340 | gen_qemu_st16(ctx, cpu_gpr[reg], EA); | |
27b95bfe TM |
3341 | #if defined(TARGET_PPC64) |
3342 | } else if (size == 16) { | |
3707cd62 | 3343 | TCGv gpr1, gpr2 , EA8; |
27b95bfe TM |
3344 | if (unlikely(ctx->le_mode)) { |
3345 | gpr1 = cpu_gpr[reg+1]; | |
3346 | gpr2 = cpu_gpr[reg]; | |
3347 | } else { | |
3348 | gpr1 = cpu_gpr[reg]; | |
3349 | gpr2 = cpu_gpr[reg+1]; | |
3350 | } | |
3351 | gen_qemu_st64(ctx, gpr1, EA); | |
3707cd62 TM |
3352 | EA8 = tcg_temp_local_new(); |
3353 | gen_addr_add(ctx, EA8, EA, 8); | |
3354 | gen_qemu_st64(ctx, gpr2, EA8); | |
3355 | tcg_temp_free(EA8); | |
27b95bfe | 3356 | #endif |
587c51f7 TM |
3357 | } else { |
3358 | gen_qemu_st8(ctx, cpu_gpr[reg], EA); | |
4425265b | 3359 | } |
587c51f7 TM |
3360 | gen_set_label(l1); |
3361 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3362 | } | |
4425265b | 3363 | #endif |
587c51f7 TM |
3364 | |
3365 | #define STCX(name, len) \ | |
3366 | static void gen_##name(DisasContext *ctx) \ | |
3367 | { \ | |
3368 | TCGv t0; \ | |
27b95bfe TM |
3369 | if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \ |
3370 | gen_inval_exception(ctx, \ | |
3371 | POWERPC_EXCP_INVAL_INVAL); \ | |
3372 | return; \ | |
3373 | } \ | |
587c51f7 TM |
3374 | gen_set_access_type(ctx, ACCESS_RES); \ |
3375 | t0 = tcg_temp_local_new(); \ | |
3376 | gen_addr_reg_index(ctx, t0); \ | |
3377 | if (len > 1) { \ | |
3378 | gen_check_align(ctx, t0, (len)-1); \ | |
3379 | } \ | |
3380 | gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \ | |
3381 | tcg_temp_free(t0); \ | |
79aceca5 FB |
3382 | } |
3383 | ||
587c51f7 TM |
3384 | STCX(stbcx_, 1); |
3385 | STCX(sthcx_, 2); | |
3386 | STCX(stwcx_, 4); | |
3387 | ||
426613db | 3388 | #if defined(TARGET_PPC64) |
426613db | 3389 | /* ldarx */ |
5c77a786 | 3390 | LARX(ldarx, 8, ld64); |
426613db | 3391 | |
9c294d5a TM |
3392 | /* lqarx */ |
3393 | static void gen_lqarx(DisasContext *ctx) | |
3394 | { | |
3395 | TCGv EA; | |
3396 | int rd = rD(ctx->opcode); | |
3397 | TCGv gpr1, gpr2; | |
3398 | ||
3399 | if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) || | |
3400 | (rd == rB(ctx->opcode)))) { | |
3401 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
3402 | return; | |
3403 | } | |
3404 | ||
3405 | gen_set_access_type(ctx, ACCESS_RES); | |
3406 | EA = tcg_temp_local_new(); | |
3407 | gen_addr_reg_index(ctx, EA); | |
3408 | gen_check_align(ctx, EA, 15); | |
3409 | if (unlikely(ctx->le_mode)) { | |
3410 | gpr1 = cpu_gpr[rd+1]; | |
3411 | gpr2 = cpu_gpr[rd]; | |
3412 | } else { | |
3413 | gpr1 = cpu_gpr[rd]; | |
3414 | gpr2 = cpu_gpr[rd+1]; | |
3415 | } | |
3416 | gen_qemu_ld64(ctx, gpr1, EA); | |
3417 | tcg_gen_mov_tl(cpu_reserve, EA); | |
3418 | ||
3419 | gen_addr_add(ctx, EA, EA, 8); | |
3420 | gen_qemu_ld64(ctx, gpr2, EA); | |
3421 | ||
3422 | tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val)); | |
3423 | tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2)); | |
3424 | ||
3425 | tcg_temp_free(EA); | |
3426 | } | |
3427 | ||
426613db | 3428 | /* stdcx. */ |
587c51f7 | 3429 | STCX(stdcx_, 8); |
27b95bfe | 3430 | STCX(stqcx_, 16); |
426613db JM |
3431 | #endif /* defined(TARGET_PPC64) */ |
3432 | ||
79aceca5 | 3433 | /* sync */ |
99e300ef | 3434 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3435 | { |
79aceca5 FB |
3436 | } |
3437 | ||
0db1b20e | 3438 | /* wait */ |
99e300ef | 3439 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3440 | { |
931ff272 | 3441 | TCGv_i32 t0 = tcg_temp_new_i32(); |
259186a7 AF |
3442 | tcg_gen_st_i32(t0, cpu_env, |
3443 | -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted)); | |
931ff272 | 3444 | tcg_temp_free_i32(t0); |
0db1b20e | 3445 | /* Stop translation, as the CPU is supposed to sleep from now */ |
e06fcd75 | 3446 | gen_exception_err(ctx, EXCP_HLT, 1); |
0db1b20e JM |
3447 | } |
3448 | ||
79aceca5 | 3449 | /*** Floating-point load ***/ |
a0d7d5a7 | 3450 | #define GEN_LDF(name, ldop, opc, type) \ |
99e300ef | 3451 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3452 | { \ |
a0d7d5a7 | 3453 | TCGv EA; \ |
76a66253 | 3454 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3455 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3456 | return; \ |
3457 | } \ | |
76db3ba4 | 3458 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3459 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3460 | gen_addr_imm_index(ctx, EA, 0); \ |
3461 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3462 | tcg_temp_free(EA); \ |
79aceca5 FB |
3463 | } |
3464 | ||
a0d7d5a7 | 3465 | #define GEN_LDUF(name, ldop, opc, type) \ |
99e300ef | 3466 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3467 | { \ |
a0d7d5a7 | 3468 | TCGv EA; \ |
76a66253 | 3469 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3470 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3471 | return; \ |
3472 | } \ | |
76a66253 | 3473 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3474 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3475 | return; \ |
9a64fbe4 | 3476 | } \ |
76db3ba4 | 3477 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3478 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3479 | gen_addr_imm_index(ctx, EA, 0); \ |
3480 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3481 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3482 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3483 | } |
3484 | ||
a0d7d5a7 | 3485 | #define GEN_LDUXF(name, ldop, opc, type) \ |
99e300ef | 3486 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3487 | { \ |
a0d7d5a7 | 3488 | TCGv EA; \ |
76a66253 | 3489 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3490 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3491 | return; \ |
3492 | } \ | |
76a66253 | 3493 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3494 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3495 | return; \ |
9a64fbe4 | 3496 | } \ |
76db3ba4 | 3497 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3498 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3499 | gen_addr_reg_index(ctx, EA); \ |
3500 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3501 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3502 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3503 | } |
3504 | ||
a0d7d5a7 | 3505 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ |
99e300ef | 3506 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3507 | { \ |
a0d7d5a7 | 3508 | TCGv EA; \ |
76a66253 | 3509 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3510 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3511 | return; \ |
3512 | } \ | |
76db3ba4 | 3513 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3514 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3515 | gen_addr_reg_index(ctx, EA); \ |
3516 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3517 | tcg_temp_free(EA); \ |
79aceca5 FB |
3518 | } |
3519 | ||
a0d7d5a7 AJ |
3520 | #define GEN_LDFS(name, ldop, op, type) \ |
3521 | GEN_LDF(name, ldop, op | 0x20, type); \ | |
3522 | GEN_LDUF(name, ldop, op | 0x21, type); \ | |
3523 | GEN_LDUXF(name, ldop, op | 0x01, type); \ | |
3524 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
3525 | ||
636aa200 | 3526 | static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3527 | { |
3528 | TCGv t0 = tcg_temp_new(); | |
3529 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
76db3ba4 | 3530 | gen_qemu_ld32u(ctx, t0, arg2); |
a0d7d5a7 AJ |
3531 | tcg_gen_trunc_tl_i32(t1, t0); |
3532 | tcg_temp_free(t0); | |
8e703949 | 3533 | gen_helper_float32_to_float64(arg1, cpu_env, t1); |
a0d7d5a7 AJ |
3534 | tcg_temp_free_i32(t1); |
3535 | } | |
79aceca5 | 3536 | |
a0d7d5a7 AJ |
3537 | /* lfd lfdu lfdux lfdx */ |
3538 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT); | |
3539 | /* lfs lfsu lfsux lfsx */ | |
3540 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT); | |
79aceca5 | 3541 | |
05050ee8 AJ |
3542 | /* lfdp */ |
3543 | static void gen_lfdp(DisasContext *ctx) | |
3544 | { | |
3545 | TCGv EA; | |
3546 | if (unlikely(!ctx->fpu_enabled)) { | |
3547 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3548 | return; | |
3549 | } | |
3550 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3551 | EA = tcg_temp_new(); | |
3552 | gen_addr_imm_index(ctx, EA, 0); \ | |
3553 | if (unlikely(ctx->le_mode)) { | |
3554 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3555 | tcg_gen_addi_tl(EA, EA, 8); | |
3556 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3557 | } else { | |
3558 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3559 | tcg_gen_addi_tl(EA, EA, 8); | |
3560 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3561 | } | |
3562 | tcg_temp_free(EA); | |
3563 | } | |
3564 | ||
3565 | /* lfdpx */ | |
3566 | static void gen_lfdpx(DisasContext *ctx) | |
3567 | { | |
3568 | TCGv EA; | |
3569 | if (unlikely(!ctx->fpu_enabled)) { | |
3570 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3571 | return; | |
3572 | } | |
3573 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3574 | EA = tcg_temp_new(); | |
3575 | gen_addr_reg_index(ctx, EA); | |
3576 | if (unlikely(ctx->le_mode)) { | |
3577 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3578 | tcg_gen_addi_tl(EA, EA, 8); | |
3579 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3580 | } else { | |
3581 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3582 | tcg_gen_addi_tl(EA, EA, 8); | |
3583 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3584 | } | |
3585 | tcg_temp_free(EA); | |
3586 | } | |
3587 | ||
199f830d AJ |
3588 | /* lfiwax */ |
3589 | static void gen_lfiwax(DisasContext *ctx) | |
3590 | { | |
3591 | TCGv EA; | |
3592 | TCGv t0; | |
3593 | if (unlikely(!ctx->fpu_enabled)) { | |
3594 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3595 | return; | |
3596 | } | |
3597 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3598 | EA = tcg_temp_new(); | |
3599 | t0 = tcg_temp_new(); | |
3600 | gen_addr_reg_index(ctx, EA); | |
909eedb7 | 3601 | gen_qemu_ld32s(ctx, t0, EA); |
199f830d | 3602 | tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0); |
199f830d AJ |
3603 | tcg_temp_free(EA); |
3604 | tcg_temp_free(t0); | |
3605 | } | |
3606 | ||
66c3e328 TM |
3607 | /* lfiwzx */ |
3608 | static void gen_lfiwzx(DisasContext *ctx) | |
3609 | { | |
3610 | TCGv EA; | |
3611 | if (unlikely(!ctx->fpu_enabled)) { | |
3612 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3613 | return; | |
3614 | } | |
3615 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3616 | EA = tcg_temp_new(); | |
3617 | gen_addr_reg_index(ctx, EA); | |
3618 | gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3619 | tcg_temp_free(EA); | |
3620 | } | |
79aceca5 | 3621 | /*** Floating-point store ***/ |
a0d7d5a7 | 3622 | #define GEN_STF(name, stop, opc, type) \ |
99e300ef | 3623 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3624 | { \ |
a0d7d5a7 | 3625 | TCGv EA; \ |
76a66253 | 3626 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3627 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3628 | return; \ |
3629 | } \ | |
76db3ba4 | 3630 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3631 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3632 | gen_addr_imm_index(ctx, EA, 0); \ |
3633 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3634 | tcg_temp_free(EA); \ |
79aceca5 FB |
3635 | } |
3636 | ||
a0d7d5a7 | 3637 | #define GEN_STUF(name, stop, opc, type) \ |
99e300ef | 3638 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3639 | { \ |
a0d7d5a7 | 3640 | TCGv EA; \ |
76a66253 | 3641 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3642 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3643 | return; \ |
3644 | } \ | |
76a66253 | 3645 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3646 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3647 | return; \ |
9a64fbe4 | 3648 | } \ |
76db3ba4 | 3649 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3650 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3651 | gen_addr_imm_index(ctx, EA, 0); \ |
3652 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3653 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3654 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3655 | } |
3656 | ||
a0d7d5a7 | 3657 | #define GEN_STUXF(name, stop, opc, type) \ |
99e300ef | 3658 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3659 | { \ |
a0d7d5a7 | 3660 | TCGv EA; \ |
76a66253 | 3661 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3662 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3663 | return; \ |
3664 | } \ | |
76a66253 | 3665 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3666 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3667 | return; \ |
9a64fbe4 | 3668 | } \ |
76db3ba4 | 3669 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3670 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3671 | gen_addr_reg_index(ctx, EA); \ |
3672 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3673 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3674 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3675 | } |
3676 | ||
a0d7d5a7 | 3677 | #define GEN_STXF(name, stop, opc2, opc3, type) \ |
99e300ef | 3678 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3679 | { \ |
a0d7d5a7 | 3680 | TCGv EA; \ |
76a66253 | 3681 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3682 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3683 | return; \ |
3684 | } \ | |
76db3ba4 | 3685 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3686 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3687 | gen_addr_reg_index(ctx, EA); \ |
3688 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3689 | tcg_temp_free(EA); \ |
79aceca5 FB |
3690 | } |
3691 | ||
a0d7d5a7 AJ |
3692 | #define GEN_STFS(name, stop, op, type) \ |
3693 | GEN_STF(name, stop, op | 0x20, type); \ | |
3694 | GEN_STUF(name, stop, op | 0x21, type); \ | |
3695 | GEN_STUXF(name, stop, op | 0x01, type); \ | |
3696 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
3697 | ||
636aa200 | 3698 | static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3699 | { |
3700 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
3701 | TCGv t1 = tcg_temp_new(); | |
8e703949 | 3702 | gen_helper_float64_to_float32(t0, cpu_env, arg1); |
a0d7d5a7 AJ |
3703 | tcg_gen_extu_i32_tl(t1, t0); |
3704 | tcg_temp_free_i32(t0); | |
76db3ba4 | 3705 | gen_qemu_st32(ctx, t1, arg2); |
a0d7d5a7 AJ |
3706 | tcg_temp_free(t1); |
3707 | } | |
79aceca5 FB |
3708 | |
3709 | /* stfd stfdu stfdux stfdx */ | |
a0d7d5a7 | 3710 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT); |
79aceca5 | 3711 | /* stfs stfsu stfsux stfsx */ |
a0d7d5a7 | 3712 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT); |
79aceca5 | 3713 | |
44bc0c4d AJ |
3714 | /* stfdp */ |
3715 | static void gen_stfdp(DisasContext *ctx) | |
3716 | { | |
3717 | TCGv EA; | |
3718 | if (unlikely(!ctx->fpu_enabled)) { | |
3719 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3720 | return; | |
3721 | } | |
3722 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3723 | EA = tcg_temp_new(); | |
3724 | gen_addr_imm_index(ctx, EA, 0); \ | |
3725 | if (unlikely(ctx->le_mode)) { | |
3726 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3727 | tcg_gen_addi_tl(EA, EA, 8); | |
3728 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3729 | } else { | |
3730 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3731 | tcg_gen_addi_tl(EA, EA, 8); | |
3732 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3733 | } | |
3734 | tcg_temp_free(EA); | |
3735 | } | |
3736 | ||
3737 | /* stfdpx */ | |
3738 | static void gen_stfdpx(DisasContext *ctx) | |
3739 | { | |
3740 | TCGv EA; | |
3741 | if (unlikely(!ctx->fpu_enabled)) { | |
3742 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3743 | return; | |
3744 | } | |
3745 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3746 | EA = tcg_temp_new(); | |
3747 | gen_addr_reg_index(ctx, EA); | |
3748 | if (unlikely(ctx->le_mode)) { | |
3749 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3750 | tcg_gen_addi_tl(EA, EA, 8); | |
3751 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3752 | } else { | |
3753 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3754 | tcg_gen_addi_tl(EA, EA, 8); | |
3755 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3756 | } | |
3757 | tcg_temp_free(EA); | |
3758 | } | |
3759 | ||
79aceca5 | 3760 | /* Optional: */ |
636aa200 | 3761 | static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3762 | { |
3763 | TCGv t0 = tcg_temp_new(); | |
3764 | tcg_gen_trunc_i64_tl(t0, arg1), | |
76db3ba4 | 3765 | gen_qemu_st32(ctx, t0, arg2); |
a0d7d5a7 AJ |
3766 | tcg_temp_free(t0); |
3767 | } | |
79aceca5 | 3768 | /* stfiwx */ |
a0d7d5a7 | 3769 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
79aceca5 | 3770 | |
697ab892 DG |
3771 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3772 | { | |
3773 | #if defined(TARGET_PPC64) | |
3774 | if (ctx->has_cfar) | |
3775 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3776 | #endif | |
3777 | } | |
3778 | ||
79aceca5 | 3779 | /*** Branch ***/ |
636aa200 | 3780 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 FB |
3781 | { |
3782 | TranslationBlock *tb; | |
3783 | tb = ctx->tb; | |
e0c8f9ce | 3784 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3785 | dest = (uint32_t) dest; |
e0c8f9ce | 3786 | } |
57fec1fe | 3787 | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && |
8cbcb4fa | 3788 | likely(!ctx->singlestep_enabled)) { |
57fec1fe | 3789 | tcg_gen_goto_tb(n); |
a2ffb812 | 3790 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cfd0495 | 3791 | tcg_gen_exit_tb((uintptr_t)tb + n); |
c1942362 | 3792 | } else { |
a2ffb812 | 3793 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cbcb4fa AJ |
3794 | if (unlikely(ctx->singlestep_enabled)) { |
3795 | if ((ctx->singlestep_enabled & | |
bdc4e053 | 3796 | (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) && |
f0cc4aa8 JG |
3797 | (ctx->exception == POWERPC_EXCP_BRANCH || |
3798 | ctx->exception == POWERPC_EXCP_TRACE)) { | |
8cbcb4fa AJ |
3799 | target_ulong tmp = ctx->nip; |
3800 | ctx->nip = dest; | |
e06fcd75 | 3801 | gen_exception(ctx, POWERPC_EXCP_TRACE); |
8cbcb4fa AJ |
3802 | ctx->nip = tmp; |
3803 | } | |
3804 | if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) { | |
e06fcd75 | 3805 | gen_debug_exception(ctx); |
8cbcb4fa AJ |
3806 | } |
3807 | } | |
57fec1fe | 3808 | tcg_gen_exit_tb(0); |
c1942362 | 3809 | } |
c53be334 FB |
3810 | } |
3811 | ||
636aa200 | 3812 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f | 3813 | { |
e0c8f9ce RH |
3814 | if (NARROW_MODE(ctx)) { |
3815 | nip = (uint32_t)nip; | |
3816 | } | |
3817 | tcg_gen_movi_tl(cpu_lr, nip); | |
e1833e1f JM |
3818 | } |
3819 | ||
79aceca5 | 3820 | /* b ba bl bla */ |
99e300ef | 3821 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3822 | { |
76a66253 | 3823 | target_ulong li, target; |
38a64f9d | 3824 | |
8cbcb4fa | 3825 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3826 | /* sign extend LI */ |
e0c8f9ce RH |
3827 | li = LI(ctx->opcode); |
3828 | li = (li ^ 0x02000000) - 0x02000000; | |
3829 | if (likely(AA(ctx->opcode) == 0)) { | |
046d6672 | 3830 | target = ctx->nip + li - 4; |
e0c8f9ce | 3831 | } else { |
9a64fbe4 | 3832 | target = li; |
e0c8f9ce RH |
3833 | } |
3834 | if (LK(ctx->opcode)) { | |
e1833e1f | 3835 | gen_setlr(ctx, ctx->nip); |
e0c8f9ce | 3836 | } |
697ab892 | 3837 | gen_update_cfar(ctx, ctx->nip); |
c1942362 | 3838 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3839 | } |
3840 | ||
e98a6e40 FB |
3841 | #define BCOND_IM 0 |
3842 | #define BCOND_LR 1 | |
3843 | #define BCOND_CTR 2 | |
52a4984d | 3844 | #define BCOND_TAR 3 |
e98a6e40 | 3845 | |
636aa200 | 3846 | static inline void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3847 | { |
d9bce9d9 | 3848 | uint32_t bo = BO(ctx->opcode); |
05f92404 | 3849 | int l1; |
a2ffb812 | 3850 | TCGv target; |
e98a6e40 | 3851 | |
8cbcb4fa | 3852 | ctx->exception = POWERPC_EXCP_BRANCH; |
52a4984d | 3853 | if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) { |
a7812ae4 | 3854 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3855 | if (type == BCOND_CTR) |
3856 | tcg_gen_mov_tl(target, cpu_ctr); | |
52a4984d TM |
3857 | else if (type == BCOND_TAR) |
3858 | gen_load_spr(target, SPR_TAR); | |
a2ffb812 AJ |
3859 | else |
3860 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3861 | } else { |
3862 | TCGV_UNUSED(target); | |
e98a6e40 | 3863 | } |
e1833e1f JM |
3864 | if (LK(ctx->opcode)) |
3865 | gen_setlr(ctx, ctx->nip); | |
a2ffb812 AJ |
3866 | l1 = gen_new_label(); |
3867 | if ((bo & 0x4) == 0) { | |
3868 | /* Decrement and test CTR */ | |
a7812ae4 | 3869 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3870 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3871 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3872 | return; |
3873 | } | |
3874 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
e0c8f9ce | 3875 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3876 | tcg_gen_ext32u_tl(temp, cpu_ctr); |
e0c8f9ce | 3877 | } else { |
a2ffb812 | 3878 | tcg_gen_mov_tl(temp, cpu_ctr); |
e0c8f9ce | 3879 | } |
a2ffb812 AJ |
3880 | if (bo & 0x2) { |
3881 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3882 | } else { | |
3883 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3884 | } |
a7812ae4 | 3885 | tcg_temp_free(temp); |
a2ffb812 AJ |
3886 | } |
3887 | if ((bo & 0x10) == 0) { | |
3888 | /* Test CR */ | |
3889 | uint32_t bi = BI(ctx->opcode); | |
3890 | uint32_t mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 3891 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3892 | |
d9bce9d9 | 3893 | if (bo & 0x8) { |
a2ffb812 AJ |
3894 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3895 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3896 | } else { |
a2ffb812 AJ |
3897 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3898 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3899 | } |
a7812ae4 | 3900 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3901 | } |
697ab892 | 3902 | gen_update_cfar(ctx, ctx->nip); |
e98a6e40 | 3903 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3904 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3905 | if (likely(AA(ctx->opcode) == 0)) { | |
3906 | gen_goto_tb(ctx, 0, ctx->nip + li - 4); | |
3907 | } else { | |
3908 | gen_goto_tb(ctx, 0, li); | |
3909 | } | |
c53be334 | 3910 | gen_set_label(l1); |
c1942362 | 3911 | gen_goto_tb(ctx, 1, ctx->nip); |
e98a6e40 | 3912 | } else { |
e0c8f9ce | 3913 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3914 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); |
e0c8f9ce | 3915 | } else { |
a2ffb812 | 3916 | tcg_gen_andi_tl(cpu_nip, target, ~3); |
e0c8f9ce | 3917 | } |
a2ffb812 AJ |
3918 | tcg_gen_exit_tb(0); |
3919 | gen_set_label(l1); | |
e0c8f9ce | 3920 | gen_update_nip(ctx, ctx->nip); |
57fec1fe | 3921 | tcg_gen_exit_tb(0); |
08e46e54 | 3922 | } |
e98a6e40 FB |
3923 | } |
3924 | ||
99e300ef | 3925 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3926 | { |
e98a6e40 FB |
3927 | gen_bcond(ctx, BCOND_IM); |
3928 | } | |
3929 | ||
99e300ef | 3930 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3931 | { |
e98a6e40 FB |
3932 | gen_bcond(ctx, BCOND_CTR); |
3933 | } | |
3934 | ||
99e300ef | 3935 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3936 | { |
e98a6e40 FB |
3937 | gen_bcond(ctx, BCOND_LR); |
3938 | } | |
79aceca5 | 3939 | |
52a4984d TM |
3940 | static void gen_bctar(DisasContext *ctx) |
3941 | { | |
3942 | gen_bcond(ctx, BCOND_TAR); | |
3943 | } | |
3944 | ||
79aceca5 | 3945 | /*** Condition register logical ***/ |
e1571908 | 3946 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3947 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3948 | { \ |
fc0d441e JM |
3949 | uint8_t bitmask; \ |
3950 | int sh; \ | |
a7812ae4 | 3951 | TCGv_i32 t0, t1; \ |
fc0d441e | 3952 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3953 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3954 | if (sh > 0) \ |
fea0c503 | 3955 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3956 | else if (sh < 0) \ |
fea0c503 | 3957 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3958 | else \ |
fea0c503 | 3959 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3960 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3961 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3962 | if (sh > 0) \ | |
fea0c503 | 3963 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3964 | else if (sh < 0) \ |
fea0c503 | 3965 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3966 | else \ |
fea0c503 AJ |
3967 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3968 | tcg_op(t0, t0, t1); \ | |
fc0d441e | 3969 | bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \ |
fea0c503 AJ |
3970 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3971 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3972 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3973 | tcg_temp_free_i32(t0); \ |
3974 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3975 | } |
3976 | ||
3977 | /* crand */ | |
e1571908 | 3978 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3979 | /* crandc */ |
e1571908 | 3980 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3981 | /* creqv */ |
e1571908 | 3982 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3983 | /* crnand */ |
e1571908 | 3984 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3985 | /* crnor */ |
e1571908 | 3986 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3987 | /* cror */ |
e1571908 | 3988 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3989 | /* crorc */ |
e1571908 | 3990 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3991 | /* crxor */ |
e1571908 | 3992 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3993 | |
54623277 | 3994 | /* mcrf */ |
99e300ef | 3995 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3996 | { |
47e4661c | 3997 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3998 | } |
3999 | ||
4000 | /*** System linkage ***/ | |
99e300ef | 4001 | |
54623277 | 4002 | /* rfi (mem_idx only) */ |
99e300ef | 4003 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 4004 | { |
9a64fbe4 | 4005 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4006 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 FB |
4007 | #else |
4008 | /* Restore CPU state */ | |
76db3ba4 | 4009 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4010 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4011 | return; |
9a64fbe4 | 4012 | } |
697ab892 | 4013 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 4014 | gen_helper_rfi(cpu_env); |
e06fcd75 | 4015 | gen_sync_exception(ctx); |
9a64fbe4 | 4016 | #endif |
79aceca5 FB |
4017 | } |
4018 | ||
426613db | 4019 | #if defined(TARGET_PPC64) |
99e300ef | 4020 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
4021 | { |
4022 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4023 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4024 | #else |
4025 | /* Restore CPU state */ | |
76db3ba4 | 4026 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4027 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4028 | return; |
4029 | } | |
697ab892 | 4030 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 4031 | gen_helper_rfid(cpu_env); |
e06fcd75 | 4032 | gen_sync_exception(ctx); |
426613db JM |
4033 | #endif |
4034 | } | |
426613db | 4035 | |
99e300ef | 4036 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
4037 | { |
4038 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4039 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
4040 | #else |
4041 | /* Restore CPU state */ | |
76db3ba4 | 4042 | if (unlikely(ctx->mem_idx <= 1)) { |
e06fcd75 | 4043 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
4044 | return; |
4045 | } | |
e5f17ac6 | 4046 | gen_helper_hrfid(cpu_env); |
e06fcd75 | 4047 | gen_sync_exception(ctx); |
be147d08 JM |
4048 | #endif |
4049 | } | |
4050 | #endif | |
4051 | ||
79aceca5 | 4052 | /* sc */ |
417bf010 JM |
4053 | #if defined(CONFIG_USER_ONLY) |
4054 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
4055 | #else | |
4056 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
4057 | #endif | |
99e300ef | 4058 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 4059 | { |
e1833e1f JM |
4060 | uint32_t lev; |
4061 | ||
4062 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 4063 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
4064 | } |
4065 | ||
4066 | /*** Trap ***/ | |
99e300ef | 4067 | |
54623277 | 4068 | /* tw */ |
99e300ef | 4069 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 4070 | { |
cab3bee2 | 4071 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
4072 | /* Update the nip since this might generate a trap exception */ |
4073 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
4074 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
4075 | t0); | |
cab3bee2 | 4076 | tcg_temp_free_i32(t0); |
79aceca5 FB |
4077 | } |
4078 | ||
4079 | /* twi */ | |
99e300ef | 4080 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 4081 | { |
cab3bee2 AJ |
4082 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
4083 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
4084 | /* Update the nip since this might generate a trap exception */ |
4085 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 4086 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
4087 | tcg_temp_free(t0); |
4088 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
4089 | } |
4090 | ||
d9bce9d9 JM |
4091 | #if defined(TARGET_PPC64) |
4092 | /* td */ | |
99e300ef | 4093 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 4094 | { |
cab3bee2 | 4095 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
4096 | /* Update the nip since this might generate a trap exception */ |
4097 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
4098 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
4099 | t0); | |
cab3bee2 | 4100 | tcg_temp_free_i32(t0); |
d9bce9d9 JM |
4101 | } |
4102 | ||
4103 | /* tdi */ | |
99e300ef | 4104 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 4105 | { |
cab3bee2 AJ |
4106 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
4107 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
4108 | /* Update the nip since this might generate a trap exception */ |
4109 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 4110 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
4111 | tcg_temp_free(t0); |
4112 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
4113 | } |
4114 | #endif | |
4115 | ||
79aceca5 | 4116 | /*** Processor control ***/ |
99e300ef | 4117 | |
da91a00f RH |
4118 | static void gen_read_xer(TCGv dst) |
4119 | { | |
4120 | TCGv t0 = tcg_temp_new(); | |
4121 | TCGv t1 = tcg_temp_new(); | |
4122 | TCGv t2 = tcg_temp_new(); | |
4123 | tcg_gen_mov_tl(dst, cpu_xer); | |
4124 | tcg_gen_shli_tl(t0, cpu_so, XER_SO); | |
4125 | tcg_gen_shli_tl(t1, cpu_ov, XER_OV); | |
4126 | tcg_gen_shli_tl(t2, cpu_ca, XER_CA); | |
4127 | tcg_gen_or_tl(t0, t0, t1); | |
4128 | tcg_gen_or_tl(dst, dst, t2); | |
4129 | tcg_gen_or_tl(dst, dst, t0); | |
4130 | tcg_temp_free(t0); | |
4131 | tcg_temp_free(t1); | |
4132 | tcg_temp_free(t2); | |
4133 | } | |
4134 | ||
4135 | static void gen_write_xer(TCGv src) | |
4136 | { | |
4137 | tcg_gen_andi_tl(cpu_xer, src, | |
4138 | ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA))); | |
4139 | tcg_gen_shri_tl(cpu_so, src, XER_SO); | |
4140 | tcg_gen_shri_tl(cpu_ov, src, XER_OV); | |
4141 | tcg_gen_shri_tl(cpu_ca, src, XER_CA); | |
4142 | tcg_gen_andi_tl(cpu_so, cpu_so, 1); | |
4143 | tcg_gen_andi_tl(cpu_ov, cpu_ov, 1); | |
4144 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
4145 | } | |
4146 | ||
54623277 | 4147 | /* mcrxr */ |
99e300ef | 4148 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 4149 | { |
da91a00f RH |
4150 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4151 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
4152 | TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)]; | |
4153 | ||
4154 | tcg_gen_trunc_tl_i32(t0, cpu_so); | |
4155 | tcg_gen_trunc_tl_i32(t1, cpu_ov); | |
4156 | tcg_gen_trunc_tl_i32(dst, cpu_ca); | |
4157 | tcg_gen_shri_i32(t0, t0, 2); | |
4158 | tcg_gen_shri_i32(t1, t1, 1); | |
4159 | tcg_gen_or_i32(dst, dst, t0); | |
4160 | tcg_gen_or_i32(dst, dst, t1); | |
4161 | tcg_temp_free_i32(t0); | |
4162 | tcg_temp_free_i32(t1); | |
4163 | ||
4164 | tcg_gen_movi_tl(cpu_so, 0); | |
4165 | tcg_gen_movi_tl(cpu_ov, 0); | |
4166 | tcg_gen_movi_tl(cpu_ca, 0); | |
79aceca5 FB |
4167 | } |
4168 | ||
0cfe11ea | 4169 | /* mfcr mfocrf */ |
99e300ef | 4170 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 4171 | { |
76a66253 | 4172 | uint32_t crm, crn; |
3b46e624 | 4173 | |
76a66253 JM |
4174 | if (likely(ctx->opcode & 0x00100000)) { |
4175 | crm = CRM(ctx->opcode); | |
8dd640e4 | 4176 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 4177 | crn = ctz32 (crm); |
e1571908 | 4178 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
4179 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
4180 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 4181 | } |
d9bce9d9 | 4182 | } else { |
651721b2 AJ |
4183 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4184 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
4185 | tcg_gen_shli_i32(t0, t0, 4); | |
4186 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
4187 | tcg_gen_shli_i32(t0, t0, 4); | |
4188 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
4189 | tcg_gen_shli_i32(t0, t0, 4); | |
4190 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
4191 | tcg_gen_shli_i32(t0, t0, 4); | |
4192 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
4193 | tcg_gen_shli_i32(t0, t0, 4); | |
4194 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
4195 | tcg_gen_shli_i32(t0, t0, 4); | |
4196 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
4197 | tcg_gen_shli_i32(t0, t0, 4); | |
4198 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
4199 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4200 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 4201 | } |
79aceca5 FB |
4202 | } |
4203 | ||
4204 | /* mfmsr */ | |
99e300ef | 4205 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 4206 | { |
9a64fbe4 | 4207 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4208 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4209 | #else |
76db3ba4 | 4210 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4211 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4212 | return; |
9a64fbe4 | 4213 | } |
6527f6ea | 4214 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
9a64fbe4 | 4215 | #endif |
79aceca5 FB |
4216 | } |
4217 | ||
7b13448f | 4218 | static void spr_noaccess(void *opaque, int gprn, int sprn) |
3fc6c082 | 4219 | { |
7b13448f | 4220 | #if 0 |
3fc6c082 FB |
4221 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
4222 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 4223 | #endif |
3fc6c082 FB |
4224 | } |
4225 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 4226 | |
79aceca5 | 4227 | /* mfspr */ |
636aa200 | 4228 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 4229 | { |
45d827d2 | 4230 | void (*read_cb)(void *opaque, int gprn, int sprn); |
79aceca5 FB |
4231 | uint32_t sprn = SPR(ctx->opcode); |
4232 | ||
3fc6c082 | 4233 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4234 | if (ctx->mem_idx == 2) |
be147d08 | 4235 | read_cb = ctx->spr_cb[sprn].hea_read; |
76db3ba4 | 4236 | else if (ctx->mem_idx) |
3fc6c082 FB |
4237 | read_cb = ctx->spr_cb[sprn].oea_read; |
4238 | else | |
9a64fbe4 | 4239 | #endif |
3fc6c082 | 4240 | read_cb = ctx->spr_cb[sprn].uea_read; |
76a66253 JM |
4241 | if (likely(read_cb != NULL)) { |
4242 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 4243 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
4244 | } else { |
4245 | /* Privilege exception */ | |
9fceefa7 JM |
4246 | /* This is a hack to avoid warnings when running Linux: |
4247 | * this OS breaks the PowerPC virtualisation model, | |
4248 | * allowing userland application to read the PVR | |
4249 | */ | |
4250 | if (sprn != SPR_PVR) { | |
c05541ee AB |
4251 | qemu_log("Trying to read privileged spr %d (0x%03x) at " |
4252 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4253 | printf("Trying to read privileged spr %d (0x%03x) at " | |
4254 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
f24e5695 | 4255 | } |
e06fcd75 | 4256 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 4257 | } |
3fc6c082 FB |
4258 | } else { |
4259 | /* Not defined */ | |
c05541ee AB |
4260 | qemu_log("Trying to read invalid spr %d (0x%03x) at " |
4261 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4262 | printf("Trying to read invalid spr %d (0x%03x) at " | |
4263 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4264 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4265 | } |
79aceca5 FB |
4266 | } |
4267 | ||
99e300ef | 4268 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 4269 | { |
3fc6c082 | 4270 | gen_op_mfspr(ctx); |
76a66253 | 4271 | } |
3fc6c082 FB |
4272 | |
4273 | /* mftb */ | |
99e300ef | 4274 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
4275 | { |
4276 | gen_op_mfspr(ctx); | |
79aceca5 FB |
4277 | } |
4278 | ||
0cfe11ea | 4279 | /* mtcrf mtocrf*/ |
99e300ef | 4280 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 4281 | { |
76a66253 | 4282 | uint32_t crm, crn; |
3b46e624 | 4283 | |
76a66253 | 4284 | crm = CRM(ctx->opcode); |
8dd640e4 | 4285 | if (likely((ctx->opcode & 0x00100000))) { |
4286 | if (crm && ((crm & (crm - 1)) == 0)) { | |
4287 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 4288 | crn = ctz32 (crm); |
8dd640e4 | 4289 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
4290 | tcg_gen_shri_i32(temp, temp, crn * 4); |
4291 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 4292 | tcg_temp_free_i32(temp); |
4293 | } | |
76a66253 | 4294 | } else { |
651721b2 AJ |
4295 | TCGv_i32 temp = tcg_temp_new_i32(); |
4296 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
4297 | for (crn = 0 ; crn < 8 ; crn++) { | |
4298 | if (crm & (1 << crn)) { | |
4299 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
4300 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
4301 | } | |
4302 | } | |
a7812ae4 | 4303 | tcg_temp_free_i32(temp); |
76a66253 | 4304 | } |
79aceca5 FB |
4305 | } |
4306 | ||
4307 | /* mtmsr */ | |
426613db | 4308 | #if defined(TARGET_PPC64) |
99e300ef | 4309 | static void gen_mtmsrd(DisasContext *ctx) |
426613db JM |
4310 | { |
4311 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4312 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db | 4313 | #else |
76db3ba4 | 4314 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4315 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db JM |
4316 | return; |
4317 | } | |
be147d08 JM |
4318 | if (ctx->opcode & 0x00010000) { |
4319 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
4320 | TCGv t0 = tcg_temp_new(); |
4321 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
4322 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
4323 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
4324 | tcg_temp_free(t0); | |
be147d08 | 4325 | } else { |
056b05f8 JM |
4326 | /* XXX: we need to update nip before the store |
4327 | * if we enter power saving mode, we will exit the loop | |
4328 | * directly from ppc_store_msr | |
4329 | */ | |
be147d08 | 4330 | gen_update_nip(ctx, ctx->nip); |
e5f17ac6 | 4331 | gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
4332 | /* Must stop the translation as machine state (may have) changed */ |
4333 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 4334 | gen_stop_exception(ctx); |
be147d08 | 4335 | } |
426613db JM |
4336 | #endif |
4337 | } | |
4338 | #endif | |
4339 | ||
99e300ef | 4340 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 4341 | { |
9a64fbe4 | 4342 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4343 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4344 | #else |
76db3ba4 | 4345 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4346 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4347 | return; |
9a64fbe4 | 4348 | } |
be147d08 JM |
4349 | if (ctx->opcode & 0x00010000) { |
4350 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
4351 | TCGv t0 = tcg_temp_new(); |
4352 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
4353 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
4354 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
4355 | tcg_temp_free(t0); | |
be147d08 | 4356 | } else { |
8018dc63 AG |
4357 | TCGv msr = tcg_temp_new(); |
4358 | ||
056b05f8 JM |
4359 | /* XXX: we need to update nip before the store |
4360 | * if we enter power saving mode, we will exit the loop | |
4361 | * directly from ppc_store_msr | |
4362 | */ | |
be147d08 | 4363 | gen_update_nip(ctx, ctx->nip); |
d9bce9d9 | 4364 | #if defined(TARGET_PPC64) |
8018dc63 AG |
4365 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
4366 | #else | |
4367 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 4368 | #endif |
e5f17ac6 | 4369 | gen_helper_store_msr(cpu_env, msr); |
be147d08 | 4370 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 4371 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 4372 | gen_stop_exception(ctx); |
be147d08 | 4373 | } |
9a64fbe4 | 4374 | #endif |
79aceca5 FB |
4375 | } |
4376 | ||
4377 | /* mtspr */ | |
99e300ef | 4378 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 4379 | { |
45d827d2 | 4380 | void (*write_cb)(void *opaque, int sprn, int gprn); |
79aceca5 FB |
4381 | uint32_t sprn = SPR(ctx->opcode); |
4382 | ||
3fc6c082 | 4383 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4384 | if (ctx->mem_idx == 2) |
be147d08 | 4385 | write_cb = ctx->spr_cb[sprn].hea_write; |
76db3ba4 | 4386 | else if (ctx->mem_idx) |
3fc6c082 FB |
4387 | write_cb = ctx->spr_cb[sprn].oea_write; |
4388 | else | |
9a64fbe4 | 4389 | #endif |
3fc6c082 | 4390 | write_cb = ctx->spr_cb[sprn].uea_write; |
76a66253 JM |
4391 | if (likely(write_cb != NULL)) { |
4392 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 4393 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
4394 | } else { |
4395 | /* Privilege exception */ | |
c05541ee AB |
4396 | qemu_log("Trying to write privileged spr %d (0x%03x) at " |
4397 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4398 | printf("Trying to write privileged spr %d (0x%03x) at " | |
4399 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4400 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 4401 | } |
3fc6c082 FB |
4402 | } else { |
4403 | /* Not defined */ | |
c05541ee AB |
4404 | qemu_log("Trying to write invalid spr %d (0x%03x) at " |
4405 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4406 | printf("Trying to write invalid spr %d (0x%03x) at " | |
4407 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4408 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4409 | } |
79aceca5 FB |
4410 | } |
4411 | ||
4412 | /*** Cache management ***/ | |
99e300ef | 4413 | |
54623277 | 4414 | /* dcbf */ |
99e300ef | 4415 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 4416 | { |
dac454af | 4417 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
4418 | TCGv t0; |
4419 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4420 | t0 = tcg_temp_new(); | |
4421 | gen_addr_reg_index(ctx, t0); | |
4422 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4423 | tcg_temp_free(t0); |
79aceca5 FB |
4424 | } |
4425 | ||
4426 | /* dcbi (Supervisor only) */ | |
99e300ef | 4427 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4428 | { |
a541f297 | 4429 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4430 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a541f297 | 4431 | #else |
b61f2753 | 4432 | TCGv EA, val; |
76db3ba4 | 4433 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4434 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4435 | return; |
9a64fbe4 | 4436 | } |
a7812ae4 | 4437 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4438 | gen_set_access_type(ctx, ACCESS_CACHE); |
4439 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4440 | val = tcg_temp_new(); |
76a66253 | 4441 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4442 | gen_qemu_ld8u(ctx, val, EA); |
4443 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4444 | tcg_temp_free(val); |
4445 | tcg_temp_free(EA); | |
a541f297 | 4446 | #endif |
79aceca5 FB |
4447 | } |
4448 | ||
4449 | /* dcdst */ | |
99e300ef | 4450 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4451 | { |
76a66253 | 4452 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4453 | TCGv t0; |
4454 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4455 | t0 = tcg_temp_new(); | |
4456 | gen_addr_reg_index(ctx, t0); | |
4457 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4458 | tcg_temp_free(t0); |
79aceca5 FB |
4459 | } |
4460 | ||
4461 | /* dcbt */ | |
99e300ef | 4462 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4463 | { |
0db1b20e | 4464 | /* interpreted as no-op */ |
76a66253 JM |
4465 | /* XXX: specification say this is treated as a load by the MMU |
4466 | * but does not generate any exception | |
4467 | */ | |
79aceca5 FB |
4468 | } |
4469 | ||
4470 | /* dcbtst */ | |
99e300ef | 4471 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4472 | { |
0db1b20e | 4473 | /* interpreted as no-op */ |
76a66253 JM |
4474 | /* XXX: specification say this is treated as a load by the MMU |
4475 | * but does not generate any exception | |
4476 | */ | |
79aceca5 FB |
4477 | } |
4478 | ||
4479 | /* dcbz */ | |
99e300ef | 4480 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4481 | { |
8e33944f AG |
4482 | TCGv tcgv_addr; |
4483 | TCGv_i32 tcgv_is_dcbzl; | |
4484 | int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0; | |
d63001d1 | 4485 | |
76db3ba4 | 4486 | gen_set_access_type(ctx, ACCESS_CACHE); |
799a8c8d AJ |
4487 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4488 | gen_update_nip(ctx, ctx->nip - 4); | |
8e33944f AG |
4489 | tcgv_addr = tcg_temp_new(); |
4490 | tcgv_is_dcbzl = tcg_const_i32(is_dcbzl); | |
4491 | ||
4492 | gen_addr_reg_index(ctx, tcgv_addr); | |
4493 | gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl); | |
4494 | ||
4495 | tcg_temp_free(tcgv_addr); | |
4496 | tcg_temp_free_i32(tcgv_is_dcbzl); | |
79aceca5 FB |
4497 | } |
4498 | ||
ae1c1a3d | 4499 | /* dst / dstt */ |
99e300ef | 4500 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4501 | { |
4502 | if (rA(ctx->opcode) == 0) { | |
4503 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4504 | } else { | |
4505 | /* interpreted as no-op */ | |
4506 | } | |
4507 | } | |
4508 | ||
4509 | /* dstst /dststt */ | |
99e300ef | 4510 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4511 | { |
4512 | if (rA(ctx->opcode) == 0) { | |
4513 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4514 | } else { | |
4515 | /* interpreted as no-op */ | |
4516 | } | |
4517 | ||
4518 | } | |
4519 | ||
4520 | /* dss / dssall */ | |
99e300ef | 4521 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4522 | { |
4523 | /* interpreted as no-op */ | |
4524 | } | |
4525 | ||
79aceca5 | 4526 | /* icbi */ |
99e300ef | 4527 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4528 | { |
76db3ba4 AJ |
4529 | TCGv t0; |
4530 | gen_set_access_type(ctx, ACCESS_CACHE); | |
30032c94 JM |
4531 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4532 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4533 | t0 = tcg_temp_new(); |
4534 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4535 | gen_helper_icbi(cpu_env, t0); |
37d269df | 4536 | tcg_temp_free(t0); |
79aceca5 FB |
4537 | } |
4538 | ||
4539 | /* Optional: */ | |
4540 | /* dcba */ | |
99e300ef | 4541 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4542 | { |
0db1b20e JM |
4543 | /* interpreted as no-op */ |
4544 | /* XXX: specification say this is treated as a store by the MMU | |
4545 | * but does not generate any exception | |
4546 | */ | |
79aceca5 FB |
4547 | } |
4548 | ||
4549 | /*** Segment register manipulation ***/ | |
4550 | /* Supervisor only: */ | |
99e300ef | 4551 | |
54623277 | 4552 | /* mfsr */ |
99e300ef | 4553 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4554 | { |
9a64fbe4 | 4555 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4556 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4557 | #else |
74d37793 | 4558 | TCGv t0; |
76db3ba4 | 4559 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4560 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4561 | return; |
9a64fbe4 | 4562 | } |
74d37793 | 4563 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4564 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4565 | tcg_temp_free(t0); |
9a64fbe4 | 4566 | #endif |
79aceca5 FB |
4567 | } |
4568 | ||
4569 | /* mfsrin */ | |
99e300ef | 4570 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4571 | { |
9a64fbe4 | 4572 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4573 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4574 | #else |
74d37793 | 4575 | TCGv t0; |
76db3ba4 | 4576 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4577 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4578 | return; |
9a64fbe4 | 4579 | } |
74d37793 AJ |
4580 | t0 = tcg_temp_new(); |
4581 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4582 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4583 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4584 | tcg_temp_free(t0); |
9a64fbe4 | 4585 | #endif |
79aceca5 FB |
4586 | } |
4587 | ||
4588 | /* mtsr */ | |
99e300ef | 4589 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4590 | { |
9a64fbe4 | 4591 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4592 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4593 | #else |
74d37793 | 4594 | TCGv t0; |
76db3ba4 | 4595 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4596 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4597 | return; |
9a64fbe4 | 4598 | } |
74d37793 | 4599 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4600 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4601 | tcg_temp_free(t0); |
9a64fbe4 | 4602 | #endif |
79aceca5 FB |
4603 | } |
4604 | ||
4605 | /* mtsrin */ | |
99e300ef | 4606 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4607 | { |
9a64fbe4 | 4608 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4609 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4610 | #else |
74d37793 | 4611 | TCGv t0; |
76db3ba4 | 4612 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4613 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4614 | return; |
9a64fbe4 | 4615 | } |
74d37793 AJ |
4616 | t0 = tcg_temp_new(); |
4617 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4618 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4619 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); |
74d37793 | 4620 | tcg_temp_free(t0); |
9a64fbe4 | 4621 | #endif |
79aceca5 FB |
4622 | } |
4623 | ||
12de9a39 JM |
4624 | #if defined(TARGET_PPC64) |
4625 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4626 | |
54623277 | 4627 | /* mfsr */ |
e8eaa2c0 | 4628 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4629 | { |
4630 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4631 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4632 | #else |
74d37793 | 4633 | TCGv t0; |
76db3ba4 | 4634 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4635 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4636 | return; |
4637 | } | |
74d37793 | 4638 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4639 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4640 | tcg_temp_free(t0); |
12de9a39 JM |
4641 | #endif |
4642 | } | |
4643 | ||
4644 | /* mfsrin */ | |
e8eaa2c0 | 4645 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4646 | { |
4647 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4648 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4649 | #else |
74d37793 | 4650 | TCGv t0; |
76db3ba4 | 4651 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4652 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4653 | return; |
4654 | } | |
74d37793 AJ |
4655 | t0 = tcg_temp_new(); |
4656 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4657 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4658 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4659 | tcg_temp_free(t0); |
12de9a39 JM |
4660 | #endif |
4661 | } | |
4662 | ||
4663 | /* mtsr */ | |
e8eaa2c0 | 4664 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4665 | { |
4666 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4667 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4668 | #else |
74d37793 | 4669 | TCGv t0; |
76db3ba4 | 4670 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4671 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4672 | return; |
4673 | } | |
74d37793 | 4674 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4675 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4676 | tcg_temp_free(t0); |
12de9a39 JM |
4677 | #endif |
4678 | } | |
4679 | ||
4680 | /* mtsrin */ | |
e8eaa2c0 | 4681 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4682 | { |
4683 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4684 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4685 | #else |
74d37793 | 4686 | TCGv t0; |
76db3ba4 | 4687 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4688 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4689 | return; |
4690 | } | |
74d37793 AJ |
4691 | t0 = tcg_temp_new(); |
4692 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4693 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4694 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4695 | tcg_temp_free(t0); |
12de9a39 JM |
4696 | #endif |
4697 | } | |
f6b868fc BS |
4698 | |
4699 | /* slbmte */ | |
e8eaa2c0 | 4700 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
4701 | { |
4702 | #if defined(CONFIG_USER_ONLY) | |
4703 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4704 | #else | |
4705 | if (unlikely(!ctx->mem_idx)) { | |
4706 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4707 | return; | |
4708 | } | |
c6c7cf05 BS |
4709 | gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)], |
4710 | cpu_gpr[rS(ctx->opcode)]); | |
f6b868fc BS |
4711 | #endif |
4712 | } | |
4713 | ||
efdef95f DG |
4714 | static void gen_slbmfee(DisasContext *ctx) |
4715 | { | |
4716 | #if defined(CONFIG_USER_ONLY) | |
4717 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4718 | #else | |
4719 | if (unlikely(!ctx->mem_idx)) { | |
4720 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4721 | return; | |
4722 | } | |
c6c7cf05 | 4723 | gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4724 | cpu_gpr[rB(ctx->opcode)]); |
4725 | #endif | |
4726 | } | |
4727 | ||
4728 | static void gen_slbmfev(DisasContext *ctx) | |
4729 | { | |
4730 | #if defined(CONFIG_USER_ONLY) | |
4731 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4732 | #else | |
4733 | if (unlikely(!ctx->mem_idx)) { | |
4734 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4735 | return; | |
4736 | } | |
c6c7cf05 | 4737 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4738 | cpu_gpr[rB(ctx->opcode)]); |
4739 | #endif | |
4740 | } | |
12de9a39 JM |
4741 | #endif /* defined(TARGET_PPC64) */ |
4742 | ||
79aceca5 | 4743 | /*** Lookaside buffer management ***/ |
76db3ba4 | 4744 | /* Optional & mem_idx only: */ |
99e300ef | 4745 | |
54623277 | 4746 | /* tlbia */ |
99e300ef | 4747 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4748 | { |
9a64fbe4 | 4749 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4750 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4751 | #else |
76db3ba4 | 4752 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4753 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4754 | return; |
9a64fbe4 | 4755 | } |
c6c7cf05 | 4756 | gen_helper_tlbia(cpu_env); |
9a64fbe4 | 4757 | #endif |
79aceca5 FB |
4758 | } |
4759 | ||
bf14b1ce | 4760 | /* tlbiel */ |
99e300ef | 4761 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4762 | { |
4763 | #if defined(CONFIG_USER_ONLY) | |
4764 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4765 | #else | |
4766 | if (unlikely(!ctx->mem_idx)) { | |
4767 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4768 | return; | |
4769 | } | |
c6c7cf05 | 4770 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
bf14b1ce BS |
4771 | #endif |
4772 | } | |
4773 | ||
79aceca5 | 4774 | /* tlbie */ |
99e300ef | 4775 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4776 | { |
9a64fbe4 | 4777 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4778 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4779 | #else |
76db3ba4 | 4780 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4781 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4782 | return; |
9a64fbe4 | 4783 | } |
9ca3f7f3 | 4784 | if (NARROW_MODE(ctx)) { |
74d37793 AJ |
4785 | TCGv t0 = tcg_temp_new(); |
4786 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 4787 | gen_helper_tlbie(cpu_env, t0); |
74d37793 | 4788 | tcg_temp_free(t0); |
9ca3f7f3 | 4789 | } else { |
c6c7cf05 | 4790 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9ca3f7f3 | 4791 | } |
9a64fbe4 | 4792 | #endif |
79aceca5 FB |
4793 | } |
4794 | ||
4795 | /* tlbsync */ | |
99e300ef | 4796 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4797 | { |
9a64fbe4 | 4798 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4799 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4800 | #else |
76db3ba4 | 4801 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4802 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4803 | return; |
9a64fbe4 FB |
4804 | } |
4805 | /* This has no effect: it should ensure that all previous | |
4806 | * tlbie have completed | |
4807 | */ | |
e06fcd75 | 4808 | gen_stop_exception(ctx); |
9a64fbe4 | 4809 | #endif |
79aceca5 FB |
4810 | } |
4811 | ||
426613db JM |
4812 | #if defined(TARGET_PPC64) |
4813 | /* slbia */ | |
99e300ef | 4814 | static void gen_slbia(DisasContext *ctx) |
426613db JM |
4815 | { |
4816 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4817 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4818 | #else |
76db3ba4 | 4819 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4820 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4821 | return; |
4822 | } | |
c6c7cf05 | 4823 | gen_helper_slbia(cpu_env); |
426613db JM |
4824 | #endif |
4825 | } | |
4826 | ||
4827 | /* slbie */ | |
99e300ef | 4828 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4829 | { |
4830 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4831 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4832 | #else |
76db3ba4 | 4833 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4834 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4835 | return; |
4836 | } | |
c6c7cf05 | 4837 | gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
426613db JM |
4838 | #endif |
4839 | } | |
4840 | #endif | |
4841 | ||
79aceca5 FB |
4842 | /*** External control ***/ |
4843 | /* Optional: */ | |
99e300ef | 4844 | |
54623277 | 4845 | /* eciwx */ |
99e300ef | 4846 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4847 | { |
76db3ba4 | 4848 | TCGv t0; |
fa407c03 | 4849 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4850 | gen_set_access_type(ctx, ACCESS_EXT); |
4851 | t0 = tcg_temp_new(); | |
4852 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4853 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4854 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4855 | tcg_temp_free(t0); |
76a66253 JM |
4856 | } |
4857 | ||
4858 | /* ecowx */ | |
99e300ef | 4859 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4860 | { |
76db3ba4 | 4861 | TCGv t0; |
fa407c03 | 4862 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4863 | gen_set_access_type(ctx, ACCESS_EXT); |
4864 | t0 = tcg_temp_new(); | |
4865 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4866 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4867 | gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4868 | tcg_temp_free(t0); |
76a66253 JM |
4869 | } |
4870 | ||
4871 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4872 | |
54623277 | 4873 | /* abs - abs. */ |
99e300ef | 4874 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4875 | { |
22e0e173 AJ |
4876 | int l1 = gen_new_label(); |
4877 | int l2 = gen_new_label(); | |
4878 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4879 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4880 | tcg_gen_br(l2); | |
4881 | gen_set_label(l1); | |
4882 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4883 | gen_set_label(l2); | |
76a66253 | 4884 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4885 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4886 | } |
4887 | ||
4888 | /* abso - abso. */ | |
99e300ef | 4889 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4890 | { |
22e0e173 AJ |
4891 | int l1 = gen_new_label(); |
4892 | int l2 = gen_new_label(); | |
4893 | int l3 = gen_new_label(); | |
4894 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 4895 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4896 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); |
4897 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
da91a00f RH |
4898 | tcg_gen_movi_tl(cpu_ov, 1); |
4899 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
4900 | tcg_gen_br(l2); |
4901 | gen_set_label(l1); | |
4902 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4903 | tcg_gen_br(l3); | |
4904 | gen_set_label(l2); | |
4905 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4906 | gen_set_label(l3); | |
76a66253 | 4907 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4908 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4909 | } |
4910 | ||
4911 | /* clcs */ | |
99e300ef | 4912 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 4913 | { |
22e0e173 | 4914 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
d523dd00 | 4915 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 4916 | tcg_temp_free_i32(t0); |
c7697e1f | 4917 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
4918 | } |
4919 | ||
4920 | /* div - div. */ | |
99e300ef | 4921 | static void gen_div(DisasContext *ctx) |
76a66253 | 4922 | { |
d15f74fb BS |
4923 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4924 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4925 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4926 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4927 | } |
4928 | ||
4929 | /* divo - divo. */ | |
99e300ef | 4930 | static void gen_divo(DisasContext *ctx) |
76a66253 | 4931 | { |
d15f74fb BS |
4932 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4933 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4934 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4935 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4936 | } |
4937 | ||
4938 | /* divs - divs. */ | |
99e300ef | 4939 | static void gen_divs(DisasContext *ctx) |
76a66253 | 4940 | { |
d15f74fb BS |
4941 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4942 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4943 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4944 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4945 | } |
4946 | ||
4947 | /* divso - divso. */ | |
99e300ef | 4948 | static void gen_divso(DisasContext *ctx) |
76a66253 | 4949 | { |
d15f74fb BS |
4950 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env, |
4951 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4952 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4953 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4954 | } |
4955 | ||
4956 | /* doz - doz. */ | |
99e300ef | 4957 | static void gen_doz(DisasContext *ctx) |
76a66253 | 4958 | { |
22e0e173 AJ |
4959 | int l1 = gen_new_label(); |
4960 | int l2 = gen_new_label(); | |
4961 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4962 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4963 | tcg_gen_br(l2); | |
4964 | gen_set_label(l1); | |
4965 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4966 | gen_set_label(l2); | |
76a66253 | 4967 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4968 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4969 | } |
4970 | ||
4971 | /* dozo - dozo. */ | |
99e300ef | 4972 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 4973 | { |
22e0e173 AJ |
4974 | int l1 = gen_new_label(); |
4975 | int l2 = gen_new_label(); | |
4976 | TCGv t0 = tcg_temp_new(); | |
4977 | TCGv t1 = tcg_temp_new(); | |
4978 | TCGv t2 = tcg_temp_new(); | |
4979 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 4980 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4981 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); |
4982 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4983 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4984 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
4985 | tcg_gen_andc_tl(t1, t1, t2); | |
4986 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4987 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
da91a00f RH |
4988 | tcg_gen_movi_tl(cpu_ov, 1); |
4989 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
4990 | tcg_gen_br(l2); |
4991 | gen_set_label(l1); | |
4992 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4993 | gen_set_label(l2); | |
4994 | tcg_temp_free(t0); | |
4995 | tcg_temp_free(t1); | |
4996 | tcg_temp_free(t2); | |
76a66253 | 4997 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4998 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4999 | } |
5000 | ||
5001 | /* dozi */ | |
99e300ef | 5002 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 5003 | { |
22e0e173 AJ |
5004 | target_long simm = SIMM(ctx->opcode); |
5005 | int l1 = gen_new_label(); | |
5006 | int l2 = gen_new_label(); | |
5007 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); | |
5008 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
5009 | tcg_gen_br(l2); | |
5010 | gen_set_label(l1); | |
5011 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
5012 | gen_set_label(l2); | |
5013 | if (unlikely(Rc(ctx->opcode) != 0)) | |
5014 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
5015 | } |
5016 | ||
76a66253 | 5017 | /* lscbx - lscbx. */ |
99e300ef | 5018 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 5019 | { |
bdb4b689 AJ |
5020 | TCGv t0 = tcg_temp_new(); |
5021 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
5022 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
5023 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 5024 | |
76db3ba4 | 5025 | gen_addr_reg_index(ctx, t0); |
76a66253 | 5026 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 5027 | gen_update_nip(ctx, ctx->nip - 4); |
2f5a189c | 5028 | gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3); |
bdb4b689 AJ |
5029 | tcg_temp_free_i32(t1); |
5030 | tcg_temp_free_i32(t2); | |
5031 | tcg_temp_free_i32(t3); | |
3d7b417e | 5032 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 5033 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 5034 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
5035 | gen_set_Rc0(ctx, t0); |
5036 | tcg_temp_free(t0); | |
76a66253 JM |
5037 | } |
5038 | ||
5039 | /* maskg - maskg. */ | |
99e300ef | 5040 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 5041 | { |
22e0e173 AJ |
5042 | int l1 = gen_new_label(); |
5043 | TCGv t0 = tcg_temp_new(); | |
5044 | TCGv t1 = tcg_temp_new(); | |
5045 | TCGv t2 = tcg_temp_new(); | |
5046 | TCGv t3 = tcg_temp_new(); | |
5047 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
5048 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5049 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
5050 | tcg_gen_addi_tl(t2, t0, 1); | |
5051 | tcg_gen_shr_tl(t2, t3, t2); | |
5052 | tcg_gen_shr_tl(t3, t3, t1); | |
5053 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
5054 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
5055 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5056 | gen_set_label(l1); | |
5057 | tcg_temp_free(t0); | |
5058 | tcg_temp_free(t1); | |
5059 | tcg_temp_free(t2); | |
5060 | tcg_temp_free(t3); | |
76a66253 | 5061 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5062 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5063 | } |
5064 | ||
5065 | /* maskir - maskir. */ | |
99e300ef | 5066 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 5067 | { |
22e0e173 AJ |
5068 | TCGv t0 = tcg_temp_new(); |
5069 | TCGv t1 = tcg_temp_new(); | |
5070 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
5071 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
5072 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5073 | tcg_temp_free(t0); | |
5074 | tcg_temp_free(t1); | |
76a66253 | 5075 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5076 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5077 | } |
5078 | ||
5079 | /* mul - mul. */ | |
99e300ef | 5080 | static void gen_mul(DisasContext *ctx) |
76a66253 | 5081 | { |
22e0e173 AJ |
5082 | TCGv_i64 t0 = tcg_temp_new_i64(); |
5083 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
5084 | TCGv t2 = tcg_temp_new(); | |
5085 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
5086 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
5087 | tcg_gen_mul_i64(t0, t0, t1); | |
5088 | tcg_gen_trunc_i64_tl(t2, t0); | |
5089 | gen_store_spr(SPR_MQ, t2); | |
5090 | tcg_gen_shri_i64(t1, t0, 32); | |
5091 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
5092 | tcg_temp_free_i64(t0); | |
5093 | tcg_temp_free_i64(t1); | |
5094 | tcg_temp_free(t2); | |
76a66253 | 5095 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5096 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5097 | } |
5098 | ||
5099 | /* mulo - mulo. */ | |
99e300ef | 5100 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 5101 | { |
22e0e173 AJ |
5102 | int l1 = gen_new_label(); |
5103 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
5104 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
5105 | TCGv t2 = tcg_temp_new(); | |
5106 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5107 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
5108 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); |
5109 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
5110 | tcg_gen_mul_i64(t0, t0, t1); | |
5111 | tcg_gen_trunc_i64_tl(t2, t0); | |
5112 | gen_store_spr(SPR_MQ, t2); | |
5113 | tcg_gen_shri_i64(t1, t0, 32); | |
5114 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
5115 | tcg_gen_ext32s_i64(t1, t0); | |
5116 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
da91a00f RH |
5117 | tcg_gen_movi_tl(cpu_ov, 1); |
5118 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
5119 | gen_set_label(l1); |
5120 | tcg_temp_free_i64(t0); | |
5121 | tcg_temp_free_i64(t1); | |
5122 | tcg_temp_free(t2); | |
76a66253 | 5123 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5124 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5125 | } |
5126 | ||
5127 | /* nabs - nabs. */ | |
99e300ef | 5128 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 5129 | { |
22e0e173 AJ |
5130 | int l1 = gen_new_label(); |
5131 | int l2 = gen_new_label(); | |
5132 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
5133 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5134 | tcg_gen_br(l2); | |
5135 | gen_set_label(l1); | |
5136 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5137 | gen_set_label(l2); | |
76a66253 | 5138 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5139 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5140 | } |
5141 | ||
5142 | /* nabso - nabso. */ | |
99e300ef | 5143 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 5144 | { |
22e0e173 AJ |
5145 | int l1 = gen_new_label(); |
5146 | int l2 = gen_new_label(); | |
5147 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
5148 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5149 | tcg_gen_br(l2); | |
5150 | gen_set_label(l1); | |
5151 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5152 | gen_set_label(l2); | |
5153 | /* nabs never overflows */ | |
da91a00f | 5154 | tcg_gen_movi_tl(cpu_ov, 0); |
76a66253 | 5155 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5156 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5157 | } |
5158 | ||
5159 | /* rlmi - rlmi. */ | |
99e300ef | 5160 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 5161 | { |
7487953d AJ |
5162 | uint32_t mb = MB(ctx->opcode); |
5163 | uint32_t me = ME(ctx->opcode); | |
5164 | TCGv t0 = tcg_temp_new(); | |
5165 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5166 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5167 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
5168 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
5169 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
5170 | tcg_temp_free(t0); | |
76a66253 | 5171 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5172 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5173 | } |
5174 | ||
5175 | /* rrib - rrib. */ | |
99e300ef | 5176 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 5177 | { |
7487953d AJ |
5178 | TCGv t0 = tcg_temp_new(); |
5179 | TCGv t1 = tcg_temp_new(); | |
5180 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5181 | tcg_gen_movi_tl(t1, 0x80000000); | |
5182 | tcg_gen_shr_tl(t1, t1, t0); | |
5183 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5184 | tcg_gen_and_tl(t0, t0, t1); | |
5185 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
5186 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5187 | tcg_temp_free(t0); | |
5188 | tcg_temp_free(t1); | |
76a66253 | 5189 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5190 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5191 | } |
5192 | ||
5193 | /* sle - sle. */ | |
99e300ef | 5194 | static void gen_sle(DisasContext *ctx) |
76a66253 | 5195 | { |
7487953d AJ |
5196 | TCGv t0 = tcg_temp_new(); |
5197 | TCGv t1 = tcg_temp_new(); | |
5198 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5199 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5200 | tcg_gen_subfi_tl(t1, 32, t1); | |
5201 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5202 | tcg_gen_or_tl(t1, t0, t1); | |
5203 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5204 | gen_store_spr(SPR_MQ, t1); | |
5205 | tcg_temp_free(t0); | |
5206 | tcg_temp_free(t1); | |
76a66253 | 5207 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5208 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5209 | } |
5210 | ||
5211 | /* sleq - sleq. */ | |
99e300ef | 5212 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 5213 | { |
7487953d AJ |
5214 | TCGv t0 = tcg_temp_new(); |
5215 | TCGv t1 = tcg_temp_new(); | |
5216 | TCGv t2 = tcg_temp_new(); | |
5217 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5218 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
5219 | tcg_gen_shl_tl(t2, t2, t0); | |
5220 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5221 | gen_load_spr(t1, SPR_MQ); | |
5222 | gen_store_spr(SPR_MQ, t0); | |
5223 | tcg_gen_and_tl(t0, t0, t2); | |
5224 | tcg_gen_andc_tl(t1, t1, t2); | |
5225 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5226 | tcg_temp_free(t0); | |
5227 | tcg_temp_free(t1); | |
5228 | tcg_temp_free(t2); | |
76a66253 | 5229 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5230 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5231 | } |
5232 | ||
5233 | /* sliq - sliq. */ | |
99e300ef | 5234 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 5235 | { |
7487953d AJ |
5236 | int sh = SH(ctx->opcode); |
5237 | TCGv t0 = tcg_temp_new(); | |
5238 | TCGv t1 = tcg_temp_new(); | |
5239 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5240 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5241 | tcg_gen_or_tl(t1, t0, t1); | |
5242 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5243 | gen_store_spr(SPR_MQ, t1); | |
5244 | tcg_temp_free(t0); | |
5245 | tcg_temp_free(t1); | |
76a66253 | 5246 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5247 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5248 | } |
5249 | ||
5250 | /* slliq - slliq. */ | |
99e300ef | 5251 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 5252 | { |
7487953d AJ |
5253 | int sh = SH(ctx->opcode); |
5254 | TCGv t0 = tcg_temp_new(); | |
5255 | TCGv t1 = tcg_temp_new(); | |
5256 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5257 | gen_load_spr(t1, SPR_MQ); | |
5258 | gen_store_spr(SPR_MQ, t0); | |
5259 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
5260 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
5261 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5262 | tcg_temp_free(t0); | |
5263 | tcg_temp_free(t1); | |
76a66253 | 5264 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5265 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5266 | } |
5267 | ||
5268 | /* sllq - sllq. */ | |
99e300ef | 5269 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 5270 | { |
7487953d AJ |
5271 | int l1 = gen_new_label(); |
5272 | int l2 = gen_new_label(); | |
5273 | TCGv t0 = tcg_temp_local_new(); | |
5274 | TCGv t1 = tcg_temp_local_new(); | |
5275 | TCGv t2 = tcg_temp_local_new(); | |
5276 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5277 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5278 | tcg_gen_shl_tl(t1, t1, t2); | |
5279 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5280 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5281 | gen_load_spr(t0, SPR_MQ); | |
5282 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5283 | tcg_gen_br(l2); | |
5284 | gen_set_label(l1); | |
5285 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5286 | gen_load_spr(t2, SPR_MQ); | |
5287 | tcg_gen_andc_tl(t1, t2, t1); | |
5288 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5289 | gen_set_label(l2); | |
5290 | tcg_temp_free(t0); | |
5291 | tcg_temp_free(t1); | |
5292 | tcg_temp_free(t2); | |
76a66253 | 5293 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5294 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5295 | } |
5296 | ||
5297 | /* slq - slq. */ | |
99e300ef | 5298 | static void gen_slq(DisasContext *ctx) |
76a66253 | 5299 | { |
7487953d AJ |
5300 | int l1 = gen_new_label(); |
5301 | TCGv t0 = tcg_temp_new(); | |
5302 | TCGv t1 = tcg_temp_new(); | |
5303 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5304 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5305 | tcg_gen_subfi_tl(t1, 32, t1); | |
5306 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5307 | tcg_gen_or_tl(t1, t0, t1); | |
5308 | gen_store_spr(SPR_MQ, t1); | |
5309 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5310 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5311 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
5312 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5313 | gen_set_label(l1); | |
5314 | tcg_temp_free(t0); | |
5315 | tcg_temp_free(t1); | |
76a66253 | 5316 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5317 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5318 | } |
5319 | ||
d9bce9d9 | 5320 | /* sraiq - sraiq. */ |
99e300ef | 5321 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 5322 | { |
7487953d AJ |
5323 | int sh = SH(ctx->opcode); |
5324 | int l1 = gen_new_label(); | |
5325 | TCGv t0 = tcg_temp_new(); | |
5326 | TCGv t1 = tcg_temp_new(); | |
5327 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5328 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5329 | tcg_gen_or_tl(t0, t0, t1); | |
5330 | gen_store_spr(SPR_MQ, t0); | |
da91a00f | 5331 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5332 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); |
5333 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
da91a00f | 5334 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5335 | gen_set_label(l1); |
5336 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
5337 | tcg_temp_free(t0); | |
5338 | tcg_temp_free(t1); | |
76a66253 | 5339 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5340 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5341 | } |
5342 | ||
5343 | /* sraq - sraq. */ | |
99e300ef | 5344 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 5345 | { |
7487953d AJ |
5346 | int l1 = gen_new_label(); |
5347 | int l2 = gen_new_label(); | |
5348 | TCGv t0 = tcg_temp_new(); | |
5349 | TCGv t1 = tcg_temp_local_new(); | |
5350 | TCGv t2 = tcg_temp_local_new(); | |
5351 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5352 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5353 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
5354 | tcg_gen_subfi_tl(t2, 32, t2); | |
5355 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
5356 | tcg_gen_or_tl(t0, t0, t2); | |
5357 | gen_store_spr(SPR_MQ, t0); | |
5358 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5359 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
5360 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
5361 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
5362 | gen_set_label(l1); | |
5363 | tcg_temp_free(t0); | |
5364 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
da91a00f | 5365 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5366 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); |
5367 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
da91a00f | 5368 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5369 | gen_set_label(l2); |
5370 | tcg_temp_free(t1); | |
5371 | tcg_temp_free(t2); | |
76a66253 | 5372 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5373 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5374 | } |
5375 | ||
5376 | /* sre - sre. */ | |
99e300ef | 5377 | static void gen_sre(DisasContext *ctx) |
76a66253 | 5378 | { |
7487953d AJ |
5379 | TCGv t0 = tcg_temp_new(); |
5380 | TCGv t1 = tcg_temp_new(); | |
5381 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5382 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5383 | tcg_gen_subfi_tl(t1, 32, t1); | |
5384 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5385 | tcg_gen_or_tl(t1, t0, t1); | |
5386 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5387 | gen_store_spr(SPR_MQ, t1); | |
5388 | tcg_temp_free(t0); | |
5389 | tcg_temp_free(t1); | |
76a66253 | 5390 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5391 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5392 | } |
5393 | ||
5394 | /* srea - srea. */ | |
99e300ef | 5395 | static void gen_srea(DisasContext *ctx) |
76a66253 | 5396 | { |
7487953d AJ |
5397 | TCGv t0 = tcg_temp_new(); |
5398 | TCGv t1 = tcg_temp_new(); | |
5399 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5400 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5401 | gen_store_spr(SPR_MQ, t0); | |
5402 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
5403 | tcg_temp_free(t0); | |
5404 | tcg_temp_free(t1); | |
76a66253 | 5405 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5406 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5407 | } |
5408 | ||
5409 | /* sreq */ | |
99e300ef | 5410 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 5411 | { |
7487953d AJ |
5412 | TCGv t0 = tcg_temp_new(); |
5413 | TCGv t1 = tcg_temp_new(); | |
5414 | TCGv t2 = tcg_temp_new(); | |
5415 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5416 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5417 | tcg_gen_shr_tl(t1, t1, t0); | |
5418 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5419 | gen_load_spr(t2, SPR_MQ); | |
5420 | gen_store_spr(SPR_MQ, t0); | |
5421 | tcg_gen_and_tl(t0, t0, t1); | |
5422 | tcg_gen_andc_tl(t2, t2, t1); | |
5423 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5424 | tcg_temp_free(t0); | |
5425 | tcg_temp_free(t1); | |
5426 | tcg_temp_free(t2); | |
76a66253 | 5427 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5428 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5429 | } |
5430 | ||
5431 | /* sriq */ | |
99e300ef | 5432 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5433 | { |
7487953d AJ |
5434 | int sh = SH(ctx->opcode); |
5435 | TCGv t0 = tcg_temp_new(); | |
5436 | TCGv t1 = tcg_temp_new(); | |
5437 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5438 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5439 | tcg_gen_or_tl(t1, t0, t1); | |
5440 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5441 | gen_store_spr(SPR_MQ, t1); | |
5442 | tcg_temp_free(t0); | |
5443 | tcg_temp_free(t1); | |
76a66253 | 5444 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5445 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5446 | } |
5447 | ||
5448 | /* srliq */ | |
99e300ef | 5449 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5450 | { |
7487953d AJ |
5451 | int sh = SH(ctx->opcode); |
5452 | TCGv t0 = tcg_temp_new(); | |
5453 | TCGv t1 = tcg_temp_new(); | |
5454 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5455 | gen_load_spr(t1, SPR_MQ); | |
5456 | gen_store_spr(SPR_MQ, t0); | |
5457 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5458 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5459 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5460 | tcg_temp_free(t0); | |
5461 | tcg_temp_free(t1); | |
76a66253 | 5462 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5463 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5464 | } |
5465 | ||
5466 | /* srlq */ | |
99e300ef | 5467 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5468 | { |
7487953d AJ |
5469 | int l1 = gen_new_label(); |
5470 | int l2 = gen_new_label(); | |
5471 | TCGv t0 = tcg_temp_local_new(); | |
5472 | TCGv t1 = tcg_temp_local_new(); | |
5473 | TCGv t2 = tcg_temp_local_new(); | |
5474 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5475 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5476 | tcg_gen_shr_tl(t2, t1, t2); | |
5477 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5478 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5479 | gen_load_spr(t0, SPR_MQ); | |
5480 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5481 | tcg_gen_br(l2); | |
5482 | gen_set_label(l1); | |
5483 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5484 | tcg_gen_and_tl(t0, t0, t2); | |
5485 | gen_load_spr(t1, SPR_MQ); | |
5486 | tcg_gen_andc_tl(t1, t1, t2); | |
5487 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5488 | gen_set_label(l2); | |
5489 | tcg_temp_free(t0); | |
5490 | tcg_temp_free(t1); | |
5491 | tcg_temp_free(t2); | |
76a66253 | 5492 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5493 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5494 | } |
5495 | ||
5496 | /* srq */ | |
99e300ef | 5497 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5498 | { |
7487953d AJ |
5499 | int l1 = gen_new_label(); |
5500 | TCGv t0 = tcg_temp_new(); | |
5501 | TCGv t1 = tcg_temp_new(); | |
5502 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5503 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5504 | tcg_gen_subfi_tl(t1, 32, t1); | |
5505 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5506 | tcg_gen_or_tl(t1, t0, t1); | |
5507 | gen_store_spr(SPR_MQ, t1); | |
5508 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5509 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5510 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5511 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5512 | gen_set_label(l1); | |
5513 | tcg_temp_free(t0); | |
5514 | tcg_temp_free(t1); | |
76a66253 | 5515 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5516 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5517 | } |
5518 | ||
5519 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5520 | |
54623277 | 5521 | /* dsa */ |
99e300ef | 5522 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5523 | { |
5524 | /* XXX: TODO */ | |
e06fcd75 | 5525 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5526 | } |
5527 | ||
5528 | /* esa */ | |
99e300ef | 5529 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5530 | { |
5531 | /* XXX: TODO */ | |
e06fcd75 | 5532 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5533 | } |
5534 | ||
5535 | /* mfrom */ | |
99e300ef | 5536 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5537 | { |
5538 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5539 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5540 | #else |
76db3ba4 | 5541 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5542 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5543 | return; |
5544 | } | |
cf02a65c | 5545 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5546 | #endif |
5547 | } | |
5548 | ||
5549 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5550 | |
54623277 | 5551 | /* tlbld */ |
e8eaa2c0 | 5552 | static void gen_tlbld_6xx(DisasContext *ctx) |
76a66253 JM |
5553 | { |
5554 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5555 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5556 | #else |
76db3ba4 | 5557 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5558 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5559 | return; |
5560 | } | |
c6c7cf05 | 5561 | gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5562 | #endif |
5563 | } | |
5564 | ||
5565 | /* tlbli */ | |
e8eaa2c0 | 5566 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5567 | { |
5568 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5569 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5570 | #else |
76db3ba4 | 5571 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5572 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5573 | return; |
5574 | } | |
c6c7cf05 | 5575 | gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5576 | #endif |
5577 | } | |
5578 | ||
7dbe11ac | 5579 | /* 74xx TLB management */ |
e8eaa2c0 | 5580 | |
54623277 | 5581 | /* tlbld */ |
e8eaa2c0 | 5582 | static void gen_tlbld_74xx(DisasContext *ctx) |
7dbe11ac JM |
5583 | { |
5584 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5585 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5586 | #else |
76db3ba4 | 5587 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5588 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5589 | return; |
5590 | } | |
c6c7cf05 | 5591 | gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5592 | #endif |
5593 | } | |
5594 | ||
5595 | /* tlbli */ | |
e8eaa2c0 | 5596 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5597 | { |
5598 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5599 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5600 | #else |
76db3ba4 | 5601 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5602 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5603 | return; |
5604 | } | |
c6c7cf05 | 5605 | gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5606 | #endif |
5607 | } | |
5608 | ||
76a66253 | 5609 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5610 | |
54623277 | 5611 | /* clf */ |
99e300ef | 5612 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5613 | { |
5614 | /* Cache line flush: implemented as no-op */ | |
5615 | } | |
5616 | ||
5617 | /* cli */ | |
99e300ef | 5618 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5619 | { |
7f75ffd3 | 5620 | /* Cache line invalidate: privileged and treated as no-op */ |
76a66253 | 5621 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5622 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5623 | #else |
76db3ba4 | 5624 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5625 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5626 | return; |
5627 | } | |
5628 | #endif | |
5629 | } | |
5630 | ||
5631 | /* dclst */ | |
99e300ef | 5632 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5633 | { |
5634 | /* Data cache line store: treated as no-op */ | |
5635 | } | |
5636 | ||
99e300ef | 5637 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5638 | { |
5639 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5640 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5641 | #else |
74d37793 AJ |
5642 | int ra = rA(ctx->opcode); |
5643 | int rd = rD(ctx->opcode); | |
5644 | TCGv t0; | |
76db3ba4 | 5645 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5646 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5647 | return; |
5648 | } | |
74d37793 | 5649 | t0 = tcg_temp_new(); |
76db3ba4 | 5650 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5651 | tcg_gen_shri_tl(t0, t0, 28); |
5652 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 5653 | gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0); |
74d37793 | 5654 | tcg_temp_free(t0); |
76a66253 | 5655 | if (ra != 0 && ra != rd) |
74d37793 | 5656 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
76a66253 JM |
5657 | #endif |
5658 | } | |
5659 | ||
99e300ef | 5660 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5661 | { |
5662 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5663 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5664 | #else |
22e0e173 | 5665 | TCGv t0; |
76db3ba4 | 5666 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5667 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5668 | return; |
5669 | } | |
22e0e173 | 5670 | t0 = tcg_temp_new(); |
76db3ba4 | 5671 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5672 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5673 | tcg_temp_free(t0); |
76a66253 JM |
5674 | #endif |
5675 | } | |
5676 | ||
99e300ef | 5677 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5678 | { |
5679 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5680 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5681 | #else |
76db3ba4 | 5682 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5683 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5684 | return; |
5685 | } | |
e5f17ac6 | 5686 | gen_helper_rfsvc(cpu_env); |
e06fcd75 | 5687 | gen_sync_exception(ctx); |
76a66253 JM |
5688 | #endif |
5689 | } | |
5690 | ||
5691 | /* svc is not implemented for now */ | |
5692 | ||
5693 | /* POWER2 specific instructions */ | |
5694 | /* Quad manipulation (load/store two floats at a time) */ | |
76a66253 JM |
5695 | |
5696 | /* lfq */ | |
99e300ef | 5697 | static void gen_lfq(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_imm_index(ctx, t0, 0); | |
5704 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5705 | gen_addr_add(ctx, t0, t0, 8); | |
5706 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5707 | tcg_temp_free(t0); |
76a66253 JM |
5708 | } |
5709 | ||
5710 | /* lfqu */ | |
99e300ef | 5711 | static void gen_lfqu(DisasContext *ctx) |
76a66253 JM |
5712 | { |
5713 | int ra = rA(ctx->opcode); | |
01a4afeb | 5714 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5715 | TCGv t0, t1; |
5716 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5717 | t0 = tcg_temp_new(); | |
5718 | t1 = tcg_temp_new(); | |
5719 | gen_addr_imm_index(ctx, t0, 0); | |
5720 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5721 | gen_addr_add(ctx, t1, t0, 8); | |
5722 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
76a66253 | 5723 | if (ra != 0) |
01a4afeb AJ |
5724 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5725 | tcg_temp_free(t0); | |
5726 | tcg_temp_free(t1); | |
76a66253 JM |
5727 | } |
5728 | ||
5729 | /* lfqux */ | |
99e300ef | 5730 | static void gen_lfqux(DisasContext *ctx) |
76a66253 JM |
5731 | { |
5732 | int ra = rA(ctx->opcode); | |
01a4afeb | 5733 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5734 | gen_set_access_type(ctx, ACCESS_FLOAT); |
5735 | TCGv t0, t1; | |
5736 | t0 = tcg_temp_new(); | |
5737 | gen_addr_reg_index(ctx, t0); | |
5738 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5739 | t1 = tcg_temp_new(); | |
5740 | gen_addr_add(ctx, t1, t0, 8); | |
5741 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5742 | tcg_temp_free(t1); | |
76a66253 | 5743 | if (ra != 0) |
01a4afeb AJ |
5744 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5745 | tcg_temp_free(t0); | |
76a66253 JM |
5746 | } |
5747 | ||
5748 | /* lfqx */ | |
99e300ef | 5749 | static void gen_lfqx(DisasContext *ctx) |
76a66253 | 5750 | { |
01a4afeb | 5751 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5752 | TCGv t0; |
5753 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5754 | t0 = tcg_temp_new(); | |
5755 | gen_addr_reg_index(ctx, t0); | |
5756 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5757 | gen_addr_add(ctx, t0, t0, 8); | |
5758 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5759 | tcg_temp_free(t0); |
76a66253 JM |
5760 | } |
5761 | ||
5762 | /* stfq */ | |
99e300ef | 5763 | static void gen_stfq(DisasContext *ctx) |
76a66253 | 5764 | { |
01a4afeb | 5765 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5766 | TCGv t0; |
5767 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5768 | t0 = tcg_temp_new(); | |
5769 | gen_addr_imm_index(ctx, t0, 0); | |
5770 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5771 | gen_addr_add(ctx, t0, t0, 8); | |
5772 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5773 | tcg_temp_free(t0); |
76a66253 JM |
5774 | } |
5775 | ||
5776 | /* stfqu */ | |
99e300ef | 5777 | static void gen_stfqu(DisasContext *ctx) |
76a66253 JM |
5778 | { |
5779 | int ra = rA(ctx->opcode); | |
01a4afeb | 5780 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5781 | TCGv t0, t1; |
5782 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5783 | t0 = tcg_temp_new(); | |
5784 | gen_addr_imm_index(ctx, t0, 0); | |
5785 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5786 | t1 = tcg_temp_new(); | |
5787 | gen_addr_add(ctx, t1, t0, 8); | |
5788 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5789 | tcg_temp_free(t1); | |
76a66253 | 5790 | if (ra != 0) |
01a4afeb AJ |
5791 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5792 | tcg_temp_free(t0); | |
76a66253 JM |
5793 | } |
5794 | ||
5795 | /* stfqux */ | |
99e300ef | 5796 | static void gen_stfqux(DisasContext *ctx) |
76a66253 JM |
5797 | { |
5798 | int ra = rA(ctx->opcode); | |
01a4afeb | 5799 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5800 | TCGv t0, t1; |
5801 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5802 | t0 = tcg_temp_new(); | |
5803 | gen_addr_reg_index(ctx, t0); | |
5804 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5805 | t1 = tcg_temp_new(); | |
5806 | gen_addr_add(ctx, t1, t0, 8); | |
5807 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5808 | tcg_temp_free(t1); | |
76a66253 | 5809 | if (ra != 0) |
01a4afeb AJ |
5810 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5811 | tcg_temp_free(t0); | |
76a66253 JM |
5812 | } |
5813 | ||
5814 | /* stfqx */ | |
99e300ef | 5815 | static void gen_stfqx(DisasContext *ctx) |
76a66253 | 5816 | { |
01a4afeb | 5817 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5818 | TCGv t0; |
5819 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5820 | t0 = tcg_temp_new(); | |
5821 | gen_addr_reg_index(ctx, t0); | |
5822 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5823 | gen_addr_add(ctx, t0, t0, 8); | |
5824 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5825 | tcg_temp_free(t0); |
76a66253 JM |
5826 | } |
5827 | ||
5828 | /* BookE specific instructions */ | |
99e300ef | 5829 | |
54623277 | 5830 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5831 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5832 | { |
5833 | /* XXX: TODO */ | |
e06fcd75 | 5834 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5835 | } |
5836 | ||
2662a059 | 5837 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5838 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5839 | { |
5840 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5841 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5842 | #else |
74d37793 | 5843 | TCGv t0; |
76db3ba4 | 5844 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5845 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5846 | return; |
5847 | } | |
ec72e276 | 5848 | t0 = tcg_temp_new(); |
76db3ba4 | 5849 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5850 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
74d37793 | 5851 | tcg_temp_free(t0); |
76a66253 JM |
5852 | #endif |
5853 | } | |
5854 | ||
5855 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5856 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5857 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5858 | { |
182608d4 AJ |
5859 | TCGv t0, t1; |
5860 | ||
a7812ae4 PB |
5861 | t0 = tcg_temp_local_new(); |
5862 | t1 = tcg_temp_local_new(); | |
182608d4 | 5863 | |
76a66253 JM |
5864 | switch (opc3 & 0x0D) { |
5865 | case 0x05: | |
5866 | /* macchw - macchw. - macchwo - macchwo. */ | |
5867 | /* macchws - macchws. - macchwso - macchwso. */ | |
5868 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5869 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5870 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5871 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5872 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5873 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5874 | break; |
5875 | case 0x04: | |
5876 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5877 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5878 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5879 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5880 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5881 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5882 | break; |
5883 | case 0x01: | |
5884 | /* machhw - machhw. - machhwo - machhwo. */ | |
5885 | /* machhws - machhws. - machhwso - machhwso. */ | |
5886 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5887 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5888 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5889 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5890 | tcg_gen_ext16s_tl(t0, t0); | |
5891 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5892 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5893 | break; |
5894 | case 0x00: | |
5895 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5896 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5897 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5898 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5899 | tcg_gen_ext16u_tl(t0, t0); | |
5900 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5901 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5902 | break; |
5903 | case 0x0D: | |
5904 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5905 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5906 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5907 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5908 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5909 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5910 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5911 | break; |
5912 | case 0x0C: | |
5913 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5914 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5915 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5916 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5917 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5918 | break; |
5919 | } | |
76a66253 | 5920 | if (opc2 & 0x04) { |
182608d4 AJ |
5921 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5922 | tcg_gen_mul_tl(t1, t0, t1); | |
5923 | if (opc2 & 0x02) { | |
5924 | /* nmultiply-and-accumulate (0x0E) */ | |
5925 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5926 | } else { | |
5927 | /* multiply-and-accumulate (0x0C) */ | |
5928 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5929 | } | |
5930 | ||
5931 | if (opc3 & 0x12) { | |
5932 | /* Check overflow and/or saturate */ | |
5933 | int l1 = gen_new_label(); | |
5934 | ||
5935 | if (opc3 & 0x10) { | |
5936 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5937 | tcg_gen_movi_tl(cpu_ov, 0); |
182608d4 AJ |
5938 | } |
5939 | if (opc3 & 0x01) { | |
5940 | /* Signed */ | |
5941 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5942 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5943 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5944 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5945 | if (opc3 & 0x02) { |
182608d4 AJ |
5946 | /* Saturate */ |
5947 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5948 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5949 | } | |
5950 | } else { | |
5951 | /* Unsigned */ | |
5952 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5953 | if (opc3 & 0x02) { |
182608d4 AJ |
5954 | /* Saturate */ |
5955 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5956 | } | |
5957 | } | |
5958 | if (opc3 & 0x10) { | |
5959 | /* Check overflow */ | |
da91a00f RH |
5960 | tcg_gen_movi_tl(cpu_ov, 1); |
5961 | tcg_gen_movi_tl(cpu_so, 1); | |
182608d4 AJ |
5962 | } |
5963 | gen_set_label(l1); | |
5964 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5965 | } | |
5966 | } else { | |
5967 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5968 | } |
182608d4 AJ |
5969 | tcg_temp_free(t0); |
5970 | tcg_temp_free(t1); | |
76a66253 JM |
5971 | if (unlikely(Rc) != 0) { |
5972 | /* Update Rc0 */ | |
182608d4 | 5973 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5974 | } |
5975 | } | |
5976 | ||
a750fc0b | 5977 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5978 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5979 | { \ |
5980 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5981 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5982 | } | |
5983 | ||
5984 | /* macchw - macchw. */ | |
a750fc0b | 5985 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5986 | /* macchwo - macchwo. */ |
a750fc0b | 5987 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5988 | /* macchws - macchws. */ |
a750fc0b | 5989 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5990 | /* macchwso - macchwso. */ |
a750fc0b | 5991 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5992 | /* macchwsu - macchwsu. */ |
a750fc0b | 5993 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5994 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5995 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5996 | /* macchwu - macchwu. */ |
a750fc0b | 5997 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5998 | /* macchwuo - macchwuo. */ |
a750fc0b | 5999 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 6000 | /* machhw - machhw. */ |
a750fc0b | 6001 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 6002 | /* machhwo - machhwo. */ |
a750fc0b | 6003 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 6004 | /* machhws - machhws. */ |
a750fc0b | 6005 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 6006 | /* machhwso - machhwso. */ |
a750fc0b | 6007 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 6008 | /* machhwsu - machhwsu. */ |
a750fc0b | 6009 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 6010 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 6011 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 6012 | /* machhwu - machhwu. */ |
a750fc0b | 6013 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 6014 | /* machhwuo - machhwuo. */ |
a750fc0b | 6015 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 6016 | /* maclhw - maclhw. */ |
a750fc0b | 6017 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 6018 | /* maclhwo - maclhwo. */ |
a750fc0b | 6019 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 6020 | /* maclhws - maclhws. */ |
a750fc0b | 6021 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 6022 | /* maclhwso - maclhwso. */ |
a750fc0b | 6023 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 6024 | /* maclhwu - maclhwu. */ |
a750fc0b | 6025 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 6026 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 6027 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 6028 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 6029 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 6030 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 6031 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 6032 | /* nmacchw - nmacchw. */ |
a750fc0b | 6033 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 6034 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 6035 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 6036 | /* nmacchws - nmacchws. */ |
a750fc0b | 6037 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 6038 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 6039 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 6040 | /* nmachhw - nmachhw. */ |
a750fc0b | 6041 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 6042 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 6043 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 6044 | /* nmachhws - nmachhws. */ |
a750fc0b | 6045 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 6046 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 6047 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 6048 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 6049 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 6050 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 6051 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 6052 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 6053 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 6054 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 6055 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
6056 | |
6057 | /* mulchw - mulchw. */ | |
a750fc0b | 6058 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 6059 | /* mulchwu - mulchwu. */ |
a750fc0b | 6060 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 6061 | /* mulhhw - mulhhw. */ |
a750fc0b | 6062 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 6063 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 6064 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 6065 | /* mullhw - mullhw. */ |
a750fc0b | 6066 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 6067 | /* mullhwu - mullhwu. */ |
a750fc0b | 6068 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
6069 | |
6070 | /* mfdcr */ | |
99e300ef | 6071 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
6072 | { |
6073 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6074 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 6075 | #else |
06dca6a7 | 6076 | TCGv dcrn; |
76db3ba4 | 6077 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6078 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
6079 | return; |
6080 | } | |
06dca6a7 AJ |
6081 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6082 | gen_update_nip(ctx, ctx->nip - 4); | |
6083 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 6084 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn); |
06dca6a7 | 6085 | tcg_temp_free(dcrn); |
76a66253 JM |
6086 | #endif |
6087 | } | |
6088 | ||
6089 | /* mtdcr */ | |
99e300ef | 6090 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
6091 | { |
6092 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6093 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 6094 | #else |
06dca6a7 | 6095 | TCGv dcrn; |
76db3ba4 | 6096 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6097 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
6098 | return; |
6099 | } | |
06dca6a7 AJ |
6100 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6101 | gen_update_nip(ctx, ctx->nip - 4); | |
6102 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 6103 | gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]); |
06dca6a7 | 6104 | tcg_temp_free(dcrn); |
a42bd6cc JM |
6105 | #endif |
6106 | } | |
6107 | ||
6108 | /* mfdcrx */ | |
2662a059 | 6109 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6110 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
6111 | { |
6112 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6113 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 6114 | #else |
76db3ba4 | 6115 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6116 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
6117 | return; |
6118 | } | |
06dca6a7 AJ |
6119 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6120 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6121 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6122 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 6123 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
a42bd6cc JM |
6124 | #endif |
6125 | } | |
6126 | ||
6127 | /* mtdcrx */ | |
2662a059 | 6128 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6129 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
6130 | { |
6131 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6132 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 6133 | #else |
76db3ba4 | 6134 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6135 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
6136 | return; |
6137 | } | |
06dca6a7 AJ |
6138 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6139 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6140 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6141 | cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 6142 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
76a66253 JM |
6143 | #endif |
6144 | } | |
6145 | ||
a750fc0b | 6146 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 6147 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 6148 | { |
06dca6a7 AJ |
6149 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6150 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6151 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6152 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
6153 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6154 | } | |
6155 | ||
6156 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 6157 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 6158 | { |
06dca6a7 AJ |
6159 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6160 | gen_update_nip(ctx, ctx->nip - 4); | |
975e5463 | 6161 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
d0f1562d | 6162 | cpu_gpr[rS(ctx->opcode)]); |
a750fc0b JM |
6163 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6164 | } | |
6165 | ||
76a66253 | 6166 | /* dccci */ |
99e300ef | 6167 | static void gen_dccci(DisasContext *ctx) |
76a66253 JM |
6168 | { |
6169 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6170 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6171 | #else |
76db3ba4 | 6172 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6173 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6174 | return; |
6175 | } | |
6176 | /* interpreted as no-op */ | |
6177 | #endif | |
6178 | } | |
6179 | ||
6180 | /* dcread */ | |
99e300ef | 6181 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
6182 | { |
6183 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6184 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6185 | #else |
b61f2753 | 6186 | TCGv EA, val; |
76db3ba4 | 6187 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6188 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6189 | return; |
6190 | } | |
76db3ba4 | 6191 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 6192 | EA = tcg_temp_new(); |
76db3ba4 | 6193 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 6194 | val = tcg_temp_new(); |
76db3ba4 | 6195 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
6196 | tcg_temp_free(val); |
6197 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
6198 | tcg_temp_free(EA); | |
76a66253 JM |
6199 | #endif |
6200 | } | |
6201 | ||
6202 | /* icbt */ | |
e8eaa2c0 | 6203 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
6204 | { |
6205 | /* interpreted as no-op */ | |
6206 | /* XXX: specification say this is treated as a load by the MMU | |
6207 | * but does not generate any exception | |
6208 | */ | |
6209 | } | |
6210 | ||
6211 | /* iccci */ | |
99e300ef | 6212 | static void gen_iccci(DisasContext *ctx) |
76a66253 JM |
6213 | { |
6214 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6215 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6216 | #else |
76db3ba4 | 6217 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6218 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6219 | return; |
6220 | } | |
6221 | /* interpreted as no-op */ | |
6222 | #endif | |
6223 | } | |
6224 | ||
6225 | /* icread */ | |
99e300ef | 6226 | static void gen_icread(DisasContext *ctx) |
76a66253 JM |
6227 | { |
6228 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6229 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6230 | #else |
76db3ba4 | 6231 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6232 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6233 | return; |
6234 | } | |
6235 | /* interpreted as no-op */ | |
6236 | #endif | |
6237 | } | |
6238 | ||
76db3ba4 | 6239 | /* rfci (mem_idx only) */ |
e8eaa2c0 | 6240 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
6241 | { |
6242 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6243 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6244 | #else |
76db3ba4 | 6245 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6246 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6247 | return; |
6248 | } | |
6249 | /* Restore CPU state */ | |
e5f17ac6 | 6250 | gen_helper_40x_rfci(cpu_env); |
e06fcd75 | 6251 | gen_sync_exception(ctx); |
a42bd6cc JM |
6252 | #endif |
6253 | } | |
6254 | ||
99e300ef | 6255 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
6256 | { |
6257 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6258 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6259 | #else |
76db3ba4 | 6260 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6261 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6262 | return; |
6263 | } | |
6264 | /* Restore CPU state */ | |
e5f17ac6 | 6265 | gen_helper_rfci(cpu_env); |
e06fcd75 | 6266 | gen_sync_exception(ctx); |
a42bd6cc JM |
6267 | #endif |
6268 | } | |
6269 | ||
6270 | /* BookE specific */ | |
99e300ef | 6271 | |
54623277 | 6272 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6273 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
6274 | { |
6275 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6276 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6277 | #else |
76db3ba4 | 6278 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6279 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6280 | return; |
6281 | } | |
6282 | /* Restore CPU state */ | |
e5f17ac6 | 6283 | gen_helper_rfdi(cpu_env); |
e06fcd75 | 6284 | gen_sync_exception(ctx); |
76a66253 JM |
6285 | #endif |
6286 | } | |
6287 | ||
2662a059 | 6288 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6289 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
6290 | { |
6291 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6292 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6293 | #else |
76db3ba4 | 6294 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6295 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6296 | return; |
6297 | } | |
6298 | /* Restore CPU state */ | |
e5f17ac6 | 6299 | gen_helper_rfmci(cpu_env); |
e06fcd75 | 6300 | gen_sync_exception(ctx); |
a42bd6cc JM |
6301 | #endif |
6302 | } | |
5eb7995e | 6303 | |
d9bce9d9 | 6304 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 6305 | |
54623277 | 6306 | /* tlbre */ |
e8eaa2c0 | 6307 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
6308 | { |
6309 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6310 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6311 | #else |
76db3ba4 | 6312 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6313 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6314 | return; |
6315 | } | |
6316 | switch (rB(ctx->opcode)) { | |
6317 | case 0: | |
c6c7cf05 BS |
6318 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6319 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6320 | break; |
6321 | case 1: | |
c6c7cf05 BS |
6322 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6323 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6324 | break; |
6325 | default: | |
e06fcd75 | 6326 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6327 | break; |
9a64fbe4 | 6328 | } |
76a66253 JM |
6329 | #endif |
6330 | } | |
6331 | ||
d9bce9d9 | 6332 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 6333 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
6334 | { |
6335 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6336 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6337 | #else |
74d37793 | 6338 | TCGv t0; |
76db3ba4 | 6339 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6340 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6341 | return; |
6342 | } | |
74d37793 | 6343 | t0 = tcg_temp_new(); |
76db3ba4 | 6344 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6345 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6346 | tcg_temp_free(t0); |
6347 | if (Rc(ctx->opcode)) { | |
6348 | int l1 = gen_new_label(); | |
da91a00f | 6349 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6350 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6351 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6352 | gen_set_label(l1); | |
6353 | } | |
76a66253 | 6354 | #endif |
79aceca5 FB |
6355 | } |
6356 | ||
76a66253 | 6357 | /* tlbwe */ |
e8eaa2c0 | 6358 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 6359 | { |
76a66253 | 6360 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 6361 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6362 | #else |
76db3ba4 | 6363 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6364 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6365 | return; |
6366 | } | |
6367 | switch (rB(ctx->opcode)) { | |
6368 | case 0: | |
c6c7cf05 BS |
6369 | gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6370 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6371 | break; |
6372 | case 1: | |
c6c7cf05 BS |
6373 | gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6374 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6375 | break; |
6376 | default: | |
e06fcd75 | 6377 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6378 | break; |
9a64fbe4 | 6379 | } |
76a66253 JM |
6380 | #endif |
6381 | } | |
6382 | ||
a4bb6c3e | 6383 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 6384 | |
54623277 | 6385 | /* tlbre */ |
e8eaa2c0 | 6386 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
6387 | { |
6388 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6389 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6390 | #else |
76db3ba4 | 6391 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6392 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6393 | return; |
6394 | } | |
6395 | switch (rB(ctx->opcode)) { | |
6396 | case 0: | |
5eb7995e | 6397 | case 1: |
5eb7995e | 6398 | case 2: |
74d37793 AJ |
6399 | { |
6400 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6401 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6402 | t0, cpu_gpr[rA(ctx->opcode)]); | |
74d37793 AJ |
6403 | tcg_temp_free_i32(t0); |
6404 | } | |
5eb7995e JM |
6405 | break; |
6406 | default: | |
e06fcd75 | 6407 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6408 | break; |
6409 | } | |
6410 | #endif | |
6411 | } | |
6412 | ||
6413 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 6414 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
6415 | { |
6416 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6417 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6418 | #else |
74d37793 | 6419 | TCGv t0; |
76db3ba4 | 6420 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6421 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6422 | return; |
6423 | } | |
74d37793 | 6424 | t0 = tcg_temp_new(); |
76db3ba4 | 6425 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6426 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6427 | tcg_temp_free(t0); |
6428 | if (Rc(ctx->opcode)) { | |
6429 | int l1 = gen_new_label(); | |
da91a00f | 6430 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6431 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6432 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6433 | gen_set_label(l1); | |
6434 | } | |
5eb7995e JM |
6435 | #endif |
6436 | } | |
6437 | ||
6438 | /* tlbwe */ | |
e8eaa2c0 | 6439 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6440 | { |
6441 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6442 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6443 | #else |
76db3ba4 | 6444 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6445 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6446 | return; |
6447 | } | |
6448 | switch (rB(ctx->opcode)) { | |
6449 | case 0: | |
5eb7995e | 6450 | case 1: |
5eb7995e | 6451 | case 2: |
74d37793 AJ |
6452 | { |
6453 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6454 | gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)], |
6455 | cpu_gpr[rS(ctx->opcode)]); | |
74d37793 AJ |
6456 | tcg_temp_free_i32(t0); |
6457 | } | |
5eb7995e JM |
6458 | break; |
6459 | default: | |
e06fcd75 | 6460 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6461 | break; |
6462 | } | |
6463 | #endif | |
6464 | } | |
6465 | ||
01662f3e AG |
6466 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6467 | ||
6468 | /* tlbre */ | |
6469 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6470 | { | |
6471 | #if defined(CONFIG_USER_ONLY) | |
6472 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6473 | #else | |
6474 | if (unlikely(!ctx->mem_idx)) { | |
6475 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6476 | return; | |
6477 | } | |
6478 | ||
c6c7cf05 | 6479 | gen_helper_booke206_tlbre(cpu_env); |
01662f3e AG |
6480 | #endif |
6481 | } | |
6482 | ||
6483 | /* tlbsx - tlbsx. */ | |
6484 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6485 | { | |
6486 | #if defined(CONFIG_USER_ONLY) | |
6487 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6488 | #else | |
6489 | TCGv t0; | |
6490 | if (unlikely(!ctx->mem_idx)) { | |
6491 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6492 | return; | |
6493 | } | |
6494 | ||
6495 | if (rA(ctx->opcode)) { | |
6496 | t0 = tcg_temp_new(); | |
6497 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6498 | } else { | |
6499 | t0 = tcg_const_tl(0); | |
6500 | } | |
6501 | ||
6502 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 6503 | gen_helper_booke206_tlbsx(cpu_env, t0); |
01662f3e AG |
6504 | #endif |
6505 | } | |
6506 | ||
6507 | /* tlbwe */ | |
6508 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6509 | { | |
6510 | #if defined(CONFIG_USER_ONLY) | |
6511 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6512 | #else | |
6513 | if (unlikely(!ctx->mem_idx)) { | |
6514 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6515 | return; | |
6516 | } | |
3f162d11 | 6517 | gen_update_nip(ctx, ctx->nip - 4); |
c6c7cf05 | 6518 | gen_helper_booke206_tlbwe(cpu_env); |
01662f3e AG |
6519 | #endif |
6520 | } | |
6521 | ||
6522 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6523 | { | |
6524 | #if defined(CONFIG_USER_ONLY) | |
6525 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6526 | #else | |
6527 | TCGv t0; | |
6528 | if (unlikely(!ctx->mem_idx)) { | |
6529 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6530 | return; | |
6531 | } | |
6532 | ||
6533 | t0 = tcg_temp_new(); | |
6534 | gen_addr_reg_index(ctx, t0); | |
6535 | ||
c6c7cf05 | 6536 | gen_helper_booke206_tlbivax(cpu_env, t0); |
01662f3e AG |
6537 | #endif |
6538 | } | |
6539 | ||
6d3db821 AG |
6540 | static void gen_tlbilx_booke206(DisasContext *ctx) |
6541 | { | |
6542 | #if defined(CONFIG_USER_ONLY) | |
6543 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6544 | #else | |
6545 | TCGv t0; | |
6546 | if (unlikely(!ctx->mem_idx)) { | |
6547 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6548 | return; | |
6549 | } | |
6550 | ||
6551 | t0 = tcg_temp_new(); | |
6552 | gen_addr_reg_index(ctx, t0); | |
6553 | ||
6554 | switch((ctx->opcode >> 21) & 0x3) { | |
6555 | case 0: | |
c6c7cf05 | 6556 | gen_helper_booke206_tlbilx0(cpu_env, t0); |
6d3db821 AG |
6557 | break; |
6558 | case 1: | |
c6c7cf05 | 6559 | gen_helper_booke206_tlbilx1(cpu_env, t0); |
6d3db821 AG |
6560 | break; |
6561 | case 3: | |
c6c7cf05 | 6562 | gen_helper_booke206_tlbilx3(cpu_env, t0); |
6d3db821 AG |
6563 | break; |
6564 | default: | |
6565 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6566 | break; | |
6567 | } | |
6568 | ||
6569 | tcg_temp_free(t0); | |
6570 | #endif | |
6571 | } | |
6572 | ||
01662f3e | 6573 | |
76a66253 | 6574 | /* wrtee */ |
99e300ef | 6575 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6576 | { |
6577 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6578 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6579 | #else |
6527f6ea | 6580 | TCGv t0; |
76db3ba4 | 6581 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6582 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6583 | return; |
6584 | } | |
6527f6ea AJ |
6585 | t0 = tcg_temp_new(); |
6586 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6587 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6588 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6589 | tcg_temp_free(t0); | |
dee96f6c JM |
6590 | /* Stop translation to have a chance to raise an exception |
6591 | * if we just set msr_ee to 1 | |
6592 | */ | |
e06fcd75 | 6593 | gen_stop_exception(ctx); |
76a66253 JM |
6594 | #endif |
6595 | } | |
6596 | ||
6597 | /* wrteei */ | |
99e300ef | 6598 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6599 | { |
6600 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6601 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6602 | #else |
76db3ba4 | 6603 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6604 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6605 | return; |
6606 | } | |
fbe73008 | 6607 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6608 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6609 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6610 | gen_stop_exception(ctx); |
6527f6ea | 6611 | } else { |
1b6e5f99 | 6612 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6613 | } |
76a66253 JM |
6614 | #endif |
6615 | } | |
6616 | ||
08e46e54 | 6617 | /* PowerPC 440 specific instructions */ |
99e300ef | 6618 | |
54623277 | 6619 | /* dlmzb */ |
99e300ef | 6620 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6621 | { |
ef0d51af | 6622 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
d15f74fb BS |
6623 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env, |
6624 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); | |
ef0d51af | 6625 | tcg_temp_free_i32(t0); |
76a66253 JM |
6626 | } |
6627 | ||
6628 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6629 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6630 | { |
6631 | /* interpreted as no-op */ | |
6632 | } | |
6633 | ||
6634 | /* msync replaces sync on 440 */ | |
dcb2b9e1 | 6635 | static void gen_msync_4xx(DisasContext *ctx) |
76a66253 JM |
6636 | { |
6637 | /* interpreted as no-op */ | |
6638 | } | |
6639 | ||
6640 | /* icbt */ | |
e8eaa2c0 | 6641 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6642 | { |
6643 | /* interpreted as no-op */ | |
6644 | /* XXX: specification say this is treated as a load by the MMU | |
6645 | * but does not generate any exception | |
6646 | */ | |
79aceca5 FB |
6647 | } |
6648 | ||
9e0b5cb1 AG |
6649 | /* Embedded.Processor Control */ |
6650 | ||
6651 | static void gen_msgclr(DisasContext *ctx) | |
6652 | { | |
6653 | #if defined(CONFIG_USER_ONLY) | |
6654 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6655 | #else | |
6656 | if (unlikely(ctx->mem_idx == 0)) { | |
6657 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6658 | return; | |
6659 | } | |
6660 | ||
e5f17ac6 | 6661 | gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9e0b5cb1 AG |
6662 | #endif |
6663 | } | |
6664 | ||
d5d11a39 AG |
6665 | static void gen_msgsnd(DisasContext *ctx) |
6666 | { | |
6667 | #if defined(CONFIG_USER_ONLY) | |
6668 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6669 | #else | |
6670 | if (unlikely(ctx->mem_idx == 0)) { | |
6671 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6672 | return; | |
6673 | } | |
6674 | ||
6675 | gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6676 | #endif | |
6677 | } | |
6678 | ||
a9d9eb8f JM |
6679 | /*** Altivec vector extension ***/ |
6680 | /* Altivec registers moves */ | |
a9d9eb8f | 6681 | |
636aa200 | 6682 | static inline TCGv_ptr gen_avr_ptr(int reg) |
564e571a | 6683 | { |
e4704b3b | 6684 | TCGv_ptr r = tcg_temp_new_ptr(); |
564e571a AJ |
6685 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg])); |
6686 | return r; | |
6687 | } | |
6688 | ||
a9d9eb8f | 6689 | #define GEN_VR_LDX(name, opc2, opc3) \ |
99e300ef | 6690 | static void glue(gen_, name)(DisasContext *ctx) \ |
a9d9eb8f | 6691 | { \ |
fe1e5c53 | 6692 | TCGv EA; \ |
a9d9eb8f | 6693 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6694 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6695 | return; \ |
6696 | } \ | |
76db3ba4 | 6697 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6698 | EA = tcg_temp_new(); \ |
76db3ba4 | 6699 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6700 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6701 | if (ctx->le_mode) { \ |
6702 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6703 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6704 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6705 | } else { \ |
76db3ba4 | 6706 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6707 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6708 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6709 | } \ |
6710 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6711 | } |
6712 | ||
6713 | #define GEN_VR_STX(name, opc2, opc3) \ | |
99e300ef | 6714 | static void gen_st##name(DisasContext *ctx) \ |
a9d9eb8f | 6715 | { \ |
fe1e5c53 | 6716 | TCGv EA; \ |
a9d9eb8f | 6717 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6718 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6719 | return; \ |
6720 | } \ | |
76db3ba4 | 6721 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6722 | EA = tcg_temp_new(); \ |
76db3ba4 | 6723 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6724 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6725 | if (ctx->le_mode) { \ |
6726 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6727 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6728 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6729 | } else { \ |
76db3ba4 | 6730 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6731 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6732 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6733 | } \ |
6734 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6735 | } |
6736 | ||
cbfb6ae9 | 6737 | #define GEN_VR_LVE(name, opc2, opc3) \ |
99e300ef | 6738 | static void gen_lve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6739 | { \ |
6740 | TCGv EA; \ | |
6741 | TCGv_ptr rs; \ | |
6742 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6743 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6744 | return; \ | |
6745 | } \ | |
6746 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6747 | EA = tcg_temp_new(); \ | |
6748 | gen_addr_reg_index(ctx, EA); \ | |
6749 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6750 | gen_helper_lve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6751 | tcg_temp_free(EA); \ |
6752 | tcg_temp_free_ptr(rs); \ | |
6753 | } | |
6754 | ||
6755 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
99e300ef | 6756 | static void gen_stve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6757 | { \ |
6758 | TCGv EA; \ | |
6759 | TCGv_ptr rs; \ | |
6760 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6761 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6762 | return; \ | |
6763 | } \ | |
6764 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6765 | EA = tcg_temp_new(); \ | |
6766 | gen_addr_reg_index(ctx, EA); \ | |
6767 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6768 | gen_helper_stve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6769 | tcg_temp_free(EA); \ |
6770 | tcg_temp_free_ptr(rs); \ | |
6771 | } | |
6772 | ||
fe1e5c53 | 6773 | GEN_VR_LDX(lvx, 0x07, 0x03); |
a9d9eb8f | 6774 | /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */ |
fe1e5c53 | 6775 | GEN_VR_LDX(lvxl, 0x07, 0x0B); |
a9d9eb8f | 6776 | |
cbfb6ae9 AJ |
6777 | GEN_VR_LVE(bx, 0x07, 0x00); |
6778 | GEN_VR_LVE(hx, 0x07, 0x01); | |
6779 | GEN_VR_LVE(wx, 0x07, 0x02); | |
6780 | ||
fe1e5c53 | 6781 | GEN_VR_STX(svx, 0x07, 0x07); |
a9d9eb8f | 6782 | /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */ |
fe1e5c53 | 6783 | GEN_VR_STX(svxl, 0x07, 0x0F); |
a9d9eb8f | 6784 | |
cbfb6ae9 AJ |
6785 | GEN_VR_STVE(bx, 0x07, 0x04); |
6786 | GEN_VR_STVE(hx, 0x07, 0x05); | |
6787 | GEN_VR_STVE(wx, 0x07, 0x06); | |
6788 | ||
99e300ef | 6789 | static void gen_lvsl(DisasContext *ctx) |
bf8d8ded AJ |
6790 | { |
6791 | TCGv_ptr rd; | |
6792 | TCGv EA; | |
6793 | if (unlikely(!ctx->altivec_enabled)) { | |
6794 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6795 | return; | |
6796 | } | |
6797 | EA = tcg_temp_new(); | |
6798 | gen_addr_reg_index(ctx, EA); | |
6799 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6800 | gen_helper_lvsl(rd, EA); | |
6801 | tcg_temp_free(EA); | |
6802 | tcg_temp_free_ptr(rd); | |
6803 | } | |
6804 | ||
99e300ef | 6805 | static void gen_lvsr(DisasContext *ctx) |
bf8d8ded AJ |
6806 | { |
6807 | TCGv_ptr rd; | |
6808 | TCGv EA; | |
6809 | if (unlikely(!ctx->altivec_enabled)) { | |
6810 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6811 | return; | |
6812 | } | |
6813 | EA = tcg_temp_new(); | |
6814 | gen_addr_reg_index(ctx, EA); | |
6815 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6816 | gen_helper_lvsr(rd, EA); | |
6817 | tcg_temp_free(EA); | |
6818 | tcg_temp_free_ptr(rd); | |
6819 | } | |
6820 | ||
99e300ef | 6821 | static void gen_mfvscr(DisasContext *ctx) |
785f451b AJ |
6822 | { |
6823 | TCGv_i32 t; | |
6824 | if (unlikely(!ctx->altivec_enabled)) { | |
6825 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6826 | return; | |
6827 | } | |
6828 | tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0); | |
6829 | t = tcg_temp_new_i32(); | |
1328c2bf | 6830 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr)); |
785f451b | 6831 | tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t); |
fce5ecb7 | 6832 | tcg_temp_free_i32(t); |
785f451b AJ |
6833 | } |
6834 | ||
99e300ef | 6835 | static void gen_mtvscr(DisasContext *ctx) |
785f451b | 6836 | { |
6e87b7c7 | 6837 | TCGv_ptr p; |
785f451b AJ |
6838 | if (unlikely(!ctx->altivec_enabled)) { |
6839 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6840 | return; | |
6841 | } | |
6e87b7c7 | 6842 | p = gen_avr_ptr(rD(ctx->opcode)); |
d15f74fb | 6843 | gen_helper_mtvscr(cpu_env, p); |
6e87b7c7 | 6844 | tcg_temp_free_ptr(p); |
785f451b AJ |
6845 | } |
6846 | ||
7a9b96cf AJ |
6847 | /* Logical operations */ |
6848 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
99e300ef | 6849 | static void glue(gen_, name)(DisasContext *ctx) \ |
7a9b96cf AJ |
6850 | { \ |
6851 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6852 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6853 | return; \ | |
6854 | } \ | |
6855 | tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \ | |
6856 | tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \ | |
6857 | } | |
6858 | ||
6859 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16); | |
6860 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17); | |
6861 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18); | |
6862 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19); | |
6863 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20); | |
111c5f54 TM |
6864 | GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26); |
6865 | GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22); | |
6866 | GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21); | |
7a9b96cf | 6867 | |
8e27dd6f | 6868 | #define GEN_VXFORM(name, opc2, opc3) \ |
99e300ef | 6869 | static void glue(gen_, name)(DisasContext *ctx) \ |
8e27dd6f 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)); \ | |
6879 | gen_helper_##name (rd, ra, rb); \ | |
6880 | tcg_temp_free_ptr(ra); \ | |
6881 | tcg_temp_free_ptr(rb); \ | |
6882 | tcg_temp_free_ptr(rd); \ | |
6883 | } | |
6884 | ||
d15f74fb BS |
6885 | #define GEN_VXFORM_ENV(name, opc2, opc3) \ |
6886 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6887 | { \ | |
6888 | TCGv_ptr ra, rb, rd; \ | |
6889 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6890 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6891 | return; \ | |
6892 | } \ | |
6893 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6894 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6895 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
54cddd21 | 6896 | gen_helper_##name(cpu_env, rd, ra, rb); \ |
d15f74fb BS |
6897 | tcg_temp_free_ptr(ra); \ |
6898 | tcg_temp_free_ptr(rb); \ | |
6899 | tcg_temp_free_ptr(rd); \ | |
9b47bb49 TM |
6900 | } |
6901 | ||
6902 | #define GEN_VXFORM3(name, opc2, opc3) \ | |
6903 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6904 | { \ | |
6905 | TCGv_ptr ra, rb, rc, rd; \ | |
6906 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6907 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6908 | return; \ | |
6909 | } \ | |
6910 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6911 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6912 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
6913 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6914 | gen_helper_##name(rd, ra, rb, rc); \ | |
6915 | tcg_temp_free_ptr(ra); \ | |
6916 | tcg_temp_free_ptr(rb); \ | |
6917 | tcg_temp_free_ptr(rc); \ | |
6918 | tcg_temp_free_ptr(rd); \ | |
d15f74fb BS |
6919 | } |
6920 | ||
5dffff5a TM |
6921 | /* |
6922 | * Support for Altivec instruction pairs that use bit 31 (Rc) as | |
6923 | * an opcode bit. In general, these pairs come from different | |
6924 | * versions of the ISA, so we must also support a pair of flags for | |
6925 | * each instruction. | |
6926 | */ | |
6927 | #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \ | |
6928 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ | |
6929 | { \ | |
6930 | if ((Rc(ctx->opcode) == 0) && \ | |
6931 | ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \ | |
6932 | gen_##name0(ctx); \ | |
6933 | } else if ((Rc(ctx->opcode) == 1) && \ | |
6934 | ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \ | |
6935 | gen_##name1(ctx); \ | |
6936 | } else { \ | |
6937 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ | |
6938 | } \ | |
6939 | } | |
6940 | ||
7872c51c AJ |
6941 | GEN_VXFORM(vaddubm, 0, 0); |
6942 | GEN_VXFORM(vadduhm, 0, 1); | |
6943 | GEN_VXFORM(vadduwm, 0, 2); | |
56eabc75 | 6944 | GEN_VXFORM(vaddudm, 0, 3); |
7872c51c AJ |
6945 | GEN_VXFORM(vsububm, 0, 16); |
6946 | GEN_VXFORM(vsubuhm, 0, 17); | |
6947 | GEN_VXFORM(vsubuwm, 0, 18); | |
56eabc75 | 6948 | GEN_VXFORM(vsubudm, 0, 19); |
e4039339 AJ |
6949 | GEN_VXFORM(vmaxub, 1, 0); |
6950 | GEN_VXFORM(vmaxuh, 1, 1); | |
6951 | GEN_VXFORM(vmaxuw, 1, 2); | |
8203e31b | 6952 | GEN_VXFORM(vmaxud, 1, 3); |
e4039339 AJ |
6953 | GEN_VXFORM(vmaxsb, 1, 4); |
6954 | GEN_VXFORM(vmaxsh, 1, 5); | |
6955 | GEN_VXFORM(vmaxsw, 1, 6); | |
8203e31b | 6956 | GEN_VXFORM(vmaxsd, 1, 7); |
e4039339 AJ |
6957 | GEN_VXFORM(vminub, 1, 8); |
6958 | GEN_VXFORM(vminuh, 1, 9); | |
6959 | GEN_VXFORM(vminuw, 1, 10); | |
8203e31b | 6960 | GEN_VXFORM(vminud, 1, 11); |
e4039339 AJ |
6961 | GEN_VXFORM(vminsb, 1, 12); |
6962 | GEN_VXFORM(vminsh, 1, 13); | |
6963 | GEN_VXFORM(vminsw, 1, 14); | |
8203e31b | 6964 | GEN_VXFORM(vminsd, 1, 15); |
fab3cbe9 AJ |
6965 | GEN_VXFORM(vavgub, 1, 16); |
6966 | GEN_VXFORM(vavguh, 1, 17); | |
6967 | GEN_VXFORM(vavguw, 1, 18); | |
6968 | GEN_VXFORM(vavgsb, 1, 20); | |
6969 | GEN_VXFORM(vavgsh, 1, 21); | |
6970 | GEN_VXFORM(vavgsw, 1, 22); | |
3b430048 AJ |
6971 | GEN_VXFORM(vmrghb, 6, 0); |
6972 | GEN_VXFORM(vmrghh, 6, 1); | |
6973 | GEN_VXFORM(vmrghw, 6, 2); | |
6974 | GEN_VXFORM(vmrglb, 6, 4); | |
6975 | GEN_VXFORM(vmrglh, 6, 5); | |
6976 | GEN_VXFORM(vmrglw, 6, 6); | |
e0ffe77f TM |
6977 | |
6978 | static void gen_vmrgew(DisasContext *ctx) | |
6979 | { | |
6980 | TCGv_i64 tmp; | |
6981 | int VT, VA, VB; | |
6982 | if (unlikely(!ctx->altivec_enabled)) { | |
6983 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6984 | return; | |
6985 | } | |
6986 | VT = rD(ctx->opcode); | |
6987 | VA = rA(ctx->opcode); | |
6988 | VB = rB(ctx->opcode); | |
6989 | tmp = tcg_temp_new_i64(); | |
6990 | tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32); | |
6991 | tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32); | |
6992 | tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32); | |
6993 | tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32); | |
6994 | tcg_temp_free_i64(tmp); | |
6995 | } | |
6996 | ||
6997 | static void gen_vmrgow(DisasContext *ctx) | |
6998 | { | |
6999 | int VT, VA, VB; | |
7000 | if (unlikely(!ctx->altivec_enabled)) { | |
7001 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7002 | return; | |
7003 | } | |
7004 | VT = rD(ctx->opcode); | |
7005 | VA = rA(ctx->opcode); | |
7006 | VB = rB(ctx->opcode); | |
7007 | ||
7008 | tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32); | |
7009 | tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32); | |
7010 | } | |
7011 | ||
2c277908 AJ |
7012 | GEN_VXFORM(vmuloub, 4, 0); |
7013 | GEN_VXFORM(vmulouh, 4, 1); | |
63be0936 | 7014 | GEN_VXFORM(vmulouw, 4, 2); |
953f0f58 TM |
7015 | GEN_VXFORM(vmuluwm, 4, 2); |
7016 | GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE, | |
7017 | vmuluwm, PPC_NONE, PPC2_ALTIVEC_207) | |
2c277908 AJ |
7018 | GEN_VXFORM(vmulosb, 4, 4); |
7019 | GEN_VXFORM(vmulosh, 4, 5); | |
63be0936 | 7020 | GEN_VXFORM(vmulosw, 4, 6); |
2c277908 AJ |
7021 | GEN_VXFORM(vmuleub, 4, 8); |
7022 | GEN_VXFORM(vmuleuh, 4, 9); | |
63be0936 | 7023 | GEN_VXFORM(vmuleuw, 4, 10); |
2c277908 AJ |
7024 | GEN_VXFORM(vmulesb, 4, 12); |
7025 | GEN_VXFORM(vmulesh, 4, 13); | |
63be0936 | 7026 | GEN_VXFORM(vmulesw, 4, 14); |
d79f0809 AJ |
7027 | GEN_VXFORM(vslb, 2, 4); |
7028 | GEN_VXFORM(vslh, 2, 5); | |
7029 | GEN_VXFORM(vslw, 2, 6); | |
2fdf78e6 | 7030 | GEN_VXFORM(vsld, 2, 23); |
07ef34c3 AJ |
7031 | GEN_VXFORM(vsrb, 2, 8); |
7032 | GEN_VXFORM(vsrh, 2, 9); | |
7033 | GEN_VXFORM(vsrw, 2, 10); | |
2fdf78e6 | 7034 | GEN_VXFORM(vsrd, 2, 27); |
07ef34c3 AJ |
7035 | GEN_VXFORM(vsrab, 2, 12); |
7036 | GEN_VXFORM(vsrah, 2, 13); | |
7037 | GEN_VXFORM(vsraw, 2, 14); | |
2fdf78e6 | 7038 | GEN_VXFORM(vsrad, 2, 15); |
7b239bec AJ |
7039 | GEN_VXFORM(vslo, 6, 16); |
7040 | GEN_VXFORM(vsro, 6, 17); | |
e343da72 AJ |
7041 | GEN_VXFORM(vaddcuw, 0, 6); |
7042 | GEN_VXFORM(vsubcuw, 0, 22); | |
d15f74fb BS |
7043 | GEN_VXFORM_ENV(vaddubs, 0, 8); |
7044 | GEN_VXFORM_ENV(vadduhs, 0, 9); | |
7045 | GEN_VXFORM_ENV(vadduws, 0, 10); | |
7046 | GEN_VXFORM_ENV(vaddsbs, 0, 12); | |
7047 | GEN_VXFORM_ENV(vaddshs, 0, 13); | |
7048 | GEN_VXFORM_ENV(vaddsws, 0, 14); | |
7049 | GEN_VXFORM_ENV(vsububs, 0, 24); | |
7050 | GEN_VXFORM_ENV(vsubuhs, 0, 25); | |
7051 | GEN_VXFORM_ENV(vsubuws, 0, 26); | |
7052 | GEN_VXFORM_ENV(vsubsbs, 0, 28); | |
7053 | GEN_VXFORM_ENV(vsubshs, 0, 29); | |
7054 | GEN_VXFORM_ENV(vsubsws, 0, 30); | |
b41da4eb TM |
7055 | GEN_VXFORM(vadduqm, 0, 4); |
7056 | GEN_VXFORM(vaddcuq, 0, 5); | |
7057 | GEN_VXFORM3(vaddeuqm, 30, 0); | |
7058 | GEN_VXFORM3(vaddecuq, 30, 0); | |
7059 | GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7060 | vaddecuq, PPC_NONE, PPC2_ALTIVEC_207) | |
7061 | GEN_VXFORM(vsubuqm, 0, 20); | |
7062 | GEN_VXFORM(vsubcuq, 0, 21); | |
7063 | GEN_VXFORM3(vsubeuqm, 31, 0); | |
7064 | GEN_VXFORM3(vsubecuq, 31, 0); | |
7065 | GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7066 | vsubecuq, PPC_NONE, PPC2_ALTIVEC_207) | |
5e1d0985 AJ |
7067 | GEN_VXFORM(vrlb, 2, 0); |
7068 | GEN_VXFORM(vrlh, 2, 1); | |
7069 | GEN_VXFORM(vrlw, 2, 2); | |
2fdf78e6 | 7070 | GEN_VXFORM(vrld, 2, 3); |
d9430add AJ |
7071 | GEN_VXFORM(vsl, 2, 7); |
7072 | GEN_VXFORM(vsr, 2, 11); | |
d15f74fb BS |
7073 | GEN_VXFORM_ENV(vpkuhum, 7, 0); |
7074 | GEN_VXFORM_ENV(vpkuwum, 7, 1); | |
024215b2 | 7075 | GEN_VXFORM_ENV(vpkudum, 7, 17); |
d15f74fb BS |
7076 | GEN_VXFORM_ENV(vpkuhus, 7, 2); |
7077 | GEN_VXFORM_ENV(vpkuwus, 7, 3); | |
024215b2 | 7078 | GEN_VXFORM_ENV(vpkudus, 7, 19); |
d15f74fb BS |
7079 | GEN_VXFORM_ENV(vpkshus, 7, 4); |
7080 | GEN_VXFORM_ENV(vpkswus, 7, 5); | |
024215b2 | 7081 | GEN_VXFORM_ENV(vpksdus, 7, 21); |
d15f74fb BS |
7082 | GEN_VXFORM_ENV(vpkshss, 7, 6); |
7083 | GEN_VXFORM_ENV(vpkswss, 7, 7); | |
024215b2 | 7084 | GEN_VXFORM_ENV(vpksdss, 7, 23); |
1dd9ffb9 | 7085 | GEN_VXFORM(vpkpx, 7, 12); |
d15f74fb BS |
7086 | GEN_VXFORM_ENV(vsum4ubs, 4, 24); |
7087 | GEN_VXFORM_ENV(vsum4sbs, 4, 28); | |
7088 | GEN_VXFORM_ENV(vsum4shs, 4, 25); | |
7089 | GEN_VXFORM_ENV(vsum2sws, 4, 26); | |
7090 | GEN_VXFORM_ENV(vsumsws, 4, 30); | |
7091 | GEN_VXFORM_ENV(vaddfp, 5, 0); | |
7092 | GEN_VXFORM_ENV(vsubfp, 5, 1); | |
7093 | GEN_VXFORM_ENV(vmaxfp, 5, 16); | |
7094 | GEN_VXFORM_ENV(vminfp, 5, 17); | |
fab3cbe9 | 7095 | |
0cbcd906 | 7096 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ |
e8eaa2c0 | 7097 | static void glue(gen_, name)(DisasContext *ctx) \ |
0cbcd906 AJ |
7098 | { \ |
7099 | TCGv_ptr ra, rb, rd; \ | |
7100 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7101 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7102 | return; \ | |
7103 | } \ | |
7104 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
7105 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7106 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
d15f74fb | 7107 | gen_helper_##opname(cpu_env, rd, ra, rb); \ |
0cbcd906 AJ |
7108 | tcg_temp_free_ptr(ra); \ |
7109 | tcg_temp_free_ptr(rb); \ | |
7110 | tcg_temp_free_ptr(rd); \ | |
7111 | } | |
7112 | ||
7113 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
7114 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
7115 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
7116 | ||
a737d3eb TM |
7117 | /* |
7118 | * Support for Altivec instructions that use bit 31 (Rc) as an opcode | |
7119 | * bit but also use bit 21 as an actual Rc bit. In general, thse pairs | |
7120 | * come from different versions of the ISA, so we must also support a | |
7121 | * pair of flags for each instruction. | |
7122 | */ | |
7123 | #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \ | |
7124 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ | |
7125 | { \ | |
7126 | if ((Rc(ctx->opcode) == 0) && \ | |
7127 | ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \ | |
7128 | if (Rc21(ctx->opcode) == 0) { \ | |
7129 | gen_##name0(ctx); \ | |
7130 | } else { \ | |
7131 | gen_##name0##_(ctx); \ | |
7132 | } \ | |
7133 | } else if ((Rc(ctx->opcode) == 1) && \ | |
7134 | ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \ | |
7135 | if (Rc21(ctx->opcode) == 0) { \ | |
7136 | gen_##name1(ctx); \ | |
7137 | } else { \ | |
7138 | gen_##name1##_(ctx); \ | |
7139 | } \ | |
7140 | } else { \ | |
7141 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ | |
7142 | } \ | |
7143 | } | |
7144 | ||
1add6e23 AJ |
7145 | GEN_VXRFORM(vcmpequb, 3, 0) |
7146 | GEN_VXRFORM(vcmpequh, 3, 1) | |
7147 | GEN_VXRFORM(vcmpequw, 3, 2) | |
6f3dab41 | 7148 | GEN_VXRFORM(vcmpequd, 3, 3) |
1add6e23 AJ |
7149 | GEN_VXRFORM(vcmpgtsb, 3, 12) |
7150 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
7151 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
6f3dab41 | 7152 | GEN_VXRFORM(vcmpgtsd, 3, 15) |
1add6e23 AJ |
7153 | GEN_VXRFORM(vcmpgtub, 3, 8) |
7154 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
7155 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
6f3dab41 | 7156 | GEN_VXRFORM(vcmpgtud, 3, 11) |
819ca121 AJ |
7157 | GEN_VXRFORM(vcmpeqfp, 3, 3) |
7158 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
7159 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
7160 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
1add6e23 | 7161 | |
6f3dab41 TM |
7162 | GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \ |
7163 | vcmpequd, PPC_NONE, PPC2_ALTIVEC_207) | |
7164 | GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \ | |
7165 | vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207) | |
7166 | GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \ | |
7167 | vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207) | |
7168 | ||
c026766b | 7169 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 7170 | static void glue(gen_, name)(DisasContext *ctx) \ |
c026766b AJ |
7171 | { \ |
7172 | TCGv_ptr rd; \ | |
7173 | TCGv_i32 simm; \ | |
7174 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7175 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7176 | return; \ | |
7177 | } \ | |
7178 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
7179 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7180 | gen_helper_##name (rd, simm); \ | |
7181 | tcg_temp_free_i32(simm); \ | |
7182 | tcg_temp_free_ptr(rd); \ | |
7183 | } | |
7184 | ||
7185 | GEN_VXFORM_SIMM(vspltisb, 6, 12); | |
7186 | GEN_VXFORM_SIMM(vspltish, 6, 13); | |
7187 | GEN_VXFORM_SIMM(vspltisw, 6, 14); | |
7188 | ||
de5f2484 | 7189 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ |
99e300ef | 7190 | static void glue(gen_, name)(DisasContext *ctx) \ |
de5f2484 AJ |
7191 | { \ |
7192 | TCGv_ptr rb, rd; \ | |
7193 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7194 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7195 | return; \ | |
7196 | } \ | |
7197 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7198 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7199 | gen_helper_##name (rd, rb); \ | |
7200 | tcg_temp_free_ptr(rb); \ | |
7201 | tcg_temp_free_ptr(rd); \ | |
7202 | } | |
7203 | ||
d15f74fb BS |
7204 | #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \ |
7205 | static void glue(gen_, name)(DisasContext *ctx) \ | |
7206 | { \ | |
7207 | TCGv_ptr rb, rd; \ | |
7208 | \ | |
7209 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7210 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7211 | return; \ | |
7212 | } \ | |
7213 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7214 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7215 | gen_helper_##name(cpu_env, rd, rb); \ | |
7216 | tcg_temp_free_ptr(rb); \ | |
7217 | tcg_temp_free_ptr(rd); \ | |
7218 | } | |
7219 | ||
6cf1c6e5 AJ |
7220 | GEN_VXFORM_NOA(vupkhsb, 7, 8); |
7221 | GEN_VXFORM_NOA(vupkhsh, 7, 9); | |
4430e076 | 7222 | GEN_VXFORM_NOA(vupkhsw, 7, 25); |
6cf1c6e5 AJ |
7223 | GEN_VXFORM_NOA(vupklsb, 7, 10); |
7224 | GEN_VXFORM_NOA(vupklsh, 7, 11); | |
4430e076 | 7225 | GEN_VXFORM_NOA(vupklsw, 7, 27); |
79f85c3a AJ |
7226 | GEN_VXFORM_NOA(vupkhpx, 7, 13); |
7227 | GEN_VXFORM_NOA(vupklpx, 7, 15); | |
d15f74fb BS |
7228 | GEN_VXFORM_NOA_ENV(vrefp, 5, 4); |
7229 | GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5); | |
7230 | GEN_VXFORM_NOA_ENV(vexptefp, 5, 6); | |
7231 | GEN_VXFORM_NOA_ENV(vlogefp, 5, 7); | |
7232 | GEN_VXFORM_NOA_ENV(vrfim, 5, 8); | |
7233 | GEN_VXFORM_NOA_ENV(vrfin, 5, 9); | |
7234 | GEN_VXFORM_NOA_ENV(vrfip, 5, 10); | |
7235 | GEN_VXFORM_NOA_ENV(vrfiz, 5, 11); | |
79f85c3a | 7236 | |
21d21583 | 7237 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 7238 | static void glue(gen_, name)(DisasContext *ctx) \ |
21d21583 AJ |
7239 | { \ |
7240 | TCGv_ptr rd; \ | |
7241 | TCGv_i32 simm; \ | |
7242 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7243 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7244 | return; \ | |
7245 | } \ | |
7246 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
7247 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7248 | gen_helper_##name (rd, simm); \ | |
7249 | tcg_temp_free_i32(simm); \ | |
7250 | tcg_temp_free_ptr(rd); \ | |
7251 | } | |
7252 | ||
27a4edb3 | 7253 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ |
99e300ef | 7254 | static void glue(gen_, name)(DisasContext *ctx) \ |
27a4edb3 AJ |
7255 | { \ |
7256 | TCGv_ptr rb, rd; \ | |
7257 | TCGv_i32 uimm; \ | |
7258 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7259 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7260 | return; \ | |
7261 | } \ | |
7262 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
7263 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7264 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7265 | gen_helper_##name (rd, rb, uimm); \ | |
7266 | tcg_temp_free_i32(uimm); \ | |
7267 | tcg_temp_free_ptr(rb); \ | |
7268 | tcg_temp_free_ptr(rd); \ | |
7269 | } | |
7270 | ||
d15f74fb BS |
7271 | #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \ |
7272 | static void glue(gen_, name)(DisasContext *ctx) \ | |
7273 | { \ | |
7274 | TCGv_ptr rb, rd; \ | |
7275 | TCGv_i32 uimm; \ | |
7276 | \ | |
7277 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7278 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7279 | return; \ | |
7280 | } \ | |
7281 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
7282 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7283 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7284 | gen_helper_##name(cpu_env, rd, rb, uimm); \ | |
7285 | tcg_temp_free_i32(uimm); \ | |
7286 | tcg_temp_free_ptr(rb); \ | |
7287 | tcg_temp_free_ptr(rd); \ | |
7288 | } | |
7289 | ||
e4e6bee7 AJ |
7290 | GEN_VXFORM_UIMM(vspltb, 6, 8); |
7291 | GEN_VXFORM_UIMM(vsplth, 6, 9); | |
7292 | GEN_VXFORM_UIMM(vspltw, 6, 10); | |
d15f74fb BS |
7293 | GEN_VXFORM_UIMM_ENV(vcfux, 5, 12); |
7294 | GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13); | |
7295 | GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14); | |
7296 | GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15); | |
e4e6bee7 | 7297 | |
99e300ef | 7298 | static void gen_vsldoi(DisasContext *ctx) |
cd633b10 AJ |
7299 | { |
7300 | TCGv_ptr ra, rb, rd; | |
fce5ecb7 | 7301 | TCGv_i32 sh; |
cd633b10 AJ |
7302 | if (unlikely(!ctx->altivec_enabled)) { |
7303 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7304 | return; | |
7305 | } | |
7306 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
7307 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
7308 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
7309 | sh = tcg_const_i32(VSH(ctx->opcode)); | |
7310 | gen_helper_vsldoi (rd, ra, rb, sh); | |
7311 | tcg_temp_free_ptr(ra); | |
7312 | tcg_temp_free_ptr(rb); | |
7313 | tcg_temp_free_ptr(rd); | |
fce5ecb7 | 7314 | tcg_temp_free_i32(sh); |
cd633b10 AJ |
7315 | } |
7316 | ||
707cec33 | 7317 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ |
d15f74fb | 7318 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
707cec33 AJ |
7319 | { \ |
7320 | TCGv_ptr ra, rb, rc, rd; \ | |
7321 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7322 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7323 | return; \ | |
7324 | } \ | |
7325 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
7326 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7327 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
7328 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7329 | if (Rc(ctx->opcode)) { \ | |
d15f74fb | 7330 | gen_helper_##name1(cpu_env, rd, ra, rb, rc); \ |
707cec33 | 7331 | } else { \ |
d15f74fb | 7332 | gen_helper_##name0(cpu_env, rd, ra, rb, rc); \ |
707cec33 AJ |
7333 | } \ |
7334 | tcg_temp_free_ptr(ra); \ | |
7335 | tcg_temp_free_ptr(rb); \ | |
7336 | tcg_temp_free_ptr(rc); \ | |
7337 | tcg_temp_free_ptr(rd); \ | |
7338 | } | |
7339 | ||
b161ae27 AJ |
7340 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16) |
7341 | ||
99e300ef | 7342 | static void gen_vmladduhm(DisasContext *ctx) |
bcd2ee23 AJ |
7343 | { |
7344 | TCGv_ptr ra, rb, rc, rd; | |
7345 | if (unlikely(!ctx->altivec_enabled)) { | |
7346 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7347 | return; | |
7348 | } | |
7349 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
7350 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
7351 | rc = gen_avr_ptr(rC(ctx->opcode)); | |
7352 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
7353 | gen_helper_vmladduhm(rd, ra, rb, rc); | |
7354 | tcg_temp_free_ptr(ra); | |
7355 | tcg_temp_free_ptr(rb); | |
7356 | tcg_temp_free_ptr(rc); | |
7357 | tcg_temp_free_ptr(rd); | |
7358 | } | |
7359 | ||
b04ae981 | 7360 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18) |
4d9903b6 | 7361 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19) |
eae07261 | 7362 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20) |
d1258698 | 7363 | GEN_VAFORM_PAIRED(vsel, vperm, 21) |
35cf7c7e | 7364 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23) |
b04ae981 | 7365 | |
f293f04a TM |
7366 | GEN_VXFORM_NOA(vclzb, 1, 28) |
7367 | GEN_VXFORM_NOA(vclzh, 1, 29) | |
7368 | GEN_VXFORM_NOA(vclzw, 1, 30) | |
7369 | GEN_VXFORM_NOA(vclzd, 1, 31) | |
e13500b3 TM |
7370 | GEN_VXFORM_NOA(vpopcntb, 1, 28) |
7371 | GEN_VXFORM_NOA(vpopcnth, 1, 29) | |
7372 | GEN_VXFORM_NOA(vpopcntw, 1, 30) | |
7373 | GEN_VXFORM_NOA(vpopcntd, 1, 31) | |
7374 | GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7375 | vpopcntb, PPC_NONE, PPC2_ALTIVEC_207) | |
7376 | GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7377 | vpopcnth, PPC_NONE, PPC2_ALTIVEC_207) | |
7378 | GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7379 | vpopcntw, PPC_NONE, PPC2_ALTIVEC_207) | |
7380 | GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \ | |
7381 | vpopcntd, PPC_NONE, PPC2_ALTIVEC_207) | |
4d82038e | 7382 | GEN_VXFORM(vbpermq, 6, 21); |
f1064f61 | 7383 | GEN_VXFORM_NOA(vgbbd, 6, 20); |
b8476fc7 TM |
7384 | GEN_VXFORM(vpmsumb, 4, 16) |
7385 | GEN_VXFORM(vpmsumh, 4, 17) | |
7386 | GEN_VXFORM(vpmsumw, 4, 18) | |
7387 | GEN_VXFORM(vpmsumd, 4, 19) | |
e13500b3 | 7388 | |
e8f7b27b TM |
7389 | #define GEN_BCD(op) \ |
7390 | static void gen_##op(DisasContext *ctx) \ | |
7391 | { \ | |
7392 | TCGv_ptr ra, rb, rd; \ | |
7393 | TCGv_i32 ps; \ | |
7394 | \ | |
7395 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7396 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7397 | return; \ | |
7398 | } \ | |
7399 | \ | |
7400 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
7401 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7402 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7403 | \ | |
7404 | ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \ | |
7405 | \ | |
7406 | gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \ | |
7407 | \ | |
7408 | tcg_temp_free_ptr(ra); \ | |
7409 | tcg_temp_free_ptr(rb); \ | |
7410 | tcg_temp_free_ptr(rd); \ | |
7411 | tcg_temp_free_i32(ps); \ | |
7412 | } | |
7413 | ||
7414 | GEN_BCD(bcdadd) | |
7415 | GEN_BCD(bcdsub) | |
7416 | ||
7417 | GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \ | |
7418 | bcdadd, PPC_NONE, PPC2_ALTIVEC_207) | |
7419 | GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \ | |
7420 | bcdadd, PPC_NONE, PPC2_ALTIVEC_207) | |
7421 | GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \ | |
7422 | bcdsub, PPC_NONE, PPC2_ALTIVEC_207) | |
7423 | GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \ | |
7424 | bcdsub, PPC_NONE, PPC2_ALTIVEC_207) | |
7425 | ||
557d52fa TM |
7426 | static void gen_vsbox(DisasContext *ctx) |
7427 | { | |
7428 | TCGv_ptr ra, rd; | |
7429 | if (unlikely(!ctx->altivec_enabled)) { | |
7430 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7431 | return; | |
7432 | } | |
7433 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
7434 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
7435 | gen_helper_vsbox(rd, ra); | |
7436 | tcg_temp_free_ptr(ra); | |
7437 | tcg_temp_free_ptr(rd); | |
7438 | } | |
7439 | ||
7440 | GEN_VXFORM(vcipher, 4, 20) | |
7441 | GEN_VXFORM(vcipherlast, 4, 20) | |
7442 | GEN_VXFORM(vncipher, 4, 21) | |
7443 | GEN_VXFORM(vncipherlast, 4, 21) | |
7444 | ||
7445 | GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207, | |
7446 | vcipherlast, PPC_NONE, PPC2_ALTIVEC_207) | |
7447 | GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207, | |
7448 | vncipherlast, PPC_NONE, PPC2_ALTIVEC_207) | |
7449 | ||
57354f8f TM |
7450 | #define VSHASIGMA(op) \ |
7451 | static void gen_##op(DisasContext *ctx) \ | |
7452 | { \ | |
7453 | TCGv_ptr ra, rd; \ | |
7454 | TCGv_i32 st_six; \ | |
7455 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7456 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7457 | return; \ | |
7458 | } \ | |
7459 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
7460 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7461 | st_six = tcg_const_i32(rB(ctx->opcode)); \ | |
7462 | gen_helper_##op(rd, ra, st_six); \ | |
7463 | tcg_temp_free_ptr(ra); \ | |
7464 | tcg_temp_free_ptr(rd); \ | |
7465 | tcg_temp_free_i32(st_six); \ | |
7466 | } | |
7467 | ||
7468 | VSHASIGMA(vshasigmaw) | |
7469 | VSHASIGMA(vshasigmad) | |
7470 | ||
ac174549 TM |
7471 | GEN_VXFORM3(vpermxor, 22, 0xFF) |
7472 | GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE, | |
7473 | vpermxor, PPC_NONE, PPC2_ALTIVEC_207) | |
7474 | ||
472b24ce TM |
7475 | /*** VSX extension ***/ |
7476 | ||
7477 | static inline TCGv_i64 cpu_vsrh(int n) | |
7478 | { | |
7479 | if (n < 32) { | |
7480 | return cpu_fpr[n]; | |
7481 | } else { | |
7482 | return cpu_avrh[n-32]; | |
7483 | } | |
7484 | } | |
7485 | ||
7486 | static inline TCGv_i64 cpu_vsrl(int n) | |
7487 | { | |
7488 | if (n < 32) { | |
7489 | return cpu_vsr[n]; | |
7490 | } else { | |
7491 | return cpu_avrl[n-32]; | |
7492 | } | |
7493 | } | |
7494 | ||
e072fe79 TM |
7495 | #define VSX_LOAD_SCALAR(name, operation) \ |
7496 | static void gen_##name(DisasContext *ctx) \ | |
7497 | { \ | |
7498 | TCGv EA; \ | |
7499 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7500 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7501 | return; \ | |
7502 | } \ | |
7503 | gen_set_access_type(ctx, ACCESS_INT); \ | |
7504 | EA = tcg_temp_new(); \ | |
7505 | gen_addr_reg_index(ctx, EA); \ | |
7506 | gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \ | |
7507 | /* NOTE: cpu_vsrl is undefined */ \ | |
7508 | tcg_temp_free(EA); \ | |
7509 | } | |
7510 | ||
7511 | VSX_LOAD_SCALAR(lxsdx, ld64) | |
cac7f0ba TM |
7512 | VSX_LOAD_SCALAR(lxsiwax, ld32s_i64) |
7513 | VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64) | |
7514 | VSX_LOAD_SCALAR(lxsspx, ld32fs) | |
fa1832d7 | 7515 | |
304af367 TM |
7516 | static void gen_lxvd2x(DisasContext *ctx) |
7517 | { | |
7518 | TCGv EA; | |
7519 | if (unlikely(!ctx->vsx_enabled)) { | |
7520 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7521 | return; | |
7522 | } | |
7523 | gen_set_access_type(ctx, ACCESS_INT); | |
7524 | EA = tcg_temp_new(); | |
7525 | gen_addr_reg_index(ctx, EA); | |
7526 | gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA); | |
7527 | tcg_gen_addi_tl(EA, EA, 8); | |
7528 | gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA); | |
7529 | tcg_temp_free(EA); | |
7530 | } | |
7531 | ||
ca03b467 TM |
7532 | static void gen_lxvdsx(DisasContext *ctx) |
7533 | { | |
7534 | TCGv EA; | |
7535 | if (unlikely(!ctx->vsx_enabled)) { | |
7536 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7537 | return; | |
7538 | } | |
7539 | gen_set_access_type(ctx, ACCESS_INT); | |
7540 | EA = tcg_temp_new(); | |
7541 | gen_addr_reg_index(ctx, EA); | |
7542 | gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA); | |
f976b09e | 7543 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode))); |
ca03b467 TM |
7544 | tcg_temp_free(EA); |
7545 | } | |
7546 | ||
897e61d1 TM |
7547 | static void gen_lxvw4x(DisasContext *ctx) |
7548 | { | |
f976b09e AG |
7549 | TCGv EA; |
7550 | TCGv_i64 tmp; | |
897e61d1 TM |
7551 | TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode)); |
7552 | TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode)); | |
7553 | if (unlikely(!ctx->vsx_enabled)) { | |
7554 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7555 | return; | |
7556 | } | |
7557 | gen_set_access_type(ctx, ACCESS_INT); | |
7558 | EA = tcg_temp_new(); | |
f976b09e AG |
7559 | tmp = tcg_temp_new_i64(); |
7560 | ||
897e61d1 | 7561 | gen_addr_reg_index(ctx, EA); |
f976b09e | 7562 | gen_qemu_ld32u_i64(ctx, tmp, EA); |
897e61d1 | 7563 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7564 | gen_qemu_ld32u_i64(ctx, xth, EA); |
897e61d1 TM |
7565 | tcg_gen_deposit_i64(xth, xth, tmp, 32, 32); |
7566 | ||
7567 | tcg_gen_addi_tl(EA, EA, 4); | |
f976b09e | 7568 | gen_qemu_ld32u_i64(ctx, tmp, EA); |
897e61d1 | 7569 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7570 | gen_qemu_ld32u_i64(ctx, xtl, EA); |
897e61d1 TM |
7571 | tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32); |
7572 | ||
7573 | tcg_temp_free(EA); | |
f976b09e | 7574 | tcg_temp_free_i64(tmp); |
897e61d1 TM |
7575 | } |
7576 | ||
f026da78 TM |
7577 | #define VSX_STORE_SCALAR(name, operation) \ |
7578 | static void gen_##name(DisasContext *ctx) \ | |
7579 | { \ | |
7580 | TCGv EA; \ | |
7581 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7582 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7583 | return; \ | |
7584 | } \ | |
7585 | gen_set_access_type(ctx, ACCESS_INT); \ | |
7586 | EA = tcg_temp_new(); \ | |
7587 | gen_addr_reg_index(ctx, EA); \ | |
7588 | gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \ | |
7589 | tcg_temp_free(EA); \ | |
9231ba9e TM |
7590 | } |
7591 | ||
f026da78 | 7592 | VSX_STORE_SCALAR(stxsdx, st64) |
e16a626b TM |
7593 | VSX_STORE_SCALAR(stxsiwx, st32_i64) |
7594 | VSX_STORE_SCALAR(stxsspx, st32fs) | |
f026da78 | 7595 | |
fbed2478 TM |
7596 | static void gen_stxvd2x(DisasContext *ctx) |
7597 | { | |
7598 | TCGv EA; | |
7599 | if (unlikely(!ctx->vsx_enabled)) { | |
7600 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7601 | return; | |
7602 | } | |
7603 | gen_set_access_type(ctx, ACCESS_INT); | |
7604 | EA = tcg_temp_new(); | |
7605 | gen_addr_reg_index(ctx, EA); | |
7606 | gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA); | |
7607 | tcg_gen_addi_tl(EA, EA, 8); | |
7608 | gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA); | |
7609 | tcg_temp_free(EA); | |
7610 | } | |
7611 | ||
86e61ce3 TM |
7612 | static void gen_stxvw4x(DisasContext *ctx) |
7613 | { | |
f976b09e AG |
7614 | TCGv_i64 tmp; |
7615 | TCGv EA; | |
86e61ce3 TM |
7616 | if (unlikely(!ctx->vsx_enabled)) { |
7617 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7618 | return; | |
7619 | } | |
7620 | gen_set_access_type(ctx, ACCESS_INT); | |
7621 | EA = tcg_temp_new(); | |
7622 | gen_addr_reg_index(ctx, EA); | |
f976b09e | 7623 | tmp = tcg_temp_new_i64(); |
86e61ce3 TM |
7624 | |
7625 | tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32); | |
f976b09e | 7626 | gen_qemu_st32_i64(ctx, tmp, EA); |
86e61ce3 | 7627 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7628 | gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA); |
86e61ce3 TM |
7629 | |
7630 | tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32); | |
7631 | tcg_gen_addi_tl(EA, EA, 4); | |
f976b09e | 7632 | gen_qemu_st32_i64(ctx, tmp, EA); |
86e61ce3 | 7633 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7634 | gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA); |
86e61ce3 TM |
7635 | |
7636 | tcg_temp_free(EA); | |
f976b09e | 7637 | tcg_temp_free_i64(tmp); |
86e61ce3 TM |
7638 | } |
7639 | ||
f5c0f7f9 TM |
7640 | #define MV_VSRW(name, tcgop1, tcgop2, target, source) \ |
7641 | static void gen_##name(DisasContext *ctx) \ | |
7642 | { \ | |
7643 | if (xS(ctx->opcode) < 32) { \ | |
7644 | if (unlikely(!ctx->fpu_enabled)) { \ | |
7645 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
7646 | return; \ | |
7647 | } \ | |
7648 | } else { \ | |
7649 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7650 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7651 | return; \ | |
7652 | } \ | |
7653 | } \ | |
7654 | TCGv_i64 tmp = tcg_temp_new_i64(); \ | |
7655 | tcg_gen_##tcgop1(tmp, source); \ | |
7656 | tcg_gen_##tcgop2(target, tmp); \ | |
7657 | tcg_temp_free_i64(tmp); \ | |
7658 | } | |
7659 | ||
7660 | ||
7661 | MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \ | |
7662 | cpu_vsrh(xS(ctx->opcode))) | |
7663 | MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \ | |
7664 | cpu_gpr[rA(ctx->opcode)]) | |
7665 | MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \ | |
7666 | cpu_gpr[rA(ctx->opcode)]) | |
7667 | ||
7668 | #if defined(TARGET_PPC64) | |
7669 | #define MV_VSRD(name, target, source) \ | |
7670 | static void gen_##name(DisasContext *ctx) \ | |
7671 | { \ | |
7672 | if (xS(ctx->opcode) < 32) { \ | |
7673 | if (unlikely(!ctx->fpu_enabled)) { \ | |
7674 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
7675 | return; \ | |
7676 | } \ | |
7677 | } else { \ | |
7678 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7679 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7680 | return; \ | |
7681 | } \ | |
7682 | } \ | |
7683 | tcg_gen_mov_i64(target, source); \ | |
7684 | } | |
7685 | ||
7686 | MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode))) | |
7687 | MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)]) | |
7688 | ||
7689 | #endif | |
7690 | ||
cd73f2c9 TM |
7691 | static void gen_xxpermdi(DisasContext *ctx) |
7692 | { | |
7693 | if (unlikely(!ctx->vsx_enabled)) { | |
7694 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7695 | return; | |
7696 | } | |
7697 | ||
f5bc1bfa TM |
7698 | if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) || |
7699 | (xT(ctx->opcode) == xB(ctx->opcode)))) { | |
7700 | TCGv_i64 xh, xl; | |
7701 | ||
7702 | xh = tcg_temp_new_i64(); | |
7703 | xl = tcg_temp_new_i64(); | |
7704 | ||
7705 | if ((DM(ctx->opcode) & 2) == 0) { | |
7706 | tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode))); | |
7707 | } else { | |
7708 | tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode))); | |
7709 | } | |
7710 | if ((DM(ctx->opcode) & 1) == 0) { | |
7711 | tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode))); | |
7712 | } else { | |
7713 | tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode))); | |
7714 | } | |
7715 | ||
7716 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh); | |
7717 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl); | |
7718 | ||
7719 | tcg_temp_free_i64(xh); | |
7720 | tcg_temp_free_i64(xl); | |
cd73f2c9 | 7721 | } else { |
f5bc1bfa TM |
7722 | if ((DM(ctx->opcode) & 2) == 0) { |
7723 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode))); | |
7724 | } else { | |
7725 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode))); | |
7726 | } | |
7727 | if ((DM(ctx->opcode) & 1) == 0) { | |
7728 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode))); | |
7729 | } else { | |
7730 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode))); | |
7731 | } | |
cd73f2c9 TM |
7732 | } |
7733 | } | |
7734 | ||
df020ce0 TM |
7735 | #define OP_ABS 1 |
7736 | #define OP_NABS 2 | |
7737 | #define OP_NEG 3 | |
7738 | #define OP_CPSGN 4 | |
e5d7d2b0 PM |
7739 | #define SGN_MASK_DP 0x8000000000000000ull |
7740 | #define SGN_MASK_SP 0x8000000080000000ull | |
df020ce0 TM |
7741 | |
7742 | #define VSX_SCALAR_MOVE(name, op, sgn_mask) \ | |
7743 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7744 | { \ | |
7745 | TCGv_i64 xb, sgm; \ | |
7746 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7747 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7748 | return; \ | |
7749 | } \ | |
f976b09e AG |
7750 | xb = tcg_temp_new_i64(); \ |
7751 | sgm = tcg_temp_new_i64(); \ | |
df020ce0 TM |
7752 | tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \ |
7753 | tcg_gen_movi_i64(sgm, sgn_mask); \ | |
7754 | switch (op) { \ | |
7755 | case OP_ABS: { \ | |
7756 | tcg_gen_andc_i64(xb, xb, sgm); \ | |
7757 | break; \ | |
7758 | } \ | |
7759 | case OP_NABS: { \ | |
7760 | tcg_gen_or_i64(xb, xb, sgm); \ | |
7761 | break; \ | |
7762 | } \ | |
7763 | case OP_NEG: { \ | |
7764 | tcg_gen_xor_i64(xb, xb, sgm); \ | |
7765 | break; \ | |
7766 | } \ | |
7767 | case OP_CPSGN: { \ | |
f976b09e | 7768 | TCGv_i64 xa = tcg_temp_new_i64(); \ |
df020ce0 TM |
7769 | tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \ |
7770 | tcg_gen_and_i64(xa, xa, sgm); \ | |
7771 | tcg_gen_andc_i64(xb, xb, sgm); \ | |
7772 | tcg_gen_or_i64(xb, xb, xa); \ | |
f976b09e | 7773 | tcg_temp_free_i64(xa); \ |
df020ce0 TM |
7774 | break; \ |
7775 | } \ | |
7776 | } \ | |
7777 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \ | |
f976b09e AG |
7778 | tcg_temp_free_i64(xb); \ |
7779 | tcg_temp_free_i64(sgm); \ | |
df020ce0 TM |
7780 | } |
7781 | ||
7782 | VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP) | |
7783 | VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP) | |
7784 | VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP) | |
7785 | VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP) | |
7786 | ||
be574920 TM |
7787 | #define VSX_VECTOR_MOVE(name, op, sgn_mask) \ |
7788 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7789 | { \ | |
7790 | TCGv_i64 xbh, xbl, sgm; \ | |
7791 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7792 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7793 | return; \ | |
7794 | } \ | |
f976b09e AG |
7795 | xbh = tcg_temp_new_i64(); \ |
7796 | xbl = tcg_temp_new_i64(); \ | |
7797 | sgm = tcg_temp_new_i64(); \ | |
be574920 TM |
7798 | tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \ |
7799 | tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \ | |
7800 | tcg_gen_movi_i64(sgm, sgn_mask); \ | |
7801 | switch (op) { \ | |
7802 | case OP_ABS: { \ | |
7803 | tcg_gen_andc_i64(xbh, xbh, sgm); \ | |
7804 | tcg_gen_andc_i64(xbl, xbl, sgm); \ | |
7805 | break; \ | |
7806 | } \ | |
7807 | case OP_NABS: { \ | |
7808 | tcg_gen_or_i64(xbh, xbh, sgm); \ | |
7809 | tcg_gen_or_i64(xbl, xbl, sgm); \ | |
7810 | break; \ | |
7811 | } \ | |
7812 | case OP_NEG: { \ | |
7813 | tcg_gen_xor_i64(xbh, xbh, sgm); \ | |
7814 | tcg_gen_xor_i64(xbl, xbl, sgm); \ | |
7815 | break; \ | |
7816 | } \ | |
7817 | case OP_CPSGN: { \ | |
f976b09e AG |
7818 | TCGv_i64 xah = tcg_temp_new_i64(); \ |
7819 | TCGv_i64 xal = tcg_temp_new_i64(); \ | |
be574920 TM |
7820 | tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \ |
7821 | tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \ | |
7822 | tcg_gen_and_i64(xah, xah, sgm); \ | |
7823 | tcg_gen_and_i64(xal, xal, sgm); \ | |
7824 | tcg_gen_andc_i64(xbh, xbh, sgm); \ | |
7825 | tcg_gen_andc_i64(xbl, xbl, sgm); \ | |
7826 | tcg_gen_or_i64(xbh, xbh, xah); \ | |
7827 | tcg_gen_or_i64(xbl, xbl, xal); \ | |
f976b09e AG |
7828 | tcg_temp_free_i64(xah); \ |
7829 | tcg_temp_free_i64(xal); \ | |
be574920 TM |
7830 | break; \ |
7831 | } \ | |
7832 | } \ | |
7833 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \ | |
7834 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \ | |
f976b09e AG |
7835 | tcg_temp_free_i64(xbh); \ |
7836 | tcg_temp_free_i64(xbl); \ | |
7837 | tcg_temp_free_i64(sgm); \ | |
be574920 TM |
7838 | } |
7839 | ||
7840 | VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP) | |
7841 | VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP) | |
7842 | VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP) | |
7843 | VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP) | |
7844 | VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP) | |
7845 | VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP) | |
7846 | VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP) | |
7847 | VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP) | |
7848 | ||
3c3cbbdc TM |
7849 | #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \ |
7850 | static void gen_##name(DisasContext * ctx) \ | |
7851 | { \ | |
7852 | TCGv_i32 opc; \ | |
7853 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7854 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7855 | return; \ | |
7856 | } \ | |
7857 | /* NIP cannot be restored if the memory exception comes from an helper */ \ | |
7858 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7859 | opc = tcg_const_i32(ctx->opcode); \ | |
7860 | gen_helper_##name(cpu_env, opc); \ | |
7861 | tcg_temp_free_i32(opc); \ | |
7862 | } | |
be574920 | 7863 | |
3d1140bf TM |
7864 | #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \ |
7865 | static void gen_##name(DisasContext * ctx) \ | |
7866 | { \ | |
7867 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7868 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7869 | return; \ | |
7870 | } \ | |
7871 | /* NIP cannot be restored if the exception comes */ \ | |
7872 | /* from a helper. */ \ | |
7873 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7874 | \ | |
7875 | gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \ | |
7876 | cpu_vsrh(xB(ctx->opcode))); \ | |
7877 | } | |
7878 | ||
ee6e02c0 TM |
7879 | GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX) |
7880 | GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX) | |
5e591d88 | 7881 | GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX) |
4b98eeef | 7882 | GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX) |
2009227f | 7883 | GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX) |
d32404fe | 7884 | GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX) |
d3f9df8f | 7885 | GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX) |
bc80838f | 7886 | GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX) |
5cb151ac | 7887 | GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX) |
595c6eef TM |
7888 | GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX) |
7889 | GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX) | |
7890 | GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX) | |
7891 | GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX) | |
7892 | GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX) | |
7893 | GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX) | |
7894 | GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX) | |
7895 | GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX) | |
4f17e9c7 TM |
7896 | GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX) |
7897 | GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX) | |
959e9c9d TM |
7898 | GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX) |
7899 | GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX) | |
ed8ac568 | 7900 | GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX) |
7ee19fb9 | 7901 | GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207) |
ed8ac568 | 7902 | GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX) |
7ee19fb9 | 7903 | GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207) |
5177d2ca TM |
7904 | GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX) |
7905 | GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX) | |
7906 | GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX) | |
7907 | GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX) | |
7908 | GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX) | |
7909 | GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX) | |
88e33d08 TM |
7910 | GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX) |
7911 | GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX) | |
7912 | GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX) | |
7913 | GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX) | |
7914 | GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX) | |
3d1140bf | 7915 | GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207) |
ee6e02c0 | 7916 | |
3fd0aadf TM |
7917 | GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207) |
7918 | GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207) | |
ab9408a2 | 7919 | GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207) |
b24d0b47 | 7920 | GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207) |
2c0c52ae | 7921 | GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207) |
cea4e574 | 7922 | GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207) |
968e76bc | 7923 | GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207) |
f53f81e0 TM |
7924 | GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207) |
7925 | GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207) | |
7926 | GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207) | |
7927 | GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207) | |
7928 | GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207) | |
7929 | GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207) | |
7930 | GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207) | |
7931 | GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207) | |
74698350 TM |
7932 | GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207) |
7933 | GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207) | |
3fd0aadf | 7934 | |
ee6e02c0 TM |
7935 | GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX) |
7936 | GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX) | |
5e591d88 | 7937 | GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX) |
4b98eeef | 7938 | GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX) |
2009227f | 7939 | GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX) |
d32404fe | 7940 | GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX) |
d3f9df8f | 7941 | GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX) |
bc80838f | 7942 | GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX) |
5cb151ac | 7943 | GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX) |
595c6eef TM |
7944 | GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX) |
7945 | GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX) | |
7946 | GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX) | |
7947 | GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX) | |
7948 | GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX) | |
7949 | GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX) | |
7950 | GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX) | |
7951 | GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX) | |
959e9c9d TM |
7952 | GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX) |
7953 | GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX) | |
354a6dec TM |
7954 | GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX) |
7955 | GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX) | |
7956 | GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX) | |
ed8ac568 | 7957 | GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX) |
5177d2ca TM |
7958 | GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX) |
7959 | GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX) | |
7960 | GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX) | |
7961 | GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX) | |
7962 | GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX) | |
7963 | GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX) | |
7964 | GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX) | |
7965 | GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX) | |
88e33d08 TM |
7966 | GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX) |
7967 | GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX) | |
7968 | GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX) | |
7969 | GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX) | |
7970 | GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX) | |
ee6e02c0 TM |
7971 | |
7972 | GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX) | |
7973 | GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX) | |
5e591d88 | 7974 | GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX) |
4b98eeef | 7975 | GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX) |
2009227f | 7976 | GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX) |
d32404fe | 7977 | GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX) |
d3f9df8f | 7978 | GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX) |
bc80838f | 7979 | GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX) |
5cb151ac | 7980 | GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX) |
595c6eef TM |
7981 | GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX) |
7982 | GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX) | |
7983 | GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX) | |
7984 | GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX) | |
7985 | GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX) | |
7986 | GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX) | |
7987 | GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX) | |
7988 | GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX) | |
959e9c9d TM |
7989 | GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX) |
7990 | GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX) | |
354a6dec TM |
7991 | GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX) |
7992 | GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX) | |
7993 | GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX) | |
ed8ac568 | 7994 | GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX) |
5177d2ca TM |
7995 | GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX) |
7996 | GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX) | |
7997 | GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX) | |
7998 | GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX) | |
7999 | GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX) | |
8000 | GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX) | |
8001 | GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX) | |
8002 | GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX) | |
88e33d08 TM |
8003 | GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX) |
8004 | GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX) | |
8005 | GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX) | |
8006 | GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX) | |
8007 | GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX) | |
ee6e02c0 | 8008 | |
79ca8a6a TM |
8009 | #define VSX_LOGICAL(name, tcg_op) \ |
8010 | static void glue(gen_, name)(DisasContext * ctx) \ | |
8011 | { \ | |
8012 | if (unlikely(!ctx->vsx_enabled)) { \ | |
8013 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
8014 | return; \ | |
8015 | } \ | |
8016 | tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \ | |
8017 | cpu_vsrh(xB(ctx->opcode))); \ | |
8018 | tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \ | |
8019 | cpu_vsrl(xB(ctx->opcode))); \ | |
8020 | } | |
8021 | ||
f976b09e AG |
8022 | VSX_LOGICAL(xxland, tcg_gen_and_i64) |
8023 | VSX_LOGICAL(xxlandc, tcg_gen_andc_i64) | |
8024 | VSX_LOGICAL(xxlor, tcg_gen_or_i64) | |
8025 | VSX_LOGICAL(xxlxor, tcg_gen_xor_i64) | |
8026 | VSX_LOGICAL(xxlnor, tcg_gen_nor_i64) | |
67a33f37 TM |
8027 | VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64) |
8028 | VSX_LOGICAL(xxlnand, tcg_gen_nand_i64) | |
8029 | VSX_LOGICAL(xxlorc, tcg_gen_orc_i64) | |
df020ce0 | 8030 | |
ce577d2e TM |
8031 | #define VSX_XXMRG(name, high) \ |
8032 | static void glue(gen_, name)(DisasContext * ctx) \ | |
8033 | { \ | |
8034 | TCGv_i64 a0, a1, b0, b1; \ | |
8035 | if (unlikely(!ctx->vsx_enabled)) { \ | |
8036 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
8037 | return; \ | |
8038 | } \ | |
f976b09e AG |
8039 | a0 = tcg_temp_new_i64(); \ |
8040 | a1 = tcg_temp_new_i64(); \ | |
8041 | b0 = tcg_temp_new_i64(); \ | |
8042 | b1 = tcg_temp_new_i64(); \ | |
ce577d2e TM |
8043 | if (high) { \ |
8044 | tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \ | |
8045 | tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \ | |
8046 | tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \ | |
8047 | tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \ | |
8048 | } else { \ | |
8049 | tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \ | |
8050 | tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \ | |
8051 | tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \ | |
8052 | tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \ | |
8053 | } \ | |
8054 | tcg_gen_shri_i64(a0, a0, 32); \ | |
8055 | tcg_gen_shri_i64(b0, b0, 32); \ | |
8056 | tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \ | |
8057 | b0, a0, 32, 32); \ | |
8058 | tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \ | |
8059 | b1, a1, 32, 32); \ | |
f976b09e AG |
8060 | tcg_temp_free_i64(a0); \ |
8061 | tcg_temp_free_i64(a1); \ | |
8062 | tcg_temp_free_i64(b0); \ | |
8063 | tcg_temp_free_i64(b1); \ | |
ce577d2e TM |
8064 | } |
8065 | ||
8066 | VSX_XXMRG(xxmrghw, 1) | |
8067 | VSX_XXMRG(xxmrglw, 0) | |
8068 | ||
551e3ef7 TM |
8069 | static void gen_xxsel(DisasContext * ctx) |
8070 | { | |
8071 | TCGv_i64 a, b, c; | |
8072 | if (unlikely(!ctx->vsx_enabled)) { | |
8073 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
8074 | return; | |
8075 | } | |
f976b09e AG |
8076 | a = tcg_temp_new_i64(); |
8077 | b = tcg_temp_new_i64(); | |
8078 | c = tcg_temp_new_i64(); | |
551e3ef7 TM |
8079 | |
8080 | tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode))); | |
8081 | tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode))); | |
8082 | tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode))); | |
8083 | ||
8084 | tcg_gen_and_i64(b, b, c); | |
8085 | tcg_gen_andc_i64(a, a, c); | |
8086 | tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b); | |
8087 | ||
8088 | tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode))); | |
8089 | tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode))); | |
8090 | tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode))); | |
8091 | ||
8092 | tcg_gen_and_i64(b, b, c); | |
8093 | tcg_gen_andc_i64(a, a, c); | |
8094 | tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b); | |
8095 | ||
f976b09e AG |
8096 | tcg_temp_free_i64(a); |
8097 | tcg_temp_free_i64(b); | |
8098 | tcg_temp_free_i64(c); | |
551e3ef7 TM |
8099 | } |
8100 | ||
76c15fe0 TM |
8101 | static void gen_xxspltw(DisasContext *ctx) |
8102 | { | |
8103 | TCGv_i64 b, b2; | |
8104 | TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ? | |
8105 | cpu_vsrl(xB(ctx->opcode)) : | |
8106 | cpu_vsrh(xB(ctx->opcode)); | |
8107 | ||
8108 | if (unlikely(!ctx->vsx_enabled)) { | |
8109 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
8110 | return; | |
8111 | } | |
8112 | ||
f976b09e AG |
8113 | b = tcg_temp_new_i64(); |
8114 | b2 = tcg_temp_new_i64(); | |
76c15fe0 TM |
8115 | |
8116 | if (UIM(ctx->opcode) & 1) { | |
8117 | tcg_gen_ext32u_i64(b, vsr); | |
8118 | } else { | |
8119 | tcg_gen_shri_i64(b, vsr, 32); | |
8120 | } | |
8121 | ||
8122 | tcg_gen_shli_i64(b2, b, 32); | |
8123 | tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2); | |
8124 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode))); | |
8125 | ||
f976b09e AG |
8126 | tcg_temp_free_i64(b); |
8127 | tcg_temp_free_i64(b2); | |
76c15fe0 TM |
8128 | } |
8129 | ||
acc42968 TM |
8130 | static void gen_xxsldwi(DisasContext *ctx) |
8131 | { | |
8132 | TCGv_i64 xth, xtl; | |
8133 | if (unlikely(!ctx->vsx_enabled)) { | |
8134 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
8135 | return; | |
8136 | } | |
f976b09e AG |
8137 | xth = tcg_temp_new_i64(); |
8138 | xtl = tcg_temp_new_i64(); | |
acc42968 TM |
8139 | |
8140 | switch (SHW(ctx->opcode)) { | |
8141 | case 0: { | |
8142 | tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode))); | |
8143 | tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode))); | |
8144 | break; | |
8145 | } | |
8146 | case 1: { | |
f976b09e | 8147 | TCGv_i64 t0 = tcg_temp_new_i64(); |
acc42968 TM |
8148 | tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode))); |
8149 | tcg_gen_shli_i64(xth, xth, 32); | |
8150 | tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode))); | |
8151 | tcg_gen_shri_i64(t0, t0, 32); | |
8152 | tcg_gen_or_i64(xth, xth, t0); | |
8153 | tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode))); | |
8154 | tcg_gen_shli_i64(xtl, xtl, 32); | |
8155 | tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode))); | |
8156 | tcg_gen_shri_i64(t0, t0, 32); | |
8157 | tcg_gen_or_i64(xtl, xtl, t0); | |
f976b09e | 8158 | tcg_temp_free_i64(t0); |
acc42968 TM |
8159 | break; |
8160 | } | |
8161 | case 2: { | |
8162 | tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode))); | |
8163 | tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode))); | |
8164 | break; | |
8165 | } | |
8166 | case 3: { | |
f976b09e | 8167 | TCGv_i64 t0 = tcg_temp_new_i64(); |
acc42968 TM |
8168 | tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode))); |
8169 | tcg_gen_shli_i64(xth, xth, 32); | |
8170 | tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode))); | |
8171 | tcg_gen_shri_i64(t0, t0, 32); | |
8172 | tcg_gen_or_i64(xth, xth, t0); | |
8173 | tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode))); | |
8174 | tcg_gen_shli_i64(xtl, xtl, 32); | |
8175 | tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode))); | |
8176 | tcg_gen_shri_i64(t0, t0, 32); | |
8177 | tcg_gen_or_i64(xtl, xtl, t0); | |
f976b09e | 8178 | tcg_temp_free_i64(t0); |
acc42968 TM |
8179 | break; |
8180 | } | |
8181 | } | |
8182 | ||
8183 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth); | |
8184 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl); | |
8185 | ||
f976b09e AG |
8186 | tcg_temp_free_i64(xth); |
8187 | tcg_temp_free_i64(xtl); | |
acc42968 TM |
8188 | } |
8189 | ||
f0b01f02 TM |
8190 | /*** Decimal Floating Point ***/ |
8191 | ||
8192 | static inline TCGv_ptr gen_fprp_ptr(int reg) | |
8193 | { | |
8194 | TCGv_ptr r = tcg_temp_new_ptr(); | |
8195 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg])); | |
8196 | return r; | |
8197 | } | |
8198 | ||
8199 | #if defined(TARGET_PPC64) | |
f0b01f02 TM |
8200 | static void gen_set_cr6_from_fpscr(DisasContext *ctx) |
8201 | { | |
8202 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
8203 | tcg_gen_trunc_tl_i32(tmp, cpu_fpscr); | |
8204 | tcg_gen_shri_i32(cpu_crf[1], tmp, 28); | |
8205 | tcg_temp_free_i32(tmp); | |
8206 | } | |
8207 | #else | |
f0b01f02 TM |
8208 | static void gen_set_cr6_from_fpscr(DisasContext *ctx) |
8209 | { | |
8210 | tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28); | |
8211 | } | |
8212 | #endif | |
8213 | ||
8214 | #define GEN_DFP_T_A_B_Rc(name) \ | |
8215 | static void gen_##name(DisasContext *ctx) \ | |
8216 | { \ | |
8217 | TCGv_ptr rd, ra, rb; \ | |
8218 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8219 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8220 | return; \ | |
8221 | } \ | |
8222 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8223 | rd = gen_fprp_ptr(rD(ctx->opcode)); \ | |
8224 | ra = gen_fprp_ptr(rA(ctx->opcode)); \ | |
8225 | rb = gen_fprp_ptr(rB(ctx->opcode)); \ | |
8226 | gen_helper_##name(cpu_env, rd, ra, rb); \ | |
8227 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
8228 | gen_set_cr6_from_fpscr(ctx); \ | |
8229 | } \ | |
8230 | tcg_temp_free_ptr(rd); \ | |
8231 | tcg_temp_free_ptr(ra); \ | |
8232 | tcg_temp_free_ptr(rb); \ | |
8233 | } | |
8234 | ||
8235 | #define GEN_DFP_BF_A_B(name) \ | |
8236 | static void gen_##name(DisasContext *ctx) \ | |
8237 | { \ | |
8238 | TCGv_ptr ra, rb; \ | |
8239 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8240 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8241 | return; \ | |
8242 | } \ | |
8243 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8244 | ra = gen_fprp_ptr(rA(ctx->opcode)); \ | |
8245 | rb = gen_fprp_ptr(rB(ctx->opcode)); \ | |
8246 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \ | |
8247 | cpu_env, ra, rb); \ | |
8248 | tcg_temp_free_ptr(ra); \ | |
8249 | tcg_temp_free_ptr(rb); \ | |
8250 | } | |
8251 | ||
8252 | #define GEN_DFP_BF_A_DCM(name) \ | |
8253 | static void gen_##name(DisasContext *ctx) \ | |
8254 | { \ | |
8255 | TCGv_ptr ra; \ | |
8256 | TCGv_i32 dcm; \ | |
8257 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8258 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8259 | return; \ | |
8260 | } \ | |
8261 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8262 | ra = gen_fprp_ptr(rA(ctx->opcode)); \ | |
8263 | dcm = tcg_const_i32(DCM(ctx->opcode)); \ | |
8264 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \ | |
8265 | cpu_env, ra, dcm); \ | |
8266 | tcg_temp_free_ptr(ra); \ | |
8267 | tcg_temp_free_i32(dcm); \ | |
8268 | } | |
8269 | ||
8270 | #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \ | |
8271 | static void gen_##name(DisasContext *ctx) \ | |
8272 | { \ | |
8273 | TCGv_ptr rt, rb; \ | |
8274 | TCGv_i32 u32_1, u32_2; \ | |
8275 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8276 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8277 | return; \ | |
8278 | } \ | |
8279 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8280 | rt = gen_fprp_ptr(rD(ctx->opcode)); \ | |
8281 | rb = gen_fprp_ptr(rB(ctx->opcode)); \ | |
8282 | u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \ | |
8283 | u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \ | |
8284 | gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \ | |
8285 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
8286 | gen_set_cr6_from_fpscr(ctx); \ | |
8287 | } \ | |
8288 | tcg_temp_free_ptr(rt); \ | |
8289 | tcg_temp_free_ptr(rb); \ | |
8290 | tcg_temp_free_i32(u32_1); \ | |
8291 | tcg_temp_free_i32(u32_2); \ | |
8292 | } | |
8293 | ||
8294 | #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \ | |
8295 | static void gen_##name(DisasContext *ctx) \ | |
8296 | { \ | |
8297 | TCGv_ptr rt, ra, rb; \ | |
8298 | TCGv_i32 i32; \ | |
8299 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8300 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8301 | return; \ | |
8302 | } \ | |
8303 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8304 | rt = gen_fprp_ptr(rD(ctx->opcode)); \ | |
8305 | ra = gen_fprp_ptr(rA(ctx->opcode)); \ | |
8306 | rb = gen_fprp_ptr(rB(ctx->opcode)); \ | |
8307 | i32 = tcg_const_i32(i32fld(ctx->opcode)); \ | |
8308 | gen_helper_##name(cpu_env, rt, ra, rb, i32); \ | |
8309 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
8310 | gen_set_cr6_from_fpscr(ctx); \ | |
8311 | } \ | |
8312 | tcg_temp_free_ptr(rt); \ | |
8313 | tcg_temp_free_ptr(rb); \ | |
8314 | tcg_temp_free_ptr(ra); \ | |
8315 | tcg_temp_free_i32(i32); \ | |
8316 | } | |
8317 | ||
8318 | #define GEN_DFP_T_B_Rc(name) \ | |
8319 | static void gen_##name(DisasContext *ctx) \ | |
8320 | { \ | |
8321 | TCGv_ptr rt, rb; \ | |
8322 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8323 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8324 | return; \ | |
8325 | } \ | |
8326 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8327 | rt = gen_fprp_ptr(rD(ctx->opcode)); \ | |
8328 | rb = gen_fprp_ptr(rB(ctx->opcode)); \ | |
8329 | gen_helper_##name(cpu_env, rt, rb); \ | |
8330 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
8331 | gen_set_cr6_from_fpscr(ctx); \ | |
8332 | } \ | |
8333 | tcg_temp_free_ptr(rt); \ | |
8334 | tcg_temp_free_ptr(rb); \ | |
8335 | } | |
8336 | ||
8337 | #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \ | |
8338 | static void gen_##name(DisasContext *ctx) \ | |
8339 | { \ | |
8340 | TCGv_ptr rt, rs; \ | |
8341 | TCGv_i32 i32; \ | |
8342 | if (unlikely(!ctx->fpu_enabled)) { \ | |
8343 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
8344 | return; \ | |
8345 | } \ | |
8346 | gen_update_nip(ctx, ctx->nip - 4); \ | |
8347 | rt = gen_fprp_ptr(rD(ctx->opcode)); \ | |
8348 | rs = gen_fprp_ptr(fprfld(ctx->opcode)); \ | |
8349 | i32 = tcg_const_i32(i32fld(ctx->opcode)); \ | |
8350 | gen_helper_##name(cpu_env, rt, rs, i32); \ | |
8351 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
8352 | gen_set_cr6_from_fpscr(ctx); \ | |
8353 | } \ | |
8354 | tcg_temp_free_ptr(rt); \ | |
8355 | tcg_temp_free_ptr(rs); \ | |
8356 | tcg_temp_free_i32(i32); \ | |
8357 | } | |
ce577d2e | 8358 | |
a9d7ba03 TM |
8359 | GEN_DFP_T_A_B_Rc(dadd) |
8360 | GEN_DFP_T_A_B_Rc(daddq) | |
2128f8a5 TM |
8361 | GEN_DFP_T_A_B_Rc(dsub) |
8362 | GEN_DFP_T_A_B_Rc(dsubq) | |
8de6a1cc TM |
8363 | GEN_DFP_T_A_B_Rc(dmul) |
8364 | GEN_DFP_T_A_B_Rc(dmulq) | |
9024ff40 TM |
8365 | GEN_DFP_T_A_B_Rc(ddiv) |
8366 | GEN_DFP_T_A_B_Rc(ddivq) | |
5833505b TM |
8367 | GEN_DFP_BF_A_B(dcmpu) |
8368 | GEN_DFP_BF_A_B(dcmpuq) | |
8369 | GEN_DFP_BF_A_B(dcmpo) | |
8370 | GEN_DFP_BF_A_B(dcmpoq) | |
e601c1ee TM |
8371 | GEN_DFP_BF_A_DCM(dtstdc) |
8372 | GEN_DFP_BF_A_DCM(dtstdcq) | |
1bf9c0e1 TM |
8373 | GEN_DFP_BF_A_DCM(dtstdg) |
8374 | GEN_DFP_BF_A_DCM(dtstdgq) | |
f3d2b0bc TM |
8375 | GEN_DFP_BF_A_B(dtstex) |
8376 | GEN_DFP_BF_A_B(dtstexq) | |
f6022a76 TM |
8377 | GEN_DFP_BF_A_B(dtstsf) |
8378 | GEN_DFP_BF_A_B(dtstsfq) | |
5826ebe2 TM |
8379 | GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC) |
8380 | GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC) | |
8381 | GEN_DFP_T_A_B_I32_Rc(dqua, RMC) | |
8382 | GEN_DFP_T_A_B_I32_Rc(dquaq, RMC) | |
512918aa TM |
8383 | GEN_DFP_T_A_B_I32_Rc(drrnd, RMC) |
8384 | GEN_DFP_T_A_B_I32_Rc(drrndq, RMC) | |
97c0d930 TM |
8385 | GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC) |
8386 | GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC) | |
8387 | GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC) | |
8388 | GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC) | |
290d9ee5 TM |
8389 | GEN_DFP_T_B_Rc(dctdp) |
8390 | GEN_DFP_T_B_Rc(dctqpq) | |
ca603eb4 TM |
8391 | GEN_DFP_T_B_Rc(drsp) |
8392 | GEN_DFP_T_B_Rc(drdpq) | |
f1214193 TM |
8393 | GEN_DFP_T_B_Rc(dcffix) |
8394 | GEN_DFP_T_B_Rc(dcffixq) | |
bea0dd79 TM |
8395 | GEN_DFP_T_B_Rc(dctfix) |
8396 | GEN_DFP_T_B_Rc(dctfixq) | |
7796676f TM |
8397 | GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP) |
8398 | GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP) | |
013c3ac0 TM |
8399 | GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP) |
8400 | GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP) | |
e8a48460 TM |
8401 | GEN_DFP_T_B_Rc(dxex) |
8402 | GEN_DFP_T_B_Rc(dxexq) | |
297666eb TM |
8403 | GEN_DFP_T_A_B_Rc(diex) |
8404 | GEN_DFP_T_A_B_Rc(diexq) | |
804e654a TM |
8405 | GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM) |
8406 | GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM) | |
8407 | GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM) | |
8408 | GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM) | |
8409 | ||
0487d6a8 | 8410 | /*** SPE extension ***/ |
0487d6a8 | 8411 | /* Register moves */ |
3cd7d1dd | 8412 | |
a0e13900 FC |
8413 | static inline void gen_evmra(DisasContext *ctx) |
8414 | { | |
8415 | ||
8416 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8417 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
8418 | return; |
8419 | } | |
8420 | ||
8421 | #if defined(TARGET_PPC64) | |
8422 | /* rD := rA */ | |
8423 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8424 | ||
8425 | /* spe_acc := rA */ | |
8426 | tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)], | |
8427 | cpu_env, | |
1328c2bf | 8428 | offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8429 | #else |
8430 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
8431 | ||
8432 | /* tmp := rA_lo + rA_hi << 32 */ | |
8433 | tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8434 | ||
8435 | /* spe_acc := tmp */ | |
1328c2bf | 8436 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8437 | tcg_temp_free_i64(tmp); |
8438 | ||
8439 | /* rD := rA */ | |
8440 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8441 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8442 | #endif | |
8443 | } | |
8444 | ||
636aa200 BS |
8445 | static inline void gen_load_gpr64(TCGv_i64 t, int reg) |
8446 | { | |
f78fb44e AJ |
8447 | #if defined(TARGET_PPC64) |
8448 | tcg_gen_mov_i64(t, cpu_gpr[reg]); | |
8449 | #else | |
36aa55dc | 8450 | tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]); |
3cd7d1dd | 8451 | #endif |
f78fb44e | 8452 | } |
3cd7d1dd | 8453 | |
636aa200 BS |
8454 | static inline void gen_store_gpr64(int reg, TCGv_i64 t) |
8455 | { | |
f78fb44e AJ |
8456 | #if defined(TARGET_PPC64) |
8457 | tcg_gen_mov_i64(cpu_gpr[reg], t); | |
8458 | #else | |
a7812ae4 | 8459 | TCGv_i64 tmp = tcg_temp_new_i64(); |
f78fb44e | 8460 | tcg_gen_trunc_i64_i32(cpu_gpr[reg], t); |
f78fb44e AJ |
8461 | tcg_gen_shri_i64(tmp, t, 32); |
8462 | tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp); | |
a7812ae4 | 8463 | tcg_temp_free_i64(tmp); |
3cd7d1dd | 8464 | #endif |
f78fb44e | 8465 | } |
3cd7d1dd | 8466 | |
70560da7 | 8467 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
99e300ef | 8468 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
0487d6a8 JM |
8469 | { \ |
8470 | if (Rc(ctx->opcode)) \ | |
8471 | gen_##name1(ctx); \ | |
8472 | else \ | |
8473 | gen_##name0(ctx); \ | |
8474 | } | |
8475 | ||
8476 | /* Handler for undefined SPE opcodes */ | |
636aa200 | 8477 | static inline void gen_speundef(DisasContext *ctx) |
0487d6a8 | 8478 | { |
e06fcd75 | 8479 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
0487d6a8 JM |
8480 | } |
8481 | ||
57951c27 AJ |
8482 | /* SPE logic */ |
8483 | #if defined(TARGET_PPC64) | |
8484 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 8485 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8486 | { \ |
8487 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8488 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8489 | return; \ |
8490 | } \ | |
57951c27 AJ |
8491 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
8492 | cpu_gpr[rB(ctx->opcode)]); \ | |
8493 | } | |
8494 | #else | |
8495 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 8496 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8497 | { \ |
8498 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8499 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8500 | return; \ |
8501 | } \ | |
8502 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ | |
8503 | cpu_gpr[rB(ctx->opcode)]); \ | |
8504 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
8505 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 8506 | } |
57951c27 AJ |
8507 | #endif |
8508 | ||
8509 | GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl); | |
8510 | GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl); | |
8511 | GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl); | |
8512 | GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl); | |
8513 | GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl); | |
8514 | GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl); | |
8515 | GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl); | |
8516 | GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl); | |
0487d6a8 | 8517 | |
57951c27 AJ |
8518 | /* SPE logic immediate */ |
8519 | #if defined(TARGET_PPC64) | |
8520 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 8521 | static inline void gen_##name(DisasContext *ctx) \ |
3d3a6a0a AJ |
8522 | { \ |
8523 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8524 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
3d3a6a0a AJ |
8525 | return; \ |
8526 | } \ | |
a7812ae4 PB |
8527 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8528 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8529 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8530 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8531 | tcg_opi(t0, t0, rB(ctx->opcode)); \ | |
8532 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8533 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 8534 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8535 | tcg_opi(t1, t1, rB(ctx->opcode)); \ |
8536 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
8537 | tcg_temp_free_i32(t0); \ |
8538 | tcg_temp_free_i32(t1); \ | |
3d3a6a0a | 8539 | } |
57951c27 AJ |
8540 | #else |
8541 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 8542 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8543 | { \ |
8544 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8545 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8546 | return; \ |
8547 | } \ | |
57951c27 AJ |
8548 | tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
8549 | rB(ctx->opcode)); \ | |
8550 | tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
8551 | rB(ctx->opcode)); \ | |
0487d6a8 | 8552 | } |
57951c27 AJ |
8553 | #endif |
8554 | GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32); | |
8555 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32); | |
8556 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32); | |
8557 | GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32); | |
0487d6a8 | 8558 | |
57951c27 AJ |
8559 | /* SPE arithmetic */ |
8560 | #if defined(TARGET_PPC64) | |
8561 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ | |
636aa200 | 8562 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8563 | { \ |
8564 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8565 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8566 | return; \ |
8567 | } \ | |
a7812ae4 PB |
8568 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8569 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8570 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8571 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8572 | tcg_op(t0, t0); \ | |
8573 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8574 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 8575 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8576 | tcg_op(t1, t1); \ |
8577 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
8578 | tcg_temp_free_i32(t0); \ |
8579 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 8580 | } |
57951c27 | 8581 | #else |
a7812ae4 | 8582 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ |
636aa200 | 8583 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8584 | { \ |
8585 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8586 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8587 | return; \ |
8588 | } \ | |
8589 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \ | |
8590 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \ | |
8591 | } | |
8592 | #endif | |
0487d6a8 | 8593 | |
636aa200 | 8594 | static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1) |
57951c27 AJ |
8595 | { |
8596 | int l1 = gen_new_label(); | |
8597 | int l2 = gen_new_label(); | |
0487d6a8 | 8598 | |
57951c27 AJ |
8599 | tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1); |
8600 | tcg_gen_neg_i32(ret, arg1); | |
8601 | tcg_gen_br(l2); | |
8602 | gen_set_label(l1); | |
a7812ae4 | 8603 | tcg_gen_mov_i32(ret, arg1); |
57951c27 AJ |
8604 | gen_set_label(l2); |
8605 | } | |
8606 | GEN_SPEOP_ARITH1(evabs, gen_op_evabs); | |
8607 | GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32); | |
8608 | GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32); | |
8609 | GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32); | |
636aa200 | 8610 | static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1) |
0487d6a8 | 8611 | { |
57951c27 AJ |
8612 | tcg_gen_addi_i32(ret, arg1, 0x8000); |
8613 | tcg_gen_ext16u_i32(ret, ret); | |
8614 | } | |
8615 | GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw); | |
a7812ae4 PB |
8616 | GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32); |
8617 | GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32); | |
0487d6a8 | 8618 | |
57951c27 AJ |
8619 | #if defined(TARGET_PPC64) |
8620 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 8621 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8622 | { \ |
8623 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8624 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8625 | return; \ |
8626 | } \ | |
a7812ae4 PB |
8627 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8628 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8629 | TCGv_i32 t2 = tcg_temp_local_new_i32(); \ | |
501e23c4 | 8630 | TCGv_i64 t3 = tcg_temp_local_new_i64(); \ |
57951c27 AJ |
8631 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8632 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \ | |
8633 | tcg_op(t0, t0, t2); \ | |
8634 | tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8635 | tcg_gen_trunc_i64_i32(t1, t3); \ | |
8636 | tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8637 | tcg_gen_trunc_i64_i32(t2, t3); \ | |
a7812ae4 | 8638 | tcg_temp_free_i64(t3); \ |
57951c27 | 8639 | tcg_op(t1, t1, t2); \ |
a7812ae4 | 8640 | tcg_temp_free_i32(t2); \ |
57951c27 | 8641 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ |
a7812ae4 PB |
8642 | tcg_temp_free_i32(t0); \ |
8643 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 8644 | } |
57951c27 AJ |
8645 | #else |
8646 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 8647 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8648 | { \ |
8649 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8650 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8651 | return; \ |
8652 | } \ | |
57951c27 AJ |
8653 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
8654 | cpu_gpr[rB(ctx->opcode)]); \ | |
8655 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
8656 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 8657 | } |
57951c27 | 8658 | #endif |
0487d6a8 | 8659 | |
636aa200 | 8660 | static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8661 | { |
a7812ae4 | 8662 | TCGv_i32 t0; |
57951c27 | 8663 | int l1, l2; |
0487d6a8 | 8664 | |
57951c27 AJ |
8665 | l1 = gen_new_label(); |
8666 | l2 = gen_new_label(); | |
a7812ae4 | 8667 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8668 | /* No error here: 6 bits are used */ |
8669 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8670 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8671 | tcg_gen_shr_i32(ret, arg1, t0); | |
8672 | tcg_gen_br(l2); | |
8673 | gen_set_label(l1); | |
8674 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 8675 | gen_set_label(l2); |
a7812ae4 | 8676 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8677 | } |
8678 | GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu); | |
636aa200 | 8679 | static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8680 | { |
a7812ae4 | 8681 | TCGv_i32 t0; |
57951c27 AJ |
8682 | int l1, l2; |
8683 | ||
8684 | l1 = gen_new_label(); | |
8685 | l2 = gen_new_label(); | |
a7812ae4 | 8686 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8687 | /* No error here: 6 bits are used */ |
8688 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8689 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8690 | tcg_gen_sar_i32(ret, arg1, t0); | |
8691 | tcg_gen_br(l2); | |
8692 | gen_set_label(l1); | |
8693 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 8694 | gen_set_label(l2); |
a7812ae4 | 8695 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8696 | } |
8697 | GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws); | |
636aa200 | 8698 | static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8699 | { |
a7812ae4 | 8700 | TCGv_i32 t0; |
57951c27 AJ |
8701 | int l1, l2; |
8702 | ||
8703 | l1 = gen_new_label(); | |
8704 | l2 = gen_new_label(); | |
a7812ae4 | 8705 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8706 | /* No error here: 6 bits are used */ |
8707 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8708 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8709 | tcg_gen_shl_i32(ret, arg1, t0); | |
8710 | tcg_gen_br(l2); | |
8711 | gen_set_label(l1); | |
8712 | tcg_gen_movi_i32(ret, 0); | |
e29ef9fa | 8713 | gen_set_label(l2); |
a7812ae4 | 8714 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8715 | } |
8716 | GEN_SPEOP_ARITH2(evslw, gen_op_evslw); | |
636aa200 | 8717 | static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8718 | { |
a7812ae4 | 8719 | TCGv_i32 t0 = tcg_temp_new_i32(); |
57951c27 AJ |
8720 | tcg_gen_andi_i32(t0, arg2, 0x1F); |
8721 | tcg_gen_rotl_i32(ret, arg1, t0); | |
a7812ae4 | 8722 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8723 | } |
8724 | GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw); | |
636aa200 | 8725 | static inline void gen_evmergehi(DisasContext *ctx) |
57951c27 AJ |
8726 | { |
8727 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8728 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8729 | return; |
8730 | } | |
8731 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8732 | TCGv t0 = tcg_temp_new(); |
8733 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
8734 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
8735 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); | |
8736 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8737 | tcg_temp_free(t0); | |
8738 | tcg_temp_free(t1); | |
8739 | #else | |
8740 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8741 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8742 | #endif | |
8743 | } | |
8744 | GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32); | |
636aa200 | 8745 | static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
0487d6a8 | 8746 | { |
57951c27 AJ |
8747 | tcg_gen_sub_i32(ret, arg2, arg1); |
8748 | } | |
8749 | GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf); | |
0487d6a8 | 8750 | |
57951c27 AJ |
8751 | /* SPE arithmetic immediate */ |
8752 | #if defined(TARGET_PPC64) | |
8753 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 8754 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8755 | { \ |
8756 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8757 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8758 | return; \ |
8759 | } \ | |
a7812ae4 PB |
8760 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8761 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8762 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8763 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ |
8764 | tcg_op(t0, t0, rA(ctx->opcode)); \ | |
8765 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8766 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
e06fcd75 | 8767 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8768 | tcg_op(t1, t1, rA(ctx->opcode)); \ |
8769 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
8770 | tcg_temp_free_i32(t0); \ |
8771 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
8772 | } |
8773 | #else | |
8774 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 8775 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8776 | { \ |
8777 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8778 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8779 | return; \ |
8780 | } \ | |
8781 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
8782 | rA(ctx->opcode)); \ | |
8783 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \ | |
8784 | rA(ctx->opcode)); \ | |
8785 | } | |
8786 | #endif | |
8787 | GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32); | |
8788 | GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32); | |
8789 | ||
8790 | /* SPE comparison */ | |
8791 | #if defined(TARGET_PPC64) | |
8792 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 8793 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8794 | { \ |
8795 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8796 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8797 | return; \ |
8798 | } \ | |
8799 | int l1 = gen_new_label(); \ | |
8800 | int l2 = gen_new_label(); \ | |
8801 | int l3 = gen_new_label(); \ | |
8802 | int l4 = gen_new_label(); \ | |
a7812ae4 PB |
8803 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8804 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8805 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8806 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8807 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8808 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \ | |
a7812ae4 | 8809 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \ |
57951c27 AJ |
8810 | tcg_gen_br(l2); \ |
8811 | gen_set_label(l1); \ | |
8812 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
8813 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
8814 | gen_set_label(l2); \ | |
8815 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8816 | tcg_gen_trunc_i64_i32(t0, t2); \ | |
8817 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8818 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 8819 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8820 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \ |
8821 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8822 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
8823 | tcg_gen_br(l4); \ | |
8824 | gen_set_label(l3); \ | |
8825 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8826 | CRF_CH | CRF_CH_OR_CL); \ | |
8827 | gen_set_label(l4); \ | |
a7812ae4 PB |
8828 | tcg_temp_free_i32(t0); \ |
8829 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
8830 | } |
8831 | #else | |
8832 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 8833 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8834 | { \ |
8835 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8836 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8837 | return; \ |
8838 | } \ | |
8839 | int l1 = gen_new_label(); \ | |
8840 | int l2 = gen_new_label(); \ | |
8841 | int l3 = gen_new_label(); \ | |
8842 | int l4 = gen_new_label(); \ | |
8843 | \ | |
8844 | tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \ | |
8845 | cpu_gpr[rB(ctx->opcode)], l1); \ | |
8846 | tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \ | |
8847 | tcg_gen_br(l2); \ | |
8848 | gen_set_label(l1); \ | |
8849 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
8850 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
8851 | gen_set_label(l2); \ | |
8852 | tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \ | |
8853 | cpu_gprh[rB(ctx->opcode)], l3); \ | |
8854 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8855 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
8856 | tcg_gen_br(l4); \ | |
8857 | gen_set_label(l3); \ | |
8858 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8859 | CRF_CH | CRF_CH_OR_CL); \ | |
8860 | gen_set_label(l4); \ | |
8861 | } | |
8862 | #endif | |
8863 | GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU); | |
8864 | GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT); | |
8865 | GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU); | |
8866 | GEN_SPEOP_COMP(evcmplts, TCG_COND_LT); | |
8867 | GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ); | |
8868 | ||
8869 | /* SPE misc */ | |
636aa200 | 8870 | static inline void gen_brinc(DisasContext *ctx) |
57951c27 AJ |
8871 | { |
8872 | /* Note: brinc is usable even if SPE is disabled */ | |
a7812ae4 PB |
8873 | gen_helper_brinc(cpu_gpr[rD(ctx->opcode)], |
8874 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
0487d6a8 | 8875 | } |
636aa200 | 8876 | static inline void gen_evmergelo(DisasContext *ctx) |
57951c27 AJ |
8877 | { |
8878 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8879 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8880 | return; |
8881 | } | |
8882 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8883 | TCGv t0 = tcg_temp_new(); |
8884 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 8885 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8886 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); |
8887 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8888 | tcg_temp_free(t0); | |
8889 | tcg_temp_free(t1); | |
8890 | #else | |
57951c27 | 8891 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
33890b3e | 8892 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8893 | #endif |
8894 | } | |
636aa200 | 8895 | static inline void gen_evmergehilo(DisasContext *ctx) |
57951c27 AJ |
8896 | { |
8897 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8898 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8899 | return; |
8900 | } | |
8901 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8902 | TCGv t0 = tcg_temp_new(); |
8903 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 8904 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8905 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); |
8906 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8907 | tcg_temp_free(t0); | |
8908 | tcg_temp_free(t1); | |
8909 | #else | |
8910 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
8911 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8912 | #endif | |
8913 | } | |
636aa200 | 8914 | static inline void gen_evmergelohi(DisasContext *ctx) |
57951c27 AJ |
8915 | { |
8916 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8917 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8918 | return; |
8919 | } | |
8920 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8921 | TCGv t0 = tcg_temp_new(); |
8922 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
8923 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
8924 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); | |
8925 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8926 | tcg_temp_free(t0); | |
8927 | tcg_temp_free(t1); | |
8928 | #else | |
33890b3e NF |
8929 | if (rD(ctx->opcode) == rA(ctx->opcode)) { |
8930 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
8931 | tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); | |
8932 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8933 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp); | |
8934 | tcg_temp_free_i32(tmp); | |
8935 | } else { | |
8936 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8937 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8938 | } | |
57951c27 AJ |
8939 | #endif |
8940 | } | |
636aa200 | 8941 | static inline void gen_evsplati(DisasContext *ctx) |
57951c27 | 8942 | { |
ae01847f | 8943 | uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27; |
0487d6a8 | 8944 | |
57951c27 | 8945 | #if defined(TARGET_PPC64) |
38d14952 | 8946 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
8947 | #else |
8948 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
8949 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
8950 | #endif | |
8951 | } | |
636aa200 | 8952 | static inline void gen_evsplatfi(DisasContext *ctx) |
0487d6a8 | 8953 | { |
ae01847f | 8954 | uint64_t imm = rA(ctx->opcode) << 27; |
0487d6a8 | 8955 | |
57951c27 | 8956 | #if defined(TARGET_PPC64) |
38d14952 | 8957 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
8958 | #else |
8959 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
8960 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
8961 | #endif | |
0487d6a8 JM |
8962 | } |
8963 | ||
636aa200 | 8964 | static inline void gen_evsel(DisasContext *ctx) |
57951c27 AJ |
8965 | { |
8966 | int l1 = gen_new_label(); | |
8967 | int l2 = gen_new_label(); | |
8968 | int l3 = gen_new_label(); | |
8969 | int l4 = gen_new_label(); | |
a7812ae4 | 8970 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
57951c27 | 8971 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
8972 | TCGv t1 = tcg_temp_local_new(); |
8973 | TCGv t2 = tcg_temp_local_new(); | |
57951c27 AJ |
8974 | #endif |
8975 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | |
8976 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
8977 | #if defined(TARGET_PPC64) | |
8978 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
8979 | #else | |
8980 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8981 | #endif | |
8982 | tcg_gen_br(l2); | |
8983 | gen_set_label(l1); | |
8984 | #if defined(TARGET_PPC64) | |
8985 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
8986 | #else | |
8987 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8988 | #endif | |
8989 | gen_set_label(l2); | |
8990 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2); | |
8991 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3); | |
8992 | #if defined(TARGET_PPC64) | |
17d9b3af | 8993 | tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]); |
57951c27 AJ |
8994 | #else |
8995 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8996 | #endif | |
8997 | tcg_gen_br(l4); | |
8998 | gen_set_label(l3); | |
8999 | #if defined(TARGET_PPC64) | |
17d9b3af | 9000 | tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
9001 | #else |
9002 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
9003 | #endif | |
9004 | gen_set_label(l4); | |
a7812ae4 | 9005 | tcg_temp_free_i32(t0); |
57951c27 AJ |
9006 | #if defined(TARGET_PPC64) |
9007 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2); | |
9008 | tcg_temp_free(t1); | |
9009 | tcg_temp_free(t2); | |
9010 | #endif | |
9011 | } | |
e8eaa2c0 BS |
9012 | |
9013 | static void gen_evsel0(DisasContext *ctx) | |
57951c27 AJ |
9014 | { |
9015 | gen_evsel(ctx); | |
9016 | } | |
e8eaa2c0 BS |
9017 | |
9018 | static void gen_evsel1(DisasContext *ctx) | |
57951c27 AJ |
9019 | { |
9020 | gen_evsel(ctx); | |
9021 | } | |
e8eaa2c0 BS |
9022 | |
9023 | static void gen_evsel2(DisasContext *ctx) | |
57951c27 AJ |
9024 | { |
9025 | gen_evsel(ctx); | |
9026 | } | |
e8eaa2c0 BS |
9027 | |
9028 | static void gen_evsel3(DisasContext *ctx) | |
57951c27 AJ |
9029 | { |
9030 | gen_evsel(ctx); | |
9031 | } | |
0487d6a8 | 9032 | |
a0e13900 FC |
9033 | /* Multiply */ |
9034 | ||
9035 | static inline void gen_evmwumi(DisasContext *ctx) | |
9036 | { | |
9037 | TCGv_i64 t0, t1; | |
9038 | ||
9039 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9040 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
9041 | return; |
9042 | } | |
9043 | ||
9044 | t0 = tcg_temp_new_i64(); | |
9045 | t1 = tcg_temp_new_i64(); | |
9046 | ||
9047 | /* t0 := rA; t1 := rB */ | |
9048 | #if defined(TARGET_PPC64) | |
9049 | tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
9050 | tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
9051 | #else | |
9052 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
9053 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
9054 | #endif | |
9055 | ||
9056 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
9057 | ||
9058 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
9059 | ||
9060 | tcg_temp_free_i64(t0); | |
9061 | tcg_temp_free_i64(t1); | |
9062 | } | |
9063 | ||
9064 | static inline void gen_evmwumia(DisasContext *ctx) | |
9065 | { | |
9066 | TCGv_i64 tmp; | |
9067 | ||
9068 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9069 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
9070 | return; |
9071 | } | |
9072 | ||
9073 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
9074 | ||
9075 | tmp = tcg_temp_new_i64(); | |
9076 | ||
9077 | /* acc := rD */ | |
9078 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 9079 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9080 | tcg_temp_free_i64(tmp); |
9081 | } | |
9082 | ||
9083 | static inline void gen_evmwumiaa(DisasContext *ctx) | |
9084 | { | |
9085 | TCGv_i64 acc; | |
9086 | TCGv_i64 tmp; | |
9087 | ||
9088 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9089 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
9090 | return; |
9091 | } | |
9092 | ||
9093 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
9094 | ||
9095 | acc = tcg_temp_new_i64(); | |
9096 | tmp = tcg_temp_new_i64(); | |
9097 | ||
9098 | /* tmp := rD */ | |
9099 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
9100 | ||
9101 | /* Load acc */ | |
1328c2bf | 9102 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9103 | |
9104 | /* acc := tmp + acc */ | |
9105 | tcg_gen_add_i64(acc, acc, tmp); | |
9106 | ||
9107 | /* Store acc */ | |
1328c2bf | 9108 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9109 | |
9110 | /* rD := acc */ | |
9111 | gen_store_gpr64(rD(ctx->opcode), acc); | |
9112 | ||
9113 | tcg_temp_free_i64(acc); | |
9114 | tcg_temp_free_i64(tmp); | |
9115 | } | |
9116 | ||
9117 | static inline void gen_evmwsmi(DisasContext *ctx) | |
9118 | { | |
9119 | TCGv_i64 t0, t1; | |
9120 | ||
9121 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9122 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
9123 | return; |
9124 | } | |
9125 | ||
9126 | t0 = tcg_temp_new_i64(); | |
9127 | t1 = tcg_temp_new_i64(); | |
9128 | ||
9129 | /* t0 := rA; t1 := rB */ | |
9130 | #if defined(TARGET_PPC64) | |
9131 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
9132 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
9133 | #else | |
9134 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
9135 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
9136 | #endif | |
9137 | ||
9138 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
9139 | ||
9140 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
9141 | ||
9142 | tcg_temp_free_i64(t0); | |
9143 | tcg_temp_free_i64(t1); | |
9144 | } | |
9145 | ||
9146 | static inline void gen_evmwsmia(DisasContext *ctx) | |
9147 | { | |
9148 | TCGv_i64 tmp; | |
9149 | ||
9150 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
9151 | ||
9152 | tmp = tcg_temp_new_i64(); | |
9153 | ||
9154 | /* acc := rD */ | |
9155 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 9156 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9157 | |
9158 | tcg_temp_free_i64(tmp); | |
9159 | } | |
9160 | ||
9161 | static inline void gen_evmwsmiaa(DisasContext *ctx) | |
9162 | { | |
9163 | TCGv_i64 acc = tcg_temp_new_i64(); | |
9164 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
9165 | ||
9166 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
9167 | ||
9168 | acc = tcg_temp_new_i64(); | |
9169 | tmp = tcg_temp_new_i64(); | |
9170 | ||
9171 | /* tmp := rD */ | |
9172 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
9173 | ||
9174 | /* Load acc */ | |
1328c2bf | 9175 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9176 | |
9177 | /* acc := tmp + acc */ | |
9178 | tcg_gen_add_i64(acc, acc, tmp); | |
9179 | ||
9180 | /* Store acc */ | |
1328c2bf | 9181 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
9182 | |
9183 | /* rD := acc */ | |
9184 | gen_store_gpr64(rD(ctx->opcode), acc); | |
9185 | ||
9186 | tcg_temp_free_i64(acc); | |
9187 | tcg_temp_free_i64(tmp); | |
9188 | } | |
9189 | ||
70560da7 FC |
9190 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// |
9191 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
9192 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
9193 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
9194 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
9195 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
9196 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
9197 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); // | |
9198 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE); | |
9199 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
9200 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
9201 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
9202 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
9203 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
9204 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
9205 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
9206 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
9207 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
9208 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
9209 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE); | |
9210 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
9211 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
9212 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); // | |
9213 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE); | |
9214 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
9215 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
9216 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
9217 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
9218 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); //// | |
0487d6a8 | 9219 | |
6a6ae23f | 9220 | /* SPE load and stores */ |
636aa200 | 9221 | static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh) |
6a6ae23f AJ |
9222 | { |
9223 | target_ulong uimm = rB(ctx->opcode); | |
9224 | ||
76db3ba4 | 9225 | if (rA(ctx->opcode) == 0) { |
6a6ae23f | 9226 | tcg_gen_movi_tl(EA, uimm << sh); |
76db3ba4 | 9227 | } else { |
6a6ae23f | 9228 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh); |
c791fe84 | 9229 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
9230 | tcg_gen_ext32u_tl(EA, EA); |
9231 | } | |
76db3ba4 | 9232 | } |
0487d6a8 | 9233 | } |
6a6ae23f | 9234 | |
636aa200 | 9235 | static inline void gen_op_evldd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9236 | { |
9237 | #if defined(TARGET_PPC64) | |
76db3ba4 | 9238 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
6a6ae23f AJ |
9239 | #else |
9240 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
76db3ba4 | 9241 | gen_qemu_ld64(ctx, t0, addr); |
6a6ae23f AJ |
9242 | tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0); |
9243 | tcg_gen_shri_i64(t0, t0, 32); | |
9244 | tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0); | |
9245 | tcg_temp_free_i64(t0); | |
9246 | #endif | |
0487d6a8 | 9247 | } |
6a6ae23f | 9248 | |
636aa200 | 9249 | static inline void gen_op_evldw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 9250 | { |
0487d6a8 | 9251 | #if defined(TARGET_PPC64) |
6a6ae23f | 9252 | TCGv t0 = tcg_temp_new(); |
76db3ba4 | 9253 | gen_qemu_ld32u(ctx, t0, addr); |
6a6ae23f | 9254 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
76db3ba4 AJ |
9255 | gen_addr_add(ctx, addr, addr, 4); |
9256 | gen_qemu_ld32u(ctx, t0, addr); | |
6a6ae23f AJ |
9257 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
9258 | tcg_temp_free(t0); | |
9259 | #else | |
76db3ba4 AJ |
9260 | gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
9261 | gen_addr_add(ctx, addr, addr, 4); | |
9262 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f | 9263 | #endif |
0487d6a8 | 9264 | } |
6a6ae23f | 9265 | |
636aa200 | 9266 | static inline void gen_op_evldh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9267 | { |
9268 | TCGv t0 = tcg_temp_new(); | |
9269 | #if defined(TARGET_PPC64) | |
76db3ba4 | 9270 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 9271 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
9272 | gen_addr_add(ctx, addr, addr, 2); |
9273 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9274 | tcg_gen_shli_tl(t0, t0, 32); |
9275 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
9276 | gen_addr_add(ctx, addr, addr, 2); |
9277 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9278 | tcg_gen_shli_tl(t0, t0, 16); |
9279 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
9280 | gen_addr_add(ctx, addr, addr, 2); |
9281 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 9282 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 9283 | #else |
76db3ba4 | 9284 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 9285 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
9286 | gen_addr_add(ctx, addr, addr, 2); |
9287 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 9288 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
9289 | gen_addr_add(ctx, addr, addr, 2); |
9290 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 9291 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
9292 | gen_addr_add(ctx, addr, addr, 2); |
9293 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 9294 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 9295 | #endif |
6a6ae23f | 9296 | tcg_temp_free(t0); |
0487d6a8 JM |
9297 | } |
9298 | ||
636aa200 | 9299 | static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9300 | { |
9301 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 9302 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
9303 | #if defined(TARGET_PPC64) |
9304 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); | |
9305 | tcg_gen_shli_tl(t0, t0, 16); | |
9306 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9307 | #else | |
9308 | tcg_gen_shli_tl(t0, t0, 16); | |
9309 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
9310 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
9311 | #endif | |
9312 | tcg_temp_free(t0); | |
0487d6a8 JM |
9313 | } |
9314 | ||
636aa200 | 9315 | static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9316 | { |
9317 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 9318 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
9319 | #if defined(TARGET_PPC64) |
9320 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
9321 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9322 | #else | |
9323 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
9324 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
9325 | #endif | |
9326 | tcg_temp_free(t0); | |
0487d6a8 JM |
9327 | } |
9328 | ||
636aa200 | 9329 | static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9330 | { |
9331 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 9332 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f AJ |
9333 | #if defined(TARGET_PPC64) |
9334 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
9335 | tcg_gen_ext32u_tl(t0, t0); | |
9336 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9337 | #else | |
9338 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
9339 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
9340 | #endif | |
9341 | tcg_temp_free(t0); | |
9342 | } | |
9343 | ||
636aa200 | 9344 | static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9345 | { |
9346 | TCGv t0 = tcg_temp_new(); | |
9347 | #if defined(TARGET_PPC64) | |
76db3ba4 | 9348 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 9349 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
9350 | gen_addr_add(ctx, addr, addr, 2); |
9351 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9352 | tcg_gen_shli_tl(t0, t0, 16); |
9353 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9354 | #else | |
76db3ba4 | 9355 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 9356 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
9357 | gen_addr_add(ctx, addr, addr, 2); |
9358 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9359 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
9360 | #endif | |
9361 | tcg_temp_free(t0); | |
9362 | } | |
9363 | ||
636aa200 | 9364 | static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9365 | { |
9366 | #if defined(TARGET_PPC64) | |
9367 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 AJ |
9368 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
9369 | gen_addr_add(ctx, addr, addr, 2); | |
9370 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9371 | tcg_gen_shli_tl(t0, t0, 32); |
9372 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9373 | tcg_temp_free(t0); | |
9374 | #else | |
76db3ba4 AJ |
9375 | gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
9376 | gen_addr_add(ctx, addr, addr, 2); | |
9377 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
9378 | #endif |
9379 | } | |
9380 | ||
636aa200 | 9381 | static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9382 | { |
9383 | #if defined(TARGET_PPC64) | |
9384 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 9385 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f | 9386 | tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
9387 | gen_addr_add(ctx, addr, addr, 2); |
9388 | gen_qemu_ld16s(ctx, t0, addr); | |
6a6ae23f AJ |
9389 | tcg_gen_shli_tl(t0, t0, 32); |
9390 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9391 | tcg_temp_free(t0); | |
9392 | #else | |
76db3ba4 AJ |
9393 | gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
9394 | gen_addr_add(ctx, addr, addr, 2); | |
9395 | gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
9396 | #endif |
9397 | } | |
9398 | ||
636aa200 | 9399 | static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9400 | { |
9401 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 9402 | gen_qemu_ld32u(ctx, t0, addr); |
0487d6a8 | 9403 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
9404 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
9405 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9406 | #else | |
9407 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
9408 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
9409 | #endif | |
9410 | tcg_temp_free(t0); | |
9411 | } | |
9412 | ||
636aa200 | 9413 | static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9414 | { |
9415 | TCGv t0 = tcg_temp_new(); | |
9416 | #if defined(TARGET_PPC64) | |
76db3ba4 | 9417 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
9418 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
9419 | tcg_gen_shli_tl(t0, t0, 32); | |
9420 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
9421 | gen_addr_add(ctx, addr, addr, 2); |
9422 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9423 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
9424 | tcg_gen_shli_tl(t0, t0, 16); | |
9425 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
9426 | #else | |
76db3ba4 | 9427 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
9428 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
9429 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
9430 | gen_addr_add(ctx, addr, addr, 2); |
9431 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
9432 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
9433 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
0487d6a8 | 9434 | #endif |
6a6ae23f AJ |
9435 | tcg_temp_free(t0); |
9436 | } | |
9437 | ||
636aa200 | 9438 | static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9439 | { |
9440 | #if defined(TARGET_PPC64) | |
76db3ba4 | 9441 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
0487d6a8 | 9442 | #else |
6a6ae23f AJ |
9443 | TCGv_i64 t0 = tcg_temp_new_i64(); |
9444 | tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]); | |
76db3ba4 | 9445 | gen_qemu_st64(ctx, t0, addr); |
6a6ae23f AJ |
9446 | tcg_temp_free_i64(t0); |
9447 | #endif | |
9448 | } | |
9449 | ||
636aa200 | 9450 | static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 9451 | { |
0487d6a8 | 9452 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
9453 | TCGv t0 = tcg_temp_new(); |
9454 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 9455 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
9456 | tcg_temp_free(t0); |
9457 | #else | |
76db3ba4 | 9458 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 9459 | #endif |
76db3ba4 AJ |
9460 | gen_addr_add(ctx, addr, addr, 4); |
9461 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
9462 | } |
9463 | ||
636aa200 | 9464 | static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9465 | { |
9466 | TCGv t0 = tcg_temp_new(); | |
9467 | #if defined(TARGET_PPC64) | |
9468 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
9469 | #else | |
9470 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
9471 | #endif | |
76db3ba4 AJ |
9472 | gen_qemu_st16(ctx, t0, addr); |
9473 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f AJ |
9474 | #if defined(TARGET_PPC64) |
9475 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 9476 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 9477 | #else |
76db3ba4 | 9478 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 9479 | #endif |
76db3ba4 | 9480 | gen_addr_add(ctx, addr, addr, 2); |
6a6ae23f | 9481 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 9482 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 9483 | tcg_temp_free(t0); |
76db3ba4 AJ |
9484 | gen_addr_add(ctx, addr, addr, 2); |
9485 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
9486 | } |
9487 | ||
636aa200 | 9488 | static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9489 | { |
9490 | TCGv t0 = tcg_temp_new(); | |
9491 | #if defined(TARGET_PPC64) | |
9492 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
9493 | #else | |
9494 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
9495 | #endif | |
76db3ba4 AJ |
9496 | gen_qemu_st16(ctx, t0, addr); |
9497 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f | 9498 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 9499 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
9500 | tcg_temp_free(t0); |
9501 | } | |
9502 | ||
636aa200 | 9503 | static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9504 | { |
9505 | #if defined(TARGET_PPC64) | |
9506 | TCGv t0 = tcg_temp_new(); | |
9507 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 9508 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
9509 | tcg_temp_free(t0); |
9510 | #else | |
76db3ba4 | 9511 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 9512 | #endif |
76db3ba4 AJ |
9513 | gen_addr_add(ctx, addr, addr, 2); |
9514 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
9515 | } |
9516 | ||
636aa200 | 9517 | static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
9518 | { |
9519 | #if defined(TARGET_PPC64) | |
9520 | TCGv t0 = tcg_temp_new(); | |
9521 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 9522 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
9523 | tcg_temp_free(t0); |
9524 | #else | |
76db3ba4 | 9525 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
9526 | #endif |
9527 | } | |
9528 | ||
636aa200 | 9529 | static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr) |
6a6ae23f | 9530 | { |
76db3ba4 | 9531 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
9532 | } |
9533 | ||
9534 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
99e300ef | 9535 | static void glue(gen_, name)(DisasContext *ctx) \ |
6a6ae23f AJ |
9536 | { \ |
9537 | TCGv t0; \ | |
9538 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9539 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
6a6ae23f AJ |
9540 | return; \ |
9541 | } \ | |
76db3ba4 | 9542 | gen_set_access_type(ctx, ACCESS_INT); \ |
6a6ae23f AJ |
9543 | t0 = tcg_temp_new(); \ |
9544 | if (Rc(ctx->opcode)) { \ | |
76db3ba4 | 9545 | gen_addr_spe_imm_index(ctx, t0, sh); \ |
6a6ae23f | 9546 | } else { \ |
76db3ba4 | 9547 | gen_addr_reg_index(ctx, t0); \ |
6a6ae23f AJ |
9548 | } \ |
9549 | gen_op_##name(ctx, t0); \ | |
9550 | tcg_temp_free(t0); \ | |
9551 | } | |
9552 | ||
9553 | GEN_SPEOP_LDST(evldd, 0x00, 3); | |
9554 | GEN_SPEOP_LDST(evldw, 0x01, 3); | |
9555 | GEN_SPEOP_LDST(evldh, 0x02, 3); | |
9556 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1); | |
9557 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1); | |
9558 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1); | |
9559 | GEN_SPEOP_LDST(evlwhe, 0x08, 2); | |
9560 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2); | |
9561 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2); | |
9562 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2); | |
9563 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2); | |
9564 | ||
9565 | GEN_SPEOP_LDST(evstdd, 0x10, 3); | |
9566 | GEN_SPEOP_LDST(evstdw, 0x11, 3); | |
9567 | GEN_SPEOP_LDST(evstdh, 0x12, 3); | |
9568 | GEN_SPEOP_LDST(evstwhe, 0x18, 2); | |
9569 | GEN_SPEOP_LDST(evstwho, 0x1A, 2); | |
9570 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2); | |
9571 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2); | |
0487d6a8 JM |
9572 | |
9573 | /* Multiply and add - TODO */ | |
9574 | #if 0 | |
70560da7 FC |
9575 | GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);// |
9576 | GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9577 | GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
9578 | GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9579 | GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
9580 | GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9581 | GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9582 | GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9583 | GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
9584 | GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9585 | GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
9586 | GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9587 | ||
9588 | GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9589 | GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
9590 | GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
9591 | GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9592 | GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9593 | GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9594 | GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9595 | GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
9596 | GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
9597 | GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9598 | GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9599 | GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9600 | ||
9601 | GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
9602 | GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
9603 | GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
9604 | GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
9605 | GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE); | |
9606 | ||
9607 | GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9608 | GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9609 | GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9610 | GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9611 | GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9612 | GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9613 | GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9614 | GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9615 | GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9616 | GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9617 | GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
9618 | GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9619 | ||
9620 | GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
9621 | GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
9622 | GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9623 | GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9624 | ||
9625 | GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9626 | GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9627 | GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9628 | GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9629 | GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9630 | GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9631 | GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9632 | GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9633 | GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9634 | GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9635 | GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9636 | GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9637 | ||
9638 | GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9639 | GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9640 | GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9641 | GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9642 | GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
0487d6a8 JM |
9643 | #endif |
9644 | ||
9645 | /*** SPE floating-point extension ***/ | |
1c97856d AJ |
9646 | #if defined(TARGET_PPC64) |
9647 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 9648 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 | 9649 | { \ |
1c97856d AJ |
9650 | TCGv_i32 t0; \ |
9651 | TCGv t1; \ | |
9652 | t0 = tcg_temp_new_i32(); \ | |
9653 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9654 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
9655 | t1 = tcg_temp_new(); \ |
9656 | tcg_gen_extu_i32_tl(t1, t0); \ | |
9657 | tcg_temp_free_i32(t0); \ | |
9658 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9659 | 0xFFFFFFFF00000000ULL); \ | |
9660 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
9661 | tcg_temp_free(t1); \ | |
0487d6a8 | 9662 | } |
1c97856d | 9663 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 9664 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9665 | { \ |
9666 | TCGv_i32 t0; \ | |
9667 | TCGv t1; \ | |
9668 | t0 = tcg_temp_new_i32(); \ | |
8e703949 | 9669 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
9670 | t1 = tcg_temp_new(); \ |
9671 | tcg_gen_extu_i32_tl(t1, t0); \ | |
9672 | tcg_temp_free_i32(t0); \ | |
9673 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9674 | 0xFFFFFFFF00000000ULL); \ | |
9675 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
9676 | tcg_temp_free(t1); \ | |
9677 | } | |
9678 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 9679 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9680 | { \ |
9681 | TCGv_i32 t0 = tcg_temp_new_i32(); \ | |
9682 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9683 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
9684 | tcg_temp_free_i32(t0); \ |
9685 | } | |
9686 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 9687 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 9688 | { \ |
8e703949 BS |
9689 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9690 | cpu_gpr[rB(ctx->opcode)]); \ | |
1c97856d AJ |
9691 | } |
9692 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 9693 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 9694 | { \ |
1c97856d AJ |
9695 | TCGv_i32 t0, t1; \ |
9696 | TCGv_i64 t2; \ | |
57951c27 | 9697 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 9698 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9699 | return; \ |
9700 | } \ | |
1c97856d AJ |
9701 | t0 = tcg_temp_new_i32(); \ |
9702 | t1 = tcg_temp_new_i32(); \ | |
9703 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
9704 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9705 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
9706 | tcg_temp_free_i32(t1); \ |
9707 | t2 = tcg_temp_new(); \ | |
9708 | tcg_gen_extu_i32_tl(t2, t0); \ | |
9709 | tcg_temp_free_i32(t0); \ | |
9710 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9711 | 0xFFFFFFFF00000000ULL); \ | |
9712 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \ | |
9713 | tcg_temp_free(t2); \ | |
57951c27 | 9714 | } |
1c97856d | 9715 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ |
636aa200 | 9716 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
9717 | { \ |
9718 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9719 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9720 | return; \ |
9721 | } \ | |
8e703949 BS |
9722 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9723 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 9724 | } |
1c97856d | 9725 | #define GEN_SPEFPUOP_COMP_32(name) \ |
636aa200 | 9726 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 9727 | { \ |
1c97856d | 9728 | TCGv_i32 t0, t1; \ |
57951c27 | 9729 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 9730 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9731 | return; \ |
9732 | } \ | |
1c97856d AJ |
9733 | t0 = tcg_temp_new_i32(); \ |
9734 | t1 = tcg_temp_new_i32(); \ | |
9735 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
9736 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9737 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
9738 | tcg_temp_free_i32(t0); \ |
9739 | tcg_temp_free_i32(t1); \ | |
9740 | } | |
9741 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 9742 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9743 | { \ |
9744 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9745 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9746 | return; \ |
9747 | } \ | |
8e703949 | 9748 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9749 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9750 | } | |
9751 | #else | |
9752 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 9753 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 9754 | { \ |
8e703949 BS |
9755 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9756 | cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 9757 | } |
1c97856d | 9758 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 9759 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9760 | { \ |
9761 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
9762 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 9763 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
9764 | tcg_temp_free_i64(t0); \ |
9765 | } | |
9766 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 9767 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9768 | { \ |
9769 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8e703949 | 9770 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
9771 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9772 | tcg_temp_free_i64(t0); \ | |
9773 | } | |
9774 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 9775 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9776 | { \ |
9777 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
9778 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 9779 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
9780 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9781 | tcg_temp_free_i64(t0); \ | |
9782 | } | |
9783 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 9784 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9785 | { \ |
9786 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9787 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9788 | return; \ |
9789 | } \ | |
8e703949 | 9790 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9791 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9792 | } | |
9793 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ | |
636aa200 | 9794 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9795 | { \ |
9796 | TCGv_i64 t0, t1; \ | |
9797 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9798 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9799 | return; \ |
9800 | } \ | |
9801 | t0 = tcg_temp_new_i64(); \ | |
9802 | t1 = tcg_temp_new_i64(); \ | |
9803 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
9804 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 9805 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
9806 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9807 | tcg_temp_free_i64(t0); \ | |
9808 | tcg_temp_free_i64(t1); \ | |
9809 | } | |
9810 | #define GEN_SPEFPUOP_COMP_32(name) \ | |
636aa200 | 9811 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9812 | { \ |
9813 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9814 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9815 | return; \ |
9816 | } \ | |
8e703949 | 9817 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9818 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9819 | } | |
9820 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 9821 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9822 | { \ |
9823 | TCGv_i64 t0, t1; \ | |
9824 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9825 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9826 | return; \ |
9827 | } \ | |
9828 | t0 = tcg_temp_new_i64(); \ | |
9829 | t1 = tcg_temp_new_i64(); \ | |
9830 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
9831 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 9832 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
9833 | tcg_temp_free_i64(t0); \ |
9834 | tcg_temp_free_i64(t1); \ | |
9835 | } | |
9836 | #endif | |
57951c27 | 9837 | |
0487d6a8 JM |
9838 | /* Single precision floating-point vectors operations */ |
9839 | /* Arithmetic */ | |
1c97856d AJ |
9840 | GEN_SPEFPUOP_ARITH2_64_64(evfsadd); |
9841 | GEN_SPEFPUOP_ARITH2_64_64(evfssub); | |
9842 | GEN_SPEFPUOP_ARITH2_64_64(evfsmul); | |
9843 | GEN_SPEFPUOP_ARITH2_64_64(evfsdiv); | |
636aa200 | 9844 | static inline void gen_evfsabs(DisasContext *ctx) |
1c97856d AJ |
9845 | { |
9846 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9847 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9848 | return; |
9849 | } | |
9850 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9851 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL); |
1c97856d | 9852 | #else |
6d5c34fa MP |
9853 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000); |
9854 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
9855 | #endif |
9856 | } | |
636aa200 | 9857 | static inline void gen_evfsnabs(DisasContext *ctx) |
1c97856d AJ |
9858 | { |
9859 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9860 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9861 | return; |
9862 | } | |
9863 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9864 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 9865 | #else |
6d5c34fa MP |
9866 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
9867 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9868 | #endif |
9869 | } | |
636aa200 | 9870 | static inline void gen_evfsneg(DisasContext *ctx) |
1c97856d AJ |
9871 | { |
9872 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9873 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9874 | return; |
9875 | } | |
9876 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9877 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 9878 | #else |
6d5c34fa MP |
9879 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
9880 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9881 | #endif |
9882 | } | |
9883 | ||
0487d6a8 | 9884 | /* Conversion */ |
1c97856d AJ |
9885 | GEN_SPEFPUOP_CONV_64_64(evfscfui); |
9886 | GEN_SPEFPUOP_CONV_64_64(evfscfsi); | |
9887 | GEN_SPEFPUOP_CONV_64_64(evfscfuf); | |
9888 | GEN_SPEFPUOP_CONV_64_64(evfscfsf); | |
9889 | GEN_SPEFPUOP_CONV_64_64(evfsctui); | |
9890 | GEN_SPEFPUOP_CONV_64_64(evfsctsi); | |
9891 | GEN_SPEFPUOP_CONV_64_64(evfsctuf); | |
9892 | GEN_SPEFPUOP_CONV_64_64(evfsctsf); | |
9893 | GEN_SPEFPUOP_CONV_64_64(evfsctuiz); | |
9894 | GEN_SPEFPUOP_CONV_64_64(evfsctsiz); | |
9895 | ||
0487d6a8 | 9896 | /* Comparison */ |
1c97856d AJ |
9897 | GEN_SPEFPUOP_COMP_64(evfscmpgt); |
9898 | GEN_SPEFPUOP_COMP_64(evfscmplt); | |
9899 | GEN_SPEFPUOP_COMP_64(evfscmpeq); | |
9900 | GEN_SPEFPUOP_COMP_64(evfststgt); | |
9901 | GEN_SPEFPUOP_COMP_64(evfststlt); | |
9902 | GEN_SPEFPUOP_COMP_64(evfststeq); | |
0487d6a8 JM |
9903 | |
9904 | /* Opcodes definitions */ | |
70560da7 FC |
9905 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
9906 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
9907 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9908 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
9909 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9910 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9911 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9912 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9913 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9914 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9915 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9916 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9917 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9918 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
9919 | |
9920 | /* Single precision floating-point operations */ | |
9921 | /* Arithmetic */ | |
1c97856d AJ |
9922 | GEN_SPEFPUOP_ARITH2_32_32(efsadd); |
9923 | GEN_SPEFPUOP_ARITH2_32_32(efssub); | |
9924 | GEN_SPEFPUOP_ARITH2_32_32(efsmul); | |
9925 | GEN_SPEFPUOP_ARITH2_32_32(efsdiv); | |
636aa200 | 9926 | static inline void gen_efsabs(DisasContext *ctx) |
1c97856d AJ |
9927 | { |
9928 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9929 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9930 | return; |
9931 | } | |
6d5c34fa | 9932 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL); |
1c97856d | 9933 | } |
636aa200 | 9934 | static inline void gen_efsnabs(DisasContext *ctx) |
1c97856d AJ |
9935 | { |
9936 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9937 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9938 | return; |
9939 | } | |
6d5c34fa | 9940 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d | 9941 | } |
636aa200 | 9942 | static inline void gen_efsneg(DisasContext *ctx) |
1c97856d AJ |
9943 | { |
9944 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9945 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9946 | return; |
9947 | } | |
6d5c34fa | 9948 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d AJ |
9949 | } |
9950 | ||
0487d6a8 | 9951 | /* Conversion */ |
1c97856d AJ |
9952 | GEN_SPEFPUOP_CONV_32_32(efscfui); |
9953 | GEN_SPEFPUOP_CONV_32_32(efscfsi); | |
9954 | GEN_SPEFPUOP_CONV_32_32(efscfuf); | |
9955 | GEN_SPEFPUOP_CONV_32_32(efscfsf); | |
9956 | GEN_SPEFPUOP_CONV_32_32(efsctui); | |
9957 | GEN_SPEFPUOP_CONV_32_32(efsctsi); | |
9958 | GEN_SPEFPUOP_CONV_32_32(efsctuf); | |
9959 | GEN_SPEFPUOP_CONV_32_32(efsctsf); | |
9960 | GEN_SPEFPUOP_CONV_32_32(efsctuiz); | |
9961 | GEN_SPEFPUOP_CONV_32_32(efsctsiz); | |
9962 | GEN_SPEFPUOP_CONV_32_64(efscfd); | |
9963 | ||
0487d6a8 | 9964 | /* Comparison */ |
1c97856d AJ |
9965 | GEN_SPEFPUOP_COMP_32(efscmpgt); |
9966 | GEN_SPEFPUOP_COMP_32(efscmplt); | |
9967 | GEN_SPEFPUOP_COMP_32(efscmpeq); | |
9968 | GEN_SPEFPUOP_COMP_32(efststgt); | |
9969 | GEN_SPEFPUOP_COMP_32(efststlt); | |
9970 | GEN_SPEFPUOP_COMP_32(efststeq); | |
0487d6a8 JM |
9971 | |
9972 | /* Opcodes definitions */ | |
70560da7 FC |
9973 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
9974 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
9975 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9976 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
9977 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9978 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); // | |
9979 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9980 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9981 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9982 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9983 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9984 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9985 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9986 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
9987 | |
9988 | /* Double precision floating-point operations */ | |
9989 | /* Arithmetic */ | |
1c97856d AJ |
9990 | GEN_SPEFPUOP_ARITH2_64_64(efdadd); |
9991 | GEN_SPEFPUOP_ARITH2_64_64(efdsub); | |
9992 | GEN_SPEFPUOP_ARITH2_64_64(efdmul); | |
9993 | GEN_SPEFPUOP_ARITH2_64_64(efddiv); | |
636aa200 | 9994 | static inline void gen_efdabs(DisasContext *ctx) |
1c97856d AJ |
9995 | { |
9996 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9997 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9998 | return; |
9999 | } | |
10000 | #if defined(TARGET_PPC64) | |
6d5c34fa | 10001 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL); |
1c97856d | 10002 | #else |
6d5c34fa MP |
10003 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
10004 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
10005 | #endif |
10006 | } | |
636aa200 | 10007 | static inline void gen_efdnabs(DisasContext *ctx) |
1c97856d AJ |
10008 | { |
10009 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 10010 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
10011 | return; |
10012 | } | |
10013 | #if defined(TARGET_PPC64) | |
6d5c34fa | 10014 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 10015 | #else |
6d5c34fa MP |
10016 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
10017 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
10018 | #endif |
10019 | } | |
636aa200 | 10020 | static inline void gen_efdneg(DisasContext *ctx) |
1c97856d AJ |
10021 | { |
10022 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 10023 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
10024 | return; |
10025 | } | |
10026 | #if defined(TARGET_PPC64) | |
6d5c34fa | 10027 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 10028 | #else |
6d5c34fa MP |
10029 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
10030 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
10031 | #endif |
10032 | } | |
10033 | ||
0487d6a8 | 10034 | /* Conversion */ |
1c97856d AJ |
10035 | GEN_SPEFPUOP_CONV_64_32(efdcfui); |
10036 | GEN_SPEFPUOP_CONV_64_32(efdcfsi); | |
10037 | GEN_SPEFPUOP_CONV_64_32(efdcfuf); | |
10038 | GEN_SPEFPUOP_CONV_64_32(efdcfsf); | |
10039 | GEN_SPEFPUOP_CONV_32_64(efdctui); | |
10040 | GEN_SPEFPUOP_CONV_32_64(efdctsi); | |
10041 | GEN_SPEFPUOP_CONV_32_64(efdctuf); | |
10042 | GEN_SPEFPUOP_CONV_32_64(efdctsf); | |
10043 | GEN_SPEFPUOP_CONV_32_64(efdctuiz); | |
10044 | GEN_SPEFPUOP_CONV_32_64(efdctsiz); | |
10045 | GEN_SPEFPUOP_CONV_64_32(efdcfs); | |
10046 | GEN_SPEFPUOP_CONV_64_64(efdcfuid); | |
10047 | GEN_SPEFPUOP_CONV_64_64(efdcfsid); | |
10048 | GEN_SPEFPUOP_CONV_64_64(efdctuidz); | |
10049 | GEN_SPEFPUOP_CONV_64_64(efdctsidz); | |
0487d6a8 | 10050 | |
0487d6a8 | 10051 | /* Comparison */ |
1c97856d AJ |
10052 | GEN_SPEFPUOP_COMP_64(efdcmpgt); |
10053 | GEN_SPEFPUOP_COMP_64(efdcmplt); | |
10054 | GEN_SPEFPUOP_COMP_64(efdcmpeq); | |
10055 | GEN_SPEFPUOP_COMP_64(efdtstgt); | |
10056 | GEN_SPEFPUOP_COMP_64(efdtstlt); | |
10057 | GEN_SPEFPUOP_COMP_64(efdtsteq); | |
0487d6a8 JM |
10058 | |
10059 | /* Opcodes definitions */ | |
70560da7 FC |
10060 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // |
10061 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10062 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); // | |
10063 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
10064 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // | |
10065 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10066 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
10067 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); // | |
10068 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10069 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10070 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10071 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
10072 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
10073 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
10074 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
10075 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
0487d6a8 | 10076 | |
c227f099 | 10077 | static opcode_t opcodes[] = { |
5c55ff99 BS |
10078 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
10079 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
10080 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
10081 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER), | |
10082 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
fcfda20f | 10083 | GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205), |
5c55ff99 BS |
10084 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), |
10085 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10086 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10087 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10088 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10089 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), | |
10090 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
10091 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
10092 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
10093 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10094 | #if defined(TARGET_PPC64) | |
10095 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
10096 | #endif | |
10097 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
10098 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
10099 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10100 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10101 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10102 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
10103 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), | |
10104 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
10105 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10106 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10107 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10108 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10109 | GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), | |
eaabeef2 | 10110 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
725bcec2 | 10111 | GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205), |
5c55ff99 | 10112 | #if defined(TARGET_PPC64) |
eaabeef2 | 10113 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 10114 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
725bcec2 | 10115 | GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205), |
86ba37ed | 10116 | GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206), |
5c55ff99 BS |
10117 | #endif |
10118 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10119 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10120 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10121 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
10122 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
10123 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
10124 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
10125 | #if defined(TARGET_PPC64) | |
10126 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
10127 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
10128 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
10129 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
10130 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
10131 | #endif | |
10132 | GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES), | |
10133 | GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
10134 | GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
10135 | GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT), | |
10136 | GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT), | |
bf45a2e6 | 10137 | GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT), |
5c55ff99 | 10138 | GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT), |
bf45a2e6 AJ |
10139 | GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT), |
10140 | GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT), | |
f0332888 | 10141 | GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205), |
097ec5d8 TM |
10142 | GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207), |
10143 | GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207), | |
5c55ff99 BS |
10144 | GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT), |
10145 | GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT), | |
10146 | GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT), | |
10147 | GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT), | |
7d08d856 AJ |
10148 | GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT), |
10149 | GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT), | |
5c55ff99 BS |
10150 | #if defined(TARGET_PPC64) |
10151 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
10152 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
10153 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
10154 | #endif | |
10155 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10156 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
10157 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
10158 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
10159 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
10160 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
10161 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO), | |
10162 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), | |
5c77a786 TM |
10163 | GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
10164 | GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
f844c817 | 10165 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
587c51f7 TM |
10166 | GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
10167 | GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
5c55ff99 BS |
10168 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
10169 | #if defined(TARGET_PPC64) | |
f844c817 | 10170 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
9c294d5a | 10171 | GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207), |
5c55ff99 | 10172 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
27b95bfe | 10173 | GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207), |
5c55ff99 BS |
10174 | #endif |
10175 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
10176 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
10177 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
10178 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
10179 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
10180 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
52a4984d | 10181 | GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207), |
5c55ff99 BS |
10182 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), |
10183 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
10184 | #if defined(TARGET_PPC64) | |
10185 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
10186 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), | |
10187 | #endif | |
10188 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
10189 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
10190 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
10191 | #if defined(TARGET_PPC64) | |
10192 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
10193 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
10194 | #endif | |
10195 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
10196 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
10197 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
10198 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
10199 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
10200 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
10201 | #if defined(TARGET_PPC64) | |
10202 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
10203 | #endif | |
10204 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC), | |
10205 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC), | |
10206 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), | |
10207 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), | |
10208 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
3f34cf91 CLG |
10209 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE), |
10210 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE), | |
8e33944f | 10211 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ), |
5c55ff99 BS |
10212 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), |
10213 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC), | |
10214 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), | |
10215 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
10216 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), | |
10217 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
10218 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
10219 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
10220 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
10221 | #if defined(TARGET_PPC64) | |
10222 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
10223 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
10224 | PPC_SEGMENT_64B), | |
10225 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
10226 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
10227 | PPC_SEGMENT_64B), | |
efdef95f DG |
10228 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
10229 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
10230 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
5c55ff99 BS |
10231 | #endif |
10232 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
10233 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE), | |
10234 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE), | |
10235 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), | |
10236 | #if defined(TARGET_PPC64) | |
10237 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI), | |
10238 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), | |
10239 | #endif | |
10240 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
10241 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
10242 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
10243 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
10244 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
10245 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
10246 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
10247 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
10248 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
10249 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
10250 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
10251 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
10252 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
10253 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
10254 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
10255 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
10256 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
10257 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
10258 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
10259 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
10260 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
10261 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
10262 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
10263 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
10264 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
10265 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
10266 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
10267 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
10268 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
10269 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
10270 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
10271 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
10272 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
10273 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
10274 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
10275 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
10276 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
10277 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
10278 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
10279 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
10280 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
10281 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
10282 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
10283 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
10284 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
10285 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
10286 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
10287 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
10288 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
10289 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
10290 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
10291 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
10292 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
10293 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
10294 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
10295 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
10296 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
10297 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
10298 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
10299 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
10300 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
10301 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
10302 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
10303 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
10304 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
10305 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
10306 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
10307 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
10308 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
10309 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
10310 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 10311 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
10312 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
10313 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
10314 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
10315 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
10316 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
10317 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
10318 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
10319 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
10320 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
10321 | PPC_NONE, PPC2_BOOKE206), | |
10322 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
10323 | PPC_NONE, PPC2_BOOKE206), | |
10324 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
10325 | PPC_NONE, PPC2_BOOKE206), | |
10326 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
10327 | PPC_NONE, PPC2_BOOKE206), | |
6d3db821 AG |
10328 | GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001, |
10329 | PPC_NONE, PPC2_BOOKE206), | |
d5d11a39 AG |
10330 | GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001, |
10331 | PPC_NONE, PPC2_PRCNTL), | |
9e0b5cb1 AG |
10332 | GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001, |
10333 | PPC_NONE, PPC2_PRCNTL), | |
5c55ff99 | 10334 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 10335 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 10336 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
10337 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
10338 | PPC_BOOKE, PPC2_BOOKE206), | |
dcb2b9e1 | 10339 | GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE), |
01662f3e AG |
10340 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, |
10341 | PPC_BOOKE, PPC2_BOOKE206), | |
5c55ff99 BS |
10342 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
10343 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
10344 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
10345 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
5c55ff99 BS |
10346 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), |
10347 | GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE), | |
10348 | GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE), | |
10349 | GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE), | |
10350 | GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE), | |
10351 | ||
10352 | #undef GEN_INT_ARITH_ADD | |
10353 | #undef GEN_INT_ARITH_ADD_CONST | |
10354 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
10355 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
10356 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
10357 | add_ca, compute_ca, compute_ov) \ | |
10358 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
10359 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
10360 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
10361 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
10362 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
10363 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
10364 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
10365 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
10366 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
10367 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
10368 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
10369 | ||
10370 | #undef GEN_INT_ARITH_DIVW | |
10371 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
10372 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
10373 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
10374 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
10375 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
10376 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
a98eb9e9 TM |
10377 | GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
10378 | GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
6a4fda33 TM |
10379 | GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
10380 | GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
5c55ff99 BS |
10381 | |
10382 | #if defined(TARGET_PPC64) | |
10383 | #undef GEN_INT_ARITH_DIVD | |
10384 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
10385 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
10386 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
10387 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
10388 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
10389 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
10390 | ||
98d1eb27 TM |
10391 | GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
10392 | GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
e44259b6 TM |
10393 | GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
10394 | GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
98d1eb27 | 10395 | |
5c55ff99 BS |
10396 | #undef GEN_INT_ARITH_MUL_HELPER |
10397 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
10398 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
10399 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
10400 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
10401 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
10402 | #endif | |
10403 | ||
10404 | #undef GEN_INT_ARITH_SUBF | |
10405 | #undef GEN_INT_ARITH_SUBF_CONST | |
10406 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
10407 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
10408 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
10409 | add_ca, compute_ca, compute_ov) \ | |
10410 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
10411 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
10412 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
10413 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
10414 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
10415 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
10416 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
10417 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
10418 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
10419 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
10420 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
10421 | ||
10422 | #undef GEN_LOGICAL1 | |
10423 | #undef GEN_LOGICAL2 | |
10424 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
10425 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
10426 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
10427 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
10428 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
10429 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
10430 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
10431 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
10432 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
10433 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
10434 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
10435 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
10436 | #if defined(TARGET_PPC64) | |
10437 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
10438 | #endif | |
10439 | ||
10440 | #if defined(TARGET_PPC64) | |
10441 | #undef GEN_PPC64_R2 | |
10442 | #undef GEN_PPC64_R4 | |
10443 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
10444 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
10445 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
10446 | PPC_64B) | |
10447 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
10448 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
10449 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
10450 | PPC_64B), \ | |
10451 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
10452 | PPC_64B), \ | |
10453 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
10454 | PPC_64B) | |
10455 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
10456 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
10457 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
10458 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
10459 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
10460 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
10461 | #endif | |
10462 | ||
10463 | #undef _GEN_FLOAT_ACB | |
10464 | #undef GEN_FLOAT_ACB | |
10465 | #undef _GEN_FLOAT_AB | |
10466 | #undef GEN_FLOAT_AB | |
10467 | #undef _GEN_FLOAT_AC | |
10468 | #undef GEN_FLOAT_AC | |
10469 | #undef GEN_FLOAT_B | |
10470 | #undef GEN_FLOAT_BS | |
10471 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ | |
10472 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) | |
10473 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ | |
10474 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \ | |
10475 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type) | |
10476 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
10477 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
10478 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ | |
10479 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
10480 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
10481 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
10482 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
10483 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ | |
10484 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
10485 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
10486 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ | |
10487 | GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) | |
10488 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ | |
10489 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) | |
10490 | ||
10491 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT), | |
10492 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT), | |
10493 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT), | |
10494 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT), | |
10495 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES), | |
10496 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE), | |
10497 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL), | |
10498 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT), | |
10499 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT), | |
10500 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT), | |
10501 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT), | |
10502 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT), | |
da29cb7b | 10503 | GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206), |
6d41d146 | 10504 | GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206), |
5c55ff99 | 10505 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT), |
fab7fe42 | 10506 | GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 | 10507 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT), |
fab7fe42 | 10508 | GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 BS |
10509 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT), |
10510 | #if defined(TARGET_PPC64) | |
10511 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B), | |
28288b48 TM |
10512 | GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
10513 | GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206), | |
10514 | GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206), | |
5c55ff99 | 10515 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B), |
fab7fe42 | 10516 | GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 | 10517 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B), |
fab7fe42 | 10518 | GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 BS |
10519 | #endif |
10520 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT), | |
10521 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT), | |
10522 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT), | |
10523 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), | |
5c55ff99 BS |
10524 | |
10525 | #undef GEN_LD | |
10526 | #undef GEN_LDU | |
10527 | #undef GEN_LDUX | |
cd6e9320 | 10528 | #undef GEN_LDX_E |
5c55ff99 BS |
10529 | #undef GEN_LDS |
10530 | #define GEN_LD(name, ldop, opc, type) \ | |
10531 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
10532 | #define GEN_LDU(name, ldop, opc, type) \ | |
10533 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
10534 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
10535 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
10536 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
10537 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
10538 | #define GEN_LDS(name, ldop, op, type) \ |
10539 | GEN_LD(name, ldop, op | 0x20, type) \ | |
10540 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
10541 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
10542 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
10543 | ||
10544 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
10545 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
10546 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
10547 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
10548 | #if defined(TARGET_PPC64) | |
10549 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
10550 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
10551 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B) | |
10552 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B) | |
cd6e9320 | 10553 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
10554 | #endif |
10555 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
10556 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
10557 | ||
10558 | #undef GEN_ST | |
10559 | #undef GEN_STU | |
10560 | #undef GEN_STUX | |
cd6e9320 | 10561 | #undef GEN_STX_E |
5c55ff99 BS |
10562 | #undef GEN_STS |
10563 | #define GEN_ST(name, stop, opc, type) \ | |
10564 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
10565 | #define GEN_STU(name, stop, opc, type) \ | |
10566 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
10567 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
10568 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
10569 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
10570 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
10571 | #define GEN_STS(name, stop, op, type) \ |
10572 | GEN_ST(name, stop, op | 0x20, type) \ | |
10573 | GEN_STU(name, stop, op | 0x21, type) \ | |
10574 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
10575 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
10576 | ||
10577 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
10578 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
10579 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
10580 | #if defined(TARGET_PPC64) | |
10581 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B) | |
10582 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B) | |
cd6e9320 | 10583 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
10584 | #endif |
10585 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
10586 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
10587 | ||
10588 | #undef GEN_LDF | |
10589 | #undef GEN_LDUF | |
10590 | #undef GEN_LDUXF | |
10591 | #undef GEN_LDXF | |
10592 | #undef GEN_LDFS | |
10593 | #define GEN_LDF(name, ldop, opc, type) \ | |
10594 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
10595 | #define GEN_LDUF(name, ldop, opc, type) \ | |
10596 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
10597 | #define GEN_LDUXF(name, ldop, opc, type) \ | |
10598 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
10599 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ | |
10600 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
10601 | #define GEN_LDFS(name, ldop, op, type) \ | |
10602 | GEN_LDF(name, ldop, op | 0x20, type) \ | |
10603 | GEN_LDUF(name, ldop, op | 0x21, type) \ | |
10604 | GEN_LDUXF(name, ldop, op | 0x01, type) \ | |
10605 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
10606 | ||
10607 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT) | |
10608 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT) | |
199f830d | 10609 | GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205), |
66c3e328 | 10610 | GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206), |
05050ee8 AJ |
10611 | GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205), |
10612 | GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205), | |
5c55ff99 BS |
10613 | |
10614 | #undef GEN_STF | |
10615 | #undef GEN_STUF | |
10616 | #undef GEN_STUXF | |
10617 | #undef GEN_STXF | |
10618 | #undef GEN_STFS | |
10619 | #define GEN_STF(name, stop, opc, type) \ | |
10620 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
10621 | #define GEN_STUF(name, stop, opc, type) \ | |
10622 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
10623 | #define GEN_STUXF(name, stop, opc, type) \ | |
10624 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
10625 | #define GEN_STXF(name, stop, opc2, opc3, type) \ | |
10626 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
10627 | #define GEN_STFS(name, stop, op, type) \ | |
10628 | GEN_STF(name, stop, op | 0x20, type) \ | |
10629 | GEN_STUF(name, stop, op | 0x21, type) \ | |
10630 | GEN_STUXF(name, stop, op | 0x01, type) \ | |
10631 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
10632 | ||
10633 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT) | |
10634 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT) | |
10635 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX) | |
44bc0c4d AJ |
10636 | GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205), |
10637 | GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205), | |
5c55ff99 BS |
10638 | |
10639 | #undef GEN_CRLOGIC | |
10640 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
10641 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
10642 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
10643 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
10644 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
10645 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
10646 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
10647 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
10648 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
10649 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
10650 | ||
10651 | #undef GEN_MAC_HANDLER | |
10652 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
10653 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
10654 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
10655 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
10656 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
10657 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
10658 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
10659 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
10660 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
10661 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
10662 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
10663 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
10664 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
10665 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
10666 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
10667 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
10668 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
10669 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
10670 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
10671 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
10672 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
10673 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
10674 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
10675 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
10676 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
10677 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
10678 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
10679 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
10680 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
10681 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
10682 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
10683 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
10684 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
10685 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
10686 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
10687 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
10688 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
10689 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
10690 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
10691 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
10692 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
10693 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
10694 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
10695 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
10696 | ||
10697 | #undef GEN_VR_LDX | |
10698 | #undef GEN_VR_STX | |
10699 | #undef GEN_VR_LVE | |
10700 | #undef GEN_VR_STVE | |
10701 | #define GEN_VR_LDX(name, opc2, opc3) \ | |
10702 | GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10703 | #define GEN_VR_STX(name, opc2, opc3) \ | |
10704 | GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10705 | #define GEN_VR_LVE(name, opc2, opc3) \ | |
10706 | GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10707 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
10708 | GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10709 | GEN_VR_LDX(lvx, 0x07, 0x03), | |
10710 | GEN_VR_LDX(lvxl, 0x07, 0x0B), | |
10711 | GEN_VR_LVE(bx, 0x07, 0x00), | |
10712 | GEN_VR_LVE(hx, 0x07, 0x01), | |
10713 | GEN_VR_LVE(wx, 0x07, 0x02), | |
10714 | GEN_VR_STX(svx, 0x07, 0x07), | |
10715 | GEN_VR_STX(svxl, 0x07, 0x0F), | |
10716 | GEN_VR_STVE(bx, 0x07, 0x04), | |
10717 | GEN_VR_STVE(hx, 0x07, 0x05), | |
10718 | GEN_VR_STVE(wx, 0x07, 0x06), | |
10719 | ||
10720 | #undef GEN_VX_LOGICAL | |
10721 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
10722 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
111c5f54 TM |
10723 | |
10724 | #undef GEN_VX_LOGICAL_207 | |
10725 | #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \ | |
10726 | GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207) | |
10727 | ||
5c55ff99 BS |
10728 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16), |
10729 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17), | |
10730 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18), | |
10731 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19), | |
10732 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20), | |
111c5f54 TM |
10733 | GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26), |
10734 | GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22), | |
10735 | GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21), | |
5c55ff99 BS |
10736 | |
10737 | #undef GEN_VXFORM | |
10738 | #define GEN_VXFORM(name, opc2, opc3) \ | |
10739 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
50f5fc0c TM |
10740 | |
10741 | #undef GEN_VXFORM_207 | |
10742 | #define GEN_VXFORM_207(name, opc2, opc3) \ | |
10743 | GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207) | |
10744 | ||
5dffff5a TM |
10745 | #undef GEN_VXFORM_DUAL |
10746 | #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \ | |
10747 | GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1) | |
10748 | ||
a737d3eb TM |
10749 | #undef GEN_VXRFORM_DUAL |
10750 | #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \ | |
10751 | GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \ | |
10752 | GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1), | |
10753 | ||
5c55ff99 BS |
10754 | GEN_VXFORM(vaddubm, 0, 0), |
10755 | GEN_VXFORM(vadduhm, 0, 1), | |
10756 | GEN_VXFORM(vadduwm, 0, 2), | |
56eabc75 | 10757 | GEN_VXFORM_207(vaddudm, 0, 3), |
e8f7b27b TM |
10758 | GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE), |
10759 | GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE), | |
5c55ff99 | 10760 | GEN_VXFORM(vsubuwm, 0, 18), |
56eabc75 | 10761 | GEN_VXFORM_207(vsubudm, 0, 19), |
5c55ff99 BS |
10762 | GEN_VXFORM(vmaxub, 1, 0), |
10763 | GEN_VXFORM(vmaxuh, 1, 1), | |
10764 | GEN_VXFORM(vmaxuw, 1, 2), | |
8203e31b | 10765 | GEN_VXFORM_207(vmaxud, 1, 3), |
5c55ff99 BS |
10766 | GEN_VXFORM(vmaxsb, 1, 4), |
10767 | GEN_VXFORM(vmaxsh, 1, 5), | |
10768 | GEN_VXFORM(vmaxsw, 1, 6), | |
8203e31b | 10769 | GEN_VXFORM_207(vmaxsd, 1, 7), |
5c55ff99 BS |
10770 | GEN_VXFORM(vminub, 1, 8), |
10771 | GEN_VXFORM(vminuh, 1, 9), | |
10772 | GEN_VXFORM(vminuw, 1, 10), | |
8203e31b | 10773 | GEN_VXFORM_207(vminud, 1, 11), |
5c55ff99 BS |
10774 | GEN_VXFORM(vminsb, 1, 12), |
10775 | GEN_VXFORM(vminsh, 1, 13), | |
10776 | GEN_VXFORM(vminsw, 1, 14), | |
8203e31b | 10777 | GEN_VXFORM_207(vminsd, 1, 15), |
5c55ff99 BS |
10778 | GEN_VXFORM(vavgub, 1, 16), |
10779 | GEN_VXFORM(vavguh, 1, 17), | |
10780 | GEN_VXFORM(vavguw, 1, 18), | |
10781 | GEN_VXFORM(vavgsb, 1, 20), | |
10782 | GEN_VXFORM(vavgsh, 1, 21), | |
10783 | GEN_VXFORM(vavgsw, 1, 22), | |
10784 | GEN_VXFORM(vmrghb, 6, 0), | |
10785 | GEN_VXFORM(vmrghh, 6, 1), | |
10786 | GEN_VXFORM(vmrghw, 6, 2), | |
10787 | GEN_VXFORM(vmrglb, 6, 4), | |
10788 | GEN_VXFORM(vmrglh, 6, 5), | |
10789 | GEN_VXFORM(vmrglw, 6, 6), | |
e0ffe77f TM |
10790 | GEN_VXFORM_207(vmrgew, 6, 30), |
10791 | GEN_VXFORM_207(vmrgow, 6, 26), | |
5c55ff99 BS |
10792 | GEN_VXFORM(vmuloub, 4, 0), |
10793 | GEN_VXFORM(vmulouh, 4, 1), | |
953f0f58 | 10794 | GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE), |
5c55ff99 BS |
10795 | GEN_VXFORM(vmulosb, 4, 4), |
10796 | GEN_VXFORM(vmulosh, 4, 5), | |
63be0936 | 10797 | GEN_VXFORM_207(vmulosw, 4, 6), |
5c55ff99 BS |
10798 | GEN_VXFORM(vmuleub, 4, 8), |
10799 | GEN_VXFORM(vmuleuh, 4, 9), | |
63be0936 | 10800 | GEN_VXFORM_207(vmuleuw, 4, 10), |
5c55ff99 BS |
10801 | GEN_VXFORM(vmulesb, 4, 12), |
10802 | GEN_VXFORM(vmulesh, 4, 13), | |
63be0936 | 10803 | GEN_VXFORM_207(vmulesw, 4, 14), |
5c55ff99 BS |
10804 | GEN_VXFORM(vslb, 2, 4), |
10805 | GEN_VXFORM(vslh, 2, 5), | |
10806 | GEN_VXFORM(vslw, 2, 6), | |
2fdf78e6 | 10807 | GEN_VXFORM_207(vsld, 2, 23), |
5c55ff99 BS |
10808 | GEN_VXFORM(vsrb, 2, 8), |
10809 | GEN_VXFORM(vsrh, 2, 9), | |
10810 | GEN_VXFORM(vsrw, 2, 10), | |
2fdf78e6 | 10811 | GEN_VXFORM_207(vsrd, 2, 27), |
5c55ff99 BS |
10812 | GEN_VXFORM(vsrab, 2, 12), |
10813 | GEN_VXFORM(vsrah, 2, 13), | |
10814 | GEN_VXFORM(vsraw, 2, 14), | |
2fdf78e6 | 10815 | GEN_VXFORM_207(vsrad, 2, 15), |
5c55ff99 BS |
10816 | GEN_VXFORM(vslo, 6, 16), |
10817 | GEN_VXFORM(vsro, 6, 17), | |
10818 | GEN_VXFORM(vaddcuw, 0, 6), | |
10819 | GEN_VXFORM(vsubcuw, 0, 22), | |
10820 | GEN_VXFORM(vaddubs, 0, 8), | |
10821 | GEN_VXFORM(vadduhs, 0, 9), | |
10822 | GEN_VXFORM(vadduws, 0, 10), | |
10823 | GEN_VXFORM(vaddsbs, 0, 12), | |
10824 | GEN_VXFORM(vaddshs, 0, 13), | |
10825 | GEN_VXFORM(vaddsws, 0, 14), | |
e8f7b27b TM |
10826 | GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE), |
10827 | GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE), | |
5c55ff99 BS |
10828 | GEN_VXFORM(vsubuws, 0, 26), |
10829 | GEN_VXFORM(vsubsbs, 0, 28), | |
10830 | GEN_VXFORM(vsubshs, 0, 29), | |
10831 | GEN_VXFORM(vsubsws, 0, 30), | |
b41da4eb TM |
10832 | GEN_VXFORM_207(vadduqm, 0, 4), |
10833 | GEN_VXFORM_207(vaddcuq, 0, 5), | |
10834 | GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207), | |
10835 | GEN_VXFORM_207(vsubuqm, 0, 20), | |
10836 | GEN_VXFORM_207(vsubcuq, 0, 21), | |
10837 | GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207), | |
5c55ff99 BS |
10838 | GEN_VXFORM(vrlb, 2, 0), |
10839 | GEN_VXFORM(vrlh, 2, 1), | |
10840 | GEN_VXFORM(vrlw, 2, 2), | |
2fdf78e6 | 10841 | GEN_VXFORM_207(vrld, 2, 3), |
5c55ff99 BS |
10842 | GEN_VXFORM(vsl, 2, 7), |
10843 | GEN_VXFORM(vsr, 2, 11), | |
10844 | GEN_VXFORM(vpkuhum, 7, 0), | |
10845 | GEN_VXFORM(vpkuwum, 7, 1), | |
024215b2 | 10846 | GEN_VXFORM_207(vpkudum, 7, 17), |
5c55ff99 BS |
10847 | GEN_VXFORM(vpkuhus, 7, 2), |
10848 | GEN_VXFORM(vpkuwus, 7, 3), | |
024215b2 | 10849 | GEN_VXFORM_207(vpkudus, 7, 19), |
5c55ff99 BS |
10850 | GEN_VXFORM(vpkshus, 7, 4), |
10851 | GEN_VXFORM(vpkswus, 7, 5), | |
024215b2 | 10852 | GEN_VXFORM_207(vpksdus, 7, 21), |
5c55ff99 BS |
10853 | GEN_VXFORM(vpkshss, 7, 6), |
10854 | GEN_VXFORM(vpkswss, 7, 7), | |
024215b2 | 10855 | GEN_VXFORM_207(vpksdss, 7, 23), |
5c55ff99 BS |
10856 | GEN_VXFORM(vpkpx, 7, 12), |
10857 | GEN_VXFORM(vsum4ubs, 4, 24), | |
10858 | GEN_VXFORM(vsum4sbs, 4, 28), | |
10859 | GEN_VXFORM(vsum4shs, 4, 25), | |
10860 | GEN_VXFORM(vsum2sws, 4, 26), | |
10861 | GEN_VXFORM(vsumsws, 4, 30), | |
10862 | GEN_VXFORM(vaddfp, 5, 0), | |
10863 | GEN_VXFORM(vsubfp, 5, 1), | |
10864 | GEN_VXFORM(vmaxfp, 5, 16), | |
10865 | GEN_VXFORM(vminfp, 5, 17), | |
10866 | ||
10867 | #undef GEN_VXRFORM1 | |
10868 | #undef GEN_VXRFORM | |
10869 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ | |
10870 | GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC), | |
10871 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
10872 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
10873 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
10874 | GEN_VXRFORM(vcmpequb, 3, 0) | |
10875 | GEN_VXRFORM(vcmpequh, 3, 1) | |
10876 | GEN_VXRFORM(vcmpequw, 3, 2) | |
10877 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
10878 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
10879 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
10880 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
10881 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
10882 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
6f3dab41 | 10883 | GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE) |
5c55ff99 | 10884 | GEN_VXRFORM(vcmpgefp, 3, 7) |
6f3dab41 TM |
10885 | GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE) |
10886 | GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE) | |
5c55ff99 BS |
10887 | |
10888 | #undef GEN_VXFORM_SIMM | |
10889 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ | |
10890 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10891 | GEN_VXFORM_SIMM(vspltisb, 6, 12), | |
10892 | GEN_VXFORM_SIMM(vspltish, 6, 13), | |
10893 | GEN_VXFORM_SIMM(vspltisw, 6, 14), | |
10894 | ||
10895 | #undef GEN_VXFORM_NOA | |
10896 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ | |
10897 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) | |
10898 | GEN_VXFORM_NOA(vupkhsb, 7, 8), | |
10899 | GEN_VXFORM_NOA(vupkhsh, 7, 9), | |
4430e076 | 10900 | GEN_VXFORM_207(vupkhsw, 7, 25), |
5c55ff99 BS |
10901 | GEN_VXFORM_NOA(vupklsb, 7, 10), |
10902 | GEN_VXFORM_NOA(vupklsh, 7, 11), | |
4430e076 | 10903 | GEN_VXFORM_207(vupklsw, 7, 27), |
5c55ff99 BS |
10904 | GEN_VXFORM_NOA(vupkhpx, 7, 13), |
10905 | GEN_VXFORM_NOA(vupklpx, 7, 15), | |
10906 | GEN_VXFORM_NOA(vrefp, 5, 4), | |
10907 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5), | |
0bffbc6c | 10908 | GEN_VXFORM_NOA(vexptefp, 5, 6), |
5c55ff99 BS |
10909 | GEN_VXFORM_NOA(vlogefp, 5, 7), |
10910 | GEN_VXFORM_NOA(vrfim, 5, 8), | |
10911 | GEN_VXFORM_NOA(vrfin, 5, 9), | |
10912 | GEN_VXFORM_NOA(vrfip, 5, 10), | |
10913 | GEN_VXFORM_NOA(vrfiz, 5, 11), | |
10914 | ||
10915 | #undef GEN_VXFORM_UIMM | |
10916 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ | |
10917 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10918 | GEN_VXFORM_UIMM(vspltb, 6, 8), | |
10919 | GEN_VXFORM_UIMM(vsplth, 6, 9), | |
10920 | GEN_VXFORM_UIMM(vspltw, 6, 10), | |
10921 | GEN_VXFORM_UIMM(vcfux, 5, 12), | |
10922 | GEN_VXFORM_UIMM(vcfsx, 5, 13), | |
10923 | GEN_VXFORM_UIMM(vctuxs, 5, 14), | |
10924 | GEN_VXFORM_UIMM(vctsxs, 5, 15), | |
10925 | ||
10926 | #undef GEN_VAFORM_PAIRED | |
10927 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ | |
10928 | GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) | |
10929 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16), | |
10930 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18), | |
10931 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19), | |
10932 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20), | |
10933 | GEN_VAFORM_PAIRED(vsel, vperm, 21), | |
10934 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23), | |
10935 | ||
e13500b3 TM |
10936 | GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207), |
10937 | GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207), | |
10938 | GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207), | |
10939 | GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207), | |
10940 | ||
4d82038e | 10941 | GEN_VXFORM_207(vbpermq, 6, 21), |
f1064f61 | 10942 | GEN_VXFORM_207(vgbbd, 6, 20), |
b8476fc7 TM |
10943 | GEN_VXFORM_207(vpmsumb, 4, 16), |
10944 | GEN_VXFORM_207(vpmsumh, 4, 17), | |
10945 | GEN_VXFORM_207(vpmsumw, 4, 18), | |
10946 | GEN_VXFORM_207(vpmsumd, 4, 19), | |
f293f04a | 10947 | |
557d52fa TM |
10948 | GEN_VXFORM_207(vsbox, 4, 23), |
10949 | ||
10950 | GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207), | |
10951 | GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207), | |
10952 | ||
57354f8f TM |
10953 | GEN_VXFORM_207(vshasigmaw, 1, 26), |
10954 | GEN_VXFORM_207(vshasigmad, 1, 27), | |
10955 | ||
ac174549 TM |
10956 | GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE), |
10957 | ||
fa1832d7 | 10958 | GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX), |
cac7f0ba TM |
10959 | GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207), |
10960 | GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207), | |
10961 | GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207), | |
304af367 | 10962 | GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX), |
ca03b467 | 10963 | GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX), |
897e61d1 | 10964 | GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX), |
304af367 | 10965 | |
9231ba9e | 10966 | GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX), |
e16a626b TM |
10967 | GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207), |
10968 | GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207), | |
fbed2478 | 10969 | GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX), |
86e61ce3 | 10970 | GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX), |
fbed2478 | 10971 | |
f5c0f7f9 TM |
10972 | GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207), |
10973 | GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10974 | GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10975 | #if defined(TARGET_PPC64) | |
10976 | GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10977 | GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10978 | #endif | |
10979 | ||
df020ce0 TM |
10980 | #undef GEN_XX2FORM |
10981 | #define GEN_XX2FORM(name, opc2, opc3, fl2) \ | |
10982 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \ | |
10983 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2) | |
10984 | ||
10985 | #undef GEN_XX3FORM | |
10986 | #define GEN_XX3FORM(name, opc2, opc3, fl2) \ | |
10987 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \ | |
10988 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \ | |
10989 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \ | |
10990 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2) | |
10991 | ||
354a6dec TM |
10992 | #undef GEN_XX3_RC_FORM |
10993 | #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \ | |
10994 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10995 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10996 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10997 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10998 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
10999 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
11000 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
11001 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2) | |
11002 | ||
cd73f2c9 TM |
11003 | #undef GEN_XX3FORM_DM |
11004 | #define GEN_XX3FORM_DM(name, opc2, opc3) \ | |
11005 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
11006 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
11007 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
11008 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
11009 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
11010 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
11011 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
11012 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
11013 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
11014 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
11015 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
11016 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
11017 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
11018 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
11019 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
11020 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX) | |
11021 | ||
df020ce0 TM |
11022 | GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX), |
11023 | GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX), | |
11024 | GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX), | |
11025 | GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX), | |
11026 | ||
be574920 TM |
11027 | GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX), |
11028 | GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX), | |
11029 | GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX), | |
11030 | GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX), | |
11031 | GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX), | |
11032 | GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX), | |
11033 | GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX), | |
11034 | GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX), | |
79ca8a6a | 11035 | |
ee6e02c0 TM |
11036 | GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX), |
11037 | GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX), | |
5e591d88 | 11038 | GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX), |
4b98eeef | 11039 | GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX), |
2009227f | 11040 | GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX), |
d32404fe | 11041 | GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX), |
d3f9df8f | 11042 | GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX), |
bc80838f | 11043 | GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX), |
5cb151ac | 11044 | GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX), |
595c6eef TM |
11045 | GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX), |
11046 | GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX), | |
11047 | GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX), | |
11048 | GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX), | |
11049 | GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX), | |
11050 | GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX), | |
11051 | GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX), | |
11052 | GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX), | |
4f17e9c7 TM |
11053 | GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX), |
11054 | GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX), | |
959e9c9d TM |
11055 | GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX), |
11056 | GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX), | |
ed8ac568 | 11057 | GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX), |
7ee19fb9 | 11058 | GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207), |
ed8ac568 | 11059 | GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX), |
7ee19fb9 | 11060 | GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207), |
5177d2ca TM |
11061 | GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX), |
11062 | GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX), | |
11063 | GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX), | |
11064 | GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX), | |
11065 | GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX), | |
11066 | GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX), | |
88e33d08 TM |
11067 | GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX), |
11068 | GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX), | |
11069 | GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX), | |
11070 | GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX), | |
11071 | GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX), | |
ee6e02c0 | 11072 | |
3fd0aadf TM |
11073 | GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207), |
11074 | GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207), | |
ab9408a2 | 11075 | GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207), |
b24d0b47 | 11076 | GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207), |
2c0c52ae | 11077 | GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207), |
3d1140bf | 11078 | GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207), |
cea4e574 | 11079 | GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207), |
968e76bc | 11080 | GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207), |
f53f81e0 TM |
11081 | GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207), |
11082 | GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207), | |
11083 | GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207), | |
11084 | GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207), | |
11085 | GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207), | |
11086 | GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207), | |
11087 | GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207), | |
11088 | GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207), | |
74698350 TM |
11089 | GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207), |
11090 | GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207), | |
3fd0aadf | 11091 | |
ee6e02c0 TM |
11092 | GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX), |
11093 | GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX), | |
5e591d88 | 11094 | GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX), |
4b98eeef | 11095 | GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX), |
2009227f | 11096 | GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX), |
d32404fe | 11097 | GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX), |
d3f9df8f | 11098 | GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX), |
bc80838f | 11099 | GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX), |
5cb151ac | 11100 | GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX), |
595c6eef TM |
11101 | GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX), |
11102 | GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX), | |
11103 | GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX), | |
11104 | GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX), | |
11105 | GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX), | |
11106 | GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX), | |
11107 | GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX), | |
11108 | GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX), | |
959e9c9d TM |
11109 | GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX), |
11110 | GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX), | |
354a6dec TM |
11111 | GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX), |
11112 | GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX), | |
11113 | GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX), | |
ed8ac568 | 11114 | GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX), |
5177d2ca TM |
11115 | GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX), |
11116 | GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX), | |
11117 | GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX), | |
11118 | GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX), | |
11119 | GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX), | |
11120 | GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX), | |
11121 | GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX), | |
11122 | GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX), | |
88e33d08 TM |
11123 | GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX), |
11124 | GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX), | |
11125 | GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX), | |
11126 | GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX), | |
11127 | GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX), | |
ee6e02c0 TM |
11128 | |
11129 | GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX), | |
11130 | GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX), | |
5e591d88 | 11131 | GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX), |
4b98eeef | 11132 | GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX), |
2009227f | 11133 | GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX), |
d32404fe | 11134 | GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX), |
d3f9df8f | 11135 | GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX), |
bc80838f | 11136 | GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX), |
5cb151ac | 11137 | GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX), |
595c6eef TM |
11138 | GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX), |
11139 | GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX), | |
11140 | GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX), | |
11141 | GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX), | |
11142 | GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX), | |
11143 | GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX), | |
11144 | GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX), | |
11145 | GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX), | |
959e9c9d TM |
11146 | GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX), |
11147 | GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX), | |
354a6dec TM |
11148 | GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX), |
11149 | GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX), | |
11150 | GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX), | |
ed8ac568 | 11151 | GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX), |
5177d2ca TM |
11152 | GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX), |
11153 | GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX), | |
11154 | GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX), | |
11155 | GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX), | |
11156 | GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX), | |
11157 | GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX), | |
11158 | GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX), | |
11159 | GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX), | |
88e33d08 TM |
11160 | GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX), |
11161 | GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX), | |
11162 | GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX), | |
11163 | GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX), | |
11164 | GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX), | |
ee6e02c0 | 11165 | |
79ca8a6a TM |
11166 | #undef VSX_LOGICAL |
11167 | #define VSX_LOGICAL(name, opc2, opc3, fl2) \ | |
11168 | GEN_XX3FORM(name, opc2, opc3, fl2) | |
11169 | ||
11170 | VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX), | |
11171 | VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX), | |
11172 | VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX), | |
11173 | VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX), | |
11174 | VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX), | |
67a33f37 TM |
11175 | VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207), |
11176 | VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207), | |
11177 | VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207), | |
ce577d2e TM |
11178 | GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX), |
11179 | GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX), | |
76c15fe0 | 11180 | GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX), |
acc42968 | 11181 | GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00), |
79ca8a6a | 11182 | |
551e3ef7 TM |
11183 | #define GEN_XXSEL_ROW(opc3) \ |
11184 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11185 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11186 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11187 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11188 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11189 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11190 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11191 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
11192 | ||
11193 | GEN_XXSEL_ROW(0x00) | |
11194 | GEN_XXSEL_ROW(0x01) | |
11195 | GEN_XXSEL_ROW(0x02) | |
11196 | GEN_XXSEL_ROW(0x03) | |
11197 | GEN_XXSEL_ROW(0x04) | |
11198 | GEN_XXSEL_ROW(0x05) | |
11199 | GEN_XXSEL_ROW(0x06) | |
11200 | GEN_XXSEL_ROW(0x07) | |
11201 | GEN_XXSEL_ROW(0x08) | |
11202 | GEN_XXSEL_ROW(0x09) | |
11203 | GEN_XXSEL_ROW(0x0A) | |
11204 | GEN_XXSEL_ROW(0x0B) | |
11205 | GEN_XXSEL_ROW(0x0C) | |
11206 | GEN_XXSEL_ROW(0x0D) | |
11207 | GEN_XXSEL_ROW(0x0E) | |
11208 | GEN_XXSEL_ROW(0x0F) | |
11209 | GEN_XXSEL_ROW(0x10) | |
11210 | GEN_XXSEL_ROW(0x11) | |
11211 | GEN_XXSEL_ROW(0x12) | |
11212 | GEN_XXSEL_ROW(0x13) | |
11213 | GEN_XXSEL_ROW(0x14) | |
11214 | GEN_XXSEL_ROW(0x15) | |
11215 | GEN_XXSEL_ROW(0x16) | |
11216 | GEN_XXSEL_ROW(0x17) | |
11217 | GEN_XXSEL_ROW(0x18) | |
11218 | GEN_XXSEL_ROW(0x19) | |
11219 | GEN_XXSEL_ROW(0x1A) | |
11220 | GEN_XXSEL_ROW(0x1B) | |
11221 | GEN_XXSEL_ROW(0x1C) | |
11222 | GEN_XXSEL_ROW(0x1D) | |
11223 | GEN_XXSEL_ROW(0x1E) | |
11224 | GEN_XXSEL_ROW(0x1F) | |
11225 | ||
cd73f2c9 TM |
11226 | GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01), |
11227 | ||
275e35c6 TM |
11228 | #undef GEN_DFP_T_A_B_Rc |
11229 | #undef GEN_DFP_BF_A_B | |
11230 | #undef GEN_DFP_BF_A_DCM | |
11231 | #undef GEN_DFP_T_B_U32_U32_Rc | |
11232 | #undef GEN_DFP_T_A_B_I32_Rc | |
11233 | #undef GEN_DFP_T_B_Rc | |
11234 | #undef GEN_DFP_T_FPR_I32_Rc | |
11235 | ||
11236 | #define _GEN_DFP_LONG(name, op1, op2, mask) \ | |
11237 | GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP) | |
11238 | ||
11239 | #define _GEN_DFP_LONGx2(name, op1, op2, mask) \ | |
11240 | GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11241 | GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP) | |
11242 | ||
11243 | #define _GEN_DFP_LONGx4(name, op1, op2, mask) \ | |
11244 | GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11245 | GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11246 | GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11247 | GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP) | |
11248 | ||
11249 | #define _GEN_DFP_QUAD(name, op1, op2, mask) \ | |
11250 | GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP) | |
11251 | ||
11252 | #define _GEN_DFP_QUADx2(name, op1, op2, mask) \ | |
11253 | GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11254 | GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP) | |
11255 | ||
11256 | #define _GEN_DFP_QUADx4(name, op1, op2, mask) \ | |
11257 | GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11258 | GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11259 | GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \ | |
11260 | GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP) | |
11261 | ||
11262 | #define GEN_DFP_T_A_B_Rc(name, op1, op2) \ | |
11263 | _GEN_DFP_LONG(name, op1, op2, 0x00000000) | |
11264 | ||
11265 | #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \ | |
11266 | _GEN_DFP_QUAD(name, op1, op2, 0x00210800) | |
11267 | ||
11268 | #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \ | |
11269 | _GEN_DFP_QUAD(name, op1, op2, 0x00200800) | |
11270 | ||
11271 | #define GEN_DFP_T_B_Rc(name, op1, op2) \ | |
11272 | _GEN_DFP_LONG(name, op1, op2, 0x001F0000) | |
11273 | ||
11274 | #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \ | |
11275 | _GEN_DFP_QUAD(name, op1, op2, 0x003F0800) | |
11276 | ||
11277 | #define GEN_DFP_Tp_B_Rc(name, op1, op2) \ | |
11278 | _GEN_DFP_QUAD(name, op1, op2, 0x003F0000) | |
11279 | ||
11280 | #define GEN_DFP_T_Bp_Rc(name, op1, op2) \ | |
11281 | _GEN_DFP_QUAD(name, op1, op2, 0x001F0800) | |
11282 | ||
11283 | #define GEN_DFP_BF_A_B(name, op1, op2) \ | |
11284 | _GEN_DFP_LONG(name, op1, op2, 0x00000001) | |
11285 | ||
11286 | #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \ | |
11287 | _GEN_DFP_QUAD(name, op1, op2, 0x00610801) | |
11288 | ||
11289 | #define GEN_DFP_BF_A_Bp(name, op1, op2) \ | |
11290 | _GEN_DFP_QUAD(name, op1, op2, 0x00600801) | |
11291 | ||
11292 | #define GEN_DFP_BF_A_DCM(name, op1, op2) \ | |
11293 | _GEN_DFP_LONGx2(name, op1, op2, 0x00600001) | |
11294 | ||
11295 | #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \ | |
11296 | _GEN_DFP_QUADx2(name, op1, op2, 0x00610001) | |
11297 | ||
11298 | #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \ | |
11299 | _GEN_DFP_LONGx4(name, op1, op2, 0x00000000) | |
11300 | ||
11301 | #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \ | |
11302 | _GEN_DFP_QUADx4(name, op1, op2, 0x02010800) | |
11303 | ||
11304 | #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \ | |
11305 | _GEN_DFP_QUADx4(name, op1, op2, 0x02000800) | |
11306 | ||
11307 | #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \ | |
11308 | _GEN_DFP_LONGx4(name, op1, op2, 0x00000000) | |
11309 | ||
11310 | #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \ | |
11311 | _GEN_DFP_QUADx4(name, op1, op2, 0x00200800) | |
11312 | ||
11313 | #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \ | |
11314 | _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000) | |
11315 | ||
11316 | #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \ | |
11317 | _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800) | |
11318 | ||
11319 | #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \ | |
11320 | _GEN_DFP_LONG(name, op1, op2, 0x00070000) | |
11321 | ||
11322 | #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \ | |
11323 | _GEN_DFP_QUAD(name, op1, op2, 0x00270800) | |
11324 | ||
11325 | #define GEN_DFP_S_T_B_Rc(name, op1, op2) \ | |
11326 | _GEN_DFP_LONG(name, op1, op2, 0x000F0000) | |
11327 | ||
11328 | #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \ | |
11329 | _GEN_DFP_QUAD(name, op1, op2, 0x002F0800) | |
11330 | ||
11331 | #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \ | |
11332 | _GEN_DFP_LONGx2(name, op1, op2, 0x00000000) | |
11333 | ||
11334 | #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \ | |
11335 | _GEN_DFP_QUADx2(name, op1, op2, 0x00210000) | |
11336 | ||
a9d7ba03 TM |
11337 | GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00), |
11338 | GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00), | |
2128f8a5 TM |
11339 | GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10), |
11340 | GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10), | |
8de6a1cc TM |
11341 | GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01), |
11342 | GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01), | |
9024ff40 TM |
11343 | GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11), |
11344 | GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11), | |
5833505b TM |
11345 | GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14), |
11346 | GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14), | |
11347 | GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04), | |
11348 | GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04), | |
e601c1ee TM |
11349 | GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06), |
11350 | GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06), | |
1bf9c0e1 TM |
11351 | GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07), |
11352 | GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07), | |
f3d2b0bc TM |
11353 | GEN_DFP_BF_A_B(dtstex, 0x02, 0x05), |
11354 | GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05), | |
f6022a76 TM |
11355 | GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15), |
11356 | GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15), | |
5826ebe2 TM |
11357 | GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02), |
11358 | GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02), | |
11359 | GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00), | |
11360 | GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00), | |
512918aa TM |
11361 | GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01), |
11362 | GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01), | |
97c0d930 TM |
11363 | GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03), |
11364 | GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03), | |
11365 | GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07), | |
11366 | GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07), | |
290d9ee5 TM |
11367 | GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08), |
11368 | GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08), | |
ca603eb4 TM |
11369 | GEN_DFP_T_B_Rc(drsp, 0x02, 0x18), |
11370 | GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18), | |
f1214193 TM |
11371 | GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19), |
11372 | GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19), | |
bea0dd79 TM |
11373 | GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09), |
11374 | GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09), | |
7796676f TM |
11375 | GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a), |
11376 | GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a), | |
013c3ac0 TM |
11377 | GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a), |
11378 | GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a), | |
e8a48460 TM |
11379 | GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b), |
11380 | GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b), | |
297666eb TM |
11381 | GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b), |
11382 | GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b), | |
804e654a TM |
11383 | GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02), |
11384 | GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02), | |
11385 | GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03), | |
11386 | GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03), | |
11387 | ||
5c55ff99 | 11388 | #undef GEN_SPE |
70560da7 FC |
11389 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
11390 | GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE) | |
11391 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11392 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11393 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11394 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11395 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
11396 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
11397 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
11398 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE), | |
11399 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE), | |
11400 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
11401 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11402 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11403 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11404 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
11405 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
11406 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE), | |
11407 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
11408 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11409 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11410 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11411 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11412 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
11413 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
11414 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
11415 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11416 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
11417 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
11418 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
11419 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE), | |
11420 | ||
11421 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
11422 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
11423 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11424 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
11425 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
11426 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11427 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11428 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11429 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11430 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11431 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11432 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11433 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
11434 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11435 | ||
11436 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
11437 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
11438 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11439 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
11440 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
11441 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE), | |
11442 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11443 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11444 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11445 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
11446 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11447 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11448 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
11449 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
11450 | ||
11451 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
11452 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11453 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE), | |
11454 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
11455 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
11456 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11457 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
11458 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE), | |
11459 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11460 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11461 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11462 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
11463 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
11464 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
11465 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
11466 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
5c55ff99 BS |
11467 | |
11468 | #undef GEN_SPEOP_LDST | |
11469 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
11470 | GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) | |
11471 | GEN_SPEOP_LDST(evldd, 0x00, 3), | |
11472 | GEN_SPEOP_LDST(evldw, 0x01, 3), | |
11473 | GEN_SPEOP_LDST(evldh, 0x02, 3), | |
11474 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1), | |
11475 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1), | |
11476 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1), | |
11477 | GEN_SPEOP_LDST(evlwhe, 0x08, 2), | |
11478 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2), | |
11479 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2), | |
11480 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2), | |
11481 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2), | |
11482 | ||
11483 | GEN_SPEOP_LDST(evstdd, 0x10, 3), | |
11484 | GEN_SPEOP_LDST(evstdw, 0x11, 3), | |
11485 | GEN_SPEOP_LDST(evstdh, 0x12, 3), | |
11486 | GEN_SPEOP_LDST(evstwhe, 0x18, 2), | |
11487 | GEN_SPEOP_LDST(evstwho, 0x1A, 2), | |
11488 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2), | |
11489 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2), | |
11490 | }; | |
11491 | ||
0411a972 | 11492 | #include "helper_regs.h" |
a1389542 | 11493 | #include "translate_init.c" |
79aceca5 | 11494 | |
9a64fbe4 | 11495 | /*****************************************************************************/ |
3fc6c082 | 11496 | /* Misc PowerPC helpers */ |
878096ee AF |
11497 | void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, |
11498 | int flags) | |
79aceca5 | 11499 | { |
3fc6c082 FB |
11500 | #define RGPL 4 |
11501 | #define RFPL 4 | |
3fc6c082 | 11502 | |
878096ee AF |
11503 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
11504 | CPUPPCState *env = &cpu->env; | |
79aceca5 FB |
11505 | int i; |
11506 | ||
90e189ec | 11507 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
9a78eead | 11508 | TARGET_FMT_lx " XER " TARGET_FMT_lx "\n", |
da91a00f | 11509 | env->nip, env->lr, env->ctr, cpu_read_xer(env)); |
90e189ec BS |
11510 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
11511 | TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0], | |
11512 | env->hflags, env->mmu_idx); | |
d9bce9d9 | 11513 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 11514 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 11515 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 11516 | " DECR %08" PRIu32 |
76a66253 JM |
11517 | #endif |
11518 | "\n", | |
077fc206 | 11519 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
11520 | #if !defined(CONFIG_USER_ONLY) |
11521 | , cpu_ppc_load_decr(env) | |
11522 | #endif | |
11523 | ); | |
077fc206 | 11524 | #endif |
76a66253 | 11525 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
11526 | if ((i & (RGPL - 1)) == 0) |
11527 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 11528 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 11529 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 11530 | cpu_fprintf(f, "\n"); |
76a66253 | 11531 | } |
3fc6c082 | 11532 | cpu_fprintf(f, "CR "); |
76a66253 | 11533 | for (i = 0; i < 8; i++) |
7fe48483 FB |
11534 | cpu_fprintf(f, "%01x", env->crf[i]); |
11535 | cpu_fprintf(f, " ["); | |
76a66253 JM |
11536 | for (i = 0; i < 8; i++) { |
11537 | char a = '-'; | |
11538 | if (env->crf[i] & 0x08) | |
11539 | a = 'L'; | |
11540 | else if (env->crf[i] & 0x04) | |
11541 | a = 'G'; | |
11542 | else if (env->crf[i] & 0x02) | |
11543 | a = 'E'; | |
7fe48483 | 11544 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 11545 | } |
90e189ec BS |
11546 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
11547 | env->reserve_addr); | |
3fc6c082 FB |
11548 | for (i = 0; i < 32; i++) { |
11549 | if ((i & (RFPL - 1)) == 0) | |
11550 | cpu_fprintf(f, "FPR%02d", i); | |
26a76461 | 11551 | cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); |
3fc6c082 | 11552 | if ((i & (RFPL - 1)) == (RFPL - 1)) |
7fe48483 | 11553 | cpu_fprintf(f, "\n"); |
79aceca5 | 11554 | } |
30304420 | 11555 | cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); |
f2e63a42 | 11556 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
11557 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
11558 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
11559 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
11560 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
11561 | ||
11562 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
11563 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
11564 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
11565 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
11566 | ||
11567 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
11568 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
11569 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
11570 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
11571 | ||
11572 | if (env->excp_model == POWERPC_EXCP_BOOKE) { | |
11573 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
11574 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
11575 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
11576 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
11577 | ||
11578 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
11579 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
11580 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
11581 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
11582 | ||
11583 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
11584 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
11585 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
11586 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
11587 | ||
11588 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
11589 | " EPR " TARGET_FMT_lx "\n", | |
11590 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
11591 | env->spr[SPR_BOOKE_EPR]); | |
11592 | ||
11593 | /* FSL-specific */ | |
11594 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
11595 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
11596 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
11597 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
11598 | ||
11599 | /* | |
11600 | * IVORs are left out as they are large and do not change often -- | |
11601 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
11602 | */ | |
11603 | } | |
11604 | ||
697ab892 DG |
11605 | #if defined(TARGET_PPC64) |
11606 | if (env->flags & POWERPC_FLAG_CFAR) { | |
11607 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
11608 | } | |
11609 | #endif | |
11610 | ||
90dc8812 SW |
11611 | switch (env->mmu_model) { |
11612 | case POWERPC_MMU_32B: | |
11613 | case POWERPC_MMU_601: | |
11614 | case POWERPC_MMU_SOFT_6xx: | |
11615 | case POWERPC_MMU_SOFT_74xx: | |
11616 | #if defined(TARGET_PPC64) | |
90dc8812 | 11617 | case POWERPC_MMU_64B: |
ca480de6 AB |
11618 | case POWERPC_MMU_2_06: |
11619 | case POWERPC_MMU_2_06a: | |
11620 | case POWERPC_MMU_2_06d: | |
90dc8812 | 11621 | #endif |
ca480de6 AB |
11622 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx |
11623 | " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1], | |
11624 | env->spr[SPR_DAR], env->spr[SPR_DSISR]); | |
90dc8812 | 11625 | break; |
01662f3e | 11626 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
11627 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
11628 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
11629 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
11630 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
11631 | ||
11632 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
11633 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
11634 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
11635 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
11636 | ||
11637 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
11638 | " TLB1CFG " TARGET_FMT_lx "\n", | |
11639 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
11640 | env->spr[SPR_BOOKE_TLB1CFG]); | |
11641 | break; | |
11642 | default: | |
11643 | break; | |
11644 | } | |
f2e63a42 | 11645 | #endif |
79aceca5 | 11646 | |
3fc6c082 FB |
11647 | #undef RGPL |
11648 | #undef RFPL | |
79aceca5 FB |
11649 | } |
11650 | ||
878096ee AF |
11651 | void ppc_cpu_dump_statistics(CPUState *cs, FILE*f, |
11652 | fprintf_function cpu_fprintf, int flags) | |
76a66253 JM |
11653 | { |
11654 | #if defined(DO_PPC_STATISTICS) | |
878096ee | 11655 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
c227f099 | 11656 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
11657 | int op1, op2, op3; |
11658 | ||
878096ee | 11659 | t1 = cpu->env.opcodes; |
76a66253 JM |
11660 | for (op1 = 0; op1 < 64; op1++) { |
11661 | handler = t1[op1]; | |
11662 | if (is_indirect_opcode(handler)) { | |
11663 | t2 = ind_table(handler); | |
11664 | for (op2 = 0; op2 < 32; op2++) { | |
11665 | handler = t2[op2]; | |
11666 | if (is_indirect_opcode(handler)) { | |
11667 | t3 = ind_table(handler); | |
11668 | for (op3 = 0; op3 < 32; op3++) { | |
11669 | handler = t3[op3]; | |
11670 | if (handler->count == 0) | |
11671 | continue; | |
11672 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 11673 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
11674 | op1, op2, op3, op1, (op3 << 5) | op2, |
11675 | handler->oname, | |
11676 | handler->count, handler->count); | |
11677 | } | |
11678 | } else { | |
11679 | if (handler->count == 0) | |
11680 | continue; | |
11681 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 11682 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
11683 | op1, op2, op1, op2, handler->oname, |
11684 | handler->count, handler->count); | |
11685 | } | |
11686 | } | |
11687 | } else { | |
11688 | if (handler->count == 0) | |
11689 | continue; | |
0bfcd599 BS |
11690 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
11691 | " %" PRId64 "\n", | |
76a66253 JM |
11692 | op1, op1, handler->oname, |
11693 | handler->count, handler->count); | |
11694 | } | |
11695 | } | |
11696 | #endif | |
11697 | } | |
11698 | ||
9a64fbe4 | 11699 | /*****************************************************************************/ |
213fe1f5 | 11700 | static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, |
636aa200 | 11701 | TranslationBlock *tb, |
213fe1f5 | 11702 | bool search_pc) |
79aceca5 | 11703 | { |
ed2803da | 11704 | CPUState *cs = CPU(cpu); |
213fe1f5 | 11705 | CPUPPCState *env = &cpu->env; |
9fddaa0c | 11706 | DisasContext ctx, *ctxp = &ctx; |
c227f099 | 11707 | opc_handler_t **table, *handler; |
0fa85d43 | 11708 | target_ulong pc_start; |
79aceca5 | 11709 | uint16_t *gen_opc_end; |
a1d1bb31 | 11710 | CPUBreakpoint *bp; |
79aceca5 | 11711 | int j, lj = -1; |
2e70f6ef PB |
11712 | int num_insns; |
11713 | int max_insns; | |
79aceca5 FB |
11714 | |
11715 | pc_start = tb->pc; | |
92414b31 | 11716 | gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
046d6672 | 11717 | ctx.nip = pc_start; |
79aceca5 | 11718 | ctx.tb = tb; |
e1833e1f | 11719 | ctx.exception = POWERPC_EXCP_NONE; |
3fc6c082 | 11720 | ctx.spr_cb = env->spr_cb; |
76db3ba4 | 11721 | ctx.mem_idx = env->mmu_idx; |
7d08d856 AJ |
11722 | ctx.insns_flags = env->insns_flags; |
11723 | ctx.insns_flags2 = env->insns_flags2; | |
76db3ba4 AJ |
11724 | ctx.access_type = -1; |
11725 | ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0; | |
d9bce9d9 | 11726 | #if defined(TARGET_PPC64) |
e42a61f1 | 11727 | ctx.sf_mode = msr_is_64bit(env, env->msr); |
697ab892 | 11728 | ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); |
9a64fbe4 | 11729 | #endif |
3cc62370 | 11730 | ctx.fpu_enabled = msr_fp; |
a9d9eb8f | 11731 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
d26bfc9a JM |
11732 | ctx.spe_enabled = msr_spe; |
11733 | else | |
11734 | ctx.spe_enabled = 0; | |
a9d9eb8f JM |
11735 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
11736 | ctx.altivec_enabled = msr_vr; | |
11737 | else | |
11738 | ctx.altivec_enabled = 0; | |
1f29871c TM |
11739 | if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) { |
11740 | ctx.vsx_enabled = msr_vsx; | |
11741 | } else { | |
11742 | ctx.vsx_enabled = 0; | |
11743 | } | |
d26bfc9a | 11744 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
8cbcb4fa | 11745 | ctx.singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 11746 | else |
8cbcb4fa | 11747 | ctx.singlestep_enabled = 0; |
d26bfc9a | 11748 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
8cbcb4fa | 11749 | ctx.singlestep_enabled |= CPU_BRANCH_STEP; |
ed2803da | 11750 | if (unlikely(cs->singlestep_enabled)) { |
8cbcb4fa | 11751 | ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP; |
ed2803da | 11752 | } |
3fc6c082 | 11753 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
11754 | /* Single step trace mode */ |
11755 | msr_se = 1; | |
11756 | #endif | |
2e70f6ef PB |
11757 | num_insns = 0; |
11758 | max_insns = tb->cflags & CF_COUNT_MASK; | |
11759 | if (max_insns == 0) | |
11760 | max_insns = CF_COUNT_MASK; | |
11761 | ||
806f352d | 11762 | gen_tb_start(); |
9a64fbe4 | 11763 | /* Set env in case of segfault during code fetch */ |
efd7f486 EV |
11764 | while (ctx.exception == POWERPC_EXCP_NONE |
11765 | && tcg_ctx.gen_opc_ptr < gen_opc_end) { | |
f0c3c505 AF |
11766 | if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { |
11767 | QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { | |
a1d1bb31 | 11768 | if (bp->pc == ctx.nip) { |
e06fcd75 | 11769 | gen_debug_exception(ctxp); |
ea4e754f FB |
11770 | break; |
11771 | } | |
11772 | } | |
11773 | } | |
76a66253 | 11774 | if (unlikely(search_pc)) { |
92414b31 | 11775 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
79aceca5 FB |
11776 | if (lj < j) { |
11777 | lj++; | |
11778 | while (lj < j) | |
ab1103de | 11779 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
79aceca5 | 11780 | } |
25983cad | 11781 | tcg_ctx.gen_opc_pc[lj] = ctx.nip; |
ab1103de | 11782 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 11783 | tcg_ctx.gen_opc_icount[lj] = num_insns; |
79aceca5 | 11784 | } |
d12d51d5 | 11785 | LOG_DISAS("----------------\n"); |
90e189ec | 11786 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", |
d12d51d5 | 11787 | ctx.nip, ctx.mem_idx, (int)msr_ir); |
2e70f6ef PB |
11788 | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
11789 | gen_io_start(); | |
76db3ba4 | 11790 | if (unlikely(ctx.le_mode)) { |
2f5a189c | 11791 | ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip)); |
056401ea | 11792 | } else { |
2f5a189c | 11793 | ctx.opcode = cpu_ldl_code(env, ctx.nip); |
111bfab3 | 11794 | } |
d12d51d5 | 11795 | LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n", |
9a64fbe4 | 11796 | ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
476b6d16 | 11797 | opc3(ctx.opcode), ctx.le_mode ? "little" : "big"); |
fdefe51c | 11798 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { |
731c54f8 | 11799 | tcg_gen_debug_insn_start(ctx.nip); |
fdefe51c | 11800 | } |
046d6672 | 11801 | ctx.nip += 4; |
3fc6c082 | 11802 | table = env->opcodes; |
2e70f6ef | 11803 | num_insns++; |
79aceca5 FB |
11804 | handler = table[opc1(ctx.opcode)]; |
11805 | if (is_indirect_opcode(handler)) { | |
11806 | table = ind_table(handler); | |
11807 | handler = table[opc2(ctx.opcode)]; | |
11808 | if (is_indirect_opcode(handler)) { | |
11809 | table = ind_table(handler); | |
11810 | handler = table[opc3(ctx.opcode)]; | |
11811 | } | |
11812 | } | |
11813 | /* Is opcode *REALLY* valid ? */ | |
76a66253 | 11814 | if (unlikely(handler->handler == &gen_invalid)) { |
93fcfe39 AL |
11815 | if (qemu_log_enabled()) { |
11816 | qemu_log("invalid/unsupported opcode: " | |
90e189ec BS |
11817 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n", |
11818 | opc1(ctx.opcode), opc2(ctx.opcode), | |
11819 | opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir); | |
4b3686fa | 11820 | } |
76a66253 | 11821 | } else { |
70560da7 FC |
11822 | uint32_t inval; |
11823 | ||
11824 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) { | |
11825 | inval = handler->inval2; | |
11826 | } else { | |
11827 | inval = handler->inval1; | |
11828 | } | |
11829 | ||
11830 | if (unlikely((ctx.opcode & inval) != 0)) { | |
93fcfe39 AL |
11831 | if (qemu_log_enabled()) { |
11832 | qemu_log("invalid bits: %08x for opcode: " | |
90e189ec | 11833 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n", |
70560da7 | 11834 | ctx.opcode & inval, opc1(ctx.opcode), |
90e189ec BS |
11835 | opc2(ctx.opcode), opc3(ctx.opcode), |
11836 | ctx.opcode, ctx.nip - 4); | |
76a66253 | 11837 | } |
e06fcd75 | 11838 | gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL); |
4b3686fa | 11839 | break; |
79aceca5 | 11840 | } |
79aceca5 | 11841 | } |
4b3686fa | 11842 | (*(handler->handler))(&ctx); |
76a66253 JM |
11843 | #if defined(DO_PPC_STATISTICS) |
11844 | handler->count++; | |
11845 | #endif | |
9a64fbe4 | 11846 | /* Check trace mode exceptions */ |
8cbcb4fa AJ |
11847 | if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP && |
11848 | (ctx.nip <= 0x100 || ctx.nip > 0xF00) && | |
11849 | ctx.exception != POWERPC_SYSCALL && | |
11850 | ctx.exception != POWERPC_EXCP_TRAP && | |
11851 | ctx.exception != POWERPC_EXCP_BRANCH)) { | |
e06fcd75 | 11852 | gen_exception(ctxp, POWERPC_EXCP_TRACE); |
d26bfc9a | 11853 | } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
ed2803da | 11854 | (cs->singlestep_enabled) || |
1b530a6d | 11855 | singlestep || |
2e70f6ef | 11856 | num_insns >= max_insns)) { |
d26bfc9a JM |
11857 | /* if we reach a page boundary or are single stepping, stop |
11858 | * generation | |
11859 | */ | |
8dd4983c | 11860 | break; |
76a66253 | 11861 | } |
3fc6c082 | 11862 | } |
2e70f6ef PB |
11863 | if (tb->cflags & CF_LAST_IO) |
11864 | gen_io_end(); | |
e1833e1f | 11865 | if (ctx.exception == POWERPC_EXCP_NONE) { |
c1942362 | 11866 | gen_goto_tb(&ctx, 0, ctx.nip); |
e1833e1f | 11867 | } else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
ed2803da | 11868 | if (unlikely(cs->singlestep_enabled)) { |
e06fcd75 | 11869 | gen_debug_exception(ctxp); |
8cbcb4fa | 11870 | } |
76a66253 | 11871 | /* Generate the return instruction */ |
57fec1fe | 11872 | tcg_gen_exit_tb(0); |
9a64fbe4 | 11873 | } |
806f352d | 11874 | gen_tb_end(tb, num_insns); |
efd7f486 | 11875 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
76a66253 | 11876 | if (unlikely(search_pc)) { |
92414b31 | 11877 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
9a64fbe4 FB |
11878 | lj++; |
11879 | while (lj <= j) | |
ab1103de | 11880 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
9a64fbe4 | 11881 | } else { |
046d6672 | 11882 | tb->size = ctx.nip - pc_start; |
2e70f6ef | 11883 | tb->icount = num_insns; |
9a64fbe4 | 11884 | } |
d9bce9d9 | 11885 | #if defined(DEBUG_DISAS) |
8fec2b8c | 11886 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
76a66253 | 11887 | int flags; |
237c0af0 | 11888 | flags = env->bfd_mach; |
76db3ba4 | 11889 | flags |= ctx.le_mode << 16; |
93fcfe39 | 11890 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); |
f4359b9f | 11891 | log_target_disas(env, pc_start, ctx.nip - pc_start, flags); |
93fcfe39 | 11892 | qemu_log("\n"); |
9fddaa0c | 11893 | } |
79aceca5 | 11894 | #endif |
79aceca5 FB |
11895 | } |
11896 | ||
1328c2bf | 11897 | void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 11898 | { |
213fe1f5 | 11899 | gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false); |
79aceca5 FB |
11900 | } |
11901 | ||
1328c2bf | 11902 | void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 11903 | { |
213fe1f5 | 11904 | gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true); |
79aceca5 | 11905 | } |
d2856f1a | 11906 | |
1328c2bf | 11907 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos) |
d2856f1a | 11908 | { |
25983cad | 11909 | env->nip = tcg_ctx.gen_opc_pc[pc_pos]; |
d2856f1a | 11910 | } |