]>
Commit | Line | Data |
---|---|---|
79aceca5 | 1 | /* |
3fc6c082 | 2 | * PowerPC emulation for qemu: main translation routines. |
5fafdf24 | 3 | * |
76a66253 | 4 | * Copyright (c) 2003-2007 Jocelyn Mayer |
90dc8812 | 5 | * Copyright (C) 2011 Freescale Semiconductor, Inc. |
79aceca5 FB |
6 | * |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
8167ee88 | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
79aceca5 | 19 | */ |
c6a1c22b | 20 | |
79aceca5 | 21 | #include "cpu.h" |
76cad711 | 22 | #include "disas/disas.h" |
57fec1fe | 23 | #include "tcg-op.h" |
1de7afc9 | 24 | #include "qemu/host-utils.h" |
79aceca5 | 25 | |
a7812ae4 PB |
26 | #include "helper.h" |
27 | #define GEN_HELPER 1 | |
28 | #include "helper.h" | |
29 | ||
8cbcb4fa AJ |
30 | #define CPU_SINGLE_STEP 0x1 |
31 | #define CPU_BRANCH_STEP 0x2 | |
32 | #define GDBSTUB_SINGLE_STEP 0x4 | |
33 | ||
a750fc0b | 34 | /* Include definitions for instructions classes and implementations flags */ |
9fddaa0c | 35 | //#define PPC_DEBUG_DISAS |
76a66253 | 36 | //#define DO_PPC_STATISTICS |
79aceca5 | 37 | |
d12d51d5 | 38 | #ifdef PPC_DEBUG_DISAS |
93fcfe39 | 39 | # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) |
d12d51d5 AL |
40 | #else |
41 | # define LOG_DISAS(...) do { } while (0) | |
42 | #endif | |
a750fc0b JM |
43 | /*****************************************************************************/ |
44 | /* Code translation helpers */ | |
c53be334 | 45 | |
f78fb44e | 46 | /* global register indexes */ |
a7812ae4 | 47 | static TCGv_ptr cpu_env; |
1d542695 | 48 | static char cpu_reg_names[10*3 + 22*4 /* GPR */ |
f78fb44e | 49 | #if !defined(TARGET_PPC64) |
1d542695 | 50 | + 10*4 + 22*5 /* SPE GPRh */ |
f78fb44e | 51 | #endif |
a5e26afa | 52 | + 10*4 + 22*5 /* FPR */ |
47e4661c AJ |
53 | + 2*(10*6 + 22*7) /* AVRh, AVRl */ |
54 | + 8*5 /* CRF */]; | |
f78fb44e AJ |
55 | static TCGv cpu_gpr[32]; |
56 | #if !defined(TARGET_PPC64) | |
57 | static TCGv cpu_gprh[32]; | |
58 | #endif | |
a7812ae4 PB |
59 | static TCGv_i64 cpu_fpr[32]; |
60 | static TCGv_i64 cpu_avrh[32], cpu_avrl[32]; | |
61 | static TCGv_i32 cpu_crf[8]; | |
bd568f18 | 62 | static TCGv cpu_nip; |
6527f6ea | 63 | static TCGv cpu_msr; |
cfdcd37a AJ |
64 | static TCGv cpu_ctr; |
65 | static TCGv cpu_lr; | |
697ab892 DG |
66 | #if defined(TARGET_PPC64) |
67 | static TCGv cpu_cfar; | |
68 | #endif | |
3d7b417e | 69 | static TCGv cpu_xer; |
cf360a32 | 70 | static TCGv cpu_reserve; |
30304420 | 71 | static TCGv cpu_fpscr; |
a7859e89 | 72 | static TCGv_i32 cpu_access_type; |
f78fb44e | 73 | |
022c62cb | 74 | #include "exec/gen-icount.h" |
2e70f6ef PB |
75 | |
76 | void ppc_translate_init(void) | |
77 | { | |
f78fb44e AJ |
78 | int i; |
79 | char* p; | |
2dc766da | 80 | size_t cpu_reg_names_size; |
b2437bf2 | 81 | static int done_init = 0; |
f78fb44e | 82 | |
2e70f6ef PB |
83 | if (done_init) |
84 | return; | |
f78fb44e | 85 | |
a7812ae4 | 86 | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); |
a7812ae4 | 87 | |
f78fb44e | 88 | p = cpu_reg_names; |
2dc766da | 89 | cpu_reg_names_size = sizeof(cpu_reg_names); |
47e4661c AJ |
90 | |
91 | for (i = 0; i < 8; i++) { | |
2dc766da | 92 | snprintf(p, cpu_reg_names_size, "crf%d", i); |
a7812ae4 | 93 | cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 94 | offsetof(CPUPPCState, crf[i]), p); |
47e4661c | 95 | p += 5; |
2dc766da | 96 | cpu_reg_names_size -= 5; |
47e4661c AJ |
97 | } |
98 | ||
f78fb44e | 99 | for (i = 0; i < 32; i++) { |
2dc766da | 100 | snprintf(p, cpu_reg_names_size, "r%d", i); |
a7812ae4 | 101 | cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 102 | offsetof(CPUPPCState, gpr[i]), p); |
f78fb44e | 103 | p += (i < 10) ? 3 : 4; |
2dc766da | 104 | cpu_reg_names_size -= (i < 10) ? 3 : 4; |
f78fb44e | 105 | #if !defined(TARGET_PPC64) |
2dc766da | 106 | snprintf(p, cpu_reg_names_size, "r%dH", i); |
a7812ae4 | 107 | cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 108 | offsetof(CPUPPCState, gprh[i]), p); |
f78fb44e | 109 | p += (i < 10) ? 4 : 5; |
2dc766da | 110 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
f78fb44e | 111 | #endif |
1d542695 | 112 | |
2dc766da | 113 | snprintf(p, cpu_reg_names_size, "fp%d", i); |
a7812ae4 | 114 | cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 115 | offsetof(CPUPPCState, fpr[i]), p); |
ec1ac72d | 116 | p += (i < 10) ? 4 : 5; |
2dc766da | 117 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
a5e26afa | 118 | |
2dc766da | 119 | snprintf(p, cpu_reg_names_size, "avr%dH", i); |
e2542fe2 | 120 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 | 121 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 122 | offsetof(CPUPPCState, avr[i].u64[0]), p); |
fe1e5c53 | 123 | #else |
a7812ae4 | 124 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 125 | offsetof(CPUPPCState, avr[i].u64[1]), p); |
fe1e5c53 | 126 | #endif |
1d542695 | 127 | p += (i < 10) ? 6 : 7; |
2dc766da | 128 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
ec1ac72d | 129 | |
2dc766da | 130 | snprintf(p, cpu_reg_names_size, "avr%dL", i); |
e2542fe2 | 131 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 | 132 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 133 | offsetof(CPUPPCState, avr[i].u64[1]), p); |
fe1e5c53 | 134 | #else |
a7812ae4 | 135 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 136 | offsetof(CPUPPCState, avr[i].u64[0]), p); |
fe1e5c53 | 137 | #endif |
1d542695 | 138 | p += (i < 10) ? 6 : 7; |
2dc766da | 139 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
f78fb44e | 140 | } |
f10dc08e | 141 | |
a7812ae4 | 142 | cpu_nip = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 143 | offsetof(CPUPPCState, nip), "nip"); |
bd568f18 | 144 | |
6527f6ea | 145 | cpu_msr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 146 | offsetof(CPUPPCState, msr), "msr"); |
6527f6ea | 147 | |
a7812ae4 | 148 | cpu_ctr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 149 | offsetof(CPUPPCState, ctr), "ctr"); |
cfdcd37a | 150 | |
a7812ae4 | 151 | cpu_lr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 152 | offsetof(CPUPPCState, lr), "lr"); |
cfdcd37a | 153 | |
697ab892 DG |
154 | #if defined(TARGET_PPC64) |
155 | cpu_cfar = tcg_global_mem_new(TCG_AREG0, | |
1328c2bf | 156 | offsetof(CPUPPCState, cfar), "cfar"); |
697ab892 DG |
157 | #endif |
158 | ||
a7812ae4 | 159 | cpu_xer = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 160 | offsetof(CPUPPCState, xer), "xer"); |
3d7b417e | 161 | |
cf360a32 | 162 | cpu_reserve = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 163 | offsetof(CPUPPCState, reserve_addr), |
18b21a2f | 164 | "reserve_addr"); |
cf360a32 | 165 | |
30304420 DG |
166 | cpu_fpscr = tcg_global_mem_new(TCG_AREG0, |
167 | offsetof(CPUPPCState, fpscr), "fpscr"); | |
e1571908 | 168 | |
a7859e89 | 169 | cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 170 | offsetof(CPUPPCState, access_type), "access_type"); |
a7859e89 | 171 | |
f10dc08e | 172 | /* register helpers */ |
a7812ae4 | 173 | #define GEN_HELPER 2 |
f10dc08e AJ |
174 | #include "helper.h" |
175 | ||
2e70f6ef PB |
176 | done_init = 1; |
177 | } | |
178 | ||
79aceca5 FB |
179 | /* internal defines */ |
180 | typedef struct DisasContext { | |
181 | struct TranslationBlock *tb; | |
0fa85d43 | 182 | target_ulong nip; |
79aceca5 | 183 | uint32_t opcode; |
9a64fbe4 | 184 | uint32_t exception; |
3cc62370 FB |
185 | /* Routine used to access memory */ |
186 | int mem_idx; | |
76db3ba4 | 187 | int access_type; |
3cc62370 | 188 | /* Translation flags */ |
76db3ba4 | 189 | int le_mode; |
d9bce9d9 JM |
190 | #if defined(TARGET_PPC64) |
191 | int sf_mode; | |
697ab892 | 192 | int has_cfar; |
9a64fbe4 | 193 | #endif |
3cc62370 | 194 | int fpu_enabled; |
a9d9eb8f | 195 | int altivec_enabled; |
0487d6a8 | 196 | int spe_enabled; |
c227f099 | 197 | ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ |
ea4e754f | 198 | int singlestep_enabled; |
79aceca5 FB |
199 | } DisasContext; |
200 | ||
c227f099 | 201 | struct opc_handler_t { |
70560da7 FC |
202 | /* invalid bits for instruction 1 (Rc(opcode) == 0) */ |
203 | uint32_t inval1; | |
204 | /* invalid bits for instruction 2 (Rc(opcode) == 1) */ | |
205 | uint32_t inval2; | |
9a64fbe4 | 206 | /* instruction type */ |
0487d6a8 | 207 | uint64_t type; |
a5858d7a AG |
208 | /* extended instruction type */ |
209 | uint64_t type2; | |
79aceca5 FB |
210 | /* handler */ |
211 | void (*handler)(DisasContext *ctx); | |
a750fc0b | 212 | #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU) |
b55266b5 | 213 | const char *oname; |
a750fc0b JM |
214 | #endif |
215 | #if defined(DO_PPC_STATISTICS) | |
76a66253 JM |
216 | uint64_t count; |
217 | #endif | |
3fc6c082 | 218 | }; |
79aceca5 | 219 | |
636aa200 | 220 | static inline void gen_reset_fpstatus(void) |
7c58044c | 221 | { |
8e703949 | 222 | gen_helper_reset_fpstatus(cpu_env); |
7c58044c JM |
223 | } |
224 | ||
636aa200 | 225 | static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc) |
7c58044c | 226 | { |
0f2f39c2 | 227 | TCGv_i32 t0 = tcg_temp_new_i32(); |
af12906f | 228 | |
7c58044c JM |
229 | if (set_fprf != 0) { |
230 | /* This case might be optimized later */ | |
0f2f39c2 | 231 | tcg_gen_movi_i32(t0, 1); |
8e703949 | 232 | gen_helper_compute_fprf(t0, cpu_env, arg, t0); |
a7812ae4 | 233 | if (unlikely(set_rc)) { |
0f2f39c2 | 234 | tcg_gen_mov_i32(cpu_crf[1], t0); |
a7812ae4 | 235 | } |
8e703949 | 236 | gen_helper_float_check_status(cpu_env); |
7c58044c JM |
237 | } else if (unlikely(set_rc)) { |
238 | /* We always need to compute fpcc */ | |
0f2f39c2 | 239 | tcg_gen_movi_i32(t0, 0); |
8e703949 | 240 | gen_helper_compute_fprf(t0, cpu_env, arg, t0); |
0f2f39c2 | 241 | tcg_gen_mov_i32(cpu_crf[1], t0); |
7c58044c | 242 | } |
af12906f | 243 | |
0f2f39c2 | 244 | tcg_temp_free_i32(t0); |
7c58044c JM |
245 | } |
246 | ||
636aa200 | 247 | static inline void gen_set_access_type(DisasContext *ctx, int access_type) |
a7859e89 | 248 | { |
76db3ba4 AJ |
249 | if (ctx->access_type != access_type) { |
250 | tcg_gen_movi_i32(cpu_access_type, access_type); | |
251 | ctx->access_type = access_type; | |
252 | } | |
a7859e89 AJ |
253 | } |
254 | ||
636aa200 | 255 | static inline void gen_update_nip(DisasContext *ctx, target_ulong nip) |
d9bce9d9 JM |
256 | { |
257 | #if defined(TARGET_PPC64) | |
258 | if (ctx->sf_mode) | |
bd568f18 | 259 | tcg_gen_movi_tl(cpu_nip, nip); |
d9bce9d9 JM |
260 | else |
261 | #endif | |
bd568f18 | 262 | tcg_gen_movi_tl(cpu_nip, (uint32_t)nip); |
d9bce9d9 JM |
263 | } |
264 | ||
636aa200 | 265 | static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error) |
e06fcd75 AJ |
266 | { |
267 | TCGv_i32 t0, t1; | |
268 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
269 | gen_update_nip(ctx, ctx->nip); | |
270 | } | |
271 | t0 = tcg_const_i32(excp); | |
272 | t1 = tcg_const_i32(error); | |
e5f17ac6 | 273 | gen_helper_raise_exception_err(cpu_env, t0, t1); |
e06fcd75 AJ |
274 | tcg_temp_free_i32(t0); |
275 | tcg_temp_free_i32(t1); | |
276 | ctx->exception = (excp); | |
277 | } | |
e1833e1f | 278 | |
636aa200 | 279 | static inline void gen_exception(DisasContext *ctx, uint32_t excp) |
e06fcd75 AJ |
280 | { |
281 | TCGv_i32 t0; | |
282 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
283 | gen_update_nip(ctx, ctx->nip); | |
284 | } | |
285 | t0 = tcg_const_i32(excp); | |
e5f17ac6 | 286 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
287 | tcg_temp_free_i32(t0); |
288 | ctx->exception = (excp); | |
289 | } | |
e1833e1f | 290 | |
636aa200 | 291 | static inline void gen_debug_exception(DisasContext *ctx) |
e06fcd75 AJ |
292 | { |
293 | TCGv_i32 t0; | |
5518f3a6 | 294 | |
ee2b3994 SB |
295 | if ((ctx->exception != POWERPC_EXCP_BRANCH) && |
296 | (ctx->exception != POWERPC_EXCP_SYNC)) { | |
5518f3a6 | 297 | gen_update_nip(ctx, ctx->nip); |
ee2b3994 | 298 | } |
e06fcd75 | 299 | t0 = tcg_const_i32(EXCP_DEBUG); |
e5f17ac6 | 300 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
301 | tcg_temp_free_i32(t0); |
302 | } | |
9a64fbe4 | 303 | |
636aa200 | 304 | static inline void gen_inval_exception(DisasContext *ctx, uint32_t error) |
e06fcd75 AJ |
305 | { |
306 | gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error); | |
307 | } | |
a9d9eb8f | 308 | |
f24e5695 | 309 | /* Stop translation */ |
636aa200 | 310 | static inline void gen_stop_exception(DisasContext *ctx) |
3fc6c082 | 311 | { |
d9bce9d9 | 312 | gen_update_nip(ctx, ctx->nip); |
e1833e1f | 313 | ctx->exception = POWERPC_EXCP_STOP; |
3fc6c082 FB |
314 | } |
315 | ||
f24e5695 | 316 | /* No need to update nip here, as execution flow will change */ |
636aa200 | 317 | static inline void gen_sync_exception(DisasContext *ctx) |
2be0071f | 318 | { |
e1833e1f | 319 | ctx->exception = POWERPC_EXCP_SYNC; |
2be0071f FB |
320 | } |
321 | ||
79aceca5 | 322 | #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
323 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE) |
324 | ||
325 | #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \ | |
326 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2) | |
79aceca5 | 327 | |
c7697e1f | 328 | #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
329 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) |
330 | ||
331 | #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \ | |
332 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2) | |
c7697e1f | 333 | |
c227f099 | 334 | typedef struct opcode_t { |
79aceca5 | 335 | unsigned char opc1, opc2, opc3; |
1235fc06 | 336 | #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */ |
18fba28c FB |
337 | unsigned char pad[5]; |
338 | #else | |
339 | unsigned char pad[1]; | |
340 | #endif | |
c227f099 | 341 | opc_handler_t handler; |
b55266b5 | 342 | const char *oname; |
c227f099 | 343 | } opcode_t; |
79aceca5 | 344 | |
a750fc0b | 345 | /*****************************************************************************/ |
79aceca5 FB |
346 | /*** Instruction decoding ***/ |
347 | #define EXTRACT_HELPER(name, shift, nb) \ | |
636aa200 | 348 | static inline uint32_t name(uint32_t opcode) \ |
79aceca5 FB |
349 | { \ |
350 | return (opcode >> (shift)) & ((1 << (nb)) - 1); \ | |
351 | } | |
352 | ||
353 | #define EXTRACT_SHELPER(name, shift, nb) \ | |
636aa200 | 354 | static inline int32_t name(uint32_t opcode) \ |
79aceca5 | 355 | { \ |
18fba28c | 356 | return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \ |
79aceca5 FB |
357 | } |
358 | ||
359 | /* Opcode part 1 */ | |
360 | EXTRACT_HELPER(opc1, 26, 6); | |
361 | /* Opcode part 2 */ | |
362 | EXTRACT_HELPER(opc2, 1, 5); | |
363 | /* Opcode part 3 */ | |
364 | EXTRACT_HELPER(opc3, 6, 5); | |
365 | /* Update Cr0 flags */ | |
366 | EXTRACT_HELPER(Rc, 0, 1); | |
367 | /* Destination */ | |
368 | EXTRACT_HELPER(rD, 21, 5); | |
369 | /* Source */ | |
370 | EXTRACT_HELPER(rS, 21, 5); | |
371 | /* First operand */ | |
372 | EXTRACT_HELPER(rA, 16, 5); | |
373 | /* Second operand */ | |
374 | EXTRACT_HELPER(rB, 11, 5); | |
375 | /* Third operand */ | |
376 | EXTRACT_HELPER(rC, 6, 5); | |
377 | /*** Get CRn ***/ | |
378 | EXTRACT_HELPER(crfD, 23, 3); | |
379 | EXTRACT_HELPER(crfS, 18, 3); | |
380 | EXTRACT_HELPER(crbD, 21, 5); | |
381 | EXTRACT_HELPER(crbA, 16, 5); | |
382 | EXTRACT_HELPER(crbB, 11, 5); | |
383 | /* SPR / TBL */ | |
3fc6c082 | 384 | EXTRACT_HELPER(_SPR, 11, 10); |
636aa200 | 385 | static inline uint32_t SPR(uint32_t opcode) |
3fc6c082 FB |
386 | { |
387 | uint32_t sprn = _SPR(opcode); | |
388 | ||
389 | return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); | |
390 | } | |
79aceca5 FB |
391 | /*** Get constants ***/ |
392 | EXTRACT_HELPER(IMM, 12, 8); | |
393 | /* 16 bits signed immediate value */ | |
394 | EXTRACT_SHELPER(SIMM, 0, 16); | |
395 | /* 16 bits unsigned immediate value */ | |
396 | EXTRACT_HELPER(UIMM, 0, 16); | |
21d21583 AJ |
397 | /* 5 bits signed immediate value */ |
398 | EXTRACT_HELPER(SIMM5, 16, 5); | |
27a4edb3 AJ |
399 | /* 5 bits signed immediate value */ |
400 | EXTRACT_HELPER(UIMM5, 16, 5); | |
79aceca5 FB |
401 | /* Bit count */ |
402 | EXTRACT_HELPER(NB, 11, 5); | |
403 | /* Shift count */ | |
404 | EXTRACT_HELPER(SH, 11, 5); | |
cd633b10 AJ |
405 | /* Vector shift count */ |
406 | EXTRACT_HELPER(VSH, 6, 4); | |
79aceca5 FB |
407 | /* Mask start */ |
408 | EXTRACT_HELPER(MB, 6, 5); | |
409 | /* Mask end */ | |
410 | EXTRACT_HELPER(ME, 1, 5); | |
fb0eaffc FB |
411 | /* Trap operand */ |
412 | EXTRACT_HELPER(TO, 21, 5); | |
79aceca5 FB |
413 | |
414 | EXTRACT_HELPER(CRM, 12, 8); | |
415 | EXTRACT_HELPER(FM, 17, 8); | |
416 | EXTRACT_HELPER(SR, 16, 4); | |
e4bb997e | 417 | EXTRACT_HELPER(FPIMM, 12, 4); |
fb0eaffc | 418 | |
79aceca5 FB |
419 | /*** Jump target decoding ***/ |
420 | /* Displacement */ | |
421 | EXTRACT_SHELPER(d, 0, 16); | |
422 | /* Immediate address */ | |
636aa200 | 423 | static inline target_ulong LI(uint32_t opcode) |
79aceca5 FB |
424 | { |
425 | return (opcode >> 0) & 0x03FFFFFC; | |
426 | } | |
427 | ||
636aa200 | 428 | static inline uint32_t BD(uint32_t opcode) |
79aceca5 FB |
429 | { |
430 | return (opcode >> 0) & 0xFFFC; | |
431 | } | |
432 | ||
433 | EXTRACT_HELPER(BO, 21, 5); | |
434 | EXTRACT_HELPER(BI, 16, 5); | |
435 | /* Absolute/relative address */ | |
436 | EXTRACT_HELPER(AA, 1, 1); | |
437 | /* Link */ | |
438 | EXTRACT_HELPER(LK, 0, 1); | |
439 | ||
440 | /* Create a mask between <start> and <end> bits */ | |
636aa200 | 441 | static inline target_ulong MASK(uint32_t start, uint32_t end) |
79aceca5 | 442 | { |
76a66253 | 443 | target_ulong ret; |
79aceca5 | 444 | |
76a66253 JM |
445 | #if defined(TARGET_PPC64) |
446 | if (likely(start == 0)) { | |
6f2d8978 | 447 | ret = UINT64_MAX << (63 - end); |
76a66253 | 448 | } else if (likely(end == 63)) { |
6f2d8978 | 449 | ret = UINT64_MAX >> start; |
76a66253 JM |
450 | } |
451 | #else | |
452 | if (likely(start == 0)) { | |
6f2d8978 | 453 | ret = UINT32_MAX << (31 - end); |
76a66253 | 454 | } else if (likely(end == 31)) { |
6f2d8978 | 455 | ret = UINT32_MAX >> start; |
76a66253 JM |
456 | } |
457 | #endif | |
458 | else { | |
459 | ret = (((target_ulong)(-1ULL)) >> (start)) ^ | |
460 | (((target_ulong)(-1ULL) >> (end)) >> 1); | |
461 | if (unlikely(start > end)) | |
462 | return ~ret; | |
463 | } | |
79aceca5 FB |
464 | |
465 | return ret; | |
466 | } | |
467 | ||
a750fc0b | 468 | /*****************************************************************************/ |
a750fc0b | 469 | /* PowerPC instructions table */ |
933dc6eb | 470 | |
76a66253 | 471 | #if defined(DO_PPC_STATISTICS) |
a5858d7a | 472 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 473 | { \ |
79aceca5 FB |
474 | .opc1 = op1, \ |
475 | .opc2 = op2, \ | |
476 | .opc3 = op3, \ | |
18fba28c | 477 | .pad = { 0, }, \ |
79aceca5 | 478 | .handler = { \ |
70560da7 FC |
479 | .inval1 = invl, \ |
480 | .type = _typ, \ | |
481 | .type2 = _typ2, \ | |
482 | .handler = &gen_##name, \ | |
483 | .oname = stringify(name), \ | |
484 | }, \ | |
485 | .oname = stringify(name), \ | |
486 | } | |
487 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
488 | { \ | |
489 | .opc1 = op1, \ | |
490 | .opc2 = op2, \ | |
491 | .opc3 = op3, \ | |
492 | .pad = { 0, }, \ | |
493 | .handler = { \ | |
494 | .inval1 = invl1, \ | |
495 | .inval2 = invl2, \ | |
9a64fbe4 | 496 | .type = _typ, \ |
a5858d7a | 497 | .type2 = _typ2, \ |
79aceca5 | 498 | .handler = &gen_##name, \ |
76a66253 | 499 | .oname = stringify(name), \ |
79aceca5 | 500 | }, \ |
3fc6c082 | 501 | .oname = stringify(name), \ |
79aceca5 | 502 | } |
a5858d7a | 503 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 504 | { \ |
c7697e1f JM |
505 | .opc1 = op1, \ |
506 | .opc2 = op2, \ | |
507 | .opc3 = op3, \ | |
508 | .pad = { 0, }, \ | |
509 | .handler = { \ | |
70560da7 | 510 | .inval1 = invl, \ |
c7697e1f | 511 | .type = _typ, \ |
a5858d7a | 512 | .type2 = _typ2, \ |
c7697e1f JM |
513 | .handler = &gen_##name, \ |
514 | .oname = onam, \ | |
515 | }, \ | |
516 | .oname = onam, \ | |
517 | } | |
76a66253 | 518 | #else |
a5858d7a | 519 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 520 | { \ |
c7697e1f JM |
521 | .opc1 = op1, \ |
522 | .opc2 = op2, \ | |
523 | .opc3 = op3, \ | |
524 | .pad = { 0, }, \ | |
525 | .handler = { \ | |
70560da7 FC |
526 | .inval1 = invl, \ |
527 | .type = _typ, \ | |
528 | .type2 = _typ2, \ | |
529 | .handler = &gen_##name, \ | |
530 | }, \ | |
531 | .oname = stringify(name), \ | |
532 | } | |
533 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
534 | { \ | |
535 | .opc1 = op1, \ | |
536 | .opc2 = op2, \ | |
537 | .opc3 = op3, \ | |
538 | .pad = { 0, }, \ | |
539 | .handler = { \ | |
540 | .inval1 = invl1, \ | |
541 | .inval2 = invl2, \ | |
c7697e1f | 542 | .type = _typ, \ |
a5858d7a | 543 | .type2 = _typ2, \ |
c7697e1f | 544 | .handler = &gen_##name, \ |
5c55ff99 BS |
545 | }, \ |
546 | .oname = stringify(name), \ | |
547 | } | |
a5858d7a | 548 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 BS |
549 | { \ |
550 | .opc1 = op1, \ | |
551 | .opc2 = op2, \ | |
552 | .opc3 = op3, \ | |
553 | .pad = { 0, }, \ | |
554 | .handler = { \ | |
70560da7 | 555 | .inval1 = invl, \ |
5c55ff99 | 556 | .type = _typ, \ |
a5858d7a | 557 | .type2 = _typ2, \ |
5c55ff99 BS |
558 | .handler = &gen_##name, \ |
559 | }, \ | |
560 | .oname = onam, \ | |
561 | } | |
562 | #endif | |
2e610050 | 563 | |
5c55ff99 | 564 | /* SPR load/store helpers */ |
636aa200 | 565 | static inline void gen_load_spr(TCGv t, int reg) |
5c55ff99 | 566 | { |
1328c2bf | 567 | tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 568 | } |
2e610050 | 569 | |
636aa200 | 570 | static inline void gen_store_spr(int reg, TCGv t) |
5c55ff99 | 571 | { |
1328c2bf | 572 | tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 573 | } |
2e610050 | 574 | |
54623277 | 575 | /* Invalid instruction */ |
99e300ef | 576 | static void gen_invalid(DisasContext *ctx) |
9a64fbe4 | 577 | { |
e06fcd75 | 578 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
9a64fbe4 FB |
579 | } |
580 | ||
c227f099 | 581 | static opc_handler_t invalid_handler = { |
70560da7 FC |
582 | .inval1 = 0xFFFFFFFF, |
583 | .inval2 = 0xFFFFFFFF, | |
9a64fbe4 | 584 | .type = PPC_NONE, |
a5858d7a | 585 | .type2 = PPC_NONE, |
79aceca5 FB |
586 | .handler = gen_invalid, |
587 | }; | |
588 | ||
e1571908 AJ |
589 | /*** Integer comparison ***/ |
590 | ||
636aa200 | 591 | static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 AJ |
592 | { |
593 | int l1, l2, l3; | |
594 | ||
269f3e95 AJ |
595 | tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer); |
596 | tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO); | |
e1571908 AJ |
597 | tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1); |
598 | ||
599 | l1 = gen_new_label(); | |
600 | l2 = gen_new_label(); | |
601 | l3 = gen_new_label(); | |
602 | if (s) { | |
ea363694 AJ |
603 | tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1); |
604 | tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2); | |
e1571908 | 605 | } else { |
ea363694 AJ |
606 | tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1); |
607 | tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2); | |
e1571908 AJ |
608 | } |
609 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ); | |
610 | tcg_gen_br(l3); | |
611 | gen_set_label(l1); | |
612 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT); | |
613 | tcg_gen_br(l3); | |
614 | gen_set_label(l2); | |
615 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT); | |
616 | gen_set_label(l3); | |
617 | } | |
618 | ||
636aa200 | 619 | static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 620 | { |
ea363694 AJ |
621 | TCGv t0 = tcg_const_local_tl(arg1); |
622 | gen_op_cmp(arg0, t0, s, crf); | |
623 | tcg_temp_free(t0); | |
e1571908 AJ |
624 | } |
625 | ||
626 | #if defined(TARGET_PPC64) | |
636aa200 | 627 | static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 628 | { |
ea363694 | 629 | TCGv t0, t1; |
a7812ae4 PB |
630 | t0 = tcg_temp_local_new(); |
631 | t1 = tcg_temp_local_new(); | |
e1571908 | 632 | if (s) { |
ea363694 AJ |
633 | tcg_gen_ext32s_tl(t0, arg0); |
634 | tcg_gen_ext32s_tl(t1, arg1); | |
e1571908 | 635 | } else { |
ea363694 AJ |
636 | tcg_gen_ext32u_tl(t0, arg0); |
637 | tcg_gen_ext32u_tl(t1, arg1); | |
e1571908 | 638 | } |
ea363694 AJ |
639 | gen_op_cmp(t0, t1, s, crf); |
640 | tcg_temp_free(t1); | |
641 | tcg_temp_free(t0); | |
e1571908 AJ |
642 | } |
643 | ||
636aa200 | 644 | static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 645 | { |
ea363694 AJ |
646 | TCGv t0 = tcg_const_local_tl(arg1); |
647 | gen_op_cmp32(arg0, t0, s, crf); | |
648 | tcg_temp_free(t0); | |
e1571908 AJ |
649 | } |
650 | #endif | |
651 | ||
636aa200 | 652 | static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg) |
e1571908 AJ |
653 | { |
654 | #if defined(TARGET_PPC64) | |
655 | if (!(ctx->sf_mode)) | |
656 | gen_op_cmpi32(reg, 0, 1, 0); | |
657 | else | |
658 | #endif | |
659 | gen_op_cmpi(reg, 0, 1, 0); | |
660 | } | |
661 | ||
662 | /* cmp */ | |
99e300ef | 663 | static void gen_cmp(DisasContext *ctx) |
e1571908 AJ |
664 | { |
665 | #if defined(TARGET_PPC64) | |
666 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
667 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
668 | 1, crfD(ctx->opcode)); | |
669 | else | |
670 | #endif | |
671 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
672 | 1, crfD(ctx->opcode)); | |
673 | } | |
674 | ||
675 | /* cmpi */ | |
99e300ef | 676 | static void gen_cmpi(DisasContext *ctx) |
e1571908 AJ |
677 | { |
678 | #if defined(TARGET_PPC64) | |
679 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
680 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
681 | 1, crfD(ctx->opcode)); | |
682 | else | |
683 | #endif | |
684 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
685 | 1, crfD(ctx->opcode)); | |
686 | } | |
687 | ||
688 | /* cmpl */ | |
99e300ef | 689 | static void gen_cmpl(DisasContext *ctx) |
e1571908 AJ |
690 | { |
691 | #if defined(TARGET_PPC64) | |
692 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
693 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
694 | 0, crfD(ctx->opcode)); | |
695 | else | |
696 | #endif | |
697 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
698 | 0, crfD(ctx->opcode)); | |
699 | } | |
700 | ||
701 | /* cmpli */ | |
99e300ef | 702 | static void gen_cmpli(DisasContext *ctx) |
e1571908 AJ |
703 | { |
704 | #if defined(TARGET_PPC64) | |
705 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
706 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
707 | 0, crfD(ctx->opcode)); | |
708 | else | |
709 | #endif | |
710 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
711 | 0, crfD(ctx->opcode)); | |
712 | } | |
713 | ||
714 | /* isel (PowerPC 2.03 specification) */ | |
99e300ef | 715 | static void gen_isel(DisasContext *ctx) |
e1571908 AJ |
716 | { |
717 | int l1, l2; | |
718 | uint32_t bi = rC(ctx->opcode); | |
719 | uint32_t mask; | |
a7812ae4 | 720 | TCGv_i32 t0; |
e1571908 AJ |
721 | |
722 | l1 = gen_new_label(); | |
723 | l2 = gen_new_label(); | |
724 | ||
725 | mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 726 | t0 = tcg_temp_new_i32(); |
fea0c503 AJ |
727 | tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask); |
728 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
e1571908 AJ |
729 | if (rA(ctx->opcode) == 0) |
730 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
731 | else | |
732 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
733 | tcg_gen_br(l2); | |
734 | gen_set_label(l1); | |
735 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
736 | gen_set_label(l2); | |
a7812ae4 | 737 | tcg_temp_free_i32(t0); |
e1571908 AJ |
738 | } |
739 | ||
79aceca5 | 740 | /*** Integer arithmetic ***/ |
79aceca5 | 741 | |
636aa200 BS |
742 | static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, |
743 | TCGv arg1, TCGv arg2, int sub) | |
74637406 AJ |
744 | { |
745 | int l1; | |
746 | TCGv t0; | |
79aceca5 | 747 | |
74637406 AJ |
748 | l1 = gen_new_label(); |
749 | /* Start with XER OV disabled, the most likely case */ | |
750 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
a7812ae4 | 751 | t0 = tcg_temp_local_new(); |
74637406 AJ |
752 | tcg_gen_xor_tl(t0, arg0, arg1); |
753 | #if defined(TARGET_PPC64) | |
754 | if (!ctx->sf_mode) | |
755 | tcg_gen_ext32s_tl(t0, t0); | |
756 | #endif | |
757 | if (sub) | |
758 | tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1); | |
759 | else | |
760 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
761 | tcg_gen_xor_tl(t0, arg1, arg2); | |
762 | #if defined(TARGET_PPC64) | |
763 | if (!ctx->sf_mode) | |
764 | tcg_gen_ext32s_tl(t0, t0); | |
765 | #endif | |
766 | if (sub) | |
767 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
768 | else | |
769 | tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1); | |
770 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
771 | gen_set_label(l1); | |
772 | tcg_temp_free(t0); | |
79aceca5 FB |
773 | } |
774 | ||
636aa200 BS |
775 | static inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1, |
776 | TCGv arg2, int sub) | |
74637406 AJ |
777 | { |
778 | int l1 = gen_new_label(); | |
d9bce9d9 JM |
779 | |
780 | #if defined(TARGET_PPC64) | |
74637406 AJ |
781 | if (!(ctx->sf_mode)) { |
782 | TCGv t0, t1; | |
a7812ae4 PB |
783 | t0 = tcg_temp_new(); |
784 | t1 = tcg_temp_new(); | |
d9bce9d9 | 785 | |
74637406 AJ |
786 | tcg_gen_ext32u_tl(t0, arg1); |
787 | tcg_gen_ext32u_tl(t1, arg2); | |
788 | if (sub) { | |
789 | tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1); | |
bdc4e053 | 790 | } else { |
74637406 AJ |
791 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); |
792 | } | |
a9730017 AJ |
793 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
794 | gen_set_label(l1); | |
795 | tcg_temp_free(t0); | |
796 | tcg_temp_free(t1); | |
74637406 AJ |
797 | } else |
798 | #endif | |
a9730017 AJ |
799 | { |
800 | if (sub) { | |
801 | tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1); | |
802 | } else { | |
803 | tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1); | |
804 | } | |
805 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); | |
806 | gen_set_label(l1); | |
74637406 | 807 | } |
d9bce9d9 JM |
808 | } |
809 | ||
74637406 | 810 | /* Common add function */ |
636aa200 BS |
811 | static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
812 | TCGv arg2, int add_ca, int compute_ca, | |
813 | int compute_ov) | |
74637406 AJ |
814 | { |
815 | TCGv t0, t1; | |
d9bce9d9 | 816 | |
74637406 | 817 | if ((!compute_ca && !compute_ov) || |
a7812ae4 | 818 | (!TCGV_EQUAL(ret,arg1) && !TCGV_EQUAL(ret, arg2))) { |
74637406 AJ |
819 | t0 = ret; |
820 | } else { | |
a7812ae4 | 821 | t0 = tcg_temp_local_new(); |
74637406 | 822 | } |
79aceca5 | 823 | |
74637406 | 824 | if (add_ca) { |
a7812ae4 | 825 | t1 = tcg_temp_local_new(); |
74637406 AJ |
826 | tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA)); |
827 | tcg_gen_shri_tl(t1, t1, XER_CA); | |
d2e9fd8f | 828 | } else { |
829 | TCGV_UNUSED(t1); | |
74637406 | 830 | } |
79aceca5 | 831 | |
74637406 AJ |
832 | if (compute_ca && compute_ov) { |
833 | /* Start with XER CA and OV disabled, the most likely case */ | |
834 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV))); | |
835 | } else if (compute_ca) { | |
836 | /* Start with XER CA disabled, the most likely case */ | |
837 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
838 | } else if (compute_ov) { | |
839 | /* Start with XER OV disabled, the most likely case */ | |
840 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
841 | } | |
79aceca5 | 842 | |
74637406 AJ |
843 | tcg_gen_add_tl(t0, arg1, arg2); |
844 | ||
845 | if (compute_ca) { | |
846 | gen_op_arith_compute_ca(ctx, t0, arg1, 0); | |
847 | } | |
848 | if (add_ca) { | |
849 | tcg_gen_add_tl(t0, t0, t1); | |
850 | gen_op_arith_compute_ca(ctx, t0, t1, 0); | |
851 | tcg_temp_free(t1); | |
852 | } | |
853 | if (compute_ov) { | |
854 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0); | |
855 | } | |
856 | ||
857 | if (unlikely(Rc(ctx->opcode) != 0)) | |
858 | gen_set_Rc0(ctx, t0); | |
859 | ||
a7812ae4 | 860 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
861 | tcg_gen_mov_tl(ret, t0); |
862 | tcg_temp_free(t0); | |
863 | } | |
39dd32ee | 864 | } |
74637406 AJ |
865 | /* Add functions with two operands */ |
866 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
99e300ef | 867 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
868 | { \ |
869 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
870 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
871 | add_ca, compute_ca, compute_ov); \ | |
872 | } | |
873 | /* Add functions with one operand and one immediate */ | |
874 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
875 | add_ca, compute_ca, compute_ov) \ | |
99e300ef | 876 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
877 | { \ |
878 | TCGv t0 = tcg_const_local_tl(const_val); \ | |
879 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
880 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
881 | add_ca, compute_ca, compute_ov); \ | |
882 | tcg_temp_free(t0); \ | |
883 | } | |
884 | ||
885 | /* add add. addo addo. */ | |
886 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
887 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
888 | /* addc addc. addco addco. */ | |
889 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
890 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
891 | /* adde adde. addeo addeo. */ | |
892 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
893 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
894 | /* addme addme. addmeo addmeo. */ | |
895 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
896 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
897 | /* addze addze. addzeo addzeo.*/ | |
898 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
899 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
900 | /* addi */ | |
99e300ef | 901 | static void gen_addi(DisasContext *ctx) |
d9bce9d9 | 902 | { |
74637406 AJ |
903 | target_long simm = SIMM(ctx->opcode); |
904 | ||
905 | if (rA(ctx->opcode) == 0) { | |
906 | /* li case */ | |
907 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm); | |
908 | } else { | |
909 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm); | |
910 | } | |
d9bce9d9 | 911 | } |
74637406 | 912 | /* addic addic.*/ |
636aa200 BS |
913 | static inline void gen_op_addic(DisasContext *ctx, TCGv ret, TCGv arg1, |
914 | int compute_Rc0) | |
d9bce9d9 | 915 | { |
74637406 AJ |
916 | target_long simm = SIMM(ctx->opcode); |
917 | ||
918 | /* Start with XER CA and OV disabled, the most likely case */ | |
919 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
920 | ||
921 | if (likely(simm != 0)) { | |
a7812ae4 | 922 | TCGv t0 = tcg_temp_local_new(); |
74637406 AJ |
923 | tcg_gen_addi_tl(t0, arg1, simm); |
924 | gen_op_arith_compute_ca(ctx, t0, arg1, 0); | |
925 | tcg_gen_mov_tl(ret, t0); | |
926 | tcg_temp_free(t0); | |
927 | } else { | |
928 | tcg_gen_mov_tl(ret, arg1); | |
929 | } | |
930 | if (compute_Rc0) { | |
931 | gen_set_Rc0(ctx, ret); | |
932 | } | |
d9bce9d9 | 933 | } |
99e300ef BS |
934 | |
935 | static void gen_addic(DisasContext *ctx) | |
d9bce9d9 | 936 | { |
74637406 | 937 | gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0); |
d9bce9d9 | 938 | } |
e8eaa2c0 BS |
939 | |
940 | static void gen_addic_(DisasContext *ctx) | |
d9bce9d9 | 941 | { |
74637406 | 942 | gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1); |
d9bce9d9 | 943 | } |
99e300ef | 944 | |
54623277 | 945 | /* addis */ |
99e300ef | 946 | static void gen_addis(DisasContext *ctx) |
d9bce9d9 | 947 | { |
74637406 AJ |
948 | target_long simm = SIMM(ctx->opcode); |
949 | ||
950 | if (rA(ctx->opcode) == 0) { | |
951 | /* lis case */ | |
952 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16); | |
953 | } else { | |
954 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16); | |
955 | } | |
d9bce9d9 | 956 | } |
74637406 | 957 | |
636aa200 BS |
958 | static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1, |
959 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 960 | { |
2ef1b120 AJ |
961 | int l1 = gen_new_label(); |
962 | int l2 = gen_new_label(); | |
a7812ae4 PB |
963 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
964 | TCGv_i32 t1 = tcg_temp_local_new_i32(); | |
74637406 | 965 | |
2ef1b120 AJ |
966 | tcg_gen_trunc_tl_i32(t0, arg1); |
967 | tcg_gen_trunc_tl_i32(t1, arg2); | |
968 | tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1); | |
74637406 | 969 | if (sign) { |
2ef1b120 AJ |
970 | int l3 = gen_new_label(); |
971 | tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3); | |
972 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1); | |
74637406 | 973 | gen_set_label(l3); |
2ef1b120 | 974 | tcg_gen_div_i32(t0, t0, t1); |
74637406 | 975 | } else { |
2ef1b120 | 976 | tcg_gen_divu_i32(t0, t0, t1); |
74637406 AJ |
977 | } |
978 | if (compute_ov) { | |
979 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
980 | } | |
981 | tcg_gen_br(l2); | |
982 | gen_set_label(l1); | |
983 | if (sign) { | |
2ef1b120 | 984 | tcg_gen_sari_i32(t0, t0, 31); |
74637406 AJ |
985 | } else { |
986 | tcg_gen_movi_i32(t0, 0); | |
987 | } | |
988 | if (compute_ov) { | |
989 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
990 | } | |
991 | gen_set_label(l2); | |
2ef1b120 | 992 | tcg_gen_extu_i32_tl(ret, t0); |
a7812ae4 PB |
993 | tcg_temp_free_i32(t0); |
994 | tcg_temp_free_i32(t1); | |
74637406 AJ |
995 | if (unlikely(Rc(ctx->opcode) != 0)) |
996 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 997 | } |
74637406 AJ |
998 | /* Div functions */ |
999 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
99e300ef | 1000 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1001 | { \ |
1002 | gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1003 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1004 | sign, compute_ov); \ | |
1005 | } | |
1006 | /* divwu divwu. divwuo divwuo. */ | |
1007 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0); | |
1008 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1); | |
1009 | /* divw divw. divwo divwo. */ | |
1010 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0); | |
1011 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1); | |
d9bce9d9 | 1012 | #if defined(TARGET_PPC64) |
636aa200 BS |
1013 | static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1, |
1014 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 1015 | { |
2ef1b120 AJ |
1016 | int l1 = gen_new_label(); |
1017 | int l2 = gen_new_label(); | |
74637406 AJ |
1018 | |
1019 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1); | |
1020 | if (sign) { | |
2ef1b120 | 1021 | int l3 = gen_new_label(); |
74637406 AJ |
1022 | tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3); |
1023 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1); | |
1024 | gen_set_label(l3); | |
74637406 AJ |
1025 | tcg_gen_div_i64(ret, arg1, arg2); |
1026 | } else { | |
1027 | tcg_gen_divu_i64(ret, arg1, arg2); | |
1028 | } | |
1029 | if (compute_ov) { | |
1030 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1031 | } | |
1032 | tcg_gen_br(l2); | |
1033 | gen_set_label(l1); | |
1034 | if (sign) { | |
1035 | tcg_gen_sari_i64(ret, arg1, 63); | |
1036 | } else { | |
1037 | tcg_gen_movi_i64(ret, 0); | |
1038 | } | |
1039 | if (compute_ov) { | |
1040 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1041 | } | |
1042 | gen_set_label(l2); | |
1043 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1044 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1045 | } |
74637406 | 1046 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ |
99e300ef | 1047 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1048 | { \ |
2ef1b120 AJ |
1049 | gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1050 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1051 | sign, compute_ov); \ | |
74637406 AJ |
1052 | } |
1053 | /* divwu divwu. divwuo divwuo. */ | |
1054 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0); | |
1055 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1); | |
1056 | /* divw divw. divwo divwo. */ | |
1057 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0); | |
1058 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1); | |
d9bce9d9 | 1059 | #endif |
74637406 AJ |
1060 | |
1061 | /* mulhw mulhw. */ | |
99e300ef | 1062 | static void gen_mulhw(DisasContext *ctx) |
d9bce9d9 | 1063 | { |
23ad1d5d RH |
1064 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1065 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1066 | |
23ad1d5d RH |
1067 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1068 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1069 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1070 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1071 | tcg_temp_free_i32(t0); | |
1072 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1073 | if (unlikely(Rc(ctx->opcode) != 0)) |
1074 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1075 | } |
99e300ef | 1076 | |
54623277 | 1077 | /* mulhwu mulhwu. */ |
99e300ef | 1078 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1079 | { |
23ad1d5d RH |
1080 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1081 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1082 | |
23ad1d5d RH |
1083 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1084 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1085 | tcg_gen_mulu2_i32(t0, t1, t0, t1); | |
1086 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1087 | tcg_temp_free_i32(t0); | |
1088 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1089 | if (unlikely(Rc(ctx->opcode) != 0)) |
1090 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1091 | } |
99e300ef | 1092 | |
54623277 | 1093 | /* mullw mullw. */ |
99e300ef | 1094 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1095 | { |
74637406 AJ |
1096 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1097 | cpu_gpr[rB(ctx->opcode)]); | |
1e4c090f | 1098 | tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]); |
74637406 AJ |
1099 | if (unlikely(Rc(ctx->opcode) != 0)) |
1100 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1101 | } |
99e300ef | 1102 | |
54623277 | 1103 | /* mullwo mullwo. */ |
99e300ef | 1104 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1105 | { |
74637406 | 1106 | int l1; |
a7812ae4 | 1107 | TCGv_i64 t0, t1; |
74637406 | 1108 | |
a7812ae4 PB |
1109 | t0 = tcg_temp_new_i64(); |
1110 | t1 = tcg_temp_new_i64(); | |
74637406 AJ |
1111 | l1 = gen_new_label(); |
1112 | /* Start with XER OV disabled, the most likely case */ | |
1113 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1114 | #if defined(TARGET_PPC64) | |
1115 | tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1116 | tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1117 | #else | |
1118 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1119 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
d9bce9d9 | 1120 | #endif |
74637406 AJ |
1121 | tcg_gen_mul_i64(t0, t0, t1); |
1122 | #if defined(TARGET_PPC64) | |
1123 | tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0); | |
1124 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1); | |
1125 | #else | |
1126 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1127 | tcg_gen_ext32s_i64(t1, t0); | |
1128 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
1129 | #endif | |
1130 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1131 | gen_set_label(l1); | |
a7812ae4 PB |
1132 | tcg_temp_free_i64(t0); |
1133 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1134 | if (unlikely(Rc(ctx->opcode) != 0)) |
1135 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1136 | } |
99e300ef | 1137 | |
54623277 | 1138 | /* mulli */ |
99e300ef | 1139 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1140 | { |
74637406 AJ |
1141 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1142 | SIMM(ctx->opcode)); | |
d9bce9d9 | 1143 | } |
23ad1d5d | 1144 | |
d9bce9d9 | 1145 | #if defined(TARGET_PPC64) |
74637406 | 1146 | /* mulhd mulhd. */ |
23ad1d5d RH |
1147 | static void gen_mulhd(DisasContext *ctx) |
1148 | { | |
1149 | TCGv lo = tcg_temp_new(); | |
1150 | tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1151 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1152 | tcg_temp_free(lo); | |
1153 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1154 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1155 | } | |
1156 | } | |
1157 | ||
74637406 | 1158 | /* mulhdu mulhdu. */ |
23ad1d5d RH |
1159 | static void gen_mulhdu(DisasContext *ctx) |
1160 | { | |
1161 | TCGv lo = tcg_temp_new(); | |
1162 | tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1163 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1164 | tcg_temp_free(lo); | |
1165 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1166 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1167 | } | |
1168 | } | |
99e300ef | 1169 | |
54623277 | 1170 | /* mulld mulld. */ |
99e300ef | 1171 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1172 | { |
74637406 AJ |
1173 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1174 | cpu_gpr[rB(ctx->opcode)]); | |
1175 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1176 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1177 | } |
d15f74fb | 1178 | |
74637406 | 1179 | /* mulldo mulldo. */ |
d15f74fb BS |
1180 | static void gen_mulldo(DisasContext *ctx) |
1181 | { | |
1182 | gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env, | |
1183 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1184 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1185 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1186 | } | |
1187 | } | |
d9bce9d9 | 1188 | #endif |
74637406 AJ |
1189 | |
1190 | /* neg neg. nego nego. */ | |
636aa200 BS |
1191 | static inline void gen_op_arith_neg(DisasContext *ctx, TCGv ret, TCGv arg1, |
1192 | int ov_check) | |
d9bce9d9 | 1193 | { |
ec6469a3 AJ |
1194 | int l1 = gen_new_label(); |
1195 | int l2 = gen_new_label(); | |
a7812ae4 | 1196 | TCGv t0 = tcg_temp_local_new(); |
d9bce9d9 | 1197 | #if defined(TARGET_PPC64) |
74637406 | 1198 | if (ctx->sf_mode) { |
741a7444 | 1199 | tcg_gen_mov_tl(t0, arg1); |
ec6469a3 AJ |
1200 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1); |
1201 | } else | |
1202 | #endif | |
1203 | { | |
1204 | tcg_gen_ext32s_tl(t0, arg1); | |
74637406 AJ |
1205 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1); |
1206 | } | |
74637406 AJ |
1207 | tcg_gen_neg_tl(ret, arg1); |
1208 | if (ov_check) { | |
1209 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1210 | } | |
1211 | tcg_gen_br(l2); | |
1212 | gen_set_label(l1); | |
ec6469a3 | 1213 | tcg_gen_mov_tl(ret, t0); |
74637406 AJ |
1214 | if (ov_check) { |
1215 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1216 | } | |
1217 | gen_set_label(l2); | |
ec6469a3 | 1218 | tcg_temp_free(t0); |
74637406 AJ |
1219 | if (unlikely(Rc(ctx->opcode) != 0)) |
1220 | gen_set_Rc0(ctx, ret); | |
1221 | } | |
99e300ef BS |
1222 | |
1223 | static void gen_neg(DisasContext *ctx) | |
d9bce9d9 | 1224 | { |
ec6469a3 | 1225 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0); |
d9bce9d9 | 1226 | } |
99e300ef BS |
1227 | |
1228 | static void gen_nego(DisasContext *ctx) | |
79aceca5 | 1229 | { |
ec6469a3 | 1230 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1); |
79aceca5 | 1231 | } |
74637406 AJ |
1232 | |
1233 | /* Common subf function */ | |
636aa200 BS |
1234 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
1235 | TCGv arg2, int add_ca, int compute_ca, | |
1236 | int compute_ov) | |
79aceca5 | 1237 | { |
74637406 | 1238 | TCGv t0, t1; |
76a66253 | 1239 | |
74637406 | 1240 | if ((!compute_ca && !compute_ov) || |
a7812ae4 | 1241 | (!TCGV_EQUAL(ret, arg1) && !TCGV_EQUAL(ret, arg2))) { |
74637406 | 1242 | t0 = ret; |
e864cabd | 1243 | } else { |
a7812ae4 | 1244 | t0 = tcg_temp_local_new(); |
d9bce9d9 | 1245 | } |
76a66253 | 1246 | |
74637406 | 1247 | if (add_ca) { |
a7812ae4 | 1248 | t1 = tcg_temp_local_new(); |
74637406 AJ |
1249 | tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA)); |
1250 | tcg_gen_shri_tl(t1, t1, XER_CA); | |
d2e9fd8f | 1251 | } else { |
1252 | TCGV_UNUSED(t1); | |
d9bce9d9 | 1253 | } |
79aceca5 | 1254 | |
74637406 AJ |
1255 | if (compute_ca && compute_ov) { |
1256 | /* Start with XER CA and OV disabled, the most likely case */ | |
1257 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV))); | |
1258 | } else if (compute_ca) { | |
1259 | /* Start with XER CA disabled, the most likely case */ | |
1260 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
1261 | } else if (compute_ov) { | |
1262 | /* Start with XER OV disabled, the most likely case */ | |
1263 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1264 | } | |
1265 | ||
1266 | if (add_ca) { | |
1267 | tcg_gen_not_tl(t0, arg1); | |
1268 | tcg_gen_add_tl(t0, t0, arg2); | |
1269 | gen_op_arith_compute_ca(ctx, t0, arg2, 0); | |
1270 | tcg_gen_add_tl(t0, t0, t1); | |
1271 | gen_op_arith_compute_ca(ctx, t0, t1, 0); | |
1272 | tcg_temp_free(t1); | |
79aceca5 | 1273 | } else { |
74637406 AJ |
1274 | tcg_gen_sub_tl(t0, arg2, arg1); |
1275 | if (compute_ca) { | |
1276 | gen_op_arith_compute_ca(ctx, t0, arg2, 1); | |
1277 | } | |
1278 | } | |
1279 | if (compute_ov) { | |
1280 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1281 | } | |
1282 | ||
1283 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1284 | gen_set_Rc0(ctx, t0); | |
1285 | ||
a7812ae4 | 1286 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
1287 | tcg_gen_mov_tl(ret, t0); |
1288 | tcg_temp_free(t0); | |
79aceca5 | 1289 | } |
79aceca5 | 1290 | } |
74637406 AJ |
1291 | /* Sub functions with Two operands functions */ |
1292 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1293 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1294 | { \ |
1295 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1296 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1297 | add_ca, compute_ca, compute_ov); \ | |
1298 | } | |
1299 | /* Sub functions with one operand and one immediate */ | |
1300 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1301 | add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1302 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1303 | { \ |
1304 | TCGv t0 = tcg_const_local_tl(const_val); \ | |
1305 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1306 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
1307 | add_ca, compute_ca, compute_ov); \ | |
1308 | tcg_temp_free(t0); \ | |
1309 | } | |
1310 | /* subf subf. subfo subfo. */ | |
1311 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1312 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1313 | /* subfc subfc. subfco subfco. */ | |
1314 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1315 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1316 | /* subfe subfe. subfeo subfo. */ | |
1317 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1318 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1319 | /* subfme subfme. subfmeo subfmeo. */ | |
1320 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1321 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1322 | /* subfze subfze. subfzeo subfzeo.*/ | |
1323 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1324 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1325 | |
54623277 | 1326 | /* subfic */ |
99e300ef | 1327 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1328 | { |
74637406 AJ |
1329 | /* Start with XER CA and OV disabled, the most likely case */ |
1330 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
a7812ae4 | 1331 | TCGv t0 = tcg_temp_local_new(); |
74637406 AJ |
1332 | TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode)); |
1333 | tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]); | |
1334 | gen_op_arith_compute_ca(ctx, t0, t1, 1); | |
1335 | tcg_temp_free(t1); | |
1336 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1337 | tcg_temp_free(t0); | |
79aceca5 FB |
1338 | } |
1339 | ||
79aceca5 | 1340 | /*** Integer logical ***/ |
26d67362 | 1341 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1342 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1343 | { \ |
26d67362 AJ |
1344 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1345 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1346 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1347 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1348 | } |
79aceca5 | 1349 | |
26d67362 | 1350 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1351 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1352 | { \ |
26d67362 | 1353 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1354 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1355 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1356 | } |
1357 | ||
1358 | /* and & and. */ | |
26d67362 | 1359 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1360 | /* andc & andc. */ |
26d67362 | 1361 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1362 | |
54623277 | 1363 | /* andi. */ |
e8eaa2c0 | 1364 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1365 | { |
26d67362 AJ |
1366 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1367 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1368 | } |
e8eaa2c0 | 1369 | |
54623277 | 1370 | /* andis. */ |
e8eaa2c0 | 1371 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1372 | { |
26d67362 AJ |
1373 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1374 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1375 | } |
99e300ef | 1376 | |
54623277 | 1377 | /* cntlzw */ |
99e300ef | 1378 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1379 | { |
a7812ae4 | 1380 | gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 | 1381 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1382 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1383 | } |
79aceca5 | 1384 | /* eqv & eqv. */ |
26d67362 | 1385 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1386 | /* extsb & extsb. */ |
26d67362 | 1387 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1388 | /* extsh & extsh. */ |
26d67362 | 1389 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1390 | /* nand & nand. */ |
26d67362 | 1391 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1392 | /* nor & nor. */ |
26d67362 | 1393 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1394 | |
54623277 | 1395 | /* or & or. */ |
99e300ef | 1396 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1397 | { |
76a66253 JM |
1398 | int rs, ra, rb; |
1399 | ||
1400 | rs = rS(ctx->opcode); | |
1401 | ra = rA(ctx->opcode); | |
1402 | rb = rB(ctx->opcode); | |
1403 | /* Optimisation for mr. ri case */ | |
1404 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1405 | if (rs != rb) |
1406 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1407 | else | |
1408 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1409 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1410 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1411 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1412 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 JM |
1413 | #if defined(TARGET_PPC64) |
1414 | } else { | |
26d67362 AJ |
1415 | int prio = 0; |
1416 | ||
c80f84e3 JM |
1417 | switch (rs) { |
1418 | case 1: | |
1419 | /* Set process priority to low */ | |
26d67362 | 1420 | prio = 2; |
c80f84e3 JM |
1421 | break; |
1422 | case 6: | |
1423 | /* Set process priority to medium-low */ | |
26d67362 | 1424 | prio = 3; |
c80f84e3 JM |
1425 | break; |
1426 | case 2: | |
1427 | /* Set process priority to normal */ | |
26d67362 | 1428 | prio = 4; |
c80f84e3 | 1429 | break; |
be147d08 JM |
1430 | #if !defined(CONFIG_USER_ONLY) |
1431 | case 31: | |
76db3ba4 | 1432 | if (ctx->mem_idx > 0) { |
be147d08 | 1433 | /* Set process priority to very low */ |
26d67362 | 1434 | prio = 1; |
be147d08 JM |
1435 | } |
1436 | break; | |
1437 | case 5: | |
76db3ba4 | 1438 | if (ctx->mem_idx > 0) { |
be147d08 | 1439 | /* Set process priority to medium-hight */ |
26d67362 | 1440 | prio = 5; |
be147d08 JM |
1441 | } |
1442 | break; | |
1443 | case 3: | |
76db3ba4 | 1444 | if (ctx->mem_idx > 0) { |
be147d08 | 1445 | /* Set process priority to high */ |
26d67362 | 1446 | prio = 6; |
be147d08 JM |
1447 | } |
1448 | break; | |
be147d08 | 1449 | case 7: |
76db3ba4 | 1450 | if (ctx->mem_idx > 1) { |
be147d08 | 1451 | /* Set process priority to very high */ |
26d67362 | 1452 | prio = 7; |
be147d08 JM |
1453 | } |
1454 | break; | |
be147d08 | 1455 | #endif |
c80f84e3 JM |
1456 | default: |
1457 | /* nop */ | |
1458 | break; | |
1459 | } | |
26d67362 | 1460 | if (prio) { |
a7812ae4 | 1461 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1462 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1463 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1464 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1465 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1466 | tcg_temp_free(t0); |
26d67362 | 1467 | } |
c80f84e3 | 1468 | #endif |
9a64fbe4 | 1469 | } |
9a64fbe4 | 1470 | } |
79aceca5 | 1471 | /* orc & orc. */ |
26d67362 | 1472 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1473 | |
54623277 | 1474 | /* xor & xor. */ |
99e300ef | 1475 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1476 | { |
9a64fbe4 | 1477 | /* Optimisation for "set to zero" case */ |
26d67362 | 1478 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1479 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1480 | else |
1481 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1482 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1483 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1484 | } |
99e300ef | 1485 | |
54623277 | 1486 | /* ori */ |
99e300ef | 1487 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1488 | { |
76a66253 | 1489 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1490 | |
9a64fbe4 FB |
1491 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1492 | /* NOP */ | |
76a66253 | 1493 | /* XXX: should handle special NOPs for POWER series */ |
9a64fbe4 | 1494 | return; |
76a66253 | 1495 | } |
26d67362 | 1496 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1497 | } |
99e300ef | 1498 | |
54623277 | 1499 | /* oris */ |
99e300ef | 1500 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1501 | { |
76a66253 | 1502 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1503 | |
9a64fbe4 FB |
1504 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1505 | /* NOP */ | |
1506 | return; | |
76a66253 | 1507 | } |
26d67362 | 1508 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1509 | } |
99e300ef | 1510 | |
54623277 | 1511 | /* xori */ |
99e300ef | 1512 | static void gen_xori(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); |
79aceca5 | 1521 | } |
99e300ef | 1522 | |
54623277 | 1523 | /* xoris */ |
99e300ef | 1524 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1525 | { |
76a66253 | 1526 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1527 | |
1528 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1529 | /* NOP */ | |
1530 | return; | |
1531 | } | |
26d67362 | 1532 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1533 | } |
99e300ef | 1534 | |
54623277 | 1535 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1536 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1537 | { |
eaabeef2 DG |
1538 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1539 | } | |
1540 | ||
1541 | static void gen_popcntw(DisasContext *ctx) | |
1542 | { | |
1543 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1544 | } | |
1545 | ||
d9bce9d9 | 1546 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1547 | /* popcntd: PowerPC 2.06 specification */ |
1548 | static void gen_popcntd(DisasContext *ctx) | |
1549 | { | |
1550 | gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 1551 | } |
eaabeef2 | 1552 | #endif |
d9bce9d9 JM |
1553 | |
1554 | #if defined(TARGET_PPC64) | |
1555 | /* extsw & extsw. */ | |
26d67362 | 1556 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1557 | |
54623277 | 1558 | /* cntlzd */ |
99e300ef | 1559 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1560 | { |
a7812ae4 | 1561 | gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 AJ |
1562 | if (unlikely(Rc(ctx->opcode) != 0)) |
1563 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1564 | } | |
d9bce9d9 JM |
1565 | #endif |
1566 | ||
79aceca5 | 1567 | /*** Integer rotate ***/ |
99e300ef | 1568 | |
54623277 | 1569 | /* rlwimi & rlwimi. */ |
99e300ef | 1570 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1571 | { |
76a66253 | 1572 | uint32_t mb, me, sh; |
79aceca5 FB |
1573 | |
1574 | mb = MB(ctx->opcode); | |
1575 | me = ME(ctx->opcode); | |
76a66253 | 1576 | sh = SH(ctx->opcode); |
d03ef511 AJ |
1577 | if (likely(sh == 0 && mb == 0 && me == 31)) { |
1578 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1579 | } else { | |
d03ef511 | 1580 | target_ulong mask; |
a7812ae4 PB |
1581 | TCGv t1; |
1582 | TCGv t0 = tcg_temp_new(); | |
54843a58 | 1583 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1584 | TCGv_i32 t2 = tcg_temp_new_i32(); |
1585 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]); | |
1586 | tcg_gen_rotli_i32(t2, t2, sh); | |
1587 | tcg_gen_extu_i32_i64(t0, t2); | |
1588 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1589 | #else |
1590 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1591 | #endif | |
76a66253 | 1592 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1593 | mb += 32; |
1594 | me += 32; | |
76a66253 | 1595 | #endif |
d03ef511 | 1596 | mask = MASK(mb, me); |
a7812ae4 | 1597 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1598 | tcg_gen_andi_tl(t0, t0, mask); |
1599 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1600 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1601 | tcg_temp_free(t0); | |
1602 | tcg_temp_free(t1); | |
1603 | } | |
76a66253 | 1604 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1605 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1606 | } |
99e300ef | 1607 | |
54623277 | 1608 | /* rlwinm & rlwinm. */ |
99e300ef | 1609 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 FB |
1610 | { |
1611 | uint32_t mb, me, sh; | |
3b46e624 | 1612 | |
79aceca5 FB |
1613 | sh = SH(ctx->opcode); |
1614 | mb = MB(ctx->opcode); | |
1615 | me = ME(ctx->opcode); | |
d03ef511 AJ |
1616 | |
1617 | if (likely(mb == 0 && me == (31 - sh))) { | |
1618 | if (likely(sh == 0)) { | |
1619 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1620 | } else { | |
a7812ae4 | 1621 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1622 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1623 | tcg_gen_shli_tl(t0, t0, sh); | |
1624 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1625 | tcg_temp_free(t0); | |
79aceca5 | 1626 | } |
d03ef511 | 1627 | } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) { |
a7812ae4 | 1628 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1629 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1630 | tcg_gen_shri_tl(t0, t0, mb); | |
1631 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1632 | tcg_temp_free(t0); | |
1633 | } else { | |
a7812ae4 | 1634 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1635 | #if defined(TARGET_PPC64) |
a7812ae4 | 1636 | TCGv_i32 t1 = tcg_temp_new_i32(); |
54843a58 AJ |
1637 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1638 | tcg_gen_rotli_i32(t1, t1, sh); | |
1639 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 | 1640 | tcg_temp_free_i32(t1); |
54843a58 AJ |
1641 | #else |
1642 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1643 | #endif | |
76a66253 | 1644 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1645 | mb += 32; |
1646 | me += 32; | |
76a66253 | 1647 | #endif |
d03ef511 AJ |
1648 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1649 | tcg_temp_free(t0); | |
1650 | } | |
76a66253 | 1651 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1652 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1653 | } |
99e300ef | 1654 | |
54623277 | 1655 | /* rlwnm & rlwnm. */ |
99e300ef | 1656 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 FB |
1657 | { |
1658 | uint32_t mb, me; | |
54843a58 AJ |
1659 | TCGv t0; |
1660 | #if defined(TARGET_PPC64) | |
a7812ae4 | 1661 | TCGv_i32 t1, t2; |
54843a58 | 1662 | #endif |
79aceca5 FB |
1663 | |
1664 | mb = MB(ctx->opcode); | |
1665 | me = ME(ctx->opcode); | |
a7812ae4 | 1666 | t0 = tcg_temp_new(); |
d03ef511 | 1667 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f); |
54843a58 | 1668 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1669 | t1 = tcg_temp_new_i32(); |
1670 | t2 = tcg_temp_new_i32(); | |
54843a58 AJ |
1671 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1672 | tcg_gen_trunc_i64_i32(t2, t0); | |
1673 | tcg_gen_rotl_i32(t1, t1, t2); | |
1674 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 PB |
1675 | tcg_temp_free_i32(t1); |
1676 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1677 | #else |
1678 | tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1679 | #endif | |
76a66253 JM |
1680 | if (unlikely(mb != 0 || me != 31)) { |
1681 | #if defined(TARGET_PPC64) | |
1682 | mb += 32; | |
1683 | me += 32; | |
1684 | #endif | |
54843a58 | 1685 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
d03ef511 | 1686 | } else { |
54843a58 | 1687 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
79aceca5 | 1688 | } |
54843a58 | 1689 | tcg_temp_free(t0); |
76a66253 | 1690 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1691 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 FB |
1692 | } |
1693 | ||
d9bce9d9 JM |
1694 | #if defined(TARGET_PPC64) |
1695 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1696 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1697 | { \ |
1698 | gen_##name(ctx, 0); \ | |
1699 | } \ | |
e8eaa2c0 BS |
1700 | \ |
1701 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1702 | { \ |
1703 | gen_##name(ctx, 1); \ | |
1704 | } | |
1705 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1706 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1707 | { \ |
1708 | gen_##name(ctx, 0, 0); \ | |
1709 | } \ | |
e8eaa2c0 BS |
1710 | \ |
1711 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1712 | { \ |
1713 | gen_##name(ctx, 0, 1); \ | |
1714 | } \ | |
e8eaa2c0 BS |
1715 | \ |
1716 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1717 | { \ |
1718 | gen_##name(ctx, 1, 0); \ | |
1719 | } \ | |
e8eaa2c0 BS |
1720 | \ |
1721 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1722 | { \ |
1723 | gen_##name(ctx, 1, 1); \ | |
1724 | } | |
51789c41 | 1725 | |
636aa200 BS |
1726 | static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me, |
1727 | uint32_t sh) | |
51789c41 | 1728 | { |
d03ef511 AJ |
1729 | if (likely(sh != 0 && mb == 0 && me == (63 - sh))) { |
1730 | tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
1731 | } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) { | |
1732 | tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb); | |
1733 | } else { | |
a7812ae4 | 1734 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1735 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
d03ef511 | 1736 | if (likely(mb == 0 && me == 63)) { |
54843a58 | 1737 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
d03ef511 AJ |
1738 | } else { |
1739 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); | |
51789c41 | 1740 | } |
d03ef511 | 1741 | tcg_temp_free(t0); |
51789c41 | 1742 | } |
51789c41 | 1743 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1744 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
51789c41 | 1745 | } |
d9bce9d9 | 1746 | /* rldicl - rldicl. */ |
636aa200 | 1747 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1748 | { |
51789c41 | 1749 | uint32_t sh, mb; |
d9bce9d9 | 1750 | |
9d53c753 JM |
1751 | sh = SH(ctx->opcode) | (shn << 5); |
1752 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 1753 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 1754 | } |
51789c41 | 1755 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
d9bce9d9 | 1756 | /* rldicr - rldicr. */ |
636aa200 | 1757 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 1758 | { |
51789c41 | 1759 | uint32_t sh, me; |
d9bce9d9 | 1760 | |
9d53c753 JM |
1761 | sh = SH(ctx->opcode) | (shn << 5); |
1762 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 1763 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 1764 | } |
51789c41 | 1765 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
d9bce9d9 | 1766 | /* rldic - rldic. */ |
636aa200 | 1767 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1768 | { |
51789c41 | 1769 | uint32_t sh, mb; |
d9bce9d9 | 1770 | |
9d53c753 JM |
1771 | sh = SH(ctx->opcode) | (shn << 5); |
1772 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
1773 | gen_rldinm(ctx, mb, 63 - sh, sh); |
1774 | } | |
1775 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
1776 | ||
636aa200 | 1777 | static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me) |
51789c41 | 1778 | { |
54843a58 | 1779 | TCGv t0; |
d03ef511 AJ |
1780 | |
1781 | mb = MB(ctx->opcode); | |
1782 | me = ME(ctx->opcode); | |
a7812ae4 | 1783 | t0 = tcg_temp_new(); |
d03ef511 | 1784 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f); |
54843a58 | 1785 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); |
51789c41 | 1786 | if (unlikely(mb != 0 || me != 63)) { |
54843a58 AJ |
1787 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1788 | } else { | |
1789 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1790 | } | |
1791 | tcg_temp_free(t0); | |
51789c41 | 1792 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1793 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1794 | } |
51789c41 | 1795 | |
d9bce9d9 | 1796 | /* rldcl - rldcl. */ |
636aa200 | 1797 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 1798 | { |
51789c41 | 1799 | uint32_t mb; |
d9bce9d9 | 1800 | |
9d53c753 | 1801 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 1802 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 1803 | } |
36081602 | 1804 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
d9bce9d9 | 1805 | /* rldcr - rldcr. */ |
636aa200 | 1806 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 1807 | { |
51789c41 | 1808 | uint32_t me; |
d9bce9d9 | 1809 | |
9d53c753 | 1810 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 1811 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 1812 | } |
36081602 | 1813 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
d9bce9d9 | 1814 | /* rldimi - rldimi. */ |
636aa200 | 1815 | static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1816 | { |
271a916e | 1817 | uint32_t sh, mb, me; |
d9bce9d9 | 1818 | |
9d53c753 JM |
1819 | sh = SH(ctx->opcode) | (shn << 5); |
1820 | mb = MB(ctx->opcode) | (mbn << 5); | |
271a916e | 1821 | me = 63 - sh; |
d03ef511 AJ |
1822 | if (unlikely(sh == 0 && mb == 0)) { |
1823 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1824 | } else { | |
1825 | TCGv t0, t1; | |
1826 | target_ulong mask; | |
1827 | ||
a7812ae4 | 1828 | t0 = tcg_temp_new(); |
54843a58 | 1829 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
a7812ae4 | 1830 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1831 | mask = MASK(mb, me); |
1832 | tcg_gen_andi_tl(t0, t0, mask); | |
1833 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1834 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1835 | tcg_temp_free(t0); | |
1836 | tcg_temp_free(t1); | |
51789c41 | 1837 | } |
51789c41 | 1838 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1839 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1840 | } |
36081602 | 1841 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
1842 | #endif |
1843 | ||
79aceca5 | 1844 | /*** Integer shift ***/ |
99e300ef | 1845 | |
54623277 | 1846 | /* slw & slw. */ |
99e300ef | 1847 | static void gen_slw(DisasContext *ctx) |
26d67362 | 1848 | { |
7fd6bf7d | 1849 | TCGv t0, t1; |
26d67362 | 1850 | |
7fd6bf7d AJ |
1851 | t0 = tcg_temp_new(); |
1852 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1853 | #if defined(TARGET_PPC64) | |
1854 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1855 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1856 | #else | |
1857 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1858 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1859 | #endif | |
1860 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1861 | t1 = tcg_temp_new(); | |
1862 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
1863 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1864 | tcg_temp_free(t1); | |
fea0c503 | 1865 | tcg_temp_free(t0); |
7fd6bf7d | 1866 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
1867 | if (unlikely(Rc(ctx->opcode) != 0)) |
1868 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1869 | } | |
99e300ef | 1870 | |
54623277 | 1871 | /* sraw & sraw. */ |
99e300ef | 1872 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 1873 | { |
d15f74fb | 1874 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1875 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1876 | if (unlikely(Rc(ctx->opcode) != 0)) |
1877 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1878 | } | |
99e300ef | 1879 | |
54623277 | 1880 | /* srawi & srawi. */ |
99e300ef | 1881 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 1882 | { |
26d67362 AJ |
1883 | int sh = SH(ctx->opcode); |
1884 | if (sh != 0) { | |
1885 | int l1, l2; | |
fea0c503 | 1886 | TCGv t0; |
26d67362 AJ |
1887 | l1 = gen_new_label(); |
1888 | l2 = gen_new_label(); | |
a7812ae4 | 1889 | t0 = tcg_temp_local_new(); |
fea0c503 AJ |
1890 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1891 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
1892 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); | |
1893 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1894 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1895 | tcg_gen_br(l2); |
1896 | gen_set_label(l1); | |
269f3e95 | 1897 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1898 | gen_set_label(l2); |
fea0c503 AJ |
1899 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1900 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh); | |
1901 | tcg_temp_free(t0); | |
26d67362 AJ |
1902 | } else { |
1903 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1904 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1905 | } |
76a66253 | 1906 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1907 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1908 | } |
99e300ef | 1909 | |
54623277 | 1910 | /* srw & srw. */ |
99e300ef | 1911 | static void gen_srw(DisasContext *ctx) |
26d67362 | 1912 | { |
fea0c503 | 1913 | TCGv t0, t1; |
d9bce9d9 | 1914 | |
7fd6bf7d AJ |
1915 | t0 = tcg_temp_new(); |
1916 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1917 | #if defined(TARGET_PPC64) | |
1918 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1919 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1920 | #else | |
1921 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1922 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1923 | #endif | |
1924 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1925 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 1926 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
1927 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
1928 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 1929 | tcg_temp_free(t1); |
fea0c503 | 1930 | tcg_temp_free(t0); |
26d67362 AJ |
1931 | if (unlikely(Rc(ctx->opcode) != 0)) |
1932 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1933 | } | |
54623277 | 1934 | |
d9bce9d9 JM |
1935 | #if defined(TARGET_PPC64) |
1936 | /* sld & sld. */ | |
99e300ef | 1937 | static void gen_sld(DisasContext *ctx) |
26d67362 | 1938 | { |
7fd6bf7d | 1939 | TCGv t0, t1; |
26d67362 | 1940 | |
7fd6bf7d AJ |
1941 | t0 = tcg_temp_new(); |
1942 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
1943 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
1944 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1945 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1946 | t1 = tcg_temp_new(); | |
1947 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
1948 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1949 | tcg_temp_free(t1); | |
fea0c503 | 1950 | tcg_temp_free(t0); |
26d67362 AJ |
1951 | if (unlikely(Rc(ctx->opcode) != 0)) |
1952 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1953 | } | |
99e300ef | 1954 | |
54623277 | 1955 | /* srad & srad. */ |
99e300ef | 1956 | static void gen_srad(DisasContext *ctx) |
26d67362 | 1957 | { |
d15f74fb | 1958 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1959 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1960 | if (unlikely(Rc(ctx->opcode) != 0)) |
1961 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1962 | } | |
d9bce9d9 | 1963 | /* sradi & sradi. */ |
636aa200 | 1964 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 1965 | { |
26d67362 | 1966 | int sh = SH(ctx->opcode) + (n << 5); |
d9bce9d9 | 1967 | if (sh != 0) { |
26d67362 | 1968 | int l1, l2; |
fea0c503 | 1969 | TCGv t0; |
26d67362 AJ |
1970 | l1 = gen_new_label(); |
1971 | l2 = gen_new_label(); | |
a7812ae4 | 1972 | t0 = tcg_temp_local_new(); |
26d67362 | 1973 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); |
fea0c503 AJ |
1974 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); |
1975 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1976 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1977 | tcg_gen_br(l2); |
1978 | gen_set_label(l1); | |
269f3e95 | 1979 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1980 | gen_set_label(l2); |
a9730017 | 1981 | tcg_temp_free(t0); |
26d67362 AJ |
1982 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); |
1983 | } else { | |
1984 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1985 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1986 | } |
d9bce9d9 | 1987 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1988 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1989 | } |
e8eaa2c0 BS |
1990 | |
1991 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
1992 | { |
1993 | gen_sradi(ctx, 0); | |
1994 | } | |
e8eaa2c0 BS |
1995 | |
1996 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
1997 | { |
1998 | gen_sradi(ctx, 1); | |
1999 | } | |
99e300ef | 2000 | |
54623277 | 2001 | /* srd & srd. */ |
99e300ef | 2002 | static void gen_srd(DisasContext *ctx) |
26d67362 | 2003 | { |
7fd6bf7d | 2004 | TCGv t0, t1; |
26d67362 | 2005 | |
7fd6bf7d AJ |
2006 | t0 = tcg_temp_new(); |
2007 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2008 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2009 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2010 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2011 | t1 = tcg_temp_new(); | |
2012 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2013 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2014 | tcg_temp_free(t1); | |
fea0c503 | 2015 | tcg_temp_free(t0); |
26d67362 AJ |
2016 | if (unlikely(Rc(ctx->opcode) != 0)) |
2017 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2018 | } | |
d9bce9d9 | 2019 | #endif |
79aceca5 FB |
2020 | |
2021 | /*** Floating-Point arithmetic ***/ | |
7c58044c | 2022 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ |
99e300ef | 2023 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2024 | { \ |
76a66253 | 2025 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2026 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2027 | return; \ |
2028 | } \ | |
eb44b959 AJ |
2029 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2030 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2031 | gen_reset_fpstatus(); \ |
8e703949 BS |
2032 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2033 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2034 | cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2035 | if (isfloat) { \ |
8e703949 BS |
2036 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2037 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2038 | } \ |
af12906f AJ |
2039 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \ |
2040 | Rc(ctx->opcode) != 0); \ | |
9a64fbe4 FB |
2041 | } |
2042 | ||
7c58044c JM |
2043 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ |
2044 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \ | |
2045 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type); | |
9a64fbe4 | 2046 | |
7c58044c | 2047 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2048 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2049 | { \ |
76a66253 | 2050 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2051 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2052 | return; \ |
2053 | } \ | |
eb44b959 AJ |
2054 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2055 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2056 | gen_reset_fpstatus(); \ |
8e703949 BS |
2057 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2058 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2059 | cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2060 | if (isfloat) { \ |
8e703949 BS |
2061 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2062 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2063 | } \ |
af12906f AJ |
2064 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2065 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2066 | } |
7c58044c JM |
2067 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ |
2068 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2069 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2070 | |
7c58044c | 2071 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2072 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2073 | { \ |
76a66253 | 2074 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2075 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2076 | return; \ |
2077 | } \ | |
eb44b959 AJ |
2078 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2079 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2080 | gen_reset_fpstatus(); \ |
8e703949 BS |
2081 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2082 | cpu_fpr[rA(ctx->opcode)], \ | |
2083 | cpu_fpr[rC(ctx->opcode)]); \ | |
4ecc3190 | 2084 | if (isfloat) { \ |
8e703949 BS |
2085 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2086 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2087 | } \ |
af12906f AJ |
2088 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2089 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2090 | } |
7c58044c JM |
2091 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ |
2092 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2093 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2094 | |
7c58044c | 2095 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ |
99e300ef | 2096 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2097 | { \ |
76a66253 | 2098 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2099 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2100 | return; \ |
2101 | } \ | |
eb44b959 AJ |
2102 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2103 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2104 | gen_reset_fpstatus(); \ |
8e703949 BS |
2105 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2106 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2107 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2108 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2109 | } |
2110 | ||
7c58044c | 2111 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ |
99e300ef | 2112 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2113 | { \ |
76a66253 | 2114 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2115 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2116 | return; \ |
2117 | } \ | |
eb44b959 AJ |
2118 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2119 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2120 | gen_reset_fpstatus(); \ |
8e703949 BS |
2121 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2122 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2123 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2124 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2125 | } |
2126 | ||
9a64fbe4 | 2127 | /* fadd - fadds */ |
7c58044c | 2128 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2129 | /* fdiv - fdivs */ |
7c58044c | 2130 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2131 | /* fmul - fmuls */ |
7c58044c | 2132 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT); |
79aceca5 | 2133 | |
d7e4b87e | 2134 | /* fre */ |
7c58044c | 2135 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2136 | |
a750fc0b | 2137 | /* fres */ |
7c58044c | 2138 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES); |
79aceca5 | 2139 | |
a750fc0b | 2140 | /* frsqrte */ |
7c58044c JM |
2141 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE); |
2142 | ||
2143 | /* frsqrtes */ | |
99e300ef | 2144 | static void gen_frsqrtes(DisasContext *ctx) |
7c58044c | 2145 | { |
af12906f | 2146 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2147 | gen_exception(ctx, POWERPC_EXCP_FPU); |
af12906f AJ |
2148 | return; |
2149 | } | |
eb44b959 AJ |
2150 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2151 | gen_update_nip(ctx, ctx->nip - 4); | |
af12906f | 2152 | gen_reset_fpstatus(); |
8e703949 BS |
2153 | gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2154 | cpu_fpr[rB(ctx->opcode)]); | |
2155 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2156 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2157 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
7c58044c | 2158 | } |
79aceca5 | 2159 | |
a750fc0b | 2160 | /* fsel */ |
7c58044c | 2161 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL); |
4ecc3190 | 2162 | /* fsub - fsubs */ |
7c58044c | 2163 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT); |
79aceca5 | 2164 | /* Optional: */ |
99e300ef | 2165 | |
54623277 | 2166 | /* fsqrt */ |
99e300ef | 2167 | static void gen_fsqrt(DisasContext *ctx) |
c7d344af | 2168 | { |
76a66253 | 2169 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2170 | gen_exception(ctx, POWERPC_EXCP_FPU); |
c7d344af FB |
2171 | return; |
2172 | } | |
eb44b959 AJ |
2173 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2174 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2175 | gen_reset_fpstatus(); |
8e703949 BS |
2176 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2177 | cpu_fpr[rB(ctx->opcode)]); | |
af12906f | 2178 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
c7d344af | 2179 | } |
79aceca5 | 2180 | |
99e300ef | 2181 | static void gen_fsqrts(DisasContext *ctx) |
79aceca5 | 2182 | { |
76a66253 | 2183 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2184 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2185 | return; |
2186 | } | |
eb44b959 AJ |
2187 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2188 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2189 | gen_reset_fpstatus(); |
8e703949 BS |
2190 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2191 | cpu_fpr[rB(ctx->opcode)]); | |
2192 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2193 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2194 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2195 | } |
2196 | ||
2197 | /*** Floating-Point multiply-and-add ***/ | |
4ecc3190 | 2198 | /* fmadd - fmadds */ |
7c58044c | 2199 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT); |
4ecc3190 | 2200 | /* fmsub - fmsubs */ |
7c58044c | 2201 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT); |
4ecc3190 | 2202 | /* fnmadd - fnmadds */ |
7c58044c | 2203 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT); |
4ecc3190 | 2204 | /* fnmsub - fnmsubs */ |
7c58044c | 2205 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT); |
79aceca5 FB |
2206 | |
2207 | /*** Floating-Point round & convert ***/ | |
2208 | /* fctiw */ | |
7c58044c | 2209 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2210 | /* fctiwz */ |
7c58044c | 2211 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2212 | /* frsp */ |
7c58044c | 2213 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT); |
426613db JM |
2214 | #if defined(TARGET_PPC64) |
2215 | /* fcfid */ | |
7c58044c | 2216 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B); |
426613db | 2217 | /* fctid */ |
7c58044c | 2218 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B); |
426613db | 2219 | /* fctidz */ |
7c58044c | 2220 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B); |
426613db | 2221 | #endif |
79aceca5 | 2222 | |
d7e4b87e | 2223 | /* frin */ |
7c58044c | 2224 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2225 | /* friz */ |
7c58044c | 2226 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2227 | /* frip */ |
7c58044c | 2228 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2229 | /* frim */ |
7c58044c | 2230 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2231 | |
79aceca5 | 2232 | /*** Floating-Point compare ***/ |
99e300ef | 2233 | |
54623277 | 2234 | /* fcmpo */ |
99e300ef | 2235 | static void gen_fcmpo(DisasContext *ctx) |
79aceca5 | 2236 | { |
330c483b | 2237 | TCGv_i32 crf; |
76a66253 | 2238 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2239 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2240 | return; |
2241 | } | |
eb44b959 AJ |
2242 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2243 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2244 | gen_reset_fpstatus(); |
9a819377 | 2245 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2246 | gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2247 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2248 | tcg_temp_free_i32(crf); |
8e703949 | 2249 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2250 | } |
2251 | ||
2252 | /* fcmpu */ | |
99e300ef | 2253 | static void gen_fcmpu(DisasContext *ctx) |
79aceca5 | 2254 | { |
330c483b | 2255 | TCGv_i32 crf; |
76a66253 | 2256 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2257 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2258 | return; |
2259 | } | |
eb44b959 AJ |
2260 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2261 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2262 | gen_reset_fpstatus(); |
9a819377 | 2263 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2264 | gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2265 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2266 | tcg_temp_free_i32(crf); |
8e703949 | 2267 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2268 | } |
2269 | ||
9a64fbe4 FB |
2270 | /*** Floating-point move ***/ |
2271 | /* fabs */ | |
7c58044c JM |
2272 | /* XXX: beware that fabs never checks for NaNs nor update FPSCR */ |
2273 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT); | |
9a64fbe4 FB |
2274 | |
2275 | /* fmr - fmr. */ | |
7c58044c | 2276 | /* XXX: beware that fmr never checks for NaNs nor update FPSCR */ |
99e300ef | 2277 | static void gen_fmr(DisasContext *ctx) |
9a64fbe4 | 2278 | { |
76a66253 | 2279 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2280 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2281 | return; |
2282 | } | |
af12906f AJ |
2283 | tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2284 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
9a64fbe4 FB |
2285 | } |
2286 | ||
2287 | /* fnabs */ | |
7c58044c JM |
2288 | /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */ |
2289 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT); | |
9a64fbe4 | 2290 | /* fneg */ |
7c58044c JM |
2291 | /* XXX: beware that fneg never checks for NaNs nor update FPSCR */ |
2292 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT); | |
9a64fbe4 | 2293 | |
79aceca5 | 2294 | /*** Floating-Point status & ctrl register ***/ |
99e300ef | 2295 | |
54623277 | 2296 | /* mcrfs */ |
99e300ef | 2297 | static void gen_mcrfs(DisasContext *ctx) |
79aceca5 | 2298 | { |
30304420 | 2299 | TCGv tmp = tcg_temp_new(); |
7c58044c JM |
2300 | int bfa; |
2301 | ||
76a66253 | 2302 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2303 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2304 | return; |
2305 | } | |
7c58044c | 2306 | bfa = 4 * (7 - crfS(ctx->opcode)); |
30304420 DG |
2307 | tcg_gen_shri_tl(tmp, cpu_fpscr, bfa); |
2308 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp); | |
2309 | tcg_temp_free(tmp); | |
e1571908 | 2310 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf); |
30304420 | 2311 | tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); |
79aceca5 FB |
2312 | } |
2313 | ||
2314 | /* mffs */ | |
99e300ef | 2315 | static void gen_mffs(DisasContext *ctx) |
79aceca5 | 2316 | { |
76a66253 | 2317 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2318 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2319 | return; |
2320 | } | |
7c58044c | 2321 | gen_reset_fpstatus(); |
30304420 | 2322 | tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr); |
af12906f | 2323 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2324 | } |
2325 | ||
2326 | /* mtfsb0 */ | |
99e300ef | 2327 | static void gen_mtfsb0(DisasContext *ctx) |
79aceca5 | 2328 | { |
fb0eaffc | 2329 | uint8_t crb; |
3b46e624 | 2330 | |
76a66253 | 2331 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2332 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2333 | return; |
2334 | } | |
6e35d524 | 2335 | crb = 31 - crbD(ctx->opcode); |
7c58044c | 2336 | gen_reset_fpstatus(); |
6e35d524 | 2337 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) { |
eb44b959 AJ |
2338 | TCGv_i32 t0; |
2339 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2340 | gen_update_nip(ctx, ctx->nip - 4); | |
2341 | t0 = tcg_const_i32(crb); | |
8e703949 | 2342 | gen_helper_fpscr_clrbit(cpu_env, t0); |
6e35d524 AJ |
2343 | tcg_temp_free_i32(t0); |
2344 | } | |
7c58044c | 2345 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2346 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2347 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c | 2348 | } |
79aceca5 FB |
2349 | } |
2350 | ||
2351 | /* mtfsb1 */ | |
99e300ef | 2352 | static void gen_mtfsb1(DisasContext *ctx) |
79aceca5 | 2353 | { |
fb0eaffc | 2354 | uint8_t crb; |
3b46e624 | 2355 | |
76a66253 | 2356 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2357 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2358 | return; |
2359 | } | |
6e35d524 | 2360 | crb = 31 - crbD(ctx->opcode); |
7c58044c JM |
2361 | gen_reset_fpstatus(); |
2362 | /* XXX: we pretend we can only do IEEE floating-point computations */ | |
af12906f | 2363 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) { |
eb44b959 AJ |
2364 | TCGv_i32 t0; |
2365 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2366 | gen_update_nip(ctx, ctx->nip - 4); | |
2367 | t0 = tcg_const_i32(crb); | |
8e703949 | 2368 | gen_helper_fpscr_setbit(cpu_env, t0); |
0f2f39c2 | 2369 | tcg_temp_free_i32(t0); |
af12906f | 2370 | } |
7c58044c | 2371 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2372 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2373 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2374 | } |
2375 | /* We can raise a differed exception */ | |
8e703949 | 2376 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2377 | } |
2378 | ||
2379 | /* mtfsf */ | |
99e300ef | 2380 | static void gen_mtfsf(DisasContext *ctx) |
79aceca5 | 2381 | { |
0f2f39c2 | 2382 | TCGv_i32 t0; |
4911012d | 2383 | int L = ctx->opcode & 0x02000000; |
af12906f | 2384 | |
76a66253 | 2385 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2386 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2387 | return; |
2388 | } | |
eb44b959 AJ |
2389 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2390 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2391 | gen_reset_fpstatus(); |
4911012d BS |
2392 | if (L) |
2393 | t0 = tcg_const_i32(0xff); | |
2394 | else | |
2395 | t0 = tcg_const_i32(FM(ctx->opcode)); | |
8e703949 | 2396 | gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0); |
0f2f39c2 | 2397 | tcg_temp_free_i32(t0); |
7c58044c | 2398 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2399 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2400 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2401 | } |
2402 | /* We can raise a differed exception */ | |
8e703949 | 2403 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2404 | } |
2405 | ||
2406 | /* mtfsfi */ | |
99e300ef | 2407 | static void gen_mtfsfi(DisasContext *ctx) |
79aceca5 | 2408 | { |
7c58044c | 2409 | int bf, sh; |
0f2f39c2 AJ |
2410 | TCGv_i64 t0; |
2411 | TCGv_i32 t1; | |
7c58044c | 2412 | |
76a66253 | 2413 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2414 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2415 | return; |
2416 | } | |
7c58044c JM |
2417 | bf = crbD(ctx->opcode) >> 2; |
2418 | sh = 7 - bf; | |
eb44b959 AJ |
2419 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2420 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2421 | gen_reset_fpstatus(); |
0f2f39c2 | 2422 | t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh)); |
af12906f | 2423 | t1 = tcg_const_i32(1 << sh); |
8e703949 | 2424 | gen_helper_store_fpscr(cpu_env, t0, t1); |
0f2f39c2 AJ |
2425 | tcg_temp_free_i64(t0); |
2426 | tcg_temp_free_i32(t1); | |
7c58044c | 2427 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2428 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2429 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2430 | } |
2431 | /* We can raise a differed exception */ | |
8e703949 | 2432 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2433 | } |
2434 | ||
76a66253 JM |
2435 | /*** Addressing modes ***/ |
2436 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2437 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2438 | target_long maskl) | |
76a66253 JM |
2439 | { |
2440 | target_long simm = SIMM(ctx->opcode); | |
2441 | ||
be147d08 | 2442 | simm &= ~maskl; |
76db3ba4 AJ |
2443 | if (rA(ctx->opcode) == 0) { |
2444 | #if defined(TARGET_PPC64) | |
2445 | if (!ctx->sf_mode) { | |
2446 | tcg_gen_movi_tl(EA, (uint32_t)simm); | |
2447 | } else | |
2448 | #endif | |
e2be8d8d | 2449 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2450 | } else if (likely(simm != 0)) { |
e2be8d8d | 2451 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
76db3ba4 AJ |
2452 | #if defined(TARGET_PPC64) |
2453 | if (!ctx->sf_mode) { | |
2454 | tcg_gen_ext32u_tl(EA, EA); | |
2455 | } | |
2456 | #endif | |
2457 | } else { | |
2458 | #if defined(TARGET_PPC64) | |
2459 | if (!ctx->sf_mode) { | |
2460 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2461 | } else | |
2462 | #endif | |
e2be8d8d | 2463 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 | 2464 | } |
76a66253 JM |
2465 | } |
2466 | ||
636aa200 | 2467 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2468 | { |
76db3ba4 AJ |
2469 | if (rA(ctx->opcode) == 0) { |
2470 | #if defined(TARGET_PPC64) | |
2471 | if (!ctx->sf_mode) { | |
2472 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2473 | } else | |
2474 | #endif | |
e2be8d8d | 2475 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 | 2476 | } else { |
e2be8d8d | 2477 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 AJ |
2478 | #if defined(TARGET_PPC64) |
2479 | if (!ctx->sf_mode) { | |
2480 | tcg_gen_ext32u_tl(EA, EA); | |
2481 | } | |
2482 | #endif | |
2483 | } | |
76a66253 JM |
2484 | } |
2485 | ||
636aa200 | 2486 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2487 | { |
76db3ba4 | 2488 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2489 | tcg_gen_movi_tl(EA, 0); |
76db3ba4 AJ |
2490 | } else { |
2491 | #if defined(TARGET_PPC64) | |
2492 | if (!ctx->sf_mode) { | |
2493 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2494 | } else | |
2495 | #endif | |
2496 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2497 | } | |
2498 | } | |
2499 | ||
636aa200 BS |
2500 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2501 | target_long val) | |
76db3ba4 AJ |
2502 | { |
2503 | tcg_gen_addi_tl(ret, arg1, val); | |
2504 | #if defined(TARGET_PPC64) | |
2505 | if (!ctx->sf_mode) { | |
2506 | tcg_gen_ext32u_tl(ret, ret); | |
2507 | } | |
2508 | #endif | |
76a66253 JM |
2509 | } |
2510 | ||
636aa200 | 2511 | static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask) |
cf360a32 AJ |
2512 | { |
2513 | int l1 = gen_new_label(); | |
2514 | TCGv t0 = tcg_temp_new(); | |
2515 | TCGv_i32 t1, t2; | |
2516 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2517 | gen_update_nip(ctx, ctx->nip - 4); | |
2518 | tcg_gen_andi_tl(t0, EA, mask); | |
2519 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
2520 | t1 = tcg_const_i32(POWERPC_EXCP_ALIGN); | |
2521 | t2 = tcg_const_i32(0); | |
e5f17ac6 | 2522 | gen_helper_raise_exception_err(cpu_env, t1, t2); |
cf360a32 AJ |
2523 | tcg_temp_free_i32(t1); |
2524 | tcg_temp_free_i32(t2); | |
2525 | gen_set_label(l1); | |
2526 | tcg_temp_free(t0); | |
2527 | } | |
2528 | ||
7863667f | 2529 | /*** Integer load ***/ |
636aa200 | 2530 | static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2531 | { |
2532 | tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx); | |
2533 | } | |
2534 | ||
636aa200 | 2535 | static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2536 | { |
2537 | tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx); | |
2538 | } | |
2539 | ||
636aa200 | 2540 | static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2541 | { |
2542 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); | |
2543 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2544 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2545 | } |
b61f2753 AJ |
2546 | } |
2547 | ||
636aa200 | 2548 | static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2549 | { |
76db3ba4 | 2550 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2551 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
fa3966a3 | 2552 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2553 | tcg_gen_ext16s_tl(arg1, arg1); |
76db3ba4 AJ |
2554 | } else { |
2555 | tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx); | |
2556 | } | |
b61f2753 AJ |
2557 | } |
2558 | ||
636aa200 | 2559 | static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2560 | { |
76db3ba4 AJ |
2561 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2562 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2563 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2564 | } |
b61f2753 AJ |
2565 | } |
2566 | ||
76db3ba4 | 2567 | #if defined(TARGET_PPC64) |
636aa200 | 2568 | static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2569 | { |
a457e7ee | 2570 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2571 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
fa3966a3 AJ |
2572 | tcg_gen_bswap32_tl(arg1, arg1); |
2573 | tcg_gen_ext32s_tl(arg1, arg1); | |
b61f2753 | 2574 | } else |
76db3ba4 | 2575 | tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx); |
b61f2753 | 2576 | } |
76db3ba4 | 2577 | #endif |
b61f2753 | 2578 | |
636aa200 | 2579 | static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2580 | { |
76db3ba4 AJ |
2581 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); |
2582 | if (unlikely(ctx->le_mode)) { | |
66896cb8 | 2583 | tcg_gen_bswap64_i64(arg1, arg1); |
76db3ba4 | 2584 | } |
b61f2753 AJ |
2585 | } |
2586 | ||
636aa200 | 2587 | static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2588 | { |
76db3ba4 | 2589 | tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2590 | } |
2591 | ||
636aa200 | 2592 | static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2593 | { |
76db3ba4 | 2594 | if (unlikely(ctx->le_mode)) { |
76db3ba4 AJ |
2595 | TCGv t0 = tcg_temp_new(); |
2596 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2597 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2598 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2599 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2600 | } else { |
2601 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2602 | } | |
b61f2753 AJ |
2603 | } |
2604 | ||
636aa200 | 2605 | static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2606 | { |
76db3ba4 | 2607 | if (unlikely(ctx->le_mode)) { |
fa3966a3 AJ |
2608 | TCGv t0 = tcg_temp_new(); |
2609 | tcg_gen_ext32u_tl(t0, arg1); | |
2610 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2611 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2612 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2613 | } else { |
2614 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2615 | } | |
b61f2753 AJ |
2616 | } |
2617 | ||
636aa200 | 2618 | static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2619 | { |
76db3ba4 | 2620 | if (unlikely(ctx->le_mode)) { |
a7812ae4 | 2621 | TCGv_i64 t0 = tcg_temp_new_i64(); |
66896cb8 | 2622 | tcg_gen_bswap64_i64(t0, arg1); |
76db3ba4 | 2623 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); |
a7812ae4 | 2624 | tcg_temp_free_i64(t0); |
b61f2753 | 2625 | } else |
76db3ba4 | 2626 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2627 | } |
2628 | ||
0c8aacd4 | 2629 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2630 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2631 | { \ |
76db3ba4 AJ |
2632 | TCGv EA; \ |
2633 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2634 | EA = tcg_temp_new(); \ | |
2635 | gen_addr_imm_index(ctx, EA, 0); \ | |
2636 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2637 | tcg_temp_free(EA); \ |
79aceca5 FB |
2638 | } |
2639 | ||
0c8aacd4 | 2640 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2641 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2642 | { \ |
b61f2753 | 2643 | TCGv EA; \ |
76a66253 JM |
2644 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2645 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2646 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2647 | return; \ |
9a64fbe4 | 2648 | } \ |
76db3ba4 | 2649 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2650 | EA = tcg_temp_new(); \ |
9d53c753 | 2651 | if (type == PPC_64B) \ |
76db3ba4 | 2652 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2653 | else \ |
76db3ba4 AJ |
2654 | gen_addr_imm_index(ctx, EA, 0); \ |
2655 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2656 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2657 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2658 | } |
2659 | ||
0c8aacd4 | 2660 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2661 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2662 | { \ |
b61f2753 | 2663 | TCGv EA; \ |
76a66253 JM |
2664 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2665 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2666 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2667 | return; \ |
9a64fbe4 | 2668 | } \ |
76db3ba4 | 2669 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2670 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2671 | gen_addr_reg_index(ctx, EA); \ |
2672 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2673 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2674 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2675 | } |
2676 | ||
cd6e9320 | 2677 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
99e300ef | 2678 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2679 | { \ |
76db3ba4 AJ |
2680 | TCGv EA; \ |
2681 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2682 | EA = tcg_temp_new(); \ | |
2683 | gen_addr_reg_index(ctx, EA); \ | |
2684 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2685 | tcg_temp_free(EA); \ |
79aceca5 | 2686 | } |
cd6e9320 TH |
2687 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
2688 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2689 | |
0c8aacd4 AJ |
2690 | #define GEN_LDS(name, ldop, op, type) \ |
2691 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2692 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2693 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2694 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2695 | |
2696 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2697 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2698 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2699 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2700 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2701 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2702 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2703 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
d9bce9d9 | 2704 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2705 | /* lwaux */ |
0c8aacd4 | 2706 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2707 | /* lwax */ |
0c8aacd4 | 2708 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2709 | /* ldux */ |
0c8aacd4 | 2710 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2711 | /* ldx */ |
0c8aacd4 | 2712 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B); |
99e300ef BS |
2713 | |
2714 | static void gen_ld(DisasContext *ctx) | |
d9bce9d9 | 2715 | { |
b61f2753 | 2716 | TCGv EA; |
d9bce9d9 JM |
2717 | if (Rc(ctx->opcode)) { |
2718 | if (unlikely(rA(ctx->opcode) == 0 || | |
2719 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2720 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2721 | return; |
2722 | } | |
2723 | } | |
76db3ba4 | 2724 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2725 | EA = tcg_temp_new(); |
76db3ba4 | 2726 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2727 | if (ctx->opcode & 0x02) { |
2728 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2729 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2730 | } else { |
2731 | /* ld - ldu */ | |
76db3ba4 | 2732 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2733 | } |
d9bce9d9 | 2734 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2735 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2736 | tcg_temp_free(EA); | |
d9bce9d9 | 2737 | } |
99e300ef | 2738 | |
54623277 | 2739 | /* lq */ |
99e300ef | 2740 | static void gen_lq(DisasContext *ctx) |
be147d08 JM |
2741 | { |
2742 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2743 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2744 | #else |
2745 | int ra, rd; | |
b61f2753 | 2746 | TCGv EA; |
be147d08 JM |
2747 | |
2748 | /* Restore CPU state */ | |
76db3ba4 | 2749 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2750 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2751 | return; |
2752 | } | |
2753 | ra = rA(ctx->opcode); | |
2754 | rd = rD(ctx->opcode); | |
2755 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2756 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2757 | return; |
2758 | } | |
76db3ba4 | 2759 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2760 | /* Little-endian mode is not handled */ |
e06fcd75 | 2761 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2762 | return; |
2763 | } | |
76db3ba4 | 2764 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2765 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2766 | gen_addr_imm_index(ctx, EA, 0x0F); |
2767 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2768 | gen_addr_add(ctx, EA, EA, 8); | |
2769 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
b61f2753 | 2770 | tcg_temp_free(EA); |
be147d08 JM |
2771 | #endif |
2772 | } | |
d9bce9d9 | 2773 | #endif |
79aceca5 FB |
2774 | |
2775 | /*** Integer store ***/ | |
0c8aacd4 | 2776 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2777 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2778 | { \ |
76db3ba4 AJ |
2779 | TCGv EA; \ |
2780 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2781 | EA = tcg_temp_new(); \ | |
2782 | gen_addr_imm_index(ctx, EA, 0); \ | |
2783 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2784 | tcg_temp_free(EA); \ |
79aceca5 FB |
2785 | } |
2786 | ||
0c8aacd4 | 2787 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2788 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2789 | { \ |
b61f2753 | 2790 | TCGv EA; \ |
76a66253 | 2791 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2792 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2793 | return; \ |
9a64fbe4 | 2794 | } \ |
76db3ba4 | 2795 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2796 | EA = tcg_temp_new(); \ |
9d53c753 | 2797 | if (type == PPC_64B) \ |
76db3ba4 | 2798 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2799 | else \ |
76db3ba4 AJ |
2800 | gen_addr_imm_index(ctx, EA, 0); \ |
2801 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2802 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2803 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2804 | } |
2805 | ||
0c8aacd4 | 2806 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2807 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2808 | { \ |
b61f2753 | 2809 | TCGv EA; \ |
76a66253 | 2810 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2811 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2812 | return; \ |
9a64fbe4 | 2813 | } \ |
76db3ba4 | 2814 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2815 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2816 | gen_addr_reg_index(ctx, EA); \ |
2817 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2818 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2819 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2820 | } |
2821 | ||
cd6e9320 TH |
2822 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
2823 | static void glue(gen_, name##x)(DisasContext *ctx) \ | |
79aceca5 | 2824 | { \ |
76db3ba4 AJ |
2825 | TCGv EA; \ |
2826 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2827 | EA = tcg_temp_new(); \ | |
2828 | gen_addr_reg_index(ctx, EA); \ | |
2829 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2830 | tcg_temp_free(EA); \ |
79aceca5 | 2831 | } |
cd6e9320 TH |
2832 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
2833 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2834 | |
0c8aacd4 AJ |
2835 | #define GEN_STS(name, stop, op, type) \ |
2836 | GEN_ST(name, stop, op | 0x20, type); \ | |
2837 | GEN_STU(name, stop, op | 0x21, type); \ | |
2838 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2839 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2840 | |
2841 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2842 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2843 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2844 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2845 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2846 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
d9bce9d9 | 2847 | #if defined(TARGET_PPC64) |
0c8aacd4 AJ |
2848 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B); |
2849 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B); | |
99e300ef BS |
2850 | |
2851 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 2852 | { |
be147d08 | 2853 | int rs; |
b61f2753 | 2854 | TCGv EA; |
be147d08 JM |
2855 | |
2856 | rs = rS(ctx->opcode); | |
2857 | if ((ctx->opcode & 0x3) == 0x2) { | |
2858 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2859 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2860 | #else |
2861 | /* stq */ | |
76db3ba4 | 2862 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2863 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2864 | return; |
2865 | } | |
2866 | if (unlikely(rs & 1)) { | |
e06fcd75 | 2867 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2868 | return; |
2869 | } | |
76db3ba4 | 2870 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2871 | /* Little-endian mode is not handled */ |
e06fcd75 | 2872 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2873 | return; |
2874 | } | |
76db3ba4 | 2875 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2876 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2877 | gen_addr_imm_index(ctx, EA, 0x03); |
2878 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
2879 | gen_addr_add(ctx, EA, EA, 8); | |
2880 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
b61f2753 | 2881 | tcg_temp_free(EA); |
be147d08 JM |
2882 | #endif |
2883 | } else { | |
2884 | /* std / stdu */ | |
2885 | if (Rc(ctx->opcode)) { | |
2886 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 2887 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2888 | return; |
2889 | } | |
2890 | } | |
76db3ba4 | 2891 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2892 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2893 | gen_addr_imm_index(ctx, EA, 0x03); |
2894 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
be147d08 | 2895 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2896 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2897 | tcg_temp_free(EA); | |
d9bce9d9 | 2898 | } |
d9bce9d9 JM |
2899 | } |
2900 | #endif | |
79aceca5 FB |
2901 | /*** Integer load and store with byte reverse ***/ |
2902 | /* lhbrx */ | |
86178a57 | 2903 | static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2904 | { |
76db3ba4 AJ |
2905 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
2906 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2907 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2908 | } |
b61f2753 | 2909 | } |
0c8aacd4 | 2910 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 2911 | |
79aceca5 | 2912 | /* lwbrx */ |
86178a57 | 2913 | static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2914 | { |
76db3ba4 AJ |
2915 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2916 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2917 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2918 | } |
b61f2753 | 2919 | } |
0c8aacd4 | 2920 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 2921 | |
cd6e9320 TH |
2922 | #if defined(TARGET_PPC64) |
2923 | /* ldbrx */ | |
2924 | static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
2925 | { | |
2926 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); | |
2927 | if (likely(!ctx->le_mode)) { | |
2928 | tcg_gen_bswap64_tl(arg1, arg1); | |
2929 | } | |
2930 | } | |
2931 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX); | |
2932 | #endif /* TARGET_PPC64 */ | |
2933 | ||
79aceca5 | 2934 | /* sthbrx */ |
86178a57 | 2935 | static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2936 | { |
76db3ba4 | 2937 | if (likely(!ctx->le_mode)) { |
76db3ba4 AJ |
2938 | TCGv t0 = tcg_temp_new(); |
2939 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2940 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2941 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2942 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2943 | } else { |
2944 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2945 | } | |
b61f2753 | 2946 | } |
0c8aacd4 | 2947 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
b61f2753 | 2948 | |
79aceca5 | 2949 | /* stwbrx */ |
86178a57 | 2950 | static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2951 | { |
76db3ba4 | 2952 | if (likely(!ctx->le_mode)) { |
fa3966a3 AJ |
2953 | TCGv t0 = tcg_temp_new(); |
2954 | tcg_gen_ext32u_tl(t0, arg1); | |
2955 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2956 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2957 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2958 | } else { |
2959 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2960 | } | |
b61f2753 | 2961 | } |
0c8aacd4 | 2962 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 | 2963 | |
cd6e9320 TH |
2964 | #if defined(TARGET_PPC64) |
2965 | /* stdbrx */ | |
2966 | static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
2967 | { | |
2968 | if (likely(!ctx->le_mode)) { | |
2969 | TCGv t0 = tcg_temp_new(); | |
2970 | tcg_gen_bswap64_tl(t0, arg1); | |
2971 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); | |
2972 | tcg_temp_free(t0); | |
2973 | } else { | |
2974 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); | |
2975 | } | |
2976 | } | |
2977 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX); | |
2978 | #endif /* TARGET_PPC64 */ | |
2979 | ||
79aceca5 | 2980 | /*** Integer load and store multiple ***/ |
99e300ef | 2981 | |
54623277 | 2982 | /* lmw */ |
99e300ef | 2983 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 2984 | { |
76db3ba4 AJ |
2985 | TCGv t0; |
2986 | TCGv_i32 t1; | |
2987 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 2988 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 2989 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
2990 | t0 = tcg_temp_new(); |
2991 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
2992 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 2993 | gen_helper_lmw(cpu_env, t0, t1); |
ff4a62cd AJ |
2994 | tcg_temp_free(t0); |
2995 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
2996 | } |
2997 | ||
2998 | /* stmw */ | |
99e300ef | 2999 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 3000 | { |
76db3ba4 AJ |
3001 | TCGv t0; |
3002 | TCGv_i32 t1; | |
3003 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3004 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3005 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3006 | t0 = tcg_temp_new(); |
3007 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
3008 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3009 | gen_helper_stmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3010 | tcg_temp_free(t0); |
3011 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3012 | } |
3013 | ||
3014 | /*** Integer load and store strings ***/ | |
54623277 | 3015 | |
79aceca5 | 3016 | /* lswi */ |
3fc6c082 | 3017 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
3018 | * rA is in the range of registers to be loaded. |
3019 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
3020 | * For now, I'll follow the spec... | |
3021 | */ | |
99e300ef | 3022 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 3023 | { |
dfbc799d AJ |
3024 | TCGv t0; |
3025 | TCGv_i32 t1, t2; | |
79aceca5 FB |
3026 | int nb = NB(ctx->opcode); |
3027 | int start = rD(ctx->opcode); | |
9a64fbe4 | 3028 | int ra = rA(ctx->opcode); |
79aceca5 FB |
3029 | int nr; |
3030 | ||
3031 | if (nb == 0) | |
3032 | nb = 32; | |
3033 | nr = nb / 4; | |
76a66253 JM |
3034 | if (unlikely(((start + nr) > 32 && |
3035 | start <= ra && (start + nr - 32) > ra) || | |
3036 | ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) { | |
e06fcd75 | 3037 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 3038 | return; |
297d8e62 | 3039 | } |
76db3ba4 | 3040 | gen_set_access_type(ctx, ACCESS_INT); |
8dd4983c | 3041 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3042 | gen_update_nip(ctx, ctx->nip - 4); |
dfbc799d | 3043 | t0 = tcg_temp_new(); |
76db3ba4 | 3044 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
3045 | t1 = tcg_const_i32(nb); |
3046 | t2 = tcg_const_i32(start); | |
2f5a189c | 3047 | gen_helper_lsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3048 | tcg_temp_free(t0); |
3049 | tcg_temp_free_i32(t1); | |
3050 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3051 | } |
3052 | ||
3053 | /* lswx */ | |
99e300ef | 3054 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 3055 | { |
76db3ba4 AJ |
3056 | TCGv t0; |
3057 | TCGv_i32 t1, t2, t3; | |
3058 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3059 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3060 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3061 | t0 = tcg_temp_new(); |
3062 | gen_addr_reg_index(ctx, t0); | |
3063 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3064 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
3065 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
2f5a189c | 3066 | gen_helper_lswx(cpu_env, t0, t1, t2, t3); |
dfbc799d AJ |
3067 | tcg_temp_free(t0); |
3068 | tcg_temp_free_i32(t1); | |
3069 | tcg_temp_free_i32(t2); | |
3070 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
3071 | } |
3072 | ||
3073 | /* stswi */ | |
99e300ef | 3074 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 3075 | { |
76db3ba4 AJ |
3076 | TCGv t0; |
3077 | TCGv_i32 t1, t2; | |
4b3686fa | 3078 | int nb = NB(ctx->opcode); |
76db3ba4 | 3079 | gen_set_access_type(ctx, ACCESS_INT); |
76a66253 | 3080 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3081 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3082 | t0 = tcg_temp_new(); |
3083 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
3084 | if (nb == 0) |
3085 | nb = 32; | |
dfbc799d | 3086 | t1 = tcg_const_i32(nb); |
76db3ba4 | 3087 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3088 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3089 | tcg_temp_free(t0); |
3090 | tcg_temp_free_i32(t1); | |
3091 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3092 | } |
3093 | ||
3094 | /* stswx */ | |
99e300ef | 3095 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3096 | { |
76db3ba4 AJ |
3097 | TCGv t0; |
3098 | TCGv_i32 t1, t2; | |
3099 | gen_set_access_type(ctx, ACCESS_INT); | |
8dd4983c | 3100 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5fafdf24 | 3101 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3102 | t0 = tcg_temp_new(); |
3103 | gen_addr_reg_index(ctx, t0); | |
3104 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3105 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3106 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3107 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3108 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3109 | tcg_temp_free(t0); |
3110 | tcg_temp_free_i32(t1); | |
3111 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3112 | } |
3113 | ||
3114 | /*** Memory synchronisation ***/ | |
3115 | /* eieio */ | |
99e300ef | 3116 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3117 | { |
79aceca5 FB |
3118 | } |
3119 | ||
3120 | /* isync */ | |
99e300ef | 3121 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3122 | { |
e06fcd75 | 3123 | gen_stop_exception(ctx); |
79aceca5 FB |
3124 | } |
3125 | ||
111bfab3 | 3126 | /* lwarx */ |
99e300ef | 3127 | static void gen_lwarx(DisasContext *ctx) |
79aceca5 | 3128 | { |
76db3ba4 | 3129 | TCGv t0; |
18b21a2f | 3130 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3131 | gen_set_access_type(ctx, ACCESS_RES); |
3132 | t0 = tcg_temp_local_new(); | |
3133 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3134 | gen_check_align(ctx, t0, 0x03); |
18b21a2f | 3135 | gen_qemu_ld32u(ctx, gpr, t0); |
cf360a32 | 3136 | tcg_gen_mov_tl(cpu_reserve, t0); |
1328c2bf | 3137 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); |
cf360a32 | 3138 | tcg_temp_free(t0); |
79aceca5 FB |
3139 | } |
3140 | ||
4425265b NF |
3141 | #if defined(CONFIG_USER_ONLY) |
3142 | static void gen_conditional_store (DisasContext *ctx, TCGv EA, | |
3143 | int reg, int size) | |
3144 | { | |
3145 | TCGv t0 = tcg_temp_new(); | |
3146 | uint32_t save_exception = ctx->exception; | |
3147 | ||
1328c2bf | 3148 | tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea)); |
4425265b | 3149 | tcg_gen_movi_tl(t0, (size << 5) | reg); |
1328c2bf | 3150 | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info)); |
4425265b NF |
3151 | tcg_temp_free(t0); |
3152 | gen_update_nip(ctx, ctx->nip-4); | |
3153 | ctx->exception = POWERPC_EXCP_BRANCH; | |
3154 | gen_exception(ctx, POWERPC_EXCP_STCX); | |
3155 | ctx->exception = save_exception; | |
3156 | } | |
3157 | #endif | |
3158 | ||
79aceca5 | 3159 | /* stwcx. */ |
e8eaa2c0 | 3160 | static void gen_stwcx_(DisasContext *ctx) |
79aceca5 | 3161 | { |
76db3ba4 AJ |
3162 | TCGv t0; |
3163 | gen_set_access_type(ctx, ACCESS_RES); | |
3164 | t0 = tcg_temp_local_new(); | |
3165 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3166 | gen_check_align(ctx, t0, 0x03); |
4425265b NF |
3167 | #if defined(CONFIG_USER_ONLY) |
3168 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 4); | |
3169 | #else | |
3170 | { | |
3171 | int l1; | |
3172 | ||
3173 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3174 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3175 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3176 | l1 = gen_new_label(); | |
3177 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3178 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3179 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3180 | gen_set_label(l1); | |
3181 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3182 | } | |
3183 | #endif | |
cf360a32 | 3184 | tcg_temp_free(t0); |
79aceca5 FB |
3185 | } |
3186 | ||
426613db | 3187 | #if defined(TARGET_PPC64) |
426613db | 3188 | /* ldarx */ |
99e300ef | 3189 | static void gen_ldarx(DisasContext *ctx) |
426613db | 3190 | { |
76db3ba4 | 3191 | TCGv t0; |
18b21a2f | 3192 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3193 | gen_set_access_type(ctx, ACCESS_RES); |
3194 | t0 = tcg_temp_local_new(); | |
3195 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3196 | gen_check_align(ctx, t0, 0x07); |
18b21a2f | 3197 | gen_qemu_ld64(ctx, gpr, t0); |
cf360a32 | 3198 | tcg_gen_mov_tl(cpu_reserve, t0); |
1328c2bf | 3199 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); |
cf360a32 | 3200 | tcg_temp_free(t0); |
426613db JM |
3201 | } |
3202 | ||
3203 | /* stdcx. */ | |
e8eaa2c0 | 3204 | static void gen_stdcx_(DisasContext *ctx) |
426613db | 3205 | { |
76db3ba4 AJ |
3206 | TCGv t0; |
3207 | gen_set_access_type(ctx, ACCESS_RES); | |
3208 | t0 = tcg_temp_local_new(); | |
3209 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3210 | gen_check_align(ctx, t0, 0x07); |
4425265b NF |
3211 | #if defined(CONFIG_USER_ONLY) |
3212 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 8); | |
3213 | #else | |
3214 | { | |
3215 | int l1; | |
3216 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3217 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3218 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3219 | l1 = gen_new_label(); | |
3220 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3221 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3222 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3223 | gen_set_label(l1); | |
3224 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3225 | } | |
3226 | #endif | |
cf360a32 | 3227 | tcg_temp_free(t0); |
426613db JM |
3228 | } |
3229 | #endif /* defined(TARGET_PPC64) */ | |
3230 | ||
79aceca5 | 3231 | /* sync */ |
99e300ef | 3232 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3233 | { |
79aceca5 FB |
3234 | } |
3235 | ||
0db1b20e | 3236 | /* wait */ |
99e300ef | 3237 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3238 | { |
931ff272 | 3239 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1328c2bf | 3240 | tcg_gen_st_i32(t0, cpu_env, offsetof(CPUPPCState, halted)); |
931ff272 | 3241 | tcg_temp_free_i32(t0); |
0db1b20e | 3242 | /* Stop translation, as the CPU is supposed to sleep from now */ |
e06fcd75 | 3243 | gen_exception_err(ctx, EXCP_HLT, 1); |
0db1b20e JM |
3244 | } |
3245 | ||
79aceca5 | 3246 | /*** Floating-point load ***/ |
a0d7d5a7 | 3247 | #define GEN_LDF(name, ldop, opc, type) \ |
99e300ef | 3248 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3249 | { \ |
a0d7d5a7 | 3250 | TCGv EA; \ |
76a66253 | 3251 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3252 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3253 | return; \ |
3254 | } \ | |
76db3ba4 | 3255 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3256 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3257 | gen_addr_imm_index(ctx, EA, 0); \ |
3258 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3259 | tcg_temp_free(EA); \ |
79aceca5 FB |
3260 | } |
3261 | ||
a0d7d5a7 | 3262 | #define GEN_LDUF(name, ldop, opc, type) \ |
99e300ef | 3263 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3264 | { \ |
a0d7d5a7 | 3265 | TCGv EA; \ |
76a66253 | 3266 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3267 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3268 | return; \ |
3269 | } \ | |
76a66253 | 3270 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3271 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3272 | return; \ |
9a64fbe4 | 3273 | } \ |
76db3ba4 | 3274 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3275 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3276 | gen_addr_imm_index(ctx, EA, 0); \ |
3277 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3278 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3279 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3280 | } |
3281 | ||
a0d7d5a7 | 3282 | #define GEN_LDUXF(name, ldop, opc, type) \ |
99e300ef | 3283 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3284 | { \ |
a0d7d5a7 | 3285 | TCGv EA; \ |
76a66253 | 3286 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3287 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3288 | return; \ |
3289 | } \ | |
76a66253 | 3290 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3291 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3292 | return; \ |
9a64fbe4 | 3293 | } \ |
76db3ba4 | 3294 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3295 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3296 | gen_addr_reg_index(ctx, EA); \ |
3297 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3298 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3299 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3300 | } |
3301 | ||
a0d7d5a7 | 3302 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ |
99e300ef | 3303 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3304 | { \ |
a0d7d5a7 | 3305 | TCGv EA; \ |
76a66253 | 3306 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3307 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3308 | return; \ |
3309 | } \ | |
76db3ba4 | 3310 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3311 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3312 | gen_addr_reg_index(ctx, EA); \ |
3313 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3314 | tcg_temp_free(EA); \ |
79aceca5 FB |
3315 | } |
3316 | ||
a0d7d5a7 AJ |
3317 | #define GEN_LDFS(name, ldop, op, type) \ |
3318 | GEN_LDF(name, ldop, op | 0x20, type); \ | |
3319 | GEN_LDUF(name, ldop, op | 0x21, type); \ | |
3320 | GEN_LDUXF(name, ldop, op | 0x01, type); \ | |
3321 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
3322 | ||
636aa200 | 3323 | static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3324 | { |
3325 | TCGv t0 = tcg_temp_new(); | |
3326 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
76db3ba4 | 3327 | gen_qemu_ld32u(ctx, t0, arg2); |
a0d7d5a7 AJ |
3328 | tcg_gen_trunc_tl_i32(t1, t0); |
3329 | tcg_temp_free(t0); | |
8e703949 | 3330 | gen_helper_float32_to_float64(arg1, cpu_env, t1); |
a0d7d5a7 AJ |
3331 | tcg_temp_free_i32(t1); |
3332 | } | |
79aceca5 | 3333 | |
a0d7d5a7 AJ |
3334 | /* lfd lfdu lfdux lfdx */ |
3335 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT); | |
3336 | /* lfs lfsu lfsux lfsx */ | |
3337 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT); | |
79aceca5 FB |
3338 | |
3339 | /*** Floating-point store ***/ | |
a0d7d5a7 | 3340 | #define GEN_STF(name, stop, opc, type) \ |
99e300ef | 3341 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3342 | { \ |
a0d7d5a7 | 3343 | TCGv EA; \ |
76a66253 | 3344 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3345 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3346 | return; \ |
3347 | } \ | |
76db3ba4 | 3348 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3349 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3350 | gen_addr_imm_index(ctx, EA, 0); \ |
3351 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3352 | tcg_temp_free(EA); \ |
79aceca5 FB |
3353 | } |
3354 | ||
a0d7d5a7 | 3355 | #define GEN_STUF(name, stop, opc, type) \ |
99e300ef | 3356 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3357 | { \ |
a0d7d5a7 | 3358 | TCGv EA; \ |
76a66253 | 3359 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3360 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3361 | return; \ |
3362 | } \ | |
76a66253 | 3363 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3364 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3365 | return; \ |
9a64fbe4 | 3366 | } \ |
76db3ba4 | 3367 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3368 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3369 | gen_addr_imm_index(ctx, EA, 0); \ |
3370 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3371 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3372 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3373 | } |
3374 | ||
a0d7d5a7 | 3375 | #define GEN_STUXF(name, stop, opc, type) \ |
99e300ef | 3376 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3377 | { \ |
a0d7d5a7 | 3378 | TCGv EA; \ |
76a66253 | 3379 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3380 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3381 | return; \ |
3382 | } \ | |
76a66253 | 3383 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3384 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3385 | return; \ |
9a64fbe4 | 3386 | } \ |
76db3ba4 | 3387 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3388 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3389 | gen_addr_reg_index(ctx, EA); \ |
3390 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3391 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3392 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3393 | } |
3394 | ||
a0d7d5a7 | 3395 | #define GEN_STXF(name, stop, opc2, opc3, type) \ |
99e300ef | 3396 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3397 | { \ |
a0d7d5a7 | 3398 | TCGv EA; \ |
76a66253 | 3399 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3400 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3401 | return; \ |
3402 | } \ | |
76db3ba4 | 3403 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3404 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3405 | gen_addr_reg_index(ctx, EA); \ |
3406 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3407 | tcg_temp_free(EA); \ |
79aceca5 FB |
3408 | } |
3409 | ||
a0d7d5a7 AJ |
3410 | #define GEN_STFS(name, stop, op, type) \ |
3411 | GEN_STF(name, stop, op | 0x20, type); \ | |
3412 | GEN_STUF(name, stop, op | 0x21, type); \ | |
3413 | GEN_STUXF(name, stop, op | 0x01, type); \ | |
3414 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
3415 | ||
636aa200 | 3416 | static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3417 | { |
3418 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
3419 | TCGv t1 = tcg_temp_new(); | |
8e703949 | 3420 | gen_helper_float64_to_float32(t0, cpu_env, arg1); |
a0d7d5a7 AJ |
3421 | tcg_gen_extu_i32_tl(t1, t0); |
3422 | tcg_temp_free_i32(t0); | |
76db3ba4 | 3423 | gen_qemu_st32(ctx, t1, arg2); |
a0d7d5a7 AJ |
3424 | tcg_temp_free(t1); |
3425 | } | |
79aceca5 FB |
3426 | |
3427 | /* stfd stfdu stfdux stfdx */ | |
a0d7d5a7 | 3428 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT); |
79aceca5 | 3429 | /* stfs stfsu stfsux stfsx */ |
a0d7d5a7 | 3430 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT); |
79aceca5 FB |
3431 | |
3432 | /* Optional: */ | |
636aa200 | 3433 | static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3434 | { |
3435 | TCGv t0 = tcg_temp_new(); | |
3436 | tcg_gen_trunc_i64_tl(t0, arg1), | |
76db3ba4 | 3437 | gen_qemu_st32(ctx, t0, arg2); |
a0d7d5a7 AJ |
3438 | tcg_temp_free(t0); |
3439 | } | |
79aceca5 | 3440 | /* stfiwx */ |
a0d7d5a7 | 3441 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
79aceca5 | 3442 | |
697ab892 DG |
3443 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3444 | { | |
3445 | #if defined(TARGET_PPC64) | |
3446 | if (ctx->has_cfar) | |
3447 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3448 | #endif | |
3449 | } | |
3450 | ||
79aceca5 | 3451 | /*** Branch ***/ |
636aa200 | 3452 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 FB |
3453 | { |
3454 | TranslationBlock *tb; | |
3455 | tb = ctx->tb; | |
a2ffb812 AJ |
3456 | #if defined(TARGET_PPC64) |
3457 | if (!ctx->sf_mode) | |
3458 | dest = (uint32_t) dest; | |
3459 | #endif | |
57fec1fe | 3460 | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && |
8cbcb4fa | 3461 | likely(!ctx->singlestep_enabled)) { |
57fec1fe | 3462 | tcg_gen_goto_tb(n); |
a2ffb812 | 3463 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
4b4a72e5 | 3464 | tcg_gen_exit_tb((tcg_target_long)tb + n); |
c1942362 | 3465 | } else { |
a2ffb812 | 3466 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cbcb4fa AJ |
3467 | if (unlikely(ctx->singlestep_enabled)) { |
3468 | if ((ctx->singlestep_enabled & | |
bdc4e053 | 3469 | (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) && |
f0cc4aa8 JG |
3470 | (ctx->exception == POWERPC_EXCP_BRANCH || |
3471 | ctx->exception == POWERPC_EXCP_TRACE)) { | |
8cbcb4fa AJ |
3472 | target_ulong tmp = ctx->nip; |
3473 | ctx->nip = dest; | |
e06fcd75 | 3474 | gen_exception(ctx, POWERPC_EXCP_TRACE); |
8cbcb4fa AJ |
3475 | ctx->nip = tmp; |
3476 | } | |
3477 | if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) { | |
e06fcd75 | 3478 | gen_debug_exception(ctx); |
8cbcb4fa AJ |
3479 | } |
3480 | } | |
57fec1fe | 3481 | tcg_gen_exit_tb(0); |
c1942362 | 3482 | } |
c53be334 FB |
3483 | } |
3484 | ||
636aa200 | 3485 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f JM |
3486 | { |
3487 | #if defined(TARGET_PPC64) | |
a2ffb812 AJ |
3488 | if (ctx->sf_mode == 0) |
3489 | tcg_gen_movi_tl(cpu_lr, (uint32_t)nip); | |
e1833e1f JM |
3490 | else |
3491 | #endif | |
a2ffb812 | 3492 | tcg_gen_movi_tl(cpu_lr, nip); |
e1833e1f JM |
3493 | } |
3494 | ||
79aceca5 | 3495 | /* b ba bl bla */ |
99e300ef | 3496 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3497 | { |
76a66253 | 3498 | target_ulong li, target; |
38a64f9d | 3499 | |
8cbcb4fa | 3500 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3501 | /* sign extend LI */ |
76a66253 | 3502 | #if defined(TARGET_PPC64) |
d9bce9d9 JM |
3503 | if (ctx->sf_mode) |
3504 | li = ((int64_t)LI(ctx->opcode) << 38) >> 38; | |
3505 | else | |
76a66253 | 3506 | #endif |
d9bce9d9 | 3507 | li = ((int32_t)LI(ctx->opcode) << 6) >> 6; |
76a66253 | 3508 | if (likely(AA(ctx->opcode) == 0)) |
046d6672 | 3509 | target = ctx->nip + li - 4; |
79aceca5 | 3510 | else |
9a64fbe4 | 3511 | target = li; |
e1833e1f JM |
3512 | if (LK(ctx->opcode)) |
3513 | gen_setlr(ctx, ctx->nip); | |
697ab892 | 3514 | gen_update_cfar(ctx, ctx->nip); |
c1942362 | 3515 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3516 | } |
3517 | ||
e98a6e40 FB |
3518 | #define BCOND_IM 0 |
3519 | #define BCOND_LR 1 | |
3520 | #define BCOND_CTR 2 | |
3521 | ||
636aa200 | 3522 | static inline void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3523 | { |
d9bce9d9 | 3524 | uint32_t bo = BO(ctx->opcode); |
05f92404 | 3525 | int l1; |
a2ffb812 | 3526 | TCGv target; |
e98a6e40 | 3527 | |
8cbcb4fa | 3528 | ctx->exception = POWERPC_EXCP_BRANCH; |
a2ffb812 | 3529 | if (type == BCOND_LR || type == BCOND_CTR) { |
a7812ae4 | 3530 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3531 | if (type == BCOND_CTR) |
3532 | tcg_gen_mov_tl(target, cpu_ctr); | |
3533 | else | |
3534 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3535 | } else { |
3536 | TCGV_UNUSED(target); | |
e98a6e40 | 3537 | } |
e1833e1f JM |
3538 | if (LK(ctx->opcode)) |
3539 | gen_setlr(ctx, ctx->nip); | |
a2ffb812 AJ |
3540 | l1 = gen_new_label(); |
3541 | if ((bo & 0x4) == 0) { | |
3542 | /* Decrement and test CTR */ | |
a7812ae4 | 3543 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3544 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3545 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3546 | return; |
3547 | } | |
3548 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
d9bce9d9 | 3549 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3550 | if (!ctx->sf_mode) |
3551 | tcg_gen_ext32u_tl(temp, cpu_ctr); | |
3552 | else | |
d9bce9d9 | 3553 | #endif |
a2ffb812 AJ |
3554 | tcg_gen_mov_tl(temp, cpu_ctr); |
3555 | if (bo & 0x2) { | |
3556 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3557 | } else { | |
3558 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3559 | } |
a7812ae4 | 3560 | tcg_temp_free(temp); |
a2ffb812 AJ |
3561 | } |
3562 | if ((bo & 0x10) == 0) { | |
3563 | /* Test CR */ | |
3564 | uint32_t bi = BI(ctx->opcode); | |
3565 | uint32_t mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 3566 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3567 | |
d9bce9d9 | 3568 | if (bo & 0x8) { |
a2ffb812 AJ |
3569 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3570 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3571 | } else { |
a2ffb812 AJ |
3572 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3573 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3574 | } |
a7812ae4 | 3575 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3576 | } |
697ab892 | 3577 | gen_update_cfar(ctx, ctx->nip); |
e98a6e40 | 3578 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3579 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3580 | if (likely(AA(ctx->opcode) == 0)) { | |
3581 | gen_goto_tb(ctx, 0, ctx->nip + li - 4); | |
3582 | } else { | |
3583 | gen_goto_tb(ctx, 0, li); | |
3584 | } | |
c53be334 | 3585 | gen_set_label(l1); |
c1942362 | 3586 | gen_goto_tb(ctx, 1, ctx->nip); |
e98a6e40 | 3587 | } else { |
d9bce9d9 | 3588 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3589 | if (!(ctx->sf_mode)) |
3590 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); | |
3591 | else | |
3592 | #endif | |
3593 | tcg_gen_andi_tl(cpu_nip, target, ~3); | |
3594 | tcg_gen_exit_tb(0); | |
3595 | gen_set_label(l1); | |
3596 | #if defined(TARGET_PPC64) | |
3597 | if (!(ctx->sf_mode)) | |
3598 | tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip); | |
d9bce9d9 JM |
3599 | else |
3600 | #endif | |
a2ffb812 | 3601 | tcg_gen_movi_tl(cpu_nip, ctx->nip); |
57fec1fe | 3602 | tcg_gen_exit_tb(0); |
08e46e54 | 3603 | } |
e98a6e40 FB |
3604 | } |
3605 | ||
99e300ef | 3606 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3607 | { |
e98a6e40 FB |
3608 | gen_bcond(ctx, BCOND_IM); |
3609 | } | |
3610 | ||
99e300ef | 3611 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3612 | { |
e98a6e40 FB |
3613 | gen_bcond(ctx, BCOND_CTR); |
3614 | } | |
3615 | ||
99e300ef | 3616 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3617 | { |
e98a6e40 FB |
3618 | gen_bcond(ctx, BCOND_LR); |
3619 | } | |
79aceca5 FB |
3620 | |
3621 | /*** Condition register logical ***/ | |
e1571908 | 3622 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3623 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3624 | { \ |
fc0d441e JM |
3625 | uint8_t bitmask; \ |
3626 | int sh; \ | |
a7812ae4 | 3627 | TCGv_i32 t0, t1; \ |
fc0d441e | 3628 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3629 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3630 | if (sh > 0) \ |
fea0c503 | 3631 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3632 | else if (sh < 0) \ |
fea0c503 | 3633 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3634 | else \ |
fea0c503 | 3635 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3636 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3637 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3638 | if (sh > 0) \ | |
fea0c503 | 3639 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3640 | else if (sh < 0) \ |
fea0c503 | 3641 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3642 | else \ |
fea0c503 AJ |
3643 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3644 | tcg_op(t0, t0, t1); \ | |
fc0d441e | 3645 | bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \ |
fea0c503 AJ |
3646 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3647 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3648 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3649 | tcg_temp_free_i32(t0); \ |
3650 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3651 | } |
3652 | ||
3653 | /* crand */ | |
e1571908 | 3654 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3655 | /* crandc */ |
e1571908 | 3656 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3657 | /* creqv */ |
e1571908 | 3658 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3659 | /* crnand */ |
e1571908 | 3660 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3661 | /* crnor */ |
e1571908 | 3662 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3663 | /* cror */ |
e1571908 | 3664 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3665 | /* crorc */ |
e1571908 | 3666 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3667 | /* crxor */ |
e1571908 | 3668 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3669 | |
54623277 | 3670 | /* mcrf */ |
99e300ef | 3671 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3672 | { |
47e4661c | 3673 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3674 | } |
3675 | ||
3676 | /*** System linkage ***/ | |
99e300ef | 3677 | |
54623277 | 3678 | /* rfi (mem_idx only) */ |
99e300ef | 3679 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 3680 | { |
9a64fbe4 | 3681 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3682 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 FB |
3683 | #else |
3684 | /* Restore CPU state */ | |
76db3ba4 | 3685 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3686 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 3687 | return; |
9a64fbe4 | 3688 | } |
697ab892 | 3689 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3690 | gen_helper_rfi(cpu_env); |
e06fcd75 | 3691 | gen_sync_exception(ctx); |
9a64fbe4 | 3692 | #endif |
79aceca5 FB |
3693 | } |
3694 | ||
426613db | 3695 | #if defined(TARGET_PPC64) |
99e300ef | 3696 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
3697 | { |
3698 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3699 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3700 | #else |
3701 | /* Restore CPU state */ | |
76db3ba4 | 3702 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3703 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3704 | return; |
3705 | } | |
697ab892 | 3706 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3707 | gen_helper_rfid(cpu_env); |
e06fcd75 | 3708 | gen_sync_exception(ctx); |
426613db JM |
3709 | #endif |
3710 | } | |
426613db | 3711 | |
99e300ef | 3712 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
3713 | { |
3714 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3715 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3716 | #else |
3717 | /* Restore CPU state */ | |
76db3ba4 | 3718 | if (unlikely(ctx->mem_idx <= 1)) { |
e06fcd75 | 3719 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3720 | return; |
3721 | } | |
e5f17ac6 | 3722 | gen_helper_hrfid(cpu_env); |
e06fcd75 | 3723 | gen_sync_exception(ctx); |
be147d08 JM |
3724 | #endif |
3725 | } | |
3726 | #endif | |
3727 | ||
79aceca5 | 3728 | /* sc */ |
417bf010 JM |
3729 | #if defined(CONFIG_USER_ONLY) |
3730 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
3731 | #else | |
3732 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
3733 | #endif | |
99e300ef | 3734 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 3735 | { |
e1833e1f JM |
3736 | uint32_t lev; |
3737 | ||
3738 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 3739 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
3740 | } |
3741 | ||
3742 | /*** Trap ***/ | |
99e300ef | 3743 | |
54623277 | 3744 | /* tw */ |
99e300ef | 3745 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 3746 | { |
cab3bee2 | 3747 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3748 | /* Update the nip since this might generate a trap exception */ |
3749 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3750 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3751 | t0); | |
cab3bee2 | 3752 | tcg_temp_free_i32(t0); |
79aceca5 FB |
3753 | } |
3754 | ||
3755 | /* twi */ | |
99e300ef | 3756 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 3757 | { |
cab3bee2 AJ |
3758 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3759 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3760 | /* Update the nip since this might generate a trap exception */ |
3761 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3762 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3763 | tcg_temp_free(t0); |
3764 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3765 | } |
3766 | ||
d9bce9d9 JM |
3767 | #if defined(TARGET_PPC64) |
3768 | /* td */ | |
99e300ef | 3769 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 3770 | { |
cab3bee2 | 3771 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3772 | /* Update the nip since this might generate a trap exception */ |
3773 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3774 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3775 | t0); | |
cab3bee2 | 3776 | tcg_temp_free_i32(t0); |
d9bce9d9 JM |
3777 | } |
3778 | ||
3779 | /* tdi */ | |
99e300ef | 3780 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 3781 | { |
cab3bee2 AJ |
3782 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3783 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3784 | /* Update the nip since this might generate a trap exception */ |
3785 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3786 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3787 | tcg_temp_free(t0); |
3788 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
3789 | } |
3790 | #endif | |
3791 | ||
79aceca5 | 3792 | /*** Processor control ***/ |
99e300ef | 3793 | |
54623277 | 3794 | /* mcrxr */ |
99e300ef | 3795 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 3796 | { |
3d7b417e AJ |
3797 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer); |
3798 | tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA); | |
269f3e95 | 3799 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA)); |
79aceca5 FB |
3800 | } |
3801 | ||
0cfe11ea | 3802 | /* mfcr mfocrf */ |
99e300ef | 3803 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 3804 | { |
76a66253 | 3805 | uint32_t crm, crn; |
3b46e624 | 3806 | |
76a66253 JM |
3807 | if (likely(ctx->opcode & 0x00100000)) { |
3808 | crm = CRM(ctx->opcode); | |
8dd640e4 | 3809 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 3810 | crn = ctz32 (crm); |
e1571908 | 3811 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
3812 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
3813 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 3814 | } |
d9bce9d9 | 3815 | } else { |
651721b2 AJ |
3816 | TCGv_i32 t0 = tcg_temp_new_i32(); |
3817 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
3818 | tcg_gen_shli_i32(t0, t0, 4); | |
3819 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
3820 | tcg_gen_shli_i32(t0, t0, 4); | |
3821 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
3822 | tcg_gen_shli_i32(t0, t0, 4); | |
3823 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
3824 | tcg_gen_shli_i32(t0, t0, 4); | |
3825 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
3826 | tcg_gen_shli_i32(t0, t0, 4); | |
3827 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
3828 | tcg_gen_shli_i32(t0, t0, 4); | |
3829 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
3830 | tcg_gen_shli_i32(t0, t0, 4); | |
3831 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
3832 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
3833 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 3834 | } |
79aceca5 FB |
3835 | } |
3836 | ||
3837 | /* mfmsr */ | |
99e300ef | 3838 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 3839 | { |
9a64fbe4 | 3840 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3841 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3842 | #else |
76db3ba4 | 3843 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3844 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3845 | return; |
9a64fbe4 | 3846 | } |
6527f6ea | 3847 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
9a64fbe4 | 3848 | #endif |
79aceca5 FB |
3849 | } |
3850 | ||
7b13448f | 3851 | static void spr_noaccess(void *opaque, int gprn, int sprn) |
3fc6c082 | 3852 | { |
7b13448f | 3853 | #if 0 |
3fc6c082 FB |
3854 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
3855 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 3856 | #endif |
3fc6c082 FB |
3857 | } |
3858 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 3859 | |
79aceca5 | 3860 | /* mfspr */ |
636aa200 | 3861 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 3862 | { |
45d827d2 | 3863 | void (*read_cb)(void *opaque, int gprn, int sprn); |
79aceca5 FB |
3864 | uint32_t sprn = SPR(ctx->opcode); |
3865 | ||
3fc6c082 | 3866 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 3867 | if (ctx->mem_idx == 2) |
be147d08 | 3868 | read_cb = ctx->spr_cb[sprn].hea_read; |
76db3ba4 | 3869 | else if (ctx->mem_idx) |
3fc6c082 FB |
3870 | read_cb = ctx->spr_cb[sprn].oea_read; |
3871 | else | |
9a64fbe4 | 3872 | #endif |
3fc6c082 | 3873 | read_cb = ctx->spr_cb[sprn].uea_read; |
76a66253 JM |
3874 | if (likely(read_cb != NULL)) { |
3875 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 3876 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
3877 | } else { |
3878 | /* Privilege exception */ | |
9fceefa7 JM |
3879 | /* This is a hack to avoid warnings when running Linux: |
3880 | * this OS breaks the PowerPC virtualisation model, | |
3881 | * allowing userland application to read the PVR | |
3882 | */ | |
3883 | if (sprn != SPR_PVR) { | |
93fcfe39 | 3884 | qemu_log("Trying to read privileged spr %d %03x at " |
90e189ec BS |
3885 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3886 | printf("Trying to read privileged spr %d %03x at " | |
3887 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); | |
f24e5695 | 3888 | } |
e06fcd75 | 3889 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 3890 | } |
3fc6c082 FB |
3891 | } else { |
3892 | /* Not defined */ | |
93fcfe39 | 3893 | qemu_log("Trying to read invalid spr %d %03x at " |
90e189ec BS |
3894 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3895 | printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 3896 | sprn, sprn, ctx->nip); |
e06fcd75 | 3897 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 3898 | } |
79aceca5 FB |
3899 | } |
3900 | ||
99e300ef | 3901 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 3902 | { |
3fc6c082 | 3903 | gen_op_mfspr(ctx); |
76a66253 | 3904 | } |
3fc6c082 FB |
3905 | |
3906 | /* mftb */ | |
99e300ef | 3907 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
3908 | { |
3909 | gen_op_mfspr(ctx); | |
79aceca5 FB |
3910 | } |
3911 | ||
0cfe11ea | 3912 | /* mtcrf mtocrf*/ |
99e300ef | 3913 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 3914 | { |
76a66253 | 3915 | uint32_t crm, crn; |
3b46e624 | 3916 | |
76a66253 | 3917 | crm = CRM(ctx->opcode); |
8dd640e4 | 3918 | if (likely((ctx->opcode & 0x00100000))) { |
3919 | if (crm && ((crm & (crm - 1)) == 0)) { | |
3920 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 3921 | crn = ctz32 (crm); |
8dd640e4 | 3922 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
3923 | tcg_gen_shri_i32(temp, temp, crn * 4); |
3924 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 3925 | tcg_temp_free_i32(temp); |
3926 | } | |
76a66253 | 3927 | } else { |
651721b2 AJ |
3928 | TCGv_i32 temp = tcg_temp_new_i32(); |
3929 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
3930 | for (crn = 0 ; crn < 8 ; crn++) { | |
3931 | if (crm & (1 << crn)) { | |
3932 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
3933 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
3934 | } | |
3935 | } | |
a7812ae4 | 3936 | tcg_temp_free_i32(temp); |
76a66253 | 3937 | } |
79aceca5 FB |
3938 | } |
3939 | ||
3940 | /* mtmsr */ | |
426613db | 3941 | #if defined(TARGET_PPC64) |
99e300ef | 3942 | static void gen_mtmsrd(DisasContext *ctx) |
426613db JM |
3943 | { |
3944 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3945 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db | 3946 | #else |
76db3ba4 | 3947 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3948 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db JM |
3949 | return; |
3950 | } | |
be147d08 JM |
3951 | if (ctx->opcode & 0x00010000) { |
3952 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3953 | TCGv t0 = tcg_temp_new(); |
3954 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3955 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3956 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3957 | tcg_temp_free(t0); | |
be147d08 | 3958 | } else { |
056b05f8 JM |
3959 | /* XXX: we need to update nip before the store |
3960 | * if we enter power saving mode, we will exit the loop | |
3961 | * directly from ppc_store_msr | |
3962 | */ | |
be147d08 | 3963 | gen_update_nip(ctx, ctx->nip); |
e5f17ac6 | 3964 | gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
3965 | /* Must stop the translation as machine state (may have) changed */ |
3966 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 3967 | gen_stop_exception(ctx); |
be147d08 | 3968 | } |
426613db JM |
3969 | #endif |
3970 | } | |
3971 | #endif | |
3972 | ||
99e300ef | 3973 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 3974 | { |
9a64fbe4 | 3975 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3976 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3977 | #else |
76db3ba4 | 3978 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3979 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3980 | return; |
9a64fbe4 | 3981 | } |
be147d08 JM |
3982 | if (ctx->opcode & 0x00010000) { |
3983 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3984 | TCGv t0 = tcg_temp_new(); |
3985 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3986 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3987 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3988 | tcg_temp_free(t0); | |
be147d08 | 3989 | } else { |
8018dc63 AG |
3990 | TCGv msr = tcg_temp_new(); |
3991 | ||
056b05f8 JM |
3992 | /* XXX: we need to update nip before the store |
3993 | * if we enter power saving mode, we will exit the loop | |
3994 | * directly from ppc_store_msr | |
3995 | */ | |
be147d08 | 3996 | gen_update_nip(ctx, ctx->nip); |
d9bce9d9 | 3997 | #if defined(TARGET_PPC64) |
8018dc63 AG |
3998 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
3999 | #else | |
4000 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 4001 | #endif |
e5f17ac6 | 4002 | gen_helper_store_msr(cpu_env, msr); |
be147d08 | 4003 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 4004 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 4005 | gen_stop_exception(ctx); |
be147d08 | 4006 | } |
9a64fbe4 | 4007 | #endif |
79aceca5 FB |
4008 | } |
4009 | ||
4010 | /* mtspr */ | |
99e300ef | 4011 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 4012 | { |
45d827d2 | 4013 | void (*write_cb)(void *opaque, int sprn, int gprn); |
79aceca5 FB |
4014 | uint32_t sprn = SPR(ctx->opcode); |
4015 | ||
3fc6c082 | 4016 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4017 | if (ctx->mem_idx == 2) |
be147d08 | 4018 | write_cb = ctx->spr_cb[sprn].hea_write; |
76db3ba4 | 4019 | else if (ctx->mem_idx) |
3fc6c082 FB |
4020 | write_cb = ctx->spr_cb[sprn].oea_write; |
4021 | else | |
9a64fbe4 | 4022 | #endif |
3fc6c082 | 4023 | write_cb = ctx->spr_cb[sprn].uea_write; |
76a66253 JM |
4024 | if (likely(write_cb != NULL)) { |
4025 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 4026 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
4027 | } else { |
4028 | /* Privilege exception */ | |
93fcfe39 | 4029 | qemu_log("Trying to write privileged spr %d %03x at " |
90e189ec BS |
4030 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
4031 | printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx | |
4032 | "\n", sprn, sprn, ctx->nip); | |
e06fcd75 | 4033 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 4034 | } |
3fc6c082 FB |
4035 | } else { |
4036 | /* Not defined */ | |
93fcfe39 | 4037 | qemu_log("Trying to write invalid spr %d %03x at " |
90e189ec BS |
4038 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
4039 | printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 4040 | sprn, sprn, ctx->nip); |
e06fcd75 | 4041 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4042 | } |
79aceca5 FB |
4043 | } |
4044 | ||
4045 | /*** Cache management ***/ | |
99e300ef | 4046 | |
54623277 | 4047 | /* dcbf */ |
99e300ef | 4048 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 4049 | { |
dac454af | 4050 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
4051 | TCGv t0; |
4052 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4053 | t0 = tcg_temp_new(); | |
4054 | gen_addr_reg_index(ctx, t0); | |
4055 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4056 | tcg_temp_free(t0); |
79aceca5 FB |
4057 | } |
4058 | ||
4059 | /* dcbi (Supervisor only) */ | |
99e300ef | 4060 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4061 | { |
a541f297 | 4062 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4063 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a541f297 | 4064 | #else |
b61f2753 | 4065 | TCGv EA, val; |
76db3ba4 | 4066 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4067 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4068 | return; |
9a64fbe4 | 4069 | } |
a7812ae4 | 4070 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4071 | gen_set_access_type(ctx, ACCESS_CACHE); |
4072 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4073 | val = tcg_temp_new(); |
76a66253 | 4074 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4075 | gen_qemu_ld8u(ctx, val, EA); |
4076 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4077 | tcg_temp_free(val); |
4078 | tcg_temp_free(EA); | |
a541f297 | 4079 | #endif |
79aceca5 FB |
4080 | } |
4081 | ||
4082 | /* dcdst */ | |
99e300ef | 4083 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4084 | { |
76a66253 | 4085 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4086 | TCGv t0; |
4087 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4088 | t0 = tcg_temp_new(); | |
4089 | gen_addr_reg_index(ctx, t0); | |
4090 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4091 | tcg_temp_free(t0); |
79aceca5 FB |
4092 | } |
4093 | ||
4094 | /* dcbt */ | |
99e300ef | 4095 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4096 | { |
0db1b20e | 4097 | /* interpreted as no-op */ |
76a66253 JM |
4098 | /* XXX: specification say this is treated as a load by the MMU |
4099 | * but does not generate any exception | |
4100 | */ | |
79aceca5 FB |
4101 | } |
4102 | ||
4103 | /* dcbtst */ | |
99e300ef | 4104 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4105 | { |
0db1b20e | 4106 | /* interpreted as no-op */ |
76a66253 JM |
4107 | /* XXX: specification say this is treated as a load by the MMU |
4108 | * but does not generate any exception | |
4109 | */ | |
79aceca5 FB |
4110 | } |
4111 | ||
4112 | /* dcbz */ | |
99e300ef | 4113 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4114 | { |
8e33944f AG |
4115 | TCGv tcgv_addr; |
4116 | TCGv_i32 tcgv_is_dcbzl; | |
4117 | int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0; | |
d63001d1 | 4118 | |
76db3ba4 | 4119 | gen_set_access_type(ctx, ACCESS_CACHE); |
799a8c8d AJ |
4120 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4121 | gen_update_nip(ctx, ctx->nip - 4); | |
8e33944f AG |
4122 | tcgv_addr = tcg_temp_new(); |
4123 | tcgv_is_dcbzl = tcg_const_i32(is_dcbzl); | |
4124 | ||
4125 | gen_addr_reg_index(ctx, tcgv_addr); | |
4126 | gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl); | |
4127 | ||
4128 | tcg_temp_free(tcgv_addr); | |
4129 | tcg_temp_free_i32(tcgv_is_dcbzl); | |
79aceca5 FB |
4130 | } |
4131 | ||
ae1c1a3d | 4132 | /* dst / dstt */ |
99e300ef | 4133 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4134 | { |
4135 | if (rA(ctx->opcode) == 0) { | |
4136 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4137 | } else { | |
4138 | /* interpreted as no-op */ | |
4139 | } | |
4140 | } | |
4141 | ||
4142 | /* dstst /dststt */ | |
99e300ef | 4143 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4144 | { |
4145 | if (rA(ctx->opcode) == 0) { | |
4146 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4147 | } else { | |
4148 | /* interpreted as no-op */ | |
4149 | } | |
4150 | ||
4151 | } | |
4152 | ||
4153 | /* dss / dssall */ | |
99e300ef | 4154 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4155 | { |
4156 | /* interpreted as no-op */ | |
4157 | } | |
4158 | ||
79aceca5 | 4159 | /* icbi */ |
99e300ef | 4160 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4161 | { |
76db3ba4 AJ |
4162 | TCGv t0; |
4163 | gen_set_access_type(ctx, ACCESS_CACHE); | |
30032c94 JM |
4164 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4165 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4166 | t0 = tcg_temp_new(); |
4167 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4168 | gen_helper_icbi(cpu_env, t0); |
37d269df | 4169 | tcg_temp_free(t0); |
79aceca5 FB |
4170 | } |
4171 | ||
4172 | /* Optional: */ | |
4173 | /* dcba */ | |
99e300ef | 4174 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4175 | { |
0db1b20e JM |
4176 | /* interpreted as no-op */ |
4177 | /* XXX: specification say this is treated as a store by the MMU | |
4178 | * but does not generate any exception | |
4179 | */ | |
79aceca5 FB |
4180 | } |
4181 | ||
4182 | /*** Segment register manipulation ***/ | |
4183 | /* Supervisor only: */ | |
99e300ef | 4184 | |
54623277 | 4185 | /* mfsr */ |
99e300ef | 4186 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4187 | { |
9a64fbe4 | 4188 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4189 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4190 | #else |
74d37793 | 4191 | TCGv t0; |
76db3ba4 | 4192 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4193 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4194 | return; |
9a64fbe4 | 4195 | } |
74d37793 | 4196 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4197 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4198 | tcg_temp_free(t0); |
9a64fbe4 | 4199 | #endif |
79aceca5 FB |
4200 | } |
4201 | ||
4202 | /* mfsrin */ | |
99e300ef | 4203 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4204 | { |
9a64fbe4 | 4205 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4206 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4207 | #else |
74d37793 | 4208 | TCGv t0; |
76db3ba4 | 4209 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4210 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4211 | return; |
9a64fbe4 | 4212 | } |
74d37793 AJ |
4213 | t0 = tcg_temp_new(); |
4214 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4215 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4216 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4217 | tcg_temp_free(t0); |
9a64fbe4 | 4218 | #endif |
79aceca5 FB |
4219 | } |
4220 | ||
4221 | /* mtsr */ | |
99e300ef | 4222 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4223 | { |
9a64fbe4 | 4224 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4225 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4226 | #else |
74d37793 | 4227 | TCGv t0; |
76db3ba4 | 4228 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4229 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4230 | return; |
9a64fbe4 | 4231 | } |
74d37793 | 4232 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4233 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4234 | tcg_temp_free(t0); |
9a64fbe4 | 4235 | #endif |
79aceca5 FB |
4236 | } |
4237 | ||
4238 | /* mtsrin */ | |
99e300ef | 4239 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4240 | { |
9a64fbe4 | 4241 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4242 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4243 | #else |
74d37793 | 4244 | TCGv t0; |
76db3ba4 | 4245 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4246 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4247 | return; |
9a64fbe4 | 4248 | } |
74d37793 AJ |
4249 | t0 = tcg_temp_new(); |
4250 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4251 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4252 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); |
74d37793 | 4253 | tcg_temp_free(t0); |
9a64fbe4 | 4254 | #endif |
79aceca5 FB |
4255 | } |
4256 | ||
12de9a39 JM |
4257 | #if defined(TARGET_PPC64) |
4258 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4259 | |
54623277 | 4260 | /* mfsr */ |
e8eaa2c0 | 4261 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4262 | { |
4263 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4264 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4265 | #else |
74d37793 | 4266 | TCGv t0; |
76db3ba4 | 4267 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4268 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4269 | return; |
4270 | } | |
74d37793 | 4271 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4272 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4273 | tcg_temp_free(t0); |
12de9a39 JM |
4274 | #endif |
4275 | } | |
4276 | ||
4277 | /* mfsrin */ | |
e8eaa2c0 | 4278 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4279 | { |
4280 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4281 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4282 | #else |
74d37793 | 4283 | TCGv t0; |
76db3ba4 | 4284 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4285 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4286 | return; |
4287 | } | |
74d37793 AJ |
4288 | t0 = tcg_temp_new(); |
4289 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4290 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4291 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4292 | tcg_temp_free(t0); |
12de9a39 JM |
4293 | #endif |
4294 | } | |
4295 | ||
4296 | /* mtsr */ | |
e8eaa2c0 | 4297 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4298 | { |
4299 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4300 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4301 | #else |
74d37793 | 4302 | TCGv t0; |
76db3ba4 | 4303 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4304 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4305 | return; |
4306 | } | |
74d37793 | 4307 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4308 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4309 | tcg_temp_free(t0); |
12de9a39 JM |
4310 | #endif |
4311 | } | |
4312 | ||
4313 | /* mtsrin */ | |
e8eaa2c0 | 4314 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4315 | { |
4316 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4317 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4318 | #else |
74d37793 | 4319 | TCGv t0; |
76db3ba4 | 4320 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4321 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4322 | return; |
4323 | } | |
74d37793 AJ |
4324 | t0 = tcg_temp_new(); |
4325 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4326 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4327 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4328 | tcg_temp_free(t0); |
12de9a39 JM |
4329 | #endif |
4330 | } | |
f6b868fc BS |
4331 | |
4332 | /* slbmte */ | |
e8eaa2c0 | 4333 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
4334 | { |
4335 | #if defined(CONFIG_USER_ONLY) | |
4336 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4337 | #else | |
4338 | if (unlikely(!ctx->mem_idx)) { | |
4339 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4340 | return; | |
4341 | } | |
c6c7cf05 BS |
4342 | gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)], |
4343 | cpu_gpr[rS(ctx->opcode)]); | |
f6b868fc BS |
4344 | #endif |
4345 | } | |
4346 | ||
efdef95f DG |
4347 | static void gen_slbmfee(DisasContext *ctx) |
4348 | { | |
4349 | #if defined(CONFIG_USER_ONLY) | |
4350 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4351 | #else | |
4352 | if (unlikely(!ctx->mem_idx)) { | |
4353 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4354 | return; | |
4355 | } | |
c6c7cf05 | 4356 | gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4357 | cpu_gpr[rB(ctx->opcode)]); |
4358 | #endif | |
4359 | } | |
4360 | ||
4361 | static void gen_slbmfev(DisasContext *ctx) | |
4362 | { | |
4363 | #if defined(CONFIG_USER_ONLY) | |
4364 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4365 | #else | |
4366 | if (unlikely(!ctx->mem_idx)) { | |
4367 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4368 | return; | |
4369 | } | |
c6c7cf05 | 4370 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4371 | cpu_gpr[rB(ctx->opcode)]); |
4372 | #endif | |
4373 | } | |
12de9a39 JM |
4374 | #endif /* defined(TARGET_PPC64) */ |
4375 | ||
79aceca5 | 4376 | /*** Lookaside buffer management ***/ |
76db3ba4 | 4377 | /* Optional & mem_idx only: */ |
99e300ef | 4378 | |
54623277 | 4379 | /* tlbia */ |
99e300ef | 4380 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4381 | { |
9a64fbe4 | 4382 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4383 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4384 | #else |
76db3ba4 | 4385 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4386 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4387 | return; |
9a64fbe4 | 4388 | } |
c6c7cf05 | 4389 | gen_helper_tlbia(cpu_env); |
9a64fbe4 | 4390 | #endif |
79aceca5 FB |
4391 | } |
4392 | ||
bf14b1ce | 4393 | /* tlbiel */ |
99e300ef | 4394 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4395 | { |
4396 | #if defined(CONFIG_USER_ONLY) | |
4397 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4398 | #else | |
4399 | if (unlikely(!ctx->mem_idx)) { | |
4400 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4401 | return; | |
4402 | } | |
c6c7cf05 | 4403 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
bf14b1ce BS |
4404 | #endif |
4405 | } | |
4406 | ||
79aceca5 | 4407 | /* tlbie */ |
99e300ef | 4408 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4409 | { |
9a64fbe4 | 4410 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4411 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4412 | #else |
76db3ba4 | 4413 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4414 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4415 | return; |
9a64fbe4 | 4416 | } |
d9bce9d9 | 4417 | #if defined(TARGET_PPC64) |
74d37793 AJ |
4418 | if (!ctx->sf_mode) { |
4419 | TCGv t0 = tcg_temp_new(); | |
4420 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 4421 | gen_helper_tlbie(cpu_env, t0); |
74d37793 AJ |
4422 | tcg_temp_free(t0); |
4423 | } else | |
d9bce9d9 | 4424 | #endif |
c6c7cf05 | 4425 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9a64fbe4 | 4426 | #endif |
79aceca5 FB |
4427 | } |
4428 | ||
4429 | /* tlbsync */ | |
99e300ef | 4430 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4431 | { |
9a64fbe4 | 4432 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4433 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4434 | #else |
76db3ba4 | 4435 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4436 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4437 | return; |
9a64fbe4 FB |
4438 | } |
4439 | /* This has no effect: it should ensure that all previous | |
4440 | * tlbie have completed | |
4441 | */ | |
e06fcd75 | 4442 | gen_stop_exception(ctx); |
9a64fbe4 | 4443 | #endif |
79aceca5 FB |
4444 | } |
4445 | ||
426613db JM |
4446 | #if defined(TARGET_PPC64) |
4447 | /* slbia */ | |
99e300ef | 4448 | static void gen_slbia(DisasContext *ctx) |
426613db JM |
4449 | { |
4450 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4451 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4452 | #else |
76db3ba4 | 4453 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4454 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4455 | return; |
4456 | } | |
c6c7cf05 | 4457 | gen_helper_slbia(cpu_env); |
426613db JM |
4458 | #endif |
4459 | } | |
4460 | ||
4461 | /* slbie */ | |
99e300ef | 4462 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4463 | { |
4464 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4465 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4466 | #else |
76db3ba4 | 4467 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4468 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4469 | return; |
4470 | } | |
c6c7cf05 | 4471 | gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
426613db JM |
4472 | #endif |
4473 | } | |
4474 | #endif | |
4475 | ||
79aceca5 FB |
4476 | /*** External control ***/ |
4477 | /* Optional: */ | |
99e300ef | 4478 | |
54623277 | 4479 | /* eciwx */ |
99e300ef | 4480 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4481 | { |
76db3ba4 | 4482 | TCGv t0; |
fa407c03 | 4483 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4484 | gen_set_access_type(ctx, ACCESS_EXT); |
4485 | t0 = tcg_temp_new(); | |
4486 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4487 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4488 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4489 | tcg_temp_free(t0); |
76a66253 JM |
4490 | } |
4491 | ||
4492 | /* ecowx */ | |
99e300ef | 4493 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4494 | { |
76db3ba4 | 4495 | TCGv t0; |
fa407c03 | 4496 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4497 | gen_set_access_type(ctx, ACCESS_EXT); |
4498 | t0 = tcg_temp_new(); | |
4499 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4500 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4501 | gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4502 | tcg_temp_free(t0); |
76a66253 JM |
4503 | } |
4504 | ||
4505 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4506 | |
54623277 | 4507 | /* abs - abs. */ |
99e300ef | 4508 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4509 | { |
22e0e173 AJ |
4510 | int l1 = gen_new_label(); |
4511 | int l2 = gen_new_label(); | |
4512 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4513 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4514 | tcg_gen_br(l2); | |
4515 | gen_set_label(l1); | |
4516 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4517 | gen_set_label(l2); | |
76a66253 | 4518 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4519 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4520 | } |
4521 | ||
4522 | /* abso - abso. */ | |
99e300ef | 4523 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4524 | { |
22e0e173 AJ |
4525 | int l1 = gen_new_label(); |
4526 | int l2 = gen_new_label(); | |
4527 | int l3 = gen_new_label(); | |
4528 | /* Start with XER OV disabled, the most likely case */ | |
4529 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4530 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); | |
4531 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
4532 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4533 | tcg_gen_br(l2); | |
4534 | gen_set_label(l1); | |
4535 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4536 | tcg_gen_br(l3); | |
4537 | gen_set_label(l2); | |
4538 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4539 | gen_set_label(l3); | |
76a66253 | 4540 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4541 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4542 | } |
4543 | ||
4544 | /* clcs */ | |
99e300ef | 4545 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 4546 | { |
22e0e173 | 4547 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
d523dd00 | 4548 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 4549 | tcg_temp_free_i32(t0); |
c7697e1f | 4550 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
4551 | } |
4552 | ||
4553 | /* div - div. */ | |
99e300ef | 4554 | static void gen_div(DisasContext *ctx) |
76a66253 | 4555 | { |
d15f74fb BS |
4556 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4557 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4558 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4559 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4560 | } |
4561 | ||
4562 | /* divo - divo. */ | |
99e300ef | 4563 | static void gen_divo(DisasContext *ctx) |
76a66253 | 4564 | { |
d15f74fb BS |
4565 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4566 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4567 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4568 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4569 | } |
4570 | ||
4571 | /* divs - divs. */ | |
99e300ef | 4572 | static void gen_divs(DisasContext *ctx) |
76a66253 | 4573 | { |
d15f74fb BS |
4574 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4575 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4576 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4577 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4578 | } |
4579 | ||
4580 | /* divso - divso. */ | |
99e300ef | 4581 | static void gen_divso(DisasContext *ctx) |
76a66253 | 4582 | { |
d15f74fb BS |
4583 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env, |
4584 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4585 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4586 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4587 | } |
4588 | ||
4589 | /* doz - doz. */ | |
99e300ef | 4590 | static void gen_doz(DisasContext *ctx) |
76a66253 | 4591 | { |
22e0e173 AJ |
4592 | int l1 = gen_new_label(); |
4593 | int l2 = gen_new_label(); | |
4594 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4595 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4596 | tcg_gen_br(l2); | |
4597 | gen_set_label(l1); | |
4598 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4599 | gen_set_label(l2); | |
76a66253 | 4600 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4601 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4602 | } |
4603 | ||
4604 | /* dozo - dozo. */ | |
99e300ef | 4605 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 4606 | { |
22e0e173 AJ |
4607 | int l1 = gen_new_label(); |
4608 | int l2 = gen_new_label(); | |
4609 | TCGv t0 = tcg_temp_new(); | |
4610 | TCGv t1 = tcg_temp_new(); | |
4611 | TCGv t2 = tcg_temp_new(); | |
4612 | /* Start with XER OV disabled, the most likely case */ | |
4613 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4614 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4615 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4616 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4617 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
4618 | tcg_gen_andc_tl(t1, t1, t2); | |
4619 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4620 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
4621 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4622 | tcg_gen_br(l2); | |
4623 | gen_set_label(l1); | |
4624 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4625 | gen_set_label(l2); | |
4626 | tcg_temp_free(t0); | |
4627 | tcg_temp_free(t1); | |
4628 | tcg_temp_free(t2); | |
76a66253 | 4629 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4630 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4631 | } |
4632 | ||
4633 | /* dozi */ | |
99e300ef | 4634 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 4635 | { |
22e0e173 AJ |
4636 | target_long simm = SIMM(ctx->opcode); |
4637 | int l1 = gen_new_label(); | |
4638 | int l2 = gen_new_label(); | |
4639 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); | |
4640 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
4641 | tcg_gen_br(l2); | |
4642 | gen_set_label(l1); | |
4643 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4644 | gen_set_label(l2); | |
4645 | if (unlikely(Rc(ctx->opcode) != 0)) | |
4646 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
4647 | } |
4648 | ||
76a66253 | 4649 | /* lscbx - lscbx. */ |
99e300ef | 4650 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 4651 | { |
bdb4b689 AJ |
4652 | TCGv t0 = tcg_temp_new(); |
4653 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
4654 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
4655 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 4656 | |
76db3ba4 | 4657 | gen_addr_reg_index(ctx, t0); |
76a66253 | 4658 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 4659 | gen_update_nip(ctx, ctx->nip - 4); |
2f5a189c | 4660 | gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3); |
bdb4b689 AJ |
4661 | tcg_temp_free_i32(t1); |
4662 | tcg_temp_free_i32(t2); | |
4663 | tcg_temp_free_i32(t3); | |
3d7b417e | 4664 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 4665 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 4666 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
4667 | gen_set_Rc0(ctx, t0); |
4668 | tcg_temp_free(t0); | |
76a66253 JM |
4669 | } |
4670 | ||
4671 | /* maskg - maskg. */ | |
99e300ef | 4672 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 4673 | { |
22e0e173 AJ |
4674 | int l1 = gen_new_label(); |
4675 | TCGv t0 = tcg_temp_new(); | |
4676 | TCGv t1 = tcg_temp_new(); | |
4677 | TCGv t2 = tcg_temp_new(); | |
4678 | TCGv t3 = tcg_temp_new(); | |
4679 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
4680 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4681 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
4682 | tcg_gen_addi_tl(t2, t0, 1); | |
4683 | tcg_gen_shr_tl(t2, t3, t2); | |
4684 | tcg_gen_shr_tl(t3, t3, t1); | |
4685 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
4686 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
4687 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4688 | gen_set_label(l1); | |
4689 | tcg_temp_free(t0); | |
4690 | tcg_temp_free(t1); | |
4691 | tcg_temp_free(t2); | |
4692 | tcg_temp_free(t3); | |
76a66253 | 4693 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4694 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4695 | } |
4696 | ||
4697 | /* maskir - maskir. */ | |
99e300ef | 4698 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 4699 | { |
22e0e173 AJ |
4700 | TCGv t0 = tcg_temp_new(); |
4701 | TCGv t1 = tcg_temp_new(); | |
4702 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4703 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4704 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4705 | tcg_temp_free(t0); | |
4706 | tcg_temp_free(t1); | |
76a66253 | 4707 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4708 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4709 | } |
4710 | ||
4711 | /* mul - mul. */ | |
99e300ef | 4712 | static void gen_mul(DisasContext *ctx) |
76a66253 | 4713 | { |
22e0e173 AJ |
4714 | TCGv_i64 t0 = tcg_temp_new_i64(); |
4715 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4716 | TCGv t2 = tcg_temp_new(); | |
4717 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4718 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4719 | tcg_gen_mul_i64(t0, t0, t1); | |
4720 | tcg_gen_trunc_i64_tl(t2, t0); | |
4721 | gen_store_spr(SPR_MQ, t2); | |
4722 | tcg_gen_shri_i64(t1, t0, 32); | |
4723 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4724 | tcg_temp_free_i64(t0); | |
4725 | tcg_temp_free_i64(t1); | |
4726 | tcg_temp_free(t2); | |
76a66253 | 4727 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4728 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4729 | } |
4730 | ||
4731 | /* mulo - mulo. */ | |
99e300ef | 4732 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 4733 | { |
22e0e173 AJ |
4734 | int l1 = gen_new_label(); |
4735 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
4736 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4737 | TCGv t2 = tcg_temp_new(); | |
4738 | /* Start with XER OV disabled, the most likely case */ | |
4739 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4740 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4741 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4742 | tcg_gen_mul_i64(t0, t0, t1); | |
4743 | tcg_gen_trunc_i64_tl(t2, t0); | |
4744 | gen_store_spr(SPR_MQ, t2); | |
4745 | tcg_gen_shri_i64(t1, t0, 32); | |
4746 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4747 | tcg_gen_ext32s_i64(t1, t0); | |
4748 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
4749 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4750 | gen_set_label(l1); | |
4751 | tcg_temp_free_i64(t0); | |
4752 | tcg_temp_free_i64(t1); | |
4753 | tcg_temp_free(t2); | |
76a66253 | 4754 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4755 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4756 | } |
4757 | ||
4758 | /* nabs - nabs. */ | |
99e300ef | 4759 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 4760 | { |
22e0e173 AJ |
4761 | int l1 = gen_new_label(); |
4762 | int l2 = gen_new_label(); | |
4763 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4764 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4765 | tcg_gen_br(l2); | |
4766 | gen_set_label(l1); | |
4767 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4768 | gen_set_label(l2); | |
76a66253 | 4769 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4770 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4771 | } |
4772 | ||
4773 | /* nabso - nabso. */ | |
99e300ef | 4774 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 4775 | { |
22e0e173 AJ |
4776 | int l1 = gen_new_label(); |
4777 | int l2 = gen_new_label(); | |
4778 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4779 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4780 | tcg_gen_br(l2); | |
4781 | gen_set_label(l1); | |
4782 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4783 | gen_set_label(l2); | |
4784 | /* nabs never overflows */ | |
4785 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
76a66253 | 4786 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4787 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4788 | } |
4789 | ||
4790 | /* rlmi - rlmi. */ | |
99e300ef | 4791 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 4792 | { |
7487953d AJ |
4793 | uint32_t mb = MB(ctx->opcode); |
4794 | uint32_t me = ME(ctx->opcode); | |
4795 | TCGv t0 = tcg_temp_new(); | |
4796 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4797 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4798 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
4799 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
4800 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
4801 | tcg_temp_free(t0); | |
76a66253 | 4802 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4803 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4804 | } |
4805 | ||
4806 | /* rrib - rrib. */ | |
99e300ef | 4807 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 4808 | { |
7487953d AJ |
4809 | TCGv t0 = tcg_temp_new(); |
4810 | TCGv t1 = tcg_temp_new(); | |
4811 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4812 | tcg_gen_movi_tl(t1, 0x80000000); | |
4813 | tcg_gen_shr_tl(t1, t1, t0); | |
4814 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4815 | tcg_gen_and_tl(t0, t0, t1); | |
4816 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
4817 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4818 | tcg_temp_free(t0); | |
4819 | tcg_temp_free(t1); | |
76a66253 | 4820 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4821 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4822 | } |
4823 | ||
4824 | /* sle - sle. */ | |
99e300ef | 4825 | static void gen_sle(DisasContext *ctx) |
76a66253 | 4826 | { |
7487953d AJ |
4827 | TCGv t0 = tcg_temp_new(); |
4828 | TCGv t1 = tcg_temp_new(); | |
4829 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4830 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4831 | tcg_gen_subfi_tl(t1, 32, t1); | |
4832 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4833 | tcg_gen_or_tl(t1, t0, t1); | |
4834 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4835 | gen_store_spr(SPR_MQ, t1); | |
4836 | tcg_temp_free(t0); | |
4837 | tcg_temp_free(t1); | |
76a66253 | 4838 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4839 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4840 | } |
4841 | ||
4842 | /* sleq - sleq. */ | |
99e300ef | 4843 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 4844 | { |
7487953d AJ |
4845 | TCGv t0 = tcg_temp_new(); |
4846 | TCGv t1 = tcg_temp_new(); | |
4847 | TCGv t2 = tcg_temp_new(); | |
4848 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4849 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
4850 | tcg_gen_shl_tl(t2, t2, t0); | |
4851 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4852 | gen_load_spr(t1, SPR_MQ); | |
4853 | gen_store_spr(SPR_MQ, t0); | |
4854 | tcg_gen_and_tl(t0, t0, t2); | |
4855 | tcg_gen_andc_tl(t1, t1, t2); | |
4856 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4857 | tcg_temp_free(t0); | |
4858 | tcg_temp_free(t1); | |
4859 | tcg_temp_free(t2); | |
76a66253 | 4860 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4861 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4862 | } |
4863 | ||
4864 | /* sliq - sliq. */ | |
99e300ef | 4865 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 4866 | { |
7487953d AJ |
4867 | int sh = SH(ctx->opcode); |
4868 | TCGv t0 = tcg_temp_new(); | |
4869 | TCGv t1 = tcg_temp_new(); | |
4870 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4871 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4872 | tcg_gen_or_tl(t1, t0, t1); | |
4873 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4874 | gen_store_spr(SPR_MQ, t1); | |
4875 | tcg_temp_free(t0); | |
4876 | tcg_temp_free(t1); | |
76a66253 | 4877 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4878 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4879 | } |
4880 | ||
4881 | /* slliq - slliq. */ | |
99e300ef | 4882 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 4883 | { |
7487953d AJ |
4884 | int sh = SH(ctx->opcode); |
4885 | TCGv t0 = tcg_temp_new(); | |
4886 | TCGv t1 = tcg_temp_new(); | |
4887 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4888 | gen_load_spr(t1, SPR_MQ); | |
4889 | gen_store_spr(SPR_MQ, t0); | |
4890 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
4891 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
4892 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4893 | tcg_temp_free(t0); | |
4894 | tcg_temp_free(t1); | |
76a66253 | 4895 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4896 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4897 | } |
4898 | ||
4899 | /* sllq - sllq. */ | |
99e300ef | 4900 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 4901 | { |
7487953d AJ |
4902 | int l1 = gen_new_label(); |
4903 | int l2 = gen_new_label(); | |
4904 | TCGv t0 = tcg_temp_local_new(); | |
4905 | TCGv t1 = tcg_temp_local_new(); | |
4906 | TCGv t2 = tcg_temp_local_new(); | |
4907 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4908 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
4909 | tcg_gen_shl_tl(t1, t1, t2); | |
4910 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4911 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
4912 | gen_load_spr(t0, SPR_MQ); | |
4913 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4914 | tcg_gen_br(l2); | |
4915 | gen_set_label(l1); | |
4916 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4917 | gen_load_spr(t2, SPR_MQ); | |
4918 | tcg_gen_andc_tl(t1, t2, t1); | |
4919 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4920 | gen_set_label(l2); | |
4921 | tcg_temp_free(t0); | |
4922 | tcg_temp_free(t1); | |
4923 | tcg_temp_free(t2); | |
76a66253 | 4924 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4925 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4926 | } |
4927 | ||
4928 | /* slq - slq. */ | |
99e300ef | 4929 | static void gen_slq(DisasContext *ctx) |
76a66253 | 4930 | { |
7487953d AJ |
4931 | int l1 = gen_new_label(); |
4932 | TCGv t0 = tcg_temp_new(); | |
4933 | TCGv t1 = tcg_temp_new(); | |
4934 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4935 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4936 | tcg_gen_subfi_tl(t1, 32, t1); | |
4937 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4938 | tcg_gen_or_tl(t1, t0, t1); | |
4939 | gen_store_spr(SPR_MQ, t1); | |
4940 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4941 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4942 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4943 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
4944 | gen_set_label(l1); | |
4945 | tcg_temp_free(t0); | |
4946 | tcg_temp_free(t1); | |
76a66253 | 4947 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4948 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4949 | } |
4950 | ||
d9bce9d9 | 4951 | /* sraiq - sraiq. */ |
99e300ef | 4952 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 4953 | { |
7487953d AJ |
4954 | int sh = SH(ctx->opcode); |
4955 | int l1 = gen_new_label(); | |
4956 | TCGv t0 = tcg_temp_new(); | |
4957 | TCGv t1 = tcg_temp_new(); | |
4958 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4959 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4960 | tcg_gen_or_tl(t0, t0, t1); | |
4961 | gen_store_spr(SPR_MQ, t0); | |
4962 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
4963 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4964 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
4965 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
4966 | gen_set_label(l1); | |
4967 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
4968 | tcg_temp_free(t0); | |
4969 | tcg_temp_free(t1); | |
76a66253 | 4970 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4971 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4972 | } |
4973 | ||
4974 | /* sraq - sraq. */ | |
99e300ef | 4975 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 4976 | { |
7487953d AJ |
4977 | int l1 = gen_new_label(); |
4978 | int l2 = gen_new_label(); | |
4979 | TCGv t0 = tcg_temp_new(); | |
4980 | TCGv t1 = tcg_temp_local_new(); | |
4981 | TCGv t2 = tcg_temp_local_new(); | |
4982 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4983 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4984 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
4985 | tcg_gen_subfi_tl(t2, 32, t2); | |
4986 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
4987 | tcg_gen_or_tl(t0, t0, t2); | |
4988 | gen_store_spr(SPR_MQ, t0); | |
4989 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4990 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
4991 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
4992 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
4993 | gen_set_label(l1); | |
4994 | tcg_temp_free(t0); | |
4995 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
4996 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
4997 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
4998 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
4999 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
5000 | gen_set_label(l2); | |
5001 | tcg_temp_free(t1); | |
5002 | tcg_temp_free(t2); | |
76a66253 | 5003 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5004 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5005 | } |
5006 | ||
5007 | /* sre - sre. */ | |
99e300ef | 5008 | static void gen_sre(DisasContext *ctx) |
76a66253 | 5009 | { |
7487953d AJ |
5010 | TCGv t0 = tcg_temp_new(); |
5011 | TCGv t1 = tcg_temp_new(); | |
5012 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5013 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5014 | tcg_gen_subfi_tl(t1, 32, t1); | |
5015 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5016 | tcg_gen_or_tl(t1, t0, t1); | |
5017 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5018 | gen_store_spr(SPR_MQ, t1); | |
5019 | tcg_temp_free(t0); | |
5020 | tcg_temp_free(t1); | |
76a66253 | 5021 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5022 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5023 | } |
5024 | ||
5025 | /* srea - srea. */ | |
99e300ef | 5026 | static void gen_srea(DisasContext *ctx) |
76a66253 | 5027 | { |
7487953d AJ |
5028 | TCGv t0 = tcg_temp_new(); |
5029 | TCGv t1 = tcg_temp_new(); | |
5030 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5031 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5032 | gen_store_spr(SPR_MQ, t0); | |
5033 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
5034 | tcg_temp_free(t0); | |
5035 | tcg_temp_free(t1); | |
76a66253 | 5036 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5037 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5038 | } |
5039 | ||
5040 | /* sreq */ | |
99e300ef | 5041 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 5042 | { |
7487953d AJ |
5043 | TCGv t0 = tcg_temp_new(); |
5044 | TCGv t1 = tcg_temp_new(); | |
5045 | TCGv t2 = tcg_temp_new(); | |
5046 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5047 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5048 | tcg_gen_shr_tl(t1, t1, t0); | |
5049 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5050 | gen_load_spr(t2, SPR_MQ); | |
5051 | gen_store_spr(SPR_MQ, t0); | |
5052 | tcg_gen_and_tl(t0, t0, t1); | |
5053 | tcg_gen_andc_tl(t2, t2, t1); | |
5054 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5055 | tcg_temp_free(t0); | |
5056 | tcg_temp_free(t1); | |
5057 | tcg_temp_free(t2); | |
76a66253 | 5058 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5059 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5060 | } |
5061 | ||
5062 | /* sriq */ | |
99e300ef | 5063 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5064 | { |
7487953d AJ |
5065 | int sh = SH(ctx->opcode); |
5066 | TCGv t0 = tcg_temp_new(); | |
5067 | TCGv t1 = tcg_temp_new(); | |
5068 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5069 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5070 | tcg_gen_or_tl(t1, t0, t1); | |
5071 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5072 | gen_store_spr(SPR_MQ, t1); | |
5073 | tcg_temp_free(t0); | |
5074 | tcg_temp_free(t1); | |
76a66253 | 5075 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5076 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5077 | } |
5078 | ||
5079 | /* srliq */ | |
99e300ef | 5080 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5081 | { |
7487953d AJ |
5082 | int sh = SH(ctx->opcode); |
5083 | TCGv t0 = tcg_temp_new(); | |
5084 | TCGv t1 = tcg_temp_new(); | |
5085 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5086 | gen_load_spr(t1, SPR_MQ); | |
5087 | gen_store_spr(SPR_MQ, t0); | |
5088 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5089 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5090 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5091 | tcg_temp_free(t0); | |
5092 | tcg_temp_free(t1); | |
76a66253 | 5093 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5094 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5095 | } |
5096 | ||
5097 | /* srlq */ | |
99e300ef | 5098 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5099 | { |
7487953d AJ |
5100 | int l1 = gen_new_label(); |
5101 | int l2 = gen_new_label(); | |
5102 | TCGv t0 = tcg_temp_local_new(); | |
5103 | TCGv t1 = tcg_temp_local_new(); | |
5104 | TCGv t2 = tcg_temp_local_new(); | |
5105 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5106 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5107 | tcg_gen_shr_tl(t2, t1, t2); | |
5108 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5109 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5110 | gen_load_spr(t0, SPR_MQ); | |
5111 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5112 | tcg_gen_br(l2); | |
5113 | gen_set_label(l1); | |
5114 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5115 | tcg_gen_and_tl(t0, t0, t2); | |
5116 | gen_load_spr(t1, SPR_MQ); | |
5117 | tcg_gen_andc_tl(t1, t1, t2); | |
5118 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5119 | gen_set_label(l2); | |
5120 | tcg_temp_free(t0); | |
5121 | tcg_temp_free(t1); | |
5122 | tcg_temp_free(t2); | |
76a66253 | 5123 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5124 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5125 | } |
5126 | ||
5127 | /* srq */ | |
99e300ef | 5128 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5129 | { |
7487953d AJ |
5130 | int l1 = gen_new_label(); |
5131 | TCGv t0 = tcg_temp_new(); | |
5132 | TCGv t1 = tcg_temp_new(); | |
5133 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5134 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5135 | tcg_gen_subfi_tl(t1, 32, t1); | |
5136 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5137 | tcg_gen_or_tl(t1, t0, t1); | |
5138 | gen_store_spr(SPR_MQ, t1); | |
5139 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5140 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5141 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5142 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5143 | gen_set_label(l1); | |
5144 | tcg_temp_free(t0); | |
5145 | tcg_temp_free(t1); | |
76a66253 | 5146 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5147 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5148 | } |
5149 | ||
5150 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5151 | |
54623277 | 5152 | /* dsa */ |
99e300ef | 5153 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5154 | { |
5155 | /* XXX: TODO */ | |
e06fcd75 | 5156 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5157 | } |
5158 | ||
5159 | /* esa */ | |
99e300ef | 5160 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5161 | { |
5162 | /* XXX: TODO */ | |
e06fcd75 | 5163 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5164 | } |
5165 | ||
5166 | /* mfrom */ | |
99e300ef | 5167 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5168 | { |
5169 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5170 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5171 | #else |
76db3ba4 | 5172 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5173 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5174 | return; |
5175 | } | |
cf02a65c | 5176 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5177 | #endif |
5178 | } | |
5179 | ||
5180 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5181 | |
54623277 | 5182 | /* tlbld */ |
e8eaa2c0 | 5183 | static void gen_tlbld_6xx(DisasContext *ctx) |
76a66253 JM |
5184 | { |
5185 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5186 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5187 | #else |
76db3ba4 | 5188 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5189 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5190 | return; |
5191 | } | |
c6c7cf05 | 5192 | gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5193 | #endif |
5194 | } | |
5195 | ||
5196 | /* tlbli */ | |
e8eaa2c0 | 5197 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5198 | { |
5199 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5200 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5201 | #else |
76db3ba4 | 5202 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5203 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5204 | return; |
5205 | } | |
c6c7cf05 | 5206 | gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5207 | #endif |
5208 | } | |
5209 | ||
7dbe11ac | 5210 | /* 74xx TLB management */ |
e8eaa2c0 | 5211 | |
54623277 | 5212 | /* tlbld */ |
e8eaa2c0 | 5213 | static void gen_tlbld_74xx(DisasContext *ctx) |
7dbe11ac JM |
5214 | { |
5215 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5216 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5217 | #else |
76db3ba4 | 5218 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5219 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5220 | return; |
5221 | } | |
c6c7cf05 | 5222 | gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5223 | #endif |
5224 | } | |
5225 | ||
5226 | /* tlbli */ | |
e8eaa2c0 | 5227 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5228 | { |
5229 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5230 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5231 | #else |
76db3ba4 | 5232 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5233 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5234 | return; |
5235 | } | |
c6c7cf05 | 5236 | gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5237 | #endif |
5238 | } | |
5239 | ||
76a66253 | 5240 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5241 | |
54623277 | 5242 | /* clf */ |
99e300ef | 5243 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5244 | { |
5245 | /* Cache line flush: implemented as no-op */ | |
5246 | } | |
5247 | ||
5248 | /* cli */ | |
99e300ef | 5249 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5250 | { |
7f75ffd3 | 5251 | /* Cache line invalidate: privileged and treated as no-op */ |
76a66253 | 5252 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5253 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5254 | #else |
76db3ba4 | 5255 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5256 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5257 | return; |
5258 | } | |
5259 | #endif | |
5260 | } | |
5261 | ||
5262 | /* dclst */ | |
99e300ef | 5263 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5264 | { |
5265 | /* Data cache line store: treated as no-op */ | |
5266 | } | |
5267 | ||
99e300ef | 5268 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5269 | { |
5270 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5271 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5272 | #else |
74d37793 AJ |
5273 | int ra = rA(ctx->opcode); |
5274 | int rd = rD(ctx->opcode); | |
5275 | TCGv t0; | |
76db3ba4 | 5276 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5277 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5278 | return; |
5279 | } | |
74d37793 | 5280 | t0 = tcg_temp_new(); |
76db3ba4 | 5281 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5282 | tcg_gen_shri_tl(t0, t0, 28); |
5283 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 5284 | gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0); |
74d37793 | 5285 | tcg_temp_free(t0); |
76a66253 | 5286 | if (ra != 0 && ra != rd) |
74d37793 | 5287 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
76a66253 JM |
5288 | #endif |
5289 | } | |
5290 | ||
99e300ef | 5291 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5292 | { |
5293 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5294 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5295 | #else |
22e0e173 | 5296 | TCGv t0; |
76db3ba4 | 5297 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5298 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5299 | return; |
5300 | } | |
22e0e173 | 5301 | t0 = tcg_temp_new(); |
76db3ba4 | 5302 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5303 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5304 | tcg_temp_free(t0); |
76a66253 JM |
5305 | #endif |
5306 | } | |
5307 | ||
99e300ef | 5308 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5309 | { |
5310 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5311 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5312 | #else |
76db3ba4 | 5313 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5314 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5315 | return; |
5316 | } | |
e5f17ac6 | 5317 | gen_helper_rfsvc(cpu_env); |
e06fcd75 | 5318 | gen_sync_exception(ctx); |
76a66253 JM |
5319 | #endif |
5320 | } | |
5321 | ||
5322 | /* svc is not implemented for now */ | |
5323 | ||
5324 | /* POWER2 specific instructions */ | |
5325 | /* Quad manipulation (load/store two floats at a time) */ | |
76a66253 JM |
5326 | |
5327 | /* lfq */ | |
99e300ef | 5328 | static void gen_lfq(DisasContext *ctx) |
76a66253 | 5329 | { |
01a4afeb | 5330 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5331 | TCGv t0; |
5332 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5333 | t0 = tcg_temp_new(); | |
5334 | gen_addr_imm_index(ctx, t0, 0); | |
5335 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5336 | gen_addr_add(ctx, t0, t0, 8); | |
5337 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5338 | tcg_temp_free(t0); |
76a66253 JM |
5339 | } |
5340 | ||
5341 | /* lfqu */ | |
99e300ef | 5342 | static void gen_lfqu(DisasContext *ctx) |
76a66253 JM |
5343 | { |
5344 | int ra = rA(ctx->opcode); | |
01a4afeb | 5345 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5346 | TCGv t0, t1; |
5347 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5348 | t0 = tcg_temp_new(); | |
5349 | t1 = tcg_temp_new(); | |
5350 | gen_addr_imm_index(ctx, t0, 0); | |
5351 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5352 | gen_addr_add(ctx, t1, t0, 8); | |
5353 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
76a66253 | 5354 | if (ra != 0) |
01a4afeb AJ |
5355 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5356 | tcg_temp_free(t0); | |
5357 | tcg_temp_free(t1); | |
76a66253 JM |
5358 | } |
5359 | ||
5360 | /* lfqux */ | |
99e300ef | 5361 | static void gen_lfqux(DisasContext *ctx) |
76a66253 JM |
5362 | { |
5363 | int ra = rA(ctx->opcode); | |
01a4afeb | 5364 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5365 | gen_set_access_type(ctx, ACCESS_FLOAT); |
5366 | TCGv t0, t1; | |
5367 | t0 = tcg_temp_new(); | |
5368 | gen_addr_reg_index(ctx, t0); | |
5369 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5370 | t1 = tcg_temp_new(); | |
5371 | gen_addr_add(ctx, t1, t0, 8); | |
5372 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5373 | tcg_temp_free(t1); | |
76a66253 | 5374 | if (ra != 0) |
01a4afeb AJ |
5375 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5376 | tcg_temp_free(t0); | |
76a66253 JM |
5377 | } |
5378 | ||
5379 | /* lfqx */ | |
99e300ef | 5380 | static void gen_lfqx(DisasContext *ctx) |
76a66253 | 5381 | { |
01a4afeb | 5382 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5383 | TCGv t0; |
5384 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5385 | t0 = tcg_temp_new(); | |
5386 | gen_addr_reg_index(ctx, t0); | |
5387 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5388 | gen_addr_add(ctx, t0, t0, 8); | |
5389 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5390 | tcg_temp_free(t0); |
76a66253 JM |
5391 | } |
5392 | ||
5393 | /* stfq */ | |
99e300ef | 5394 | static void gen_stfq(DisasContext *ctx) |
76a66253 | 5395 | { |
01a4afeb | 5396 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5397 | TCGv t0; |
5398 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5399 | t0 = tcg_temp_new(); | |
5400 | gen_addr_imm_index(ctx, t0, 0); | |
5401 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5402 | gen_addr_add(ctx, t0, t0, 8); | |
5403 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5404 | tcg_temp_free(t0); |
76a66253 JM |
5405 | } |
5406 | ||
5407 | /* stfqu */ | |
99e300ef | 5408 | static void gen_stfqu(DisasContext *ctx) |
76a66253 JM |
5409 | { |
5410 | int ra = rA(ctx->opcode); | |
01a4afeb | 5411 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5412 | TCGv t0, t1; |
5413 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5414 | t0 = tcg_temp_new(); | |
5415 | gen_addr_imm_index(ctx, t0, 0); | |
5416 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5417 | t1 = tcg_temp_new(); | |
5418 | gen_addr_add(ctx, t1, t0, 8); | |
5419 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5420 | tcg_temp_free(t1); | |
76a66253 | 5421 | if (ra != 0) |
01a4afeb AJ |
5422 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5423 | tcg_temp_free(t0); | |
76a66253 JM |
5424 | } |
5425 | ||
5426 | /* stfqux */ | |
99e300ef | 5427 | static void gen_stfqux(DisasContext *ctx) |
76a66253 JM |
5428 | { |
5429 | int ra = rA(ctx->opcode); | |
01a4afeb | 5430 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5431 | TCGv t0, t1; |
5432 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5433 | t0 = tcg_temp_new(); | |
5434 | gen_addr_reg_index(ctx, t0); | |
5435 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5436 | t1 = tcg_temp_new(); | |
5437 | gen_addr_add(ctx, t1, t0, 8); | |
5438 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5439 | tcg_temp_free(t1); | |
76a66253 | 5440 | if (ra != 0) |
01a4afeb AJ |
5441 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5442 | tcg_temp_free(t0); | |
76a66253 JM |
5443 | } |
5444 | ||
5445 | /* stfqx */ | |
99e300ef | 5446 | static void gen_stfqx(DisasContext *ctx) |
76a66253 | 5447 | { |
01a4afeb | 5448 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5449 | TCGv t0; |
5450 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5451 | t0 = tcg_temp_new(); | |
5452 | gen_addr_reg_index(ctx, t0); | |
5453 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5454 | gen_addr_add(ctx, t0, t0, 8); | |
5455 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5456 | tcg_temp_free(t0); |
76a66253 JM |
5457 | } |
5458 | ||
5459 | /* BookE specific instructions */ | |
99e300ef | 5460 | |
54623277 | 5461 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5462 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5463 | { |
5464 | /* XXX: TODO */ | |
e06fcd75 | 5465 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5466 | } |
5467 | ||
2662a059 | 5468 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5469 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5470 | { |
5471 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5472 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5473 | #else |
74d37793 | 5474 | TCGv t0; |
76db3ba4 | 5475 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5476 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5477 | return; |
5478 | } | |
ec72e276 | 5479 | t0 = tcg_temp_new(); |
76db3ba4 | 5480 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5481 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
74d37793 | 5482 | tcg_temp_free(t0); |
76a66253 JM |
5483 | #endif |
5484 | } | |
5485 | ||
5486 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5487 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5488 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5489 | { |
182608d4 AJ |
5490 | TCGv t0, t1; |
5491 | ||
a7812ae4 PB |
5492 | t0 = tcg_temp_local_new(); |
5493 | t1 = tcg_temp_local_new(); | |
182608d4 | 5494 | |
76a66253 JM |
5495 | switch (opc3 & 0x0D) { |
5496 | case 0x05: | |
5497 | /* macchw - macchw. - macchwo - macchwo. */ | |
5498 | /* macchws - macchws. - macchwso - macchwso. */ | |
5499 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5500 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5501 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5502 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5503 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5504 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5505 | break; |
5506 | case 0x04: | |
5507 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5508 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5509 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5510 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5511 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5512 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5513 | break; |
5514 | case 0x01: | |
5515 | /* machhw - machhw. - machhwo - machhwo. */ | |
5516 | /* machhws - machhws. - machhwso - machhwso. */ | |
5517 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5518 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5519 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5520 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5521 | tcg_gen_ext16s_tl(t0, t0); | |
5522 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5523 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5524 | break; |
5525 | case 0x00: | |
5526 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5527 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5528 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5529 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5530 | tcg_gen_ext16u_tl(t0, t0); | |
5531 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5532 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5533 | break; |
5534 | case 0x0D: | |
5535 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5536 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5537 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5538 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5539 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5540 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5541 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5542 | break; |
5543 | case 0x0C: | |
5544 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5545 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5546 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5547 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5548 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5549 | break; |
5550 | } | |
76a66253 | 5551 | if (opc2 & 0x04) { |
182608d4 AJ |
5552 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5553 | tcg_gen_mul_tl(t1, t0, t1); | |
5554 | if (opc2 & 0x02) { | |
5555 | /* nmultiply-and-accumulate (0x0E) */ | |
5556 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5557 | } else { | |
5558 | /* multiply-and-accumulate (0x0C) */ | |
5559 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5560 | } | |
5561 | ||
5562 | if (opc3 & 0x12) { | |
5563 | /* Check overflow and/or saturate */ | |
5564 | int l1 = gen_new_label(); | |
5565 | ||
5566 | if (opc3 & 0x10) { | |
5567 | /* Start with XER OV disabled, the most likely case */ | |
5568 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
5569 | } | |
5570 | if (opc3 & 0x01) { | |
5571 | /* Signed */ | |
5572 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5573 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5574 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5575 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5576 | if (opc3 & 0x02) { |
182608d4 AJ |
5577 | /* Saturate */ |
5578 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5579 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5580 | } | |
5581 | } else { | |
5582 | /* Unsigned */ | |
5583 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5584 | if (opc3 & 0x02) { |
182608d4 AJ |
5585 | /* Saturate */ |
5586 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5587 | } | |
5588 | } | |
5589 | if (opc3 & 0x10) { | |
5590 | /* Check overflow */ | |
5591 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
5592 | } | |
5593 | gen_set_label(l1); | |
5594 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5595 | } | |
5596 | } else { | |
5597 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5598 | } |
182608d4 AJ |
5599 | tcg_temp_free(t0); |
5600 | tcg_temp_free(t1); | |
76a66253 JM |
5601 | if (unlikely(Rc) != 0) { |
5602 | /* Update Rc0 */ | |
182608d4 | 5603 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5604 | } |
5605 | } | |
5606 | ||
a750fc0b | 5607 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5608 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5609 | { \ |
5610 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5611 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5612 | } | |
5613 | ||
5614 | /* macchw - macchw. */ | |
a750fc0b | 5615 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5616 | /* macchwo - macchwo. */ |
a750fc0b | 5617 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5618 | /* macchws - macchws. */ |
a750fc0b | 5619 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5620 | /* macchwso - macchwso. */ |
a750fc0b | 5621 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5622 | /* macchwsu - macchwsu. */ |
a750fc0b | 5623 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5624 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5625 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5626 | /* macchwu - macchwu. */ |
a750fc0b | 5627 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5628 | /* macchwuo - macchwuo. */ |
a750fc0b | 5629 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 5630 | /* machhw - machhw. */ |
a750fc0b | 5631 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 5632 | /* machhwo - machhwo. */ |
a750fc0b | 5633 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 5634 | /* machhws - machhws. */ |
a750fc0b | 5635 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 5636 | /* machhwso - machhwso. */ |
a750fc0b | 5637 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 5638 | /* machhwsu - machhwsu. */ |
a750fc0b | 5639 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 5640 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 5641 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 5642 | /* machhwu - machhwu. */ |
a750fc0b | 5643 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 5644 | /* machhwuo - machhwuo. */ |
a750fc0b | 5645 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 5646 | /* maclhw - maclhw. */ |
a750fc0b | 5647 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 5648 | /* maclhwo - maclhwo. */ |
a750fc0b | 5649 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 5650 | /* maclhws - maclhws. */ |
a750fc0b | 5651 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 5652 | /* maclhwso - maclhwso. */ |
a750fc0b | 5653 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 5654 | /* maclhwu - maclhwu. */ |
a750fc0b | 5655 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 5656 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 5657 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 5658 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 5659 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 5660 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 5661 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 5662 | /* nmacchw - nmacchw. */ |
a750fc0b | 5663 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 5664 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 5665 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 5666 | /* nmacchws - nmacchws. */ |
a750fc0b | 5667 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 5668 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 5669 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 5670 | /* nmachhw - nmachhw. */ |
a750fc0b | 5671 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 5672 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 5673 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 5674 | /* nmachhws - nmachhws. */ |
a750fc0b | 5675 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 5676 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 5677 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 5678 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 5679 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 5680 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 5681 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 5682 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 5683 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 5684 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 5685 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
5686 | |
5687 | /* mulchw - mulchw. */ | |
a750fc0b | 5688 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 5689 | /* mulchwu - mulchwu. */ |
a750fc0b | 5690 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 5691 | /* mulhhw - mulhhw. */ |
a750fc0b | 5692 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 5693 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 5694 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 5695 | /* mullhw - mullhw. */ |
a750fc0b | 5696 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 5697 | /* mullhwu - mullhwu. */ |
a750fc0b | 5698 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
5699 | |
5700 | /* mfdcr */ | |
99e300ef | 5701 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
5702 | { |
5703 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5704 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5705 | #else |
06dca6a7 | 5706 | TCGv dcrn; |
76db3ba4 | 5707 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5708 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5709 | return; |
5710 | } | |
06dca6a7 AJ |
5711 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5712 | gen_update_nip(ctx, ctx->nip - 4); | |
5713 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5714 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn); |
06dca6a7 | 5715 | tcg_temp_free(dcrn); |
76a66253 JM |
5716 | #endif |
5717 | } | |
5718 | ||
5719 | /* mtdcr */ | |
99e300ef | 5720 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
5721 | { |
5722 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5723 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5724 | #else |
06dca6a7 | 5725 | TCGv dcrn; |
76db3ba4 | 5726 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5727 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5728 | return; |
5729 | } | |
06dca6a7 AJ |
5730 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5731 | gen_update_nip(ctx, ctx->nip - 4); | |
5732 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5733 | gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]); |
06dca6a7 | 5734 | tcg_temp_free(dcrn); |
a42bd6cc JM |
5735 | #endif |
5736 | } | |
5737 | ||
5738 | /* mfdcrx */ | |
2662a059 | 5739 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5740 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
5741 | { |
5742 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5743 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5744 | #else |
76db3ba4 | 5745 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5746 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5747 | return; |
5748 | } | |
06dca6a7 AJ |
5749 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5750 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5751 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5752 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 5753 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
a42bd6cc JM |
5754 | #endif |
5755 | } | |
5756 | ||
5757 | /* mtdcrx */ | |
2662a059 | 5758 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5759 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
5760 | { |
5761 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5762 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5763 | #else |
76db3ba4 | 5764 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5765 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5766 | return; |
5767 | } | |
06dca6a7 AJ |
5768 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5769 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5770 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
5771 | cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 5772 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
76a66253 JM |
5773 | #endif |
5774 | } | |
5775 | ||
a750fc0b | 5776 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 5777 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 5778 | { |
06dca6a7 AJ |
5779 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5780 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5781 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5782 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
5783 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5784 | } | |
5785 | ||
5786 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 5787 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 5788 | { |
06dca6a7 AJ |
5789 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5790 | gen_update_nip(ctx, ctx->nip - 4); | |
975e5463 | 5791 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
d0f1562d | 5792 | cpu_gpr[rS(ctx->opcode)]); |
a750fc0b JM |
5793 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5794 | } | |
5795 | ||
76a66253 | 5796 | /* dccci */ |
99e300ef | 5797 | static void gen_dccci(DisasContext *ctx) |
76a66253 JM |
5798 | { |
5799 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5800 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5801 | #else |
76db3ba4 | 5802 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5803 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5804 | return; |
5805 | } | |
5806 | /* interpreted as no-op */ | |
5807 | #endif | |
5808 | } | |
5809 | ||
5810 | /* dcread */ | |
99e300ef | 5811 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
5812 | { |
5813 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5814 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5815 | #else |
b61f2753 | 5816 | TCGv EA, val; |
76db3ba4 | 5817 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5818 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5819 | return; |
5820 | } | |
76db3ba4 | 5821 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 5822 | EA = tcg_temp_new(); |
76db3ba4 | 5823 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 5824 | val = tcg_temp_new(); |
76db3ba4 | 5825 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
5826 | tcg_temp_free(val); |
5827 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
5828 | tcg_temp_free(EA); | |
76a66253 JM |
5829 | #endif |
5830 | } | |
5831 | ||
5832 | /* icbt */ | |
e8eaa2c0 | 5833 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
5834 | { |
5835 | /* interpreted as no-op */ | |
5836 | /* XXX: specification say this is treated as a load by the MMU | |
5837 | * but does not generate any exception | |
5838 | */ | |
5839 | } | |
5840 | ||
5841 | /* iccci */ | |
99e300ef | 5842 | static void gen_iccci(DisasContext *ctx) |
76a66253 JM |
5843 | { |
5844 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5845 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5846 | #else |
76db3ba4 | 5847 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5848 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5849 | return; |
5850 | } | |
5851 | /* interpreted as no-op */ | |
5852 | #endif | |
5853 | } | |
5854 | ||
5855 | /* icread */ | |
99e300ef | 5856 | static void gen_icread(DisasContext *ctx) |
76a66253 JM |
5857 | { |
5858 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5859 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5860 | #else |
76db3ba4 | 5861 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5862 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5863 | return; |
5864 | } | |
5865 | /* interpreted as no-op */ | |
5866 | #endif | |
5867 | } | |
5868 | ||
76db3ba4 | 5869 | /* rfci (mem_idx only) */ |
e8eaa2c0 | 5870 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
5871 | { |
5872 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5873 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5874 | #else |
76db3ba4 | 5875 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5876 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5877 | return; |
5878 | } | |
5879 | /* Restore CPU state */ | |
e5f17ac6 | 5880 | gen_helper_40x_rfci(cpu_env); |
e06fcd75 | 5881 | gen_sync_exception(ctx); |
a42bd6cc JM |
5882 | #endif |
5883 | } | |
5884 | ||
99e300ef | 5885 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
5886 | { |
5887 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5888 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5889 | #else |
76db3ba4 | 5890 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5891 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5892 | return; |
5893 | } | |
5894 | /* Restore CPU state */ | |
e5f17ac6 | 5895 | gen_helper_rfci(cpu_env); |
e06fcd75 | 5896 | gen_sync_exception(ctx); |
a42bd6cc JM |
5897 | #endif |
5898 | } | |
5899 | ||
5900 | /* BookE specific */ | |
99e300ef | 5901 | |
54623277 | 5902 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5903 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
5904 | { |
5905 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5906 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5907 | #else |
76db3ba4 | 5908 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5909 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5910 | return; |
5911 | } | |
5912 | /* Restore CPU state */ | |
e5f17ac6 | 5913 | gen_helper_rfdi(cpu_env); |
e06fcd75 | 5914 | gen_sync_exception(ctx); |
76a66253 JM |
5915 | #endif |
5916 | } | |
5917 | ||
2662a059 | 5918 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5919 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
5920 | { |
5921 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5922 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5923 | #else |
76db3ba4 | 5924 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5925 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5926 | return; |
5927 | } | |
5928 | /* Restore CPU state */ | |
e5f17ac6 | 5929 | gen_helper_rfmci(cpu_env); |
e06fcd75 | 5930 | gen_sync_exception(ctx); |
a42bd6cc JM |
5931 | #endif |
5932 | } | |
5eb7995e | 5933 | |
d9bce9d9 | 5934 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 5935 | |
54623277 | 5936 | /* tlbre */ |
e8eaa2c0 | 5937 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
5938 | { |
5939 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5940 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5941 | #else |
76db3ba4 | 5942 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5943 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5944 | return; |
5945 | } | |
5946 | switch (rB(ctx->opcode)) { | |
5947 | case 0: | |
c6c7cf05 BS |
5948 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5949 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
5950 | break; |
5951 | case 1: | |
c6c7cf05 BS |
5952 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5953 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
5954 | break; |
5955 | default: | |
e06fcd75 | 5956 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 5957 | break; |
9a64fbe4 | 5958 | } |
76a66253 JM |
5959 | #endif |
5960 | } | |
5961 | ||
d9bce9d9 | 5962 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 5963 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
5964 | { |
5965 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5966 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5967 | #else |
74d37793 | 5968 | TCGv t0; |
76db3ba4 | 5969 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5970 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5971 | return; |
5972 | } | |
74d37793 | 5973 | t0 = tcg_temp_new(); |
76db3ba4 | 5974 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5975 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
5976 | tcg_temp_free(t0); |
5977 | if (Rc(ctx->opcode)) { | |
5978 | int l1 = gen_new_label(); | |
5979 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
5980 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
5981 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
5982 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
5983 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
5984 | gen_set_label(l1); | |
5985 | } | |
76a66253 | 5986 | #endif |
79aceca5 FB |
5987 | } |
5988 | ||
76a66253 | 5989 | /* tlbwe */ |
e8eaa2c0 | 5990 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 5991 | { |
76a66253 | 5992 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5993 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5994 | #else |
76db3ba4 | 5995 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5996 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5997 | return; |
5998 | } | |
5999 | switch (rB(ctx->opcode)) { | |
6000 | case 0: | |
c6c7cf05 BS |
6001 | gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6002 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6003 | break; |
6004 | case 1: | |
c6c7cf05 BS |
6005 | gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6006 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6007 | break; |
6008 | default: | |
e06fcd75 | 6009 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6010 | break; |
9a64fbe4 | 6011 | } |
76a66253 JM |
6012 | #endif |
6013 | } | |
6014 | ||
a4bb6c3e | 6015 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 6016 | |
54623277 | 6017 | /* tlbre */ |
e8eaa2c0 | 6018 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
6019 | { |
6020 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6021 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6022 | #else |
76db3ba4 | 6023 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6024 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6025 | return; |
6026 | } | |
6027 | switch (rB(ctx->opcode)) { | |
6028 | case 0: | |
5eb7995e | 6029 | case 1: |
5eb7995e | 6030 | case 2: |
74d37793 AJ |
6031 | { |
6032 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6033 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6034 | t0, cpu_gpr[rA(ctx->opcode)]); | |
74d37793 AJ |
6035 | tcg_temp_free_i32(t0); |
6036 | } | |
5eb7995e JM |
6037 | break; |
6038 | default: | |
e06fcd75 | 6039 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6040 | break; |
6041 | } | |
6042 | #endif | |
6043 | } | |
6044 | ||
6045 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 6046 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
6047 | { |
6048 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6049 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6050 | #else |
74d37793 | 6051 | TCGv t0; |
76db3ba4 | 6052 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6053 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6054 | return; |
6055 | } | |
74d37793 | 6056 | t0 = tcg_temp_new(); |
76db3ba4 | 6057 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6058 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6059 | tcg_temp_free(t0); |
6060 | if (Rc(ctx->opcode)) { | |
6061 | int l1 = gen_new_label(); | |
6062 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
6063 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
6064 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
6065 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
6066 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6067 | gen_set_label(l1); | |
6068 | } | |
5eb7995e JM |
6069 | #endif |
6070 | } | |
6071 | ||
6072 | /* tlbwe */ | |
e8eaa2c0 | 6073 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6074 | { |
6075 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6076 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6077 | #else |
76db3ba4 | 6078 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6079 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6080 | return; |
6081 | } | |
6082 | switch (rB(ctx->opcode)) { | |
6083 | case 0: | |
5eb7995e | 6084 | case 1: |
5eb7995e | 6085 | case 2: |
74d37793 AJ |
6086 | { |
6087 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6088 | gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)], |
6089 | cpu_gpr[rS(ctx->opcode)]); | |
74d37793 AJ |
6090 | tcg_temp_free_i32(t0); |
6091 | } | |
5eb7995e JM |
6092 | break; |
6093 | default: | |
e06fcd75 | 6094 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6095 | break; |
6096 | } | |
6097 | #endif | |
6098 | } | |
6099 | ||
01662f3e AG |
6100 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6101 | ||
6102 | /* tlbre */ | |
6103 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6104 | { | |
6105 | #if defined(CONFIG_USER_ONLY) | |
6106 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6107 | #else | |
6108 | if (unlikely(!ctx->mem_idx)) { | |
6109 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6110 | return; | |
6111 | } | |
6112 | ||
c6c7cf05 | 6113 | gen_helper_booke206_tlbre(cpu_env); |
01662f3e AG |
6114 | #endif |
6115 | } | |
6116 | ||
6117 | /* tlbsx - tlbsx. */ | |
6118 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6119 | { | |
6120 | #if defined(CONFIG_USER_ONLY) | |
6121 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6122 | #else | |
6123 | TCGv t0; | |
6124 | if (unlikely(!ctx->mem_idx)) { | |
6125 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6126 | return; | |
6127 | } | |
6128 | ||
6129 | if (rA(ctx->opcode)) { | |
6130 | t0 = tcg_temp_new(); | |
6131 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6132 | } else { | |
6133 | t0 = tcg_const_tl(0); | |
6134 | } | |
6135 | ||
6136 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 6137 | gen_helper_booke206_tlbsx(cpu_env, t0); |
01662f3e AG |
6138 | #endif |
6139 | } | |
6140 | ||
6141 | /* tlbwe */ | |
6142 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6143 | { | |
6144 | #if defined(CONFIG_USER_ONLY) | |
6145 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6146 | #else | |
6147 | if (unlikely(!ctx->mem_idx)) { | |
6148 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6149 | return; | |
6150 | } | |
3f162d11 | 6151 | gen_update_nip(ctx, ctx->nip - 4); |
c6c7cf05 | 6152 | gen_helper_booke206_tlbwe(cpu_env); |
01662f3e AG |
6153 | #endif |
6154 | } | |
6155 | ||
6156 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6157 | { | |
6158 | #if defined(CONFIG_USER_ONLY) | |
6159 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6160 | #else | |
6161 | TCGv t0; | |
6162 | if (unlikely(!ctx->mem_idx)) { | |
6163 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6164 | return; | |
6165 | } | |
6166 | ||
6167 | t0 = tcg_temp_new(); | |
6168 | gen_addr_reg_index(ctx, t0); | |
6169 | ||
c6c7cf05 | 6170 | gen_helper_booke206_tlbivax(cpu_env, t0); |
01662f3e AG |
6171 | #endif |
6172 | } | |
6173 | ||
6d3db821 AG |
6174 | static void gen_tlbilx_booke206(DisasContext *ctx) |
6175 | { | |
6176 | #if defined(CONFIG_USER_ONLY) | |
6177 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6178 | #else | |
6179 | TCGv t0; | |
6180 | if (unlikely(!ctx->mem_idx)) { | |
6181 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6182 | return; | |
6183 | } | |
6184 | ||
6185 | t0 = tcg_temp_new(); | |
6186 | gen_addr_reg_index(ctx, t0); | |
6187 | ||
6188 | switch((ctx->opcode >> 21) & 0x3) { | |
6189 | case 0: | |
c6c7cf05 | 6190 | gen_helper_booke206_tlbilx0(cpu_env, t0); |
6d3db821 AG |
6191 | break; |
6192 | case 1: | |
c6c7cf05 | 6193 | gen_helper_booke206_tlbilx1(cpu_env, t0); |
6d3db821 AG |
6194 | break; |
6195 | case 3: | |
c6c7cf05 | 6196 | gen_helper_booke206_tlbilx3(cpu_env, t0); |
6d3db821 AG |
6197 | break; |
6198 | default: | |
6199 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6200 | break; | |
6201 | } | |
6202 | ||
6203 | tcg_temp_free(t0); | |
6204 | #endif | |
6205 | } | |
6206 | ||
01662f3e | 6207 | |
76a66253 | 6208 | /* wrtee */ |
99e300ef | 6209 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6210 | { |
6211 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6212 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6213 | #else |
6527f6ea | 6214 | TCGv t0; |
76db3ba4 | 6215 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6216 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6217 | return; |
6218 | } | |
6527f6ea AJ |
6219 | t0 = tcg_temp_new(); |
6220 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6221 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6222 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6223 | tcg_temp_free(t0); | |
dee96f6c JM |
6224 | /* Stop translation to have a chance to raise an exception |
6225 | * if we just set msr_ee to 1 | |
6226 | */ | |
e06fcd75 | 6227 | gen_stop_exception(ctx); |
76a66253 JM |
6228 | #endif |
6229 | } | |
6230 | ||
6231 | /* wrteei */ | |
99e300ef | 6232 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6233 | { |
6234 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6235 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6236 | #else |
76db3ba4 | 6237 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6238 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6239 | return; |
6240 | } | |
fbe73008 | 6241 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6242 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6243 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6244 | gen_stop_exception(ctx); |
6527f6ea | 6245 | } else { |
1b6e5f99 | 6246 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6247 | } |
76a66253 JM |
6248 | #endif |
6249 | } | |
6250 | ||
08e46e54 | 6251 | /* PowerPC 440 specific instructions */ |
99e300ef | 6252 | |
54623277 | 6253 | /* dlmzb */ |
99e300ef | 6254 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6255 | { |
ef0d51af | 6256 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
d15f74fb BS |
6257 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env, |
6258 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); | |
ef0d51af | 6259 | tcg_temp_free_i32(t0); |
76a66253 JM |
6260 | } |
6261 | ||
6262 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6263 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6264 | { |
6265 | /* interpreted as no-op */ | |
6266 | } | |
6267 | ||
6268 | /* msync replaces sync on 440 */ | |
dcb2b9e1 | 6269 | static void gen_msync_4xx(DisasContext *ctx) |
76a66253 JM |
6270 | { |
6271 | /* interpreted as no-op */ | |
6272 | } | |
6273 | ||
6274 | /* icbt */ | |
e8eaa2c0 | 6275 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6276 | { |
6277 | /* interpreted as no-op */ | |
6278 | /* XXX: specification say this is treated as a load by the MMU | |
6279 | * but does not generate any exception | |
6280 | */ | |
79aceca5 FB |
6281 | } |
6282 | ||
9e0b5cb1 AG |
6283 | /* Embedded.Processor Control */ |
6284 | ||
6285 | static void gen_msgclr(DisasContext *ctx) | |
6286 | { | |
6287 | #if defined(CONFIG_USER_ONLY) | |
6288 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6289 | #else | |
6290 | if (unlikely(ctx->mem_idx == 0)) { | |
6291 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6292 | return; | |
6293 | } | |
6294 | ||
e5f17ac6 | 6295 | gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9e0b5cb1 AG |
6296 | #endif |
6297 | } | |
6298 | ||
d5d11a39 AG |
6299 | static void gen_msgsnd(DisasContext *ctx) |
6300 | { | |
6301 | #if defined(CONFIG_USER_ONLY) | |
6302 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6303 | #else | |
6304 | if (unlikely(ctx->mem_idx == 0)) { | |
6305 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6306 | return; | |
6307 | } | |
6308 | ||
6309 | gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6310 | #endif | |
6311 | } | |
6312 | ||
a9d9eb8f JM |
6313 | /*** Altivec vector extension ***/ |
6314 | /* Altivec registers moves */ | |
a9d9eb8f | 6315 | |
636aa200 | 6316 | static inline TCGv_ptr gen_avr_ptr(int reg) |
564e571a | 6317 | { |
e4704b3b | 6318 | TCGv_ptr r = tcg_temp_new_ptr(); |
564e571a AJ |
6319 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg])); |
6320 | return r; | |
6321 | } | |
6322 | ||
a9d9eb8f | 6323 | #define GEN_VR_LDX(name, opc2, opc3) \ |
99e300ef | 6324 | static void glue(gen_, name)(DisasContext *ctx) \ |
a9d9eb8f | 6325 | { \ |
fe1e5c53 | 6326 | TCGv EA; \ |
a9d9eb8f | 6327 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6328 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6329 | return; \ |
6330 | } \ | |
76db3ba4 | 6331 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6332 | EA = tcg_temp_new(); \ |
76db3ba4 | 6333 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6334 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6335 | if (ctx->le_mode) { \ |
6336 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6337 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6338 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6339 | } else { \ |
76db3ba4 | 6340 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6341 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6342 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6343 | } \ |
6344 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6345 | } |
6346 | ||
6347 | #define GEN_VR_STX(name, opc2, opc3) \ | |
99e300ef | 6348 | static void gen_st##name(DisasContext *ctx) \ |
a9d9eb8f | 6349 | { \ |
fe1e5c53 | 6350 | TCGv EA; \ |
a9d9eb8f | 6351 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6352 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6353 | return; \ |
6354 | } \ | |
76db3ba4 | 6355 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6356 | EA = tcg_temp_new(); \ |
76db3ba4 | 6357 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6358 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6359 | if (ctx->le_mode) { \ |
6360 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6361 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6362 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6363 | } else { \ |
76db3ba4 | 6364 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6365 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6366 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6367 | } \ |
6368 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6369 | } |
6370 | ||
cbfb6ae9 | 6371 | #define GEN_VR_LVE(name, opc2, opc3) \ |
99e300ef | 6372 | static void gen_lve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6373 | { \ |
6374 | TCGv EA; \ | |
6375 | TCGv_ptr rs; \ | |
6376 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6377 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6378 | return; \ | |
6379 | } \ | |
6380 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6381 | EA = tcg_temp_new(); \ | |
6382 | gen_addr_reg_index(ctx, EA); \ | |
6383 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6384 | gen_helper_lve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6385 | tcg_temp_free(EA); \ |
6386 | tcg_temp_free_ptr(rs); \ | |
6387 | } | |
6388 | ||
6389 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
99e300ef | 6390 | static void gen_stve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6391 | { \ |
6392 | TCGv EA; \ | |
6393 | TCGv_ptr rs; \ | |
6394 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6395 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6396 | return; \ | |
6397 | } \ | |
6398 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6399 | EA = tcg_temp_new(); \ | |
6400 | gen_addr_reg_index(ctx, EA); \ | |
6401 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6402 | gen_helper_stve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6403 | tcg_temp_free(EA); \ |
6404 | tcg_temp_free_ptr(rs); \ | |
6405 | } | |
6406 | ||
fe1e5c53 | 6407 | GEN_VR_LDX(lvx, 0x07, 0x03); |
a9d9eb8f | 6408 | /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */ |
fe1e5c53 | 6409 | GEN_VR_LDX(lvxl, 0x07, 0x0B); |
a9d9eb8f | 6410 | |
cbfb6ae9 AJ |
6411 | GEN_VR_LVE(bx, 0x07, 0x00); |
6412 | GEN_VR_LVE(hx, 0x07, 0x01); | |
6413 | GEN_VR_LVE(wx, 0x07, 0x02); | |
6414 | ||
fe1e5c53 | 6415 | GEN_VR_STX(svx, 0x07, 0x07); |
a9d9eb8f | 6416 | /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */ |
fe1e5c53 | 6417 | GEN_VR_STX(svxl, 0x07, 0x0F); |
a9d9eb8f | 6418 | |
cbfb6ae9 AJ |
6419 | GEN_VR_STVE(bx, 0x07, 0x04); |
6420 | GEN_VR_STVE(hx, 0x07, 0x05); | |
6421 | GEN_VR_STVE(wx, 0x07, 0x06); | |
6422 | ||
99e300ef | 6423 | static void gen_lvsl(DisasContext *ctx) |
bf8d8ded AJ |
6424 | { |
6425 | TCGv_ptr rd; | |
6426 | TCGv EA; | |
6427 | if (unlikely(!ctx->altivec_enabled)) { | |
6428 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6429 | return; | |
6430 | } | |
6431 | EA = tcg_temp_new(); | |
6432 | gen_addr_reg_index(ctx, EA); | |
6433 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6434 | gen_helper_lvsl(rd, EA); | |
6435 | tcg_temp_free(EA); | |
6436 | tcg_temp_free_ptr(rd); | |
6437 | } | |
6438 | ||
99e300ef | 6439 | static void gen_lvsr(DisasContext *ctx) |
bf8d8ded AJ |
6440 | { |
6441 | TCGv_ptr rd; | |
6442 | TCGv EA; | |
6443 | if (unlikely(!ctx->altivec_enabled)) { | |
6444 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6445 | return; | |
6446 | } | |
6447 | EA = tcg_temp_new(); | |
6448 | gen_addr_reg_index(ctx, EA); | |
6449 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6450 | gen_helper_lvsr(rd, EA); | |
6451 | tcg_temp_free(EA); | |
6452 | tcg_temp_free_ptr(rd); | |
6453 | } | |
6454 | ||
99e300ef | 6455 | static void gen_mfvscr(DisasContext *ctx) |
785f451b AJ |
6456 | { |
6457 | TCGv_i32 t; | |
6458 | if (unlikely(!ctx->altivec_enabled)) { | |
6459 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6460 | return; | |
6461 | } | |
6462 | tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0); | |
6463 | t = tcg_temp_new_i32(); | |
1328c2bf | 6464 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr)); |
785f451b | 6465 | tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t); |
fce5ecb7 | 6466 | tcg_temp_free_i32(t); |
785f451b AJ |
6467 | } |
6468 | ||
99e300ef | 6469 | static void gen_mtvscr(DisasContext *ctx) |
785f451b | 6470 | { |
6e87b7c7 | 6471 | TCGv_ptr p; |
785f451b AJ |
6472 | if (unlikely(!ctx->altivec_enabled)) { |
6473 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6474 | return; | |
6475 | } | |
6e87b7c7 | 6476 | p = gen_avr_ptr(rD(ctx->opcode)); |
d15f74fb | 6477 | gen_helper_mtvscr(cpu_env, p); |
6e87b7c7 | 6478 | tcg_temp_free_ptr(p); |
785f451b AJ |
6479 | } |
6480 | ||
7a9b96cf AJ |
6481 | /* Logical operations */ |
6482 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
99e300ef | 6483 | static void glue(gen_, name)(DisasContext *ctx) \ |
7a9b96cf AJ |
6484 | { \ |
6485 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6486 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6487 | return; \ | |
6488 | } \ | |
6489 | tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \ | |
6490 | tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \ | |
6491 | } | |
6492 | ||
6493 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16); | |
6494 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17); | |
6495 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18); | |
6496 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19); | |
6497 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20); | |
6498 | ||
8e27dd6f | 6499 | #define GEN_VXFORM(name, opc2, opc3) \ |
99e300ef | 6500 | static void glue(gen_, name)(DisasContext *ctx) \ |
8e27dd6f AJ |
6501 | { \ |
6502 | TCGv_ptr ra, rb, rd; \ | |
6503 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6504 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6505 | return; \ | |
6506 | } \ | |
6507 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6508 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6509 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6510 | gen_helper_##name (rd, ra, rb); \ | |
6511 | tcg_temp_free_ptr(ra); \ | |
6512 | tcg_temp_free_ptr(rb); \ | |
6513 | tcg_temp_free_ptr(rd); \ | |
6514 | } | |
6515 | ||
d15f74fb BS |
6516 | #define GEN_VXFORM_ENV(name, opc2, opc3) \ |
6517 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6518 | { \ | |
6519 | TCGv_ptr ra, rb, rd; \ | |
6520 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6521 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6522 | return; \ | |
6523 | } \ | |
6524 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6525 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6526 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
54cddd21 | 6527 | gen_helper_##name(cpu_env, rd, ra, rb); \ |
d15f74fb BS |
6528 | tcg_temp_free_ptr(ra); \ |
6529 | tcg_temp_free_ptr(rb); \ | |
6530 | tcg_temp_free_ptr(rd); \ | |
6531 | } | |
6532 | ||
7872c51c AJ |
6533 | GEN_VXFORM(vaddubm, 0, 0); |
6534 | GEN_VXFORM(vadduhm, 0, 1); | |
6535 | GEN_VXFORM(vadduwm, 0, 2); | |
6536 | GEN_VXFORM(vsububm, 0, 16); | |
6537 | GEN_VXFORM(vsubuhm, 0, 17); | |
6538 | GEN_VXFORM(vsubuwm, 0, 18); | |
e4039339 AJ |
6539 | GEN_VXFORM(vmaxub, 1, 0); |
6540 | GEN_VXFORM(vmaxuh, 1, 1); | |
6541 | GEN_VXFORM(vmaxuw, 1, 2); | |
6542 | GEN_VXFORM(vmaxsb, 1, 4); | |
6543 | GEN_VXFORM(vmaxsh, 1, 5); | |
6544 | GEN_VXFORM(vmaxsw, 1, 6); | |
6545 | GEN_VXFORM(vminub, 1, 8); | |
6546 | GEN_VXFORM(vminuh, 1, 9); | |
6547 | GEN_VXFORM(vminuw, 1, 10); | |
6548 | GEN_VXFORM(vminsb, 1, 12); | |
6549 | GEN_VXFORM(vminsh, 1, 13); | |
6550 | GEN_VXFORM(vminsw, 1, 14); | |
fab3cbe9 AJ |
6551 | GEN_VXFORM(vavgub, 1, 16); |
6552 | GEN_VXFORM(vavguh, 1, 17); | |
6553 | GEN_VXFORM(vavguw, 1, 18); | |
6554 | GEN_VXFORM(vavgsb, 1, 20); | |
6555 | GEN_VXFORM(vavgsh, 1, 21); | |
6556 | GEN_VXFORM(vavgsw, 1, 22); | |
3b430048 AJ |
6557 | GEN_VXFORM(vmrghb, 6, 0); |
6558 | GEN_VXFORM(vmrghh, 6, 1); | |
6559 | GEN_VXFORM(vmrghw, 6, 2); | |
6560 | GEN_VXFORM(vmrglb, 6, 4); | |
6561 | GEN_VXFORM(vmrglh, 6, 5); | |
6562 | GEN_VXFORM(vmrglw, 6, 6); | |
2c277908 AJ |
6563 | GEN_VXFORM(vmuloub, 4, 0); |
6564 | GEN_VXFORM(vmulouh, 4, 1); | |
6565 | GEN_VXFORM(vmulosb, 4, 4); | |
6566 | GEN_VXFORM(vmulosh, 4, 5); | |
6567 | GEN_VXFORM(vmuleub, 4, 8); | |
6568 | GEN_VXFORM(vmuleuh, 4, 9); | |
6569 | GEN_VXFORM(vmulesb, 4, 12); | |
6570 | GEN_VXFORM(vmulesh, 4, 13); | |
d79f0809 AJ |
6571 | GEN_VXFORM(vslb, 2, 4); |
6572 | GEN_VXFORM(vslh, 2, 5); | |
6573 | GEN_VXFORM(vslw, 2, 6); | |
07ef34c3 AJ |
6574 | GEN_VXFORM(vsrb, 2, 8); |
6575 | GEN_VXFORM(vsrh, 2, 9); | |
6576 | GEN_VXFORM(vsrw, 2, 10); | |
6577 | GEN_VXFORM(vsrab, 2, 12); | |
6578 | GEN_VXFORM(vsrah, 2, 13); | |
6579 | GEN_VXFORM(vsraw, 2, 14); | |
7b239bec AJ |
6580 | GEN_VXFORM(vslo, 6, 16); |
6581 | GEN_VXFORM(vsro, 6, 17); | |
e343da72 AJ |
6582 | GEN_VXFORM(vaddcuw, 0, 6); |
6583 | GEN_VXFORM(vsubcuw, 0, 22); | |
d15f74fb BS |
6584 | GEN_VXFORM_ENV(vaddubs, 0, 8); |
6585 | GEN_VXFORM_ENV(vadduhs, 0, 9); | |
6586 | GEN_VXFORM_ENV(vadduws, 0, 10); | |
6587 | GEN_VXFORM_ENV(vaddsbs, 0, 12); | |
6588 | GEN_VXFORM_ENV(vaddshs, 0, 13); | |
6589 | GEN_VXFORM_ENV(vaddsws, 0, 14); | |
6590 | GEN_VXFORM_ENV(vsububs, 0, 24); | |
6591 | GEN_VXFORM_ENV(vsubuhs, 0, 25); | |
6592 | GEN_VXFORM_ENV(vsubuws, 0, 26); | |
6593 | GEN_VXFORM_ENV(vsubsbs, 0, 28); | |
6594 | GEN_VXFORM_ENV(vsubshs, 0, 29); | |
6595 | GEN_VXFORM_ENV(vsubsws, 0, 30); | |
5e1d0985 AJ |
6596 | GEN_VXFORM(vrlb, 2, 0); |
6597 | GEN_VXFORM(vrlh, 2, 1); | |
6598 | GEN_VXFORM(vrlw, 2, 2); | |
d9430add AJ |
6599 | GEN_VXFORM(vsl, 2, 7); |
6600 | GEN_VXFORM(vsr, 2, 11); | |
d15f74fb BS |
6601 | GEN_VXFORM_ENV(vpkuhum, 7, 0); |
6602 | GEN_VXFORM_ENV(vpkuwum, 7, 1); | |
6603 | GEN_VXFORM_ENV(vpkuhus, 7, 2); | |
6604 | GEN_VXFORM_ENV(vpkuwus, 7, 3); | |
6605 | GEN_VXFORM_ENV(vpkshus, 7, 4); | |
6606 | GEN_VXFORM_ENV(vpkswus, 7, 5); | |
6607 | GEN_VXFORM_ENV(vpkshss, 7, 6); | |
6608 | GEN_VXFORM_ENV(vpkswss, 7, 7); | |
1dd9ffb9 | 6609 | GEN_VXFORM(vpkpx, 7, 12); |
d15f74fb BS |
6610 | GEN_VXFORM_ENV(vsum4ubs, 4, 24); |
6611 | GEN_VXFORM_ENV(vsum4sbs, 4, 28); | |
6612 | GEN_VXFORM_ENV(vsum4shs, 4, 25); | |
6613 | GEN_VXFORM_ENV(vsum2sws, 4, 26); | |
6614 | GEN_VXFORM_ENV(vsumsws, 4, 30); | |
6615 | GEN_VXFORM_ENV(vaddfp, 5, 0); | |
6616 | GEN_VXFORM_ENV(vsubfp, 5, 1); | |
6617 | GEN_VXFORM_ENV(vmaxfp, 5, 16); | |
6618 | GEN_VXFORM_ENV(vminfp, 5, 17); | |
fab3cbe9 | 6619 | |
0cbcd906 | 6620 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ |
e8eaa2c0 | 6621 | static void glue(gen_, name)(DisasContext *ctx) \ |
0cbcd906 AJ |
6622 | { \ |
6623 | TCGv_ptr ra, rb, rd; \ | |
6624 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6625 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6626 | return; \ | |
6627 | } \ | |
6628 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6629 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6630 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
d15f74fb | 6631 | gen_helper_##opname(cpu_env, rd, ra, rb); \ |
0cbcd906 AJ |
6632 | tcg_temp_free_ptr(ra); \ |
6633 | tcg_temp_free_ptr(rb); \ | |
6634 | tcg_temp_free_ptr(rd); \ | |
6635 | } | |
6636 | ||
6637 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
6638 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
6639 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
6640 | ||
1add6e23 AJ |
6641 | GEN_VXRFORM(vcmpequb, 3, 0) |
6642 | GEN_VXRFORM(vcmpequh, 3, 1) | |
6643 | GEN_VXRFORM(vcmpequw, 3, 2) | |
6644 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
6645 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
6646 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
6647 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
6648 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
6649 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
819ca121 AJ |
6650 | GEN_VXRFORM(vcmpeqfp, 3, 3) |
6651 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
6652 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
6653 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
1add6e23 | 6654 | |
c026766b | 6655 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6656 | static void glue(gen_, name)(DisasContext *ctx) \ |
c026766b AJ |
6657 | { \ |
6658 | TCGv_ptr rd; \ | |
6659 | TCGv_i32 simm; \ | |
6660 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6661 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6662 | return; \ | |
6663 | } \ | |
6664 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6665 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6666 | gen_helper_##name (rd, simm); \ | |
6667 | tcg_temp_free_i32(simm); \ | |
6668 | tcg_temp_free_ptr(rd); \ | |
6669 | } | |
6670 | ||
6671 | GEN_VXFORM_SIMM(vspltisb, 6, 12); | |
6672 | GEN_VXFORM_SIMM(vspltish, 6, 13); | |
6673 | GEN_VXFORM_SIMM(vspltisw, 6, 14); | |
6674 | ||
de5f2484 | 6675 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ |
99e300ef | 6676 | static void glue(gen_, name)(DisasContext *ctx) \ |
de5f2484 AJ |
6677 | { \ |
6678 | TCGv_ptr rb, rd; \ | |
6679 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6680 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6681 | return; \ | |
6682 | } \ | |
6683 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6684 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6685 | gen_helper_##name (rd, rb); \ | |
6686 | tcg_temp_free_ptr(rb); \ | |
6687 | tcg_temp_free_ptr(rd); \ | |
6688 | } | |
6689 | ||
d15f74fb BS |
6690 | #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \ |
6691 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6692 | { \ | |
6693 | TCGv_ptr rb, rd; \ | |
6694 | \ | |
6695 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6696 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6697 | return; \ | |
6698 | } \ | |
6699 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6700 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6701 | gen_helper_##name(cpu_env, rd, rb); \ | |
6702 | tcg_temp_free_ptr(rb); \ | |
6703 | tcg_temp_free_ptr(rd); \ | |
6704 | } | |
6705 | ||
6cf1c6e5 AJ |
6706 | GEN_VXFORM_NOA(vupkhsb, 7, 8); |
6707 | GEN_VXFORM_NOA(vupkhsh, 7, 9); | |
6708 | GEN_VXFORM_NOA(vupklsb, 7, 10); | |
6709 | GEN_VXFORM_NOA(vupklsh, 7, 11); | |
79f85c3a AJ |
6710 | GEN_VXFORM_NOA(vupkhpx, 7, 13); |
6711 | GEN_VXFORM_NOA(vupklpx, 7, 15); | |
d15f74fb BS |
6712 | GEN_VXFORM_NOA_ENV(vrefp, 5, 4); |
6713 | GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5); | |
6714 | GEN_VXFORM_NOA_ENV(vexptefp, 5, 6); | |
6715 | GEN_VXFORM_NOA_ENV(vlogefp, 5, 7); | |
6716 | GEN_VXFORM_NOA_ENV(vrfim, 5, 8); | |
6717 | GEN_VXFORM_NOA_ENV(vrfin, 5, 9); | |
6718 | GEN_VXFORM_NOA_ENV(vrfip, 5, 10); | |
6719 | GEN_VXFORM_NOA_ENV(vrfiz, 5, 11); | |
79f85c3a | 6720 | |
21d21583 | 6721 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6722 | static void glue(gen_, name)(DisasContext *ctx) \ |
21d21583 AJ |
6723 | { \ |
6724 | TCGv_ptr rd; \ | |
6725 | TCGv_i32 simm; \ | |
6726 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6727 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6728 | return; \ | |
6729 | } \ | |
6730 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6731 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6732 | gen_helper_##name (rd, simm); \ | |
6733 | tcg_temp_free_i32(simm); \ | |
6734 | tcg_temp_free_ptr(rd); \ | |
6735 | } | |
6736 | ||
27a4edb3 | 6737 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ |
99e300ef | 6738 | static void glue(gen_, name)(DisasContext *ctx) \ |
27a4edb3 AJ |
6739 | { \ |
6740 | TCGv_ptr rb, rd; \ | |
6741 | TCGv_i32 uimm; \ | |
6742 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6743 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6744 | return; \ | |
6745 | } \ | |
6746 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6747 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6748 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6749 | gen_helper_##name (rd, rb, uimm); \ | |
6750 | tcg_temp_free_i32(uimm); \ | |
6751 | tcg_temp_free_ptr(rb); \ | |
6752 | tcg_temp_free_ptr(rd); \ | |
6753 | } | |
6754 | ||
d15f74fb BS |
6755 | #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \ |
6756 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6757 | { \ | |
6758 | TCGv_ptr rb, rd; \ | |
6759 | TCGv_i32 uimm; \ | |
6760 | \ | |
6761 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6762 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6763 | return; \ | |
6764 | } \ | |
6765 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6766 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6767 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6768 | gen_helper_##name(cpu_env, rd, rb, uimm); \ | |
6769 | tcg_temp_free_i32(uimm); \ | |
6770 | tcg_temp_free_ptr(rb); \ | |
6771 | tcg_temp_free_ptr(rd); \ | |
6772 | } | |
6773 | ||
e4e6bee7 AJ |
6774 | GEN_VXFORM_UIMM(vspltb, 6, 8); |
6775 | GEN_VXFORM_UIMM(vsplth, 6, 9); | |
6776 | GEN_VXFORM_UIMM(vspltw, 6, 10); | |
d15f74fb BS |
6777 | GEN_VXFORM_UIMM_ENV(vcfux, 5, 12); |
6778 | GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13); | |
6779 | GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14); | |
6780 | GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15); | |
e4e6bee7 | 6781 | |
99e300ef | 6782 | static void gen_vsldoi(DisasContext *ctx) |
cd633b10 AJ |
6783 | { |
6784 | TCGv_ptr ra, rb, rd; | |
fce5ecb7 | 6785 | TCGv_i32 sh; |
cd633b10 AJ |
6786 | if (unlikely(!ctx->altivec_enabled)) { |
6787 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6788 | return; | |
6789 | } | |
6790 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6791 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6792 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6793 | sh = tcg_const_i32(VSH(ctx->opcode)); | |
6794 | gen_helper_vsldoi (rd, ra, rb, sh); | |
6795 | tcg_temp_free_ptr(ra); | |
6796 | tcg_temp_free_ptr(rb); | |
6797 | tcg_temp_free_ptr(rd); | |
fce5ecb7 | 6798 | tcg_temp_free_i32(sh); |
cd633b10 AJ |
6799 | } |
6800 | ||
707cec33 | 6801 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ |
d15f74fb | 6802 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
707cec33 AJ |
6803 | { \ |
6804 | TCGv_ptr ra, rb, rc, rd; \ | |
6805 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6806 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6807 | return; \ | |
6808 | } \ | |
6809 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6810 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6811 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
6812 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6813 | if (Rc(ctx->opcode)) { \ | |
d15f74fb | 6814 | gen_helper_##name1(cpu_env, rd, ra, rb, rc); \ |
707cec33 | 6815 | } else { \ |
d15f74fb | 6816 | gen_helper_##name0(cpu_env, rd, ra, rb, rc); \ |
707cec33 AJ |
6817 | } \ |
6818 | tcg_temp_free_ptr(ra); \ | |
6819 | tcg_temp_free_ptr(rb); \ | |
6820 | tcg_temp_free_ptr(rc); \ | |
6821 | tcg_temp_free_ptr(rd); \ | |
6822 | } | |
6823 | ||
b161ae27 AJ |
6824 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16) |
6825 | ||
99e300ef | 6826 | static void gen_vmladduhm(DisasContext *ctx) |
bcd2ee23 AJ |
6827 | { |
6828 | TCGv_ptr ra, rb, rc, rd; | |
6829 | if (unlikely(!ctx->altivec_enabled)) { | |
6830 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6831 | return; | |
6832 | } | |
6833 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6834 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6835 | rc = gen_avr_ptr(rC(ctx->opcode)); | |
6836 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6837 | gen_helper_vmladduhm(rd, ra, rb, rc); | |
6838 | tcg_temp_free_ptr(ra); | |
6839 | tcg_temp_free_ptr(rb); | |
6840 | tcg_temp_free_ptr(rc); | |
6841 | tcg_temp_free_ptr(rd); | |
6842 | } | |
6843 | ||
b04ae981 | 6844 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18) |
4d9903b6 | 6845 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19) |
eae07261 | 6846 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20) |
d1258698 | 6847 | GEN_VAFORM_PAIRED(vsel, vperm, 21) |
35cf7c7e | 6848 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23) |
b04ae981 | 6849 | |
0487d6a8 | 6850 | /*** SPE extension ***/ |
0487d6a8 | 6851 | /* Register moves */ |
3cd7d1dd | 6852 | |
a0e13900 FC |
6853 | |
6854 | static inline void gen_evmra(DisasContext *ctx) | |
6855 | { | |
6856 | ||
6857 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 6858 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
6859 | return; |
6860 | } | |
6861 | ||
6862 | #if defined(TARGET_PPC64) | |
6863 | /* rD := rA */ | |
6864 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6865 | ||
6866 | /* spe_acc := rA */ | |
6867 | tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)], | |
6868 | cpu_env, | |
1328c2bf | 6869 | offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
6870 | #else |
6871 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
6872 | ||
6873 | /* tmp := rA_lo + rA_hi << 32 */ | |
6874 | tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6875 | ||
6876 | /* spe_acc := tmp */ | |
1328c2bf | 6877 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
6878 | tcg_temp_free_i64(tmp); |
6879 | ||
6880 | /* rD := rA */ | |
6881 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6882 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6883 | #endif | |
6884 | } | |
6885 | ||
636aa200 BS |
6886 | static inline void gen_load_gpr64(TCGv_i64 t, int reg) |
6887 | { | |
f78fb44e AJ |
6888 | #if defined(TARGET_PPC64) |
6889 | tcg_gen_mov_i64(t, cpu_gpr[reg]); | |
6890 | #else | |
36aa55dc | 6891 | tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]); |
3cd7d1dd | 6892 | #endif |
f78fb44e | 6893 | } |
3cd7d1dd | 6894 | |
636aa200 BS |
6895 | static inline void gen_store_gpr64(int reg, TCGv_i64 t) |
6896 | { | |
f78fb44e AJ |
6897 | #if defined(TARGET_PPC64) |
6898 | tcg_gen_mov_i64(cpu_gpr[reg], t); | |
6899 | #else | |
a7812ae4 | 6900 | TCGv_i64 tmp = tcg_temp_new_i64(); |
f78fb44e | 6901 | tcg_gen_trunc_i64_i32(cpu_gpr[reg], t); |
f78fb44e AJ |
6902 | tcg_gen_shri_i64(tmp, t, 32); |
6903 | tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp); | |
a7812ae4 | 6904 | tcg_temp_free_i64(tmp); |
3cd7d1dd | 6905 | #endif |
f78fb44e | 6906 | } |
3cd7d1dd | 6907 | |
70560da7 | 6908 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
99e300ef | 6909 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
0487d6a8 JM |
6910 | { \ |
6911 | if (Rc(ctx->opcode)) \ | |
6912 | gen_##name1(ctx); \ | |
6913 | else \ | |
6914 | gen_##name0(ctx); \ | |
6915 | } | |
6916 | ||
6917 | /* Handler for undefined SPE opcodes */ | |
636aa200 | 6918 | static inline void gen_speundef(DisasContext *ctx) |
0487d6a8 | 6919 | { |
e06fcd75 | 6920 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
0487d6a8 JM |
6921 | } |
6922 | ||
57951c27 AJ |
6923 | /* SPE logic */ |
6924 | #if defined(TARGET_PPC64) | |
6925 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6926 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6927 | { \ |
6928 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6929 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6930 | return; \ |
6931 | } \ | |
57951c27 AJ |
6932 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6933 | cpu_gpr[rB(ctx->opcode)]); \ | |
6934 | } | |
6935 | #else | |
6936 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6937 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
6938 | { \ |
6939 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6940 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
6941 | return; \ |
6942 | } \ | |
6943 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ | |
6944 | cpu_gpr[rB(ctx->opcode)]); \ | |
6945 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6946 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 6947 | } |
57951c27 AJ |
6948 | #endif |
6949 | ||
6950 | GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl); | |
6951 | GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl); | |
6952 | GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl); | |
6953 | GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl); | |
6954 | GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl); | |
6955 | GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl); | |
6956 | GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl); | |
6957 | GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl); | |
0487d6a8 | 6958 | |
57951c27 AJ |
6959 | /* SPE logic immediate */ |
6960 | #if defined(TARGET_PPC64) | |
6961 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6962 | static inline void gen_##name(DisasContext *ctx) \ |
3d3a6a0a AJ |
6963 | { \ |
6964 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6965 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
3d3a6a0a AJ |
6966 | return; \ |
6967 | } \ | |
a7812ae4 PB |
6968 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
6969 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
6970 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
6971 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
6972 | tcg_opi(t0, t0, rB(ctx->opcode)); \ | |
6973 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
6974 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 6975 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
6976 | tcg_opi(t1, t1, rB(ctx->opcode)); \ |
6977 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
6978 | tcg_temp_free_i32(t0); \ |
6979 | tcg_temp_free_i32(t1); \ | |
3d3a6a0a | 6980 | } |
57951c27 AJ |
6981 | #else |
6982 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6983 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6984 | { \ |
6985 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6986 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6987 | return; \ |
6988 | } \ | |
57951c27 AJ |
6989 | tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6990 | rB(ctx->opcode)); \ | |
6991 | tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6992 | rB(ctx->opcode)); \ | |
0487d6a8 | 6993 | } |
57951c27 AJ |
6994 | #endif |
6995 | GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32); | |
6996 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32); | |
6997 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32); | |
6998 | GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32); | |
0487d6a8 | 6999 | |
57951c27 AJ |
7000 | /* SPE arithmetic */ |
7001 | #if defined(TARGET_PPC64) | |
7002 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ | |
636aa200 | 7003 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7004 | { \ |
7005 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7006 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7007 | return; \ |
7008 | } \ | |
a7812ae4 PB |
7009 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7010 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7011 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7012 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7013 | tcg_op(t0, t0); \ | |
7014 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7015 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7016 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7017 | tcg_op(t1, t1); \ |
7018 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7019 | tcg_temp_free_i32(t0); \ |
7020 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 7021 | } |
57951c27 | 7022 | #else |
a7812ae4 | 7023 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ |
636aa200 | 7024 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7025 | { \ |
7026 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7027 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7028 | return; \ |
7029 | } \ | |
7030 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \ | |
7031 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \ | |
7032 | } | |
7033 | #endif | |
0487d6a8 | 7034 | |
636aa200 | 7035 | static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1) |
57951c27 AJ |
7036 | { |
7037 | int l1 = gen_new_label(); | |
7038 | int l2 = gen_new_label(); | |
0487d6a8 | 7039 | |
57951c27 AJ |
7040 | tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1); |
7041 | tcg_gen_neg_i32(ret, arg1); | |
7042 | tcg_gen_br(l2); | |
7043 | gen_set_label(l1); | |
a7812ae4 | 7044 | tcg_gen_mov_i32(ret, arg1); |
57951c27 AJ |
7045 | gen_set_label(l2); |
7046 | } | |
7047 | GEN_SPEOP_ARITH1(evabs, gen_op_evabs); | |
7048 | GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32); | |
7049 | GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32); | |
7050 | GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32); | |
636aa200 | 7051 | static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1) |
0487d6a8 | 7052 | { |
57951c27 AJ |
7053 | tcg_gen_addi_i32(ret, arg1, 0x8000); |
7054 | tcg_gen_ext16u_i32(ret, ret); | |
7055 | } | |
7056 | GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw); | |
a7812ae4 PB |
7057 | GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32); |
7058 | GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32); | |
0487d6a8 | 7059 | |
57951c27 AJ |
7060 | #if defined(TARGET_PPC64) |
7061 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 7062 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7063 | { \ |
7064 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7065 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7066 | return; \ |
7067 | } \ | |
a7812ae4 PB |
7068 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7069 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7070 | TCGv_i32 t2 = tcg_temp_local_new_i32(); \ | |
501e23c4 | 7071 | TCGv_i64 t3 = tcg_temp_local_new_i64(); \ |
57951c27 AJ |
7072 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7073 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \ | |
7074 | tcg_op(t0, t0, t2); \ | |
7075 | tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7076 | tcg_gen_trunc_i64_i32(t1, t3); \ | |
7077 | tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7078 | tcg_gen_trunc_i64_i32(t2, t3); \ | |
a7812ae4 | 7079 | tcg_temp_free_i64(t3); \ |
57951c27 | 7080 | tcg_op(t1, t1, t2); \ |
a7812ae4 | 7081 | tcg_temp_free_i32(t2); \ |
57951c27 | 7082 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ |
a7812ae4 PB |
7083 | tcg_temp_free_i32(t0); \ |
7084 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 7085 | } |
57951c27 AJ |
7086 | #else |
7087 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 7088 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7089 | { \ |
7090 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7091 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7092 | return; \ |
7093 | } \ | |
57951c27 AJ |
7094 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7095 | cpu_gpr[rB(ctx->opcode)]); \ | |
7096 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
7097 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 7098 | } |
57951c27 | 7099 | #endif |
0487d6a8 | 7100 | |
636aa200 | 7101 | static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7102 | { |
a7812ae4 | 7103 | TCGv_i32 t0; |
57951c27 | 7104 | int l1, l2; |
0487d6a8 | 7105 | |
57951c27 AJ |
7106 | l1 = gen_new_label(); |
7107 | l2 = gen_new_label(); | |
a7812ae4 | 7108 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7109 | /* No error here: 6 bits are used */ |
7110 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7111 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7112 | tcg_gen_shr_i32(ret, arg1, t0); | |
7113 | tcg_gen_br(l2); | |
7114 | gen_set_label(l1); | |
7115 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 7116 | gen_set_label(l2); |
a7812ae4 | 7117 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7118 | } |
7119 | GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu); | |
636aa200 | 7120 | static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7121 | { |
a7812ae4 | 7122 | TCGv_i32 t0; |
57951c27 AJ |
7123 | int l1, l2; |
7124 | ||
7125 | l1 = gen_new_label(); | |
7126 | l2 = gen_new_label(); | |
a7812ae4 | 7127 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7128 | /* No error here: 6 bits are used */ |
7129 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7130 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7131 | tcg_gen_sar_i32(ret, arg1, t0); | |
7132 | tcg_gen_br(l2); | |
7133 | gen_set_label(l1); | |
7134 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 7135 | gen_set_label(l2); |
a7812ae4 | 7136 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7137 | } |
7138 | GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws); | |
636aa200 | 7139 | static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7140 | { |
a7812ae4 | 7141 | TCGv_i32 t0; |
57951c27 AJ |
7142 | int l1, l2; |
7143 | ||
7144 | l1 = gen_new_label(); | |
7145 | l2 = gen_new_label(); | |
a7812ae4 | 7146 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7147 | /* No error here: 6 bits are used */ |
7148 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7149 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7150 | tcg_gen_shl_i32(ret, arg1, t0); | |
7151 | tcg_gen_br(l2); | |
7152 | gen_set_label(l1); | |
7153 | tcg_gen_movi_i32(ret, 0); | |
e29ef9fa | 7154 | gen_set_label(l2); |
a7812ae4 | 7155 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7156 | } |
7157 | GEN_SPEOP_ARITH2(evslw, gen_op_evslw); | |
636aa200 | 7158 | static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7159 | { |
a7812ae4 | 7160 | TCGv_i32 t0 = tcg_temp_new_i32(); |
57951c27 AJ |
7161 | tcg_gen_andi_i32(t0, arg2, 0x1F); |
7162 | tcg_gen_rotl_i32(ret, arg1, t0); | |
a7812ae4 | 7163 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7164 | } |
7165 | GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw); | |
636aa200 | 7166 | static inline void gen_evmergehi(DisasContext *ctx) |
57951c27 AJ |
7167 | { |
7168 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7169 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7170 | return; |
7171 | } | |
7172 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7173 | TCGv t0 = tcg_temp_new(); |
7174 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
7175 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
7176 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); | |
7177 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7178 | tcg_temp_free(t0); | |
7179 | tcg_temp_free(t1); | |
7180 | #else | |
7181 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7182 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7183 | #endif | |
7184 | } | |
7185 | GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32); | |
636aa200 | 7186 | static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
0487d6a8 | 7187 | { |
57951c27 AJ |
7188 | tcg_gen_sub_i32(ret, arg2, arg1); |
7189 | } | |
7190 | GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf); | |
0487d6a8 | 7191 | |
57951c27 AJ |
7192 | /* SPE arithmetic immediate */ |
7193 | #if defined(TARGET_PPC64) | |
7194 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 7195 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7196 | { \ |
7197 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7198 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7199 | return; \ |
7200 | } \ | |
a7812ae4 PB |
7201 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7202 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7203 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7204 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ |
7205 | tcg_op(t0, t0, rA(ctx->opcode)); \ | |
7206 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7207 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
e06fcd75 | 7208 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7209 | tcg_op(t1, t1, rA(ctx->opcode)); \ |
7210 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7211 | tcg_temp_free_i32(t0); \ |
7212 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
7213 | } |
7214 | #else | |
7215 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 7216 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7217 | { \ |
7218 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7219 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7220 | return; \ |
7221 | } \ | |
7222 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
7223 | rA(ctx->opcode)); \ | |
7224 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \ | |
7225 | rA(ctx->opcode)); \ | |
7226 | } | |
7227 | #endif | |
7228 | GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32); | |
7229 | GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32); | |
7230 | ||
7231 | /* SPE comparison */ | |
7232 | #if defined(TARGET_PPC64) | |
7233 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7234 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7235 | { \ |
7236 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7237 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7238 | return; \ |
7239 | } \ | |
7240 | int l1 = gen_new_label(); \ | |
7241 | int l2 = gen_new_label(); \ | |
7242 | int l3 = gen_new_label(); \ | |
7243 | int l4 = gen_new_label(); \ | |
a7812ae4 PB |
7244 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7245 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7246 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7247 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7248 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
7249 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \ | |
a7812ae4 | 7250 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \ |
57951c27 AJ |
7251 | tcg_gen_br(l2); \ |
7252 | gen_set_label(l1); \ | |
7253 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7254 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7255 | gen_set_label(l2); \ | |
7256 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7257 | tcg_gen_trunc_i64_i32(t0, t2); \ | |
7258 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7259 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7260 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7261 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \ |
7262 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7263 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7264 | tcg_gen_br(l4); \ | |
7265 | gen_set_label(l3); \ | |
7266 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7267 | CRF_CH | CRF_CH_OR_CL); \ | |
7268 | gen_set_label(l4); \ | |
a7812ae4 PB |
7269 | tcg_temp_free_i32(t0); \ |
7270 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
7271 | } |
7272 | #else | |
7273 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7274 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7275 | { \ |
7276 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7277 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7278 | return; \ |
7279 | } \ | |
7280 | int l1 = gen_new_label(); \ | |
7281 | int l2 = gen_new_label(); \ | |
7282 | int l3 = gen_new_label(); \ | |
7283 | int l4 = gen_new_label(); \ | |
7284 | \ | |
7285 | tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \ | |
7286 | cpu_gpr[rB(ctx->opcode)], l1); \ | |
7287 | tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \ | |
7288 | tcg_gen_br(l2); \ | |
7289 | gen_set_label(l1); \ | |
7290 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7291 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7292 | gen_set_label(l2); \ | |
7293 | tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \ | |
7294 | cpu_gprh[rB(ctx->opcode)], l3); \ | |
7295 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7296 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7297 | tcg_gen_br(l4); \ | |
7298 | gen_set_label(l3); \ | |
7299 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7300 | CRF_CH | CRF_CH_OR_CL); \ | |
7301 | gen_set_label(l4); \ | |
7302 | } | |
7303 | #endif | |
7304 | GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU); | |
7305 | GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT); | |
7306 | GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU); | |
7307 | GEN_SPEOP_COMP(evcmplts, TCG_COND_LT); | |
7308 | GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ); | |
7309 | ||
7310 | /* SPE misc */ | |
636aa200 | 7311 | static inline void gen_brinc(DisasContext *ctx) |
57951c27 AJ |
7312 | { |
7313 | /* Note: brinc is usable even if SPE is disabled */ | |
a7812ae4 PB |
7314 | gen_helper_brinc(cpu_gpr[rD(ctx->opcode)], |
7315 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
0487d6a8 | 7316 | } |
636aa200 | 7317 | static inline void gen_evmergelo(DisasContext *ctx) |
57951c27 AJ |
7318 | { |
7319 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7320 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7321 | return; |
7322 | } | |
7323 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7324 | TCGv t0 = tcg_temp_new(); |
7325 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7326 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7327 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); |
7328 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7329 | tcg_temp_free(t0); | |
7330 | tcg_temp_free(t1); | |
7331 | #else | |
57951c27 | 7332 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
33890b3e | 7333 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7334 | #endif |
7335 | } | |
636aa200 | 7336 | static inline void gen_evmergehilo(DisasContext *ctx) |
57951c27 AJ |
7337 | { |
7338 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7339 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7340 | return; |
7341 | } | |
7342 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7343 | TCGv t0 = tcg_temp_new(); |
7344 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7345 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7346 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); |
7347 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7348 | tcg_temp_free(t0); | |
7349 | tcg_temp_free(t1); | |
7350 | #else | |
7351 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7352 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7353 | #endif | |
7354 | } | |
636aa200 | 7355 | static inline void gen_evmergelohi(DisasContext *ctx) |
57951c27 AJ |
7356 | { |
7357 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7358 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7359 | return; |
7360 | } | |
7361 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7362 | TCGv t0 = tcg_temp_new(); |
7363 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
7364 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
7365 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); | |
7366 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7367 | tcg_temp_free(t0); | |
7368 | tcg_temp_free(t1); | |
7369 | #else | |
33890b3e NF |
7370 | if (rD(ctx->opcode) == rA(ctx->opcode)) { |
7371 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
7372 | tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); | |
7373 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7374 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp); | |
7375 | tcg_temp_free_i32(tmp); | |
7376 | } else { | |
7377 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7378 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7379 | } | |
57951c27 AJ |
7380 | #endif |
7381 | } | |
636aa200 | 7382 | static inline void gen_evsplati(DisasContext *ctx) |
57951c27 | 7383 | { |
ae01847f | 7384 | uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27; |
0487d6a8 | 7385 | |
57951c27 | 7386 | #if defined(TARGET_PPC64) |
38d14952 | 7387 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7388 | #else |
7389 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7390 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7391 | #endif | |
7392 | } | |
636aa200 | 7393 | static inline void gen_evsplatfi(DisasContext *ctx) |
0487d6a8 | 7394 | { |
ae01847f | 7395 | uint64_t imm = rA(ctx->opcode) << 27; |
0487d6a8 | 7396 | |
57951c27 | 7397 | #if defined(TARGET_PPC64) |
38d14952 | 7398 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7399 | #else |
7400 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7401 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7402 | #endif | |
0487d6a8 JM |
7403 | } |
7404 | ||
636aa200 | 7405 | static inline void gen_evsel(DisasContext *ctx) |
57951c27 AJ |
7406 | { |
7407 | int l1 = gen_new_label(); | |
7408 | int l2 = gen_new_label(); | |
7409 | int l3 = gen_new_label(); | |
7410 | int l4 = gen_new_label(); | |
a7812ae4 | 7411 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
57951c27 | 7412 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
7413 | TCGv t1 = tcg_temp_local_new(); |
7414 | TCGv t2 = tcg_temp_local_new(); | |
57951c27 AJ |
7415 | #endif |
7416 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | |
7417 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
7418 | #if defined(TARGET_PPC64) | |
7419 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7420 | #else | |
7421 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7422 | #endif | |
7423 | tcg_gen_br(l2); | |
7424 | gen_set_label(l1); | |
7425 | #if defined(TARGET_PPC64) | |
7426 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7427 | #else | |
7428 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7429 | #endif | |
7430 | gen_set_label(l2); | |
7431 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2); | |
7432 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3); | |
7433 | #if defined(TARGET_PPC64) | |
17d9b3af | 7434 | tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]); |
57951c27 AJ |
7435 | #else |
7436 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7437 | #endif | |
7438 | tcg_gen_br(l4); | |
7439 | gen_set_label(l3); | |
7440 | #if defined(TARGET_PPC64) | |
17d9b3af | 7441 | tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7442 | #else |
7443 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7444 | #endif | |
7445 | gen_set_label(l4); | |
a7812ae4 | 7446 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7447 | #if defined(TARGET_PPC64) |
7448 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2); | |
7449 | tcg_temp_free(t1); | |
7450 | tcg_temp_free(t2); | |
7451 | #endif | |
7452 | } | |
e8eaa2c0 BS |
7453 | |
7454 | static void gen_evsel0(DisasContext *ctx) | |
57951c27 AJ |
7455 | { |
7456 | gen_evsel(ctx); | |
7457 | } | |
e8eaa2c0 BS |
7458 | |
7459 | static void gen_evsel1(DisasContext *ctx) | |
57951c27 AJ |
7460 | { |
7461 | gen_evsel(ctx); | |
7462 | } | |
e8eaa2c0 BS |
7463 | |
7464 | static void gen_evsel2(DisasContext *ctx) | |
57951c27 AJ |
7465 | { |
7466 | gen_evsel(ctx); | |
7467 | } | |
e8eaa2c0 BS |
7468 | |
7469 | static void gen_evsel3(DisasContext *ctx) | |
57951c27 AJ |
7470 | { |
7471 | gen_evsel(ctx); | |
7472 | } | |
0487d6a8 | 7473 | |
a0e13900 FC |
7474 | /* Multiply */ |
7475 | ||
7476 | static inline void gen_evmwumi(DisasContext *ctx) | |
7477 | { | |
7478 | TCGv_i64 t0, t1; | |
7479 | ||
7480 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7481 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7482 | return; |
7483 | } | |
7484 | ||
7485 | t0 = tcg_temp_new_i64(); | |
7486 | t1 = tcg_temp_new_i64(); | |
7487 | ||
7488 | /* t0 := rA; t1 := rB */ | |
7489 | #if defined(TARGET_PPC64) | |
7490 | tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7491 | tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7492 | #else | |
7493 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7494 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7495 | #endif | |
7496 | ||
7497 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7498 | ||
7499 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7500 | ||
7501 | tcg_temp_free_i64(t0); | |
7502 | tcg_temp_free_i64(t1); | |
7503 | } | |
7504 | ||
7505 | static inline void gen_evmwumia(DisasContext *ctx) | |
7506 | { | |
7507 | TCGv_i64 tmp; | |
7508 | ||
7509 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7510 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7511 | return; |
7512 | } | |
7513 | ||
7514 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7515 | ||
7516 | tmp = tcg_temp_new_i64(); | |
7517 | ||
7518 | /* acc := rD */ | |
7519 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 7520 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7521 | tcg_temp_free_i64(tmp); |
7522 | } | |
7523 | ||
7524 | static inline void gen_evmwumiaa(DisasContext *ctx) | |
7525 | { | |
7526 | TCGv_i64 acc; | |
7527 | TCGv_i64 tmp; | |
7528 | ||
7529 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7530 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7531 | return; |
7532 | } | |
7533 | ||
7534 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7535 | ||
7536 | acc = tcg_temp_new_i64(); | |
7537 | tmp = tcg_temp_new_i64(); | |
7538 | ||
7539 | /* tmp := rD */ | |
7540 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7541 | ||
7542 | /* Load acc */ | |
1328c2bf | 7543 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7544 | |
7545 | /* acc := tmp + acc */ | |
7546 | tcg_gen_add_i64(acc, acc, tmp); | |
7547 | ||
7548 | /* Store acc */ | |
1328c2bf | 7549 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7550 | |
7551 | /* rD := acc */ | |
7552 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7553 | ||
7554 | tcg_temp_free_i64(acc); | |
7555 | tcg_temp_free_i64(tmp); | |
7556 | } | |
7557 | ||
7558 | static inline void gen_evmwsmi(DisasContext *ctx) | |
7559 | { | |
7560 | TCGv_i64 t0, t1; | |
7561 | ||
7562 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7563 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7564 | return; |
7565 | } | |
7566 | ||
7567 | t0 = tcg_temp_new_i64(); | |
7568 | t1 = tcg_temp_new_i64(); | |
7569 | ||
7570 | /* t0 := rA; t1 := rB */ | |
7571 | #if defined(TARGET_PPC64) | |
7572 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7573 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7574 | #else | |
7575 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7576 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7577 | #endif | |
7578 | ||
7579 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7580 | ||
7581 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7582 | ||
7583 | tcg_temp_free_i64(t0); | |
7584 | tcg_temp_free_i64(t1); | |
7585 | } | |
7586 | ||
7587 | static inline void gen_evmwsmia(DisasContext *ctx) | |
7588 | { | |
7589 | TCGv_i64 tmp; | |
7590 | ||
7591 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7592 | ||
7593 | tmp = tcg_temp_new_i64(); | |
7594 | ||
7595 | /* acc := rD */ | |
7596 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 7597 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7598 | |
7599 | tcg_temp_free_i64(tmp); | |
7600 | } | |
7601 | ||
7602 | static inline void gen_evmwsmiaa(DisasContext *ctx) | |
7603 | { | |
7604 | TCGv_i64 acc = tcg_temp_new_i64(); | |
7605 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
7606 | ||
7607 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7608 | ||
7609 | acc = tcg_temp_new_i64(); | |
7610 | tmp = tcg_temp_new_i64(); | |
7611 | ||
7612 | /* tmp := rD */ | |
7613 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7614 | ||
7615 | /* Load acc */ | |
1328c2bf | 7616 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7617 | |
7618 | /* acc := tmp + acc */ | |
7619 | tcg_gen_add_i64(acc, acc, tmp); | |
7620 | ||
7621 | /* Store acc */ | |
1328c2bf | 7622 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7623 | |
7624 | /* rD := acc */ | |
7625 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7626 | ||
7627 | tcg_temp_free_i64(acc); | |
7628 | tcg_temp_free_i64(tmp); | |
7629 | } | |
7630 | ||
70560da7 FC |
7631 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// |
7632 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7633 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7634 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7635 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7636 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7637 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7638 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); // | |
7639 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE); | |
7640 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7641 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7642 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7643 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7644 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7645 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7646 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
7647 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7648 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7649 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7650 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE); | |
7651 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7652 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7653 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); // | |
7654 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE); | |
7655 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7656 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7657 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7658 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7659 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); //// | |
0487d6a8 | 7660 | |
6a6ae23f | 7661 | /* SPE load and stores */ |
636aa200 | 7662 | static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh) |
6a6ae23f AJ |
7663 | { |
7664 | target_ulong uimm = rB(ctx->opcode); | |
7665 | ||
76db3ba4 | 7666 | if (rA(ctx->opcode) == 0) { |
6a6ae23f | 7667 | tcg_gen_movi_tl(EA, uimm << sh); |
76db3ba4 | 7668 | } else { |
6a6ae23f | 7669 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh); |
76db3ba4 AJ |
7670 | #if defined(TARGET_PPC64) |
7671 | if (!ctx->sf_mode) { | |
7672 | tcg_gen_ext32u_tl(EA, EA); | |
7673 | } | |
7674 | #endif | |
7675 | } | |
0487d6a8 | 7676 | } |
6a6ae23f | 7677 | |
636aa200 | 7678 | static inline void gen_op_evldd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7679 | { |
7680 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7681 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
6a6ae23f AJ |
7682 | #else |
7683 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
76db3ba4 | 7684 | gen_qemu_ld64(ctx, t0, addr); |
6a6ae23f AJ |
7685 | tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0); |
7686 | tcg_gen_shri_i64(t0, t0, 32); | |
7687 | tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0); | |
7688 | tcg_temp_free_i64(t0); | |
7689 | #endif | |
0487d6a8 | 7690 | } |
6a6ae23f | 7691 | |
636aa200 | 7692 | static inline void gen_op_evldw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7693 | { |
0487d6a8 | 7694 | #if defined(TARGET_PPC64) |
6a6ae23f | 7695 | TCGv t0 = tcg_temp_new(); |
76db3ba4 | 7696 | gen_qemu_ld32u(ctx, t0, addr); |
6a6ae23f | 7697 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
76db3ba4 AJ |
7698 | gen_addr_add(ctx, addr, addr, 4); |
7699 | gen_qemu_ld32u(ctx, t0, addr); | |
6a6ae23f AJ |
7700 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7701 | tcg_temp_free(t0); | |
7702 | #else | |
76db3ba4 AJ |
7703 | gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7704 | gen_addr_add(ctx, addr, addr, 4); | |
7705 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f | 7706 | #endif |
0487d6a8 | 7707 | } |
6a6ae23f | 7708 | |
636aa200 | 7709 | static inline void gen_op_evldh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7710 | { |
7711 | TCGv t0 = tcg_temp_new(); | |
7712 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7713 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7714 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7715 | gen_addr_add(ctx, addr, addr, 2); |
7716 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7717 | tcg_gen_shli_tl(t0, t0, 32); |
7718 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7719 | gen_addr_add(ctx, addr, addr, 2); |
7720 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7721 | tcg_gen_shli_tl(t0, t0, 16); |
7722 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7723 | gen_addr_add(ctx, addr, addr, 2); |
7724 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7725 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7726 | #else |
76db3ba4 | 7727 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7728 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7729 | gen_addr_add(ctx, addr, addr, 2); |
7730 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7731 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7732 | gen_addr_add(ctx, addr, addr, 2); |
7733 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7734 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7735 | gen_addr_add(ctx, addr, addr, 2); |
7736 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7737 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7738 | #endif |
6a6ae23f | 7739 | tcg_temp_free(t0); |
0487d6a8 JM |
7740 | } |
7741 | ||
636aa200 | 7742 | static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7743 | { |
7744 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7745 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7746 | #if defined(TARGET_PPC64) |
7747 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); | |
7748 | tcg_gen_shli_tl(t0, t0, 16); | |
7749 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7750 | #else | |
7751 | tcg_gen_shli_tl(t0, t0, 16); | |
7752 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7753 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7754 | #endif | |
7755 | tcg_temp_free(t0); | |
0487d6a8 JM |
7756 | } |
7757 | ||
636aa200 | 7758 | static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7759 | { |
7760 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7761 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7762 | #if defined(TARGET_PPC64) |
7763 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
7764 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7765 | #else | |
7766 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7767 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7768 | #endif | |
7769 | tcg_temp_free(t0); | |
0487d6a8 JM |
7770 | } |
7771 | ||
636aa200 | 7772 | static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7773 | { |
7774 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7775 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f AJ |
7776 | #if defined(TARGET_PPC64) |
7777 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
7778 | tcg_gen_ext32u_tl(t0, t0); | |
7779 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7780 | #else | |
7781 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7782 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7783 | #endif | |
7784 | tcg_temp_free(t0); | |
7785 | } | |
7786 | ||
636aa200 | 7787 | static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7788 | { |
7789 | TCGv t0 = tcg_temp_new(); | |
7790 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7791 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7792 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7793 | gen_addr_add(ctx, addr, addr, 2); |
7794 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7795 | tcg_gen_shli_tl(t0, t0, 16); |
7796 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7797 | #else | |
76db3ba4 | 7798 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7799 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7800 | gen_addr_add(ctx, addr, addr, 2); |
7801 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7802 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7803 | #endif | |
7804 | tcg_temp_free(t0); | |
7805 | } | |
7806 | ||
636aa200 | 7807 | static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7808 | { |
7809 | #if defined(TARGET_PPC64) | |
7810 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 AJ |
7811 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
7812 | gen_addr_add(ctx, addr, addr, 2); | |
7813 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7814 | tcg_gen_shli_tl(t0, t0, 32); |
7815 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7816 | tcg_temp_free(t0); | |
7817 | #else | |
76db3ba4 AJ |
7818 | gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7819 | gen_addr_add(ctx, addr, addr, 2); | |
7820 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7821 | #endif |
7822 | } | |
7823 | ||
636aa200 | 7824 | static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7825 | { |
7826 | #if defined(TARGET_PPC64) | |
7827 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7828 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f | 7829 | tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7830 | gen_addr_add(ctx, addr, addr, 2); |
7831 | gen_qemu_ld16s(ctx, t0, addr); | |
6a6ae23f AJ |
7832 | tcg_gen_shli_tl(t0, t0, 32); |
7833 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7834 | tcg_temp_free(t0); | |
7835 | #else | |
76db3ba4 AJ |
7836 | gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7837 | gen_addr_add(ctx, addr, addr, 2); | |
7838 | gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7839 | #endif |
7840 | } | |
7841 | ||
636aa200 | 7842 | static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7843 | { |
7844 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7845 | gen_qemu_ld32u(ctx, t0, addr); |
0487d6a8 | 7846 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7847 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
7848 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7849 | #else | |
7850 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7851 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7852 | #endif | |
7853 | tcg_temp_free(t0); | |
7854 | } | |
7855 | ||
636aa200 | 7856 | static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7857 | { |
7858 | TCGv t0 = tcg_temp_new(); | |
7859 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7860 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7861 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
7862 | tcg_gen_shli_tl(t0, t0, 32); | |
7863 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7864 | gen_addr_add(ctx, addr, addr, 2); |
7865 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7866 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7867 | tcg_gen_shli_tl(t0, t0, 16); | |
7868 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7869 | #else | |
76db3ba4 | 7870 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7871 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
7872 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7873 | gen_addr_add(ctx, addr, addr, 2); |
7874 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7875 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7876 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
0487d6a8 | 7877 | #endif |
6a6ae23f AJ |
7878 | tcg_temp_free(t0); |
7879 | } | |
7880 | ||
636aa200 | 7881 | static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7882 | { |
7883 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7884 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
0487d6a8 | 7885 | #else |
6a6ae23f AJ |
7886 | TCGv_i64 t0 = tcg_temp_new_i64(); |
7887 | tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]); | |
76db3ba4 | 7888 | gen_qemu_st64(ctx, t0, addr); |
6a6ae23f AJ |
7889 | tcg_temp_free_i64(t0); |
7890 | #endif | |
7891 | } | |
7892 | ||
636aa200 | 7893 | static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7894 | { |
0487d6a8 | 7895 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7896 | TCGv t0 = tcg_temp_new(); |
7897 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7898 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7899 | tcg_temp_free(t0); |
7900 | #else | |
76db3ba4 | 7901 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7902 | #endif |
76db3ba4 AJ |
7903 | gen_addr_add(ctx, addr, addr, 4); |
7904 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7905 | } |
7906 | ||
636aa200 | 7907 | static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7908 | { |
7909 | TCGv t0 = tcg_temp_new(); | |
7910 | #if defined(TARGET_PPC64) | |
7911 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7912 | #else | |
7913 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7914 | #endif | |
76db3ba4 AJ |
7915 | gen_qemu_st16(ctx, t0, addr); |
7916 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f AJ |
7917 | #if defined(TARGET_PPC64) |
7918 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7919 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7920 | #else |
76db3ba4 | 7921 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7922 | #endif |
76db3ba4 | 7923 | gen_addr_add(ctx, addr, addr, 2); |
6a6ae23f | 7924 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7925 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7926 | tcg_temp_free(t0); |
76db3ba4 AJ |
7927 | gen_addr_add(ctx, addr, addr, 2); |
7928 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7929 | } |
7930 | ||
636aa200 | 7931 | static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7932 | { |
7933 | TCGv t0 = tcg_temp_new(); | |
7934 | #if defined(TARGET_PPC64) | |
7935 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7936 | #else | |
7937 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7938 | #endif | |
76db3ba4 AJ |
7939 | gen_qemu_st16(ctx, t0, addr); |
7940 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f | 7941 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7942 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
7943 | tcg_temp_free(t0); |
7944 | } | |
7945 | ||
636aa200 | 7946 | static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7947 | { |
7948 | #if defined(TARGET_PPC64) | |
7949 | TCGv t0 = tcg_temp_new(); | |
7950 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7951 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
7952 | tcg_temp_free(t0); |
7953 | #else | |
76db3ba4 | 7954 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7955 | #endif |
76db3ba4 AJ |
7956 | gen_addr_add(ctx, addr, addr, 2); |
7957 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7958 | } |
7959 | ||
636aa200 | 7960 | static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7961 | { |
7962 | #if defined(TARGET_PPC64) | |
7963 | TCGv t0 = tcg_temp_new(); | |
7964 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7965 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7966 | tcg_temp_free(t0); |
7967 | #else | |
76db3ba4 | 7968 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7969 | #endif |
7970 | } | |
7971 | ||
636aa200 | 7972 | static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7973 | { |
76db3ba4 | 7974 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7975 | } |
7976 | ||
7977 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
99e300ef | 7978 | static void glue(gen_, name)(DisasContext *ctx) \ |
6a6ae23f AJ |
7979 | { \ |
7980 | TCGv t0; \ | |
7981 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7982 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
6a6ae23f AJ |
7983 | return; \ |
7984 | } \ | |
76db3ba4 | 7985 | gen_set_access_type(ctx, ACCESS_INT); \ |
6a6ae23f AJ |
7986 | t0 = tcg_temp_new(); \ |
7987 | if (Rc(ctx->opcode)) { \ | |
76db3ba4 | 7988 | gen_addr_spe_imm_index(ctx, t0, sh); \ |
6a6ae23f | 7989 | } else { \ |
76db3ba4 | 7990 | gen_addr_reg_index(ctx, t0); \ |
6a6ae23f AJ |
7991 | } \ |
7992 | gen_op_##name(ctx, t0); \ | |
7993 | tcg_temp_free(t0); \ | |
7994 | } | |
7995 | ||
7996 | GEN_SPEOP_LDST(evldd, 0x00, 3); | |
7997 | GEN_SPEOP_LDST(evldw, 0x01, 3); | |
7998 | GEN_SPEOP_LDST(evldh, 0x02, 3); | |
7999 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1); | |
8000 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1); | |
8001 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1); | |
8002 | GEN_SPEOP_LDST(evlwhe, 0x08, 2); | |
8003 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2); | |
8004 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2); | |
8005 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2); | |
8006 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2); | |
8007 | ||
8008 | GEN_SPEOP_LDST(evstdd, 0x10, 3); | |
8009 | GEN_SPEOP_LDST(evstdw, 0x11, 3); | |
8010 | GEN_SPEOP_LDST(evstdh, 0x12, 3); | |
8011 | GEN_SPEOP_LDST(evstwhe, 0x18, 2); | |
8012 | GEN_SPEOP_LDST(evstwho, 0x1A, 2); | |
8013 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2); | |
8014 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2); | |
0487d6a8 JM |
8015 | |
8016 | /* Multiply and add - TODO */ | |
8017 | #if 0 | |
70560da7 FC |
8018 | GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);// |
8019 | GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8020 | GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8021 | GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8022 | GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8023 | GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8024 | GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8025 | GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8026 | GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8027 | GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8028 | GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8029 | GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8030 | ||
8031 | GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8032 | GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8033 | GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8034 | GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8035 | GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8036 | GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8037 | GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8038 | GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8039 | GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8040 | GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8041 | GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8042 | GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8043 | ||
8044 | GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8045 | GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8046 | GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8047 | GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8048 | GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE); | |
8049 | ||
8050 | GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8051 | GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8052 | GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8053 | GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8054 | GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8055 | GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8056 | GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8057 | GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8058 | GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8059 | GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8060 | GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8061 | GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8062 | ||
8063 | GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
8064 | GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
8065 | GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8066 | GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8067 | ||
8068 | GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8069 | GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8070 | GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8071 | GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8072 | GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8073 | GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8074 | GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8075 | GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8076 | GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8077 | GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8078 | GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8079 | GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8080 | ||
8081 | GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8082 | GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8083 | GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8084 | GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8085 | GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
0487d6a8 JM |
8086 | #endif |
8087 | ||
8088 | /*** SPE floating-point extension ***/ | |
1c97856d AJ |
8089 | #if defined(TARGET_PPC64) |
8090 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 8091 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 | 8092 | { \ |
1c97856d AJ |
8093 | TCGv_i32 t0; \ |
8094 | TCGv t1; \ | |
8095 | t0 = tcg_temp_new_i32(); \ | |
8096 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8097 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
8098 | t1 = tcg_temp_new(); \ |
8099 | tcg_gen_extu_i32_tl(t1, t0); \ | |
8100 | tcg_temp_free_i32(t0); \ | |
8101 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8102 | 0xFFFFFFFF00000000ULL); \ | |
8103 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
8104 | tcg_temp_free(t1); \ | |
0487d6a8 | 8105 | } |
1c97856d | 8106 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 8107 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8108 | { \ |
8109 | TCGv_i32 t0; \ | |
8110 | TCGv t1; \ | |
8111 | t0 = tcg_temp_new_i32(); \ | |
8e703949 | 8112 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
8113 | t1 = tcg_temp_new(); \ |
8114 | tcg_gen_extu_i32_tl(t1, t0); \ | |
8115 | tcg_temp_free_i32(t0); \ | |
8116 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8117 | 0xFFFFFFFF00000000ULL); \ | |
8118 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
8119 | tcg_temp_free(t1); \ | |
8120 | } | |
8121 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 8122 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8123 | { \ |
8124 | TCGv_i32 t0 = tcg_temp_new_i32(); \ | |
8125 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8126 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
8127 | tcg_temp_free_i32(t0); \ |
8128 | } | |
8129 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 8130 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 8131 | { \ |
8e703949 BS |
8132 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8133 | cpu_gpr[rB(ctx->opcode)]); \ | |
1c97856d AJ |
8134 | } |
8135 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 8136 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 8137 | { \ |
1c97856d AJ |
8138 | TCGv_i32 t0, t1; \ |
8139 | TCGv_i64 t2; \ | |
57951c27 | 8140 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 8141 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8142 | return; \ |
8143 | } \ | |
1c97856d AJ |
8144 | t0 = tcg_temp_new_i32(); \ |
8145 | t1 = tcg_temp_new_i32(); \ | |
8146 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
8147 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8148 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
8149 | tcg_temp_free_i32(t1); \ |
8150 | t2 = tcg_temp_new(); \ | |
8151 | tcg_gen_extu_i32_tl(t2, t0); \ | |
8152 | tcg_temp_free_i32(t0); \ | |
8153 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8154 | 0xFFFFFFFF00000000ULL); \ | |
8155 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \ | |
8156 | tcg_temp_free(t2); \ | |
57951c27 | 8157 | } |
1c97856d | 8158 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ |
636aa200 | 8159 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8160 | { \ |
8161 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8162 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8163 | return; \ |
8164 | } \ | |
8e703949 BS |
8165 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8166 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 8167 | } |
1c97856d | 8168 | #define GEN_SPEFPUOP_COMP_32(name) \ |
636aa200 | 8169 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 8170 | { \ |
1c97856d | 8171 | TCGv_i32 t0, t1; \ |
57951c27 | 8172 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 8173 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8174 | return; \ |
8175 | } \ | |
1c97856d AJ |
8176 | t0 = tcg_temp_new_i32(); \ |
8177 | t1 = tcg_temp_new_i32(); \ | |
8178 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
8179 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8180 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
8181 | tcg_temp_free_i32(t0); \ |
8182 | tcg_temp_free_i32(t1); \ | |
8183 | } | |
8184 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8185 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8186 | { \ |
8187 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8188 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8189 | return; \ |
8190 | } \ | |
8e703949 | 8191 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8192 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8193 | } | |
8194 | #else | |
8195 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 8196 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 8197 | { \ |
8e703949 BS |
8198 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8199 | cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 8200 | } |
1c97856d | 8201 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 8202 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8203 | { \ |
8204 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8205 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 8206 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
8207 | tcg_temp_free_i64(t0); \ |
8208 | } | |
8209 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 8210 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8211 | { \ |
8212 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8e703949 | 8213 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
8214 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8215 | tcg_temp_free_i64(t0); \ | |
8216 | } | |
8217 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 8218 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8219 | { \ |
8220 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8221 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 8222 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
8223 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8224 | tcg_temp_free_i64(t0); \ | |
8225 | } | |
8226 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 8227 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8228 | { \ |
8229 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8230 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8231 | return; \ |
8232 | } \ | |
8e703949 | 8233 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8234 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8235 | } | |
8236 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ | |
636aa200 | 8237 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8238 | { \ |
8239 | TCGv_i64 t0, t1; \ | |
8240 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8241 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8242 | return; \ |
8243 | } \ | |
8244 | t0 = tcg_temp_new_i64(); \ | |
8245 | t1 = tcg_temp_new_i64(); \ | |
8246 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8247 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 8248 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
8249 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8250 | tcg_temp_free_i64(t0); \ | |
8251 | tcg_temp_free_i64(t1); \ | |
8252 | } | |
8253 | #define GEN_SPEFPUOP_COMP_32(name) \ | |
636aa200 | 8254 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8255 | { \ |
8256 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8257 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8258 | return; \ |
8259 | } \ | |
8e703949 | 8260 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8261 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8262 | } | |
8263 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8264 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8265 | { \ |
8266 | TCGv_i64 t0, t1; \ | |
8267 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8268 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8269 | return; \ |
8270 | } \ | |
8271 | t0 = tcg_temp_new_i64(); \ | |
8272 | t1 = tcg_temp_new_i64(); \ | |
8273 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8274 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 8275 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
8276 | tcg_temp_free_i64(t0); \ |
8277 | tcg_temp_free_i64(t1); \ | |
8278 | } | |
8279 | #endif | |
57951c27 | 8280 | |
0487d6a8 JM |
8281 | /* Single precision floating-point vectors operations */ |
8282 | /* Arithmetic */ | |
1c97856d AJ |
8283 | GEN_SPEFPUOP_ARITH2_64_64(evfsadd); |
8284 | GEN_SPEFPUOP_ARITH2_64_64(evfssub); | |
8285 | GEN_SPEFPUOP_ARITH2_64_64(evfsmul); | |
8286 | GEN_SPEFPUOP_ARITH2_64_64(evfsdiv); | |
636aa200 | 8287 | static inline void gen_evfsabs(DisasContext *ctx) |
1c97856d AJ |
8288 | { |
8289 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8290 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8291 | return; |
8292 | } | |
8293 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8294 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL); |
1c97856d | 8295 | #else |
6d5c34fa MP |
8296 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000); |
8297 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8298 | #endif |
8299 | } | |
636aa200 | 8300 | static inline void gen_evfsnabs(DisasContext *ctx) |
1c97856d AJ |
8301 | { |
8302 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8303 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8304 | return; |
8305 | } | |
8306 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8307 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8308 | #else |
6d5c34fa MP |
8309 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8310 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8311 | #endif |
8312 | } | |
636aa200 | 8313 | static inline void gen_evfsneg(DisasContext *ctx) |
1c97856d AJ |
8314 | { |
8315 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8316 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8317 | return; |
8318 | } | |
8319 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8320 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8321 | #else |
6d5c34fa MP |
8322 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8323 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8324 | #endif |
8325 | } | |
8326 | ||
0487d6a8 | 8327 | /* Conversion */ |
1c97856d AJ |
8328 | GEN_SPEFPUOP_CONV_64_64(evfscfui); |
8329 | GEN_SPEFPUOP_CONV_64_64(evfscfsi); | |
8330 | GEN_SPEFPUOP_CONV_64_64(evfscfuf); | |
8331 | GEN_SPEFPUOP_CONV_64_64(evfscfsf); | |
8332 | GEN_SPEFPUOP_CONV_64_64(evfsctui); | |
8333 | GEN_SPEFPUOP_CONV_64_64(evfsctsi); | |
8334 | GEN_SPEFPUOP_CONV_64_64(evfsctuf); | |
8335 | GEN_SPEFPUOP_CONV_64_64(evfsctsf); | |
8336 | GEN_SPEFPUOP_CONV_64_64(evfsctuiz); | |
8337 | GEN_SPEFPUOP_CONV_64_64(evfsctsiz); | |
8338 | ||
0487d6a8 | 8339 | /* Comparison */ |
1c97856d AJ |
8340 | GEN_SPEFPUOP_COMP_64(evfscmpgt); |
8341 | GEN_SPEFPUOP_COMP_64(evfscmplt); | |
8342 | GEN_SPEFPUOP_COMP_64(evfscmpeq); | |
8343 | GEN_SPEFPUOP_COMP_64(evfststgt); | |
8344 | GEN_SPEFPUOP_COMP_64(evfststlt); | |
8345 | GEN_SPEFPUOP_COMP_64(evfststeq); | |
0487d6a8 JM |
8346 | |
8347 | /* Opcodes definitions */ | |
70560da7 FC |
8348 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8349 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8350 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8351 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8352 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8353 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8354 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8355 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8356 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8357 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8358 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8359 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8360 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8361 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8362 | |
8363 | /* Single precision floating-point operations */ | |
8364 | /* Arithmetic */ | |
1c97856d AJ |
8365 | GEN_SPEFPUOP_ARITH2_32_32(efsadd); |
8366 | GEN_SPEFPUOP_ARITH2_32_32(efssub); | |
8367 | GEN_SPEFPUOP_ARITH2_32_32(efsmul); | |
8368 | GEN_SPEFPUOP_ARITH2_32_32(efsdiv); | |
636aa200 | 8369 | static inline void gen_efsabs(DisasContext *ctx) |
1c97856d AJ |
8370 | { |
8371 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8372 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8373 | return; |
8374 | } | |
6d5c34fa | 8375 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL); |
1c97856d | 8376 | } |
636aa200 | 8377 | static inline void gen_efsnabs(DisasContext *ctx) |
1c97856d AJ |
8378 | { |
8379 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8380 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8381 | return; |
8382 | } | |
6d5c34fa | 8383 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d | 8384 | } |
636aa200 | 8385 | static inline void gen_efsneg(DisasContext *ctx) |
1c97856d AJ |
8386 | { |
8387 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8388 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8389 | return; |
8390 | } | |
6d5c34fa | 8391 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d AJ |
8392 | } |
8393 | ||
0487d6a8 | 8394 | /* Conversion */ |
1c97856d AJ |
8395 | GEN_SPEFPUOP_CONV_32_32(efscfui); |
8396 | GEN_SPEFPUOP_CONV_32_32(efscfsi); | |
8397 | GEN_SPEFPUOP_CONV_32_32(efscfuf); | |
8398 | GEN_SPEFPUOP_CONV_32_32(efscfsf); | |
8399 | GEN_SPEFPUOP_CONV_32_32(efsctui); | |
8400 | GEN_SPEFPUOP_CONV_32_32(efsctsi); | |
8401 | GEN_SPEFPUOP_CONV_32_32(efsctuf); | |
8402 | GEN_SPEFPUOP_CONV_32_32(efsctsf); | |
8403 | GEN_SPEFPUOP_CONV_32_32(efsctuiz); | |
8404 | GEN_SPEFPUOP_CONV_32_32(efsctsiz); | |
8405 | GEN_SPEFPUOP_CONV_32_64(efscfd); | |
8406 | ||
0487d6a8 | 8407 | /* Comparison */ |
1c97856d AJ |
8408 | GEN_SPEFPUOP_COMP_32(efscmpgt); |
8409 | GEN_SPEFPUOP_COMP_32(efscmplt); | |
8410 | GEN_SPEFPUOP_COMP_32(efscmpeq); | |
8411 | GEN_SPEFPUOP_COMP_32(efststgt); | |
8412 | GEN_SPEFPUOP_COMP_32(efststlt); | |
8413 | GEN_SPEFPUOP_COMP_32(efststeq); | |
0487d6a8 JM |
8414 | |
8415 | /* Opcodes definitions */ | |
70560da7 FC |
8416 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8417 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8418 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8419 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8420 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8421 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); // | |
8422 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8423 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8424 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8425 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8426 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8427 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8428 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8429 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8430 | |
8431 | /* Double precision floating-point operations */ | |
8432 | /* Arithmetic */ | |
1c97856d AJ |
8433 | GEN_SPEFPUOP_ARITH2_64_64(efdadd); |
8434 | GEN_SPEFPUOP_ARITH2_64_64(efdsub); | |
8435 | GEN_SPEFPUOP_ARITH2_64_64(efdmul); | |
8436 | GEN_SPEFPUOP_ARITH2_64_64(efddiv); | |
636aa200 | 8437 | static inline void gen_efdabs(DisasContext *ctx) |
1c97856d AJ |
8438 | { |
8439 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8440 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8441 | return; |
8442 | } | |
8443 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8444 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL); |
1c97856d | 8445 | #else |
6d5c34fa MP |
8446 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8447 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8448 | #endif |
8449 | } | |
636aa200 | 8450 | static inline void gen_efdnabs(DisasContext *ctx) |
1c97856d AJ |
8451 | { |
8452 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8453 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8454 | return; |
8455 | } | |
8456 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8457 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8458 | #else |
6d5c34fa MP |
8459 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8460 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8461 | #endif |
8462 | } | |
636aa200 | 8463 | static inline void gen_efdneg(DisasContext *ctx) |
1c97856d AJ |
8464 | { |
8465 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8466 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8467 | return; |
8468 | } | |
8469 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8470 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8471 | #else |
6d5c34fa MP |
8472 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8473 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8474 | #endif |
8475 | } | |
8476 | ||
0487d6a8 | 8477 | /* Conversion */ |
1c97856d AJ |
8478 | GEN_SPEFPUOP_CONV_64_32(efdcfui); |
8479 | GEN_SPEFPUOP_CONV_64_32(efdcfsi); | |
8480 | GEN_SPEFPUOP_CONV_64_32(efdcfuf); | |
8481 | GEN_SPEFPUOP_CONV_64_32(efdcfsf); | |
8482 | GEN_SPEFPUOP_CONV_32_64(efdctui); | |
8483 | GEN_SPEFPUOP_CONV_32_64(efdctsi); | |
8484 | GEN_SPEFPUOP_CONV_32_64(efdctuf); | |
8485 | GEN_SPEFPUOP_CONV_32_64(efdctsf); | |
8486 | GEN_SPEFPUOP_CONV_32_64(efdctuiz); | |
8487 | GEN_SPEFPUOP_CONV_32_64(efdctsiz); | |
8488 | GEN_SPEFPUOP_CONV_64_32(efdcfs); | |
8489 | GEN_SPEFPUOP_CONV_64_64(efdcfuid); | |
8490 | GEN_SPEFPUOP_CONV_64_64(efdcfsid); | |
8491 | GEN_SPEFPUOP_CONV_64_64(efdctuidz); | |
8492 | GEN_SPEFPUOP_CONV_64_64(efdctsidz); | |
0487d6a8 | 8493 | |
0487d6a8 | 8494 | /* Comparison */ |
1c97856d AJ |
8495 | GEN_SPEFPUOP_COMP_64(efdcmpgt); |
8496 | GEN_SPEFPUOP_COMP_64(efdcmplt); | |
8497 | GEN_SPEFPUOP_COMP_64(efdcmpeq); | |
8498 | GEN_SPEFPUOP_COMP_64(efdtstgt); | |
8499 | GEN_SPEFPUOP_COMP_64(efdtstlt); | |
8500 | GEN_SPEFPUOP_COMP_64(efdtsteq); | |
0487d6a8 JM |
8501 | |
8502 | /* Opcodes definitions */ | |
70560da7 FC |
8503 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // |
8504 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8505 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); // | |
8506 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8507 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // | |
8508 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8509 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8510 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); // | |
8511 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8512 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8513 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8514 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8515 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8516 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8517 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8518 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
0487d6a8 | 8519 | |
c227f099 | 8520 | static opcode_t opcodes[] = { |
5c55ff99 BS |
8521 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
8522 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
8523 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8524 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER), | |
8525 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8526 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), | |
8527 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8528 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8529 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8530 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8531 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), | |
8532 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
8533 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
8534 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
8535 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8536 | #if defined(TARGET_PPC64) | |
8537 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
8538 | #endif | |
8539 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
8540 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
8541 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8542 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8543 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8544 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
8545 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), | |
8546 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
8547 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8548 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8549 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8550 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8551 | GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), | |
eaabeef2 | 8552 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 8553 | #if defined(TARGET_PPC64) |
eaabeef2 | 8554 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 BS |
8555 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
8556 | #endif | |
8557 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8558 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8559 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8560 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
8561 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
8562 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
8563 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
8564 | #if defined(TARGET_PPC64) | |
8565 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
8566 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
8567 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
8568 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
8569 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
8570 | #endif | |
8571 | GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES), | |
8572 | GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8573 | GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8574 | GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT), | |
8575 | GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT), | |
8576 | GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT), | |
8577 | GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT), | |
8578 | GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT), | |
8579 | GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT), | |
8580 | GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT), | |
8581 | GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT), | |
8582 | GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT), | |
8583 | #if defined(TARGET_PPC64) | |
8584 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8585 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
8586 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8587 | #endif | |
8588 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8589 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8590 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
8591 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
8592 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
8593 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
8594 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO), | |
8595 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), | |
f844c817 | 8596 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
5c55ff99 BS |
8597 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
8598 | #if defined(TARGET_PPC64) | |
f844c817 | 8599 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
5c55ff99 BS |
8600 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
8601 | #endif | |
8602 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
8603 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
8604 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8605 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8606 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
8607 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
8608 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), | |
8609 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
8610 | #if defined(TARGET_PPC64) | |
8611 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
8612 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), | |
8613 | #endif | |
8614 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
8615 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
8616 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8617 | #if defined(TARGET_PPC64) | |
8618 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
8619 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8620 | #endif | |
8621 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
8622 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
8623 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
8624 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
8625 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
8626 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
8627 | #if defined(TARGET_PPC64) | |
8628 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
8629 | #endif | |
8630 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC), | |
8631 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC), | |
8632 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), | |
8633 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), | |
8634 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
8635 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE), | |
8636 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE), | |
8e33944f | 8637 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ), |
5c55ff99 BS |
8638 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), |
8639 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC), | |
8640 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), | |
8641 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
8642 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), | |
8643 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
8644 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
8645 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
8646 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
8647 | #if defined(TARGET_PPC64) | |
8648 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
8649 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
8650 | PPC_SEGMENT_64B), | |
8651 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
8652 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
8653 | PPC_SEGMENT_64B), | |
efdef95f DG |
8654 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
8655 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
8656 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
5c55ff99 BS |
8657 | #endif |
8658 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
8659 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE), | |
8660 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE), | |
8661 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), | |
8662 | #if defined(TARGET_PPC64) | |
8663 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI), | |
8664 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), | |
8665 | #endif | |
8666 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
8667 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
8668 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
8669 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
8670 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
8671 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
8672 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
8673 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
8674 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
8675 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
8676 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
8677 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8678 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
8679 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
8680 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
8681 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
8682 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
8683 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
8684 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
8685 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8686 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
8687 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
8688 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
8689 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
8690 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
8691 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
8692 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
8693 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
8694 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
8695 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
8696 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
8697 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
8698 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
8699 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
8700 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
8701 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
8702 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
8703 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
8704 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
8705 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
8706 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
8707 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
8708 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
8709 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
8710 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
8711 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
8712 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
8713 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
8714 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
8715 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8716 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8717 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
8718 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
8719 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8720 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8721 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
8722 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
8723 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
8724 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
8725 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
8726 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
8727 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
8728 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
8729 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
8730 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
8731 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
8732 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
8733 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
8734 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
8735 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
8736 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 8737 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
8738 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
8739 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
8740 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
8741 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
8742 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
8743 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
8744 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
8745 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
8746 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
8747 | PPC_NONE, PPC2_BOOKE206), | |
8748 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
8749 | PPC_NONE, PPC2_BOOKE206), | |
8750 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
8751 | PPC_NONE, PPC2_BOOKE206), | |
8752 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
8753 | PPC_NONE, PPC2_BOOKE206), | |
6d3db821 AG |
8754 | GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001, |
8755 | PPC_NONE, PPC2_BOOKE206), | |
d5d11a39 AG |
8756 | GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001, |
8757 | PPC_NONE, PPC2_PRCNTL), | |
9e0b5cb1 AG |
8758 | GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001, |
8759 | PPC_NONE, PPC2_PRCNTL), | |
5c55ff99 | 8760 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 8761 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 8762 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
8763 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
8764 | PPC_BOOKE, PPC2_BOOKE206), | |
dcb2b9e1 | 8765 | GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE), |
01662f3e AG |
8766 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, |
8767 | PPC_BOOKE, PPC2_BOOKE206), | |
5c55ff99 BS |
8768 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
8769 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
8770 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
8771 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
8772 | GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC), | |
8773 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), | |
8774 | GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE), | |
8775 | GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE), | |
8776 | GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE), | |
8777 | GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE), | |
8778 | ||
8779 | #undef GEN_INT_ARITH_ADD | |
8780 | #undef GEN_INT_ARITH_ADD_CONST | |
8781 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8782 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
8783 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
8784 | add_ca, compute_ca, compute_ov) \ | |
8785 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
8786 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
8787 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
8788 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
8789 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
8790 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
8791 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
8792 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
8793 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
8794 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
8795 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
8796 | ||
8797 | #undef GEN_INT_ARITH_DIVW | |
8798 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
8799 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
8800 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
8801 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
8802 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
8803 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
8804 | ||
8805 | #if defined(TARGET_PPC64) | |
8806 | #undef GEN_INT_ARITH_DIVD | |
8807 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
8808 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8809 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
8810 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
8811 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
8812 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
8813 | ||
8814 | #undef GEN_INT_ARITH_MUL_HELPER | |
8815 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
8816 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8817 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
8818 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
8819 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
8820 | #endif | |
8821 | ||
8822 | #undef GEN_INT_ARITH_SUBF | |
8823 | #undef GEN_INT_ARITH_SUBF_CONST | |
8824 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8825 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
8826 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
8827 | add_ca, compute_ca, compute_ov) \ | |
8828 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
8829 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
8830 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
8831 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
8832 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
8833 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
8834 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
8835 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
8836 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
8837 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
8838 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
8839 | ||
8840 | #undef GEN_LOGICAL1 | |
8841 | #undef GEN_LOGICAL2 | |
8842 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
8843 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
8844 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
8845 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
8846 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
8847 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
8848 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
8849 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
8850 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
8851 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
8852 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
8853 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
8854 | #if defined(TARGET_PPC64) | |
8855 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
8856 | #endif | |
8857 | ||
8858 | #if defined(TARGET_PPC64) | |
8859 | #undef GEN_PPC64_R2 | |
8860 | #undef GEN_PPC64_R4 | |
8861 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
8862 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8863 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8864 | PPC_64B) | |
8865 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
8866 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8867 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
8868 | PPC_64B), \ | |
8869 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8870 | PPC_64B), \ | |
8871 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
8872 | PPC_64B) | |
8873 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
8874 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
8875 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
8876 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
8877 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
8878 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
8879 | #endif | |
8880 | ||
8881 | #undef _GEN_FLOAT_ACB | |
8882 | #undef GEN_FLOAT_ACB | |
8883 | #undef _GEN_FLOAT_AB | |
8884 | #undef GEN_FLOAT_AB | |
8885 | #undef _GEN_FLOAT_AC | |
8886 | #undef GEN_FLOAT_AC | |
8887 | #undef GEN_FLOAT_B | |
8888 | #undef GEN_FLOAT_BS | |
8889 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ | |
8890 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) | |
8891 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ | |
8892 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \ | |
8893 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type) | |
8894 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8895 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8896 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ | |
8897 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8898 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8899 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8900 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8901 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ | |
8902 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8903 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8904 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ | |
8905 | GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) | |
8906 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ | |
8907 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) | |
8908 | ||
8909 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT), | |
8910 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT), | |
8911 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT), | |
8912 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT), | |
8913 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES), | |
8914 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE), | |
8915 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL), | |
8916 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT), | |
8917 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT), | |
8918 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT), | |
8919 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT), | |
8920 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT), | |
8921 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT), | |
8922 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT), | |
8923 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT), | |
8924 | #if defined(TARGET_PPC64) | |
8925 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B), | |
8926 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B), | |
8927 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B), | |
8928 | #endif | |
8929 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT), | |
8930 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT), | |
8931 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT), | |
8932 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), | |
8933 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT), | |
8934 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT), | |
8935 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT), | |
8936 | ||
8937 | #undef GEN_LD | |
8938 | #undef GEN_LDU | |
8939 | #undef GEN_LDUX | |
cd6e9320 | 8940 | #undef GEN_LDX_E |
5c55ff99 BS |
8941 | #undef GEN_LDS |
8942 | #define GEN_LD(name, ldop, opc, type) \ | |
8943 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8944 | #define GEN_LDU(name, ldop, opc, type) \ | |
8945 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8946 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
8947 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
8948 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
8949 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
8950 | #define GEN_LDS(name, ldop, op, type) \ |
8951 | GEN_LD(name, ldop, op | 0x20, type) \ | |
8952 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
8953 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
8954 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
8955 | ||
8956 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
8957 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
8958 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
8959 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
8960 | #if defined(TARGET_PPC64) | |
8961 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
8962 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
8963 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B) | |
8964 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B) | |
cd6e9320 | 8965 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
8966 | #endif |
8967 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
8968 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
8969 | ||
8970 | #undef GEN_ST | |
8971 | #undef GEN_STU | |
8972 | #undef GEN_STUX | |
cd6e9320 | 8973 | #undef GEN_STX_E |
5c55ff99 BS |
8974 | #undef GEN_STS |
8975 | #define GEN_ST(name, stop, opc, type) \ | |
8976 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8977 | #define GEN_STU(name, stop, opc, type) \ | |
8978 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8979 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
8980 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
8981 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
8982 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
8983 | #define GEN_STS(name, stop, op, type) \ |
8984 | GEN_ST(name, stop, op | 0x20, type) \ | |
8985 | GEN_STU(name, stop, op | 0x21, type) \ | |
8986 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
8987 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
8988 | ||
8989 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
8990 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
8991 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
8992 | #if defined(TARGET_PPC64) | |
8993 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B) | |
8994 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B) | |
cd6e9320 | 8995 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
8996 | #endif |
8997 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
8998 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
8999 | ||
9000 | #undef GEN_LDF | |
9001 | #undef GEN_LDUF | |
9002 | #undef GEN_LDUXF | |
9003 | #undef GEN_LDXF | |
9004 | #undef GEN_LDFS | |
9005 | #define GEN_LDF(name, ldop, opc, type) \ | |
9006 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9007 | #define GEN_LDUF(name, ldop, opc, type) \ | |
9008 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9009 | #define GEN_LDUXF(name, ldop, opc, type) \ | |
9010 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
9011 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ | |
9012 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
9013 | #define GEN_LDFS(name, ldop, op, type) \ | |
9014 | GEN_LDF(name, ldop, op | 0x20, type) \ | |
9015 | GEN_LDUF(name, ldop, op | 0x21, type) \ | |
9016 | GEN_LDUXF(name, ldop, op | 0x01, type) \ | |
9017 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
9018 | ||
9019 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT) | |
9020 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT) | |
9021 | ||
9022 | #undef GEN_STF | |
9023 | #undef GEN_STUF | |
9024 | #undef GEN_STUXF | |
9025 | #undef GEN_STXF | |
9026 | #undef GEN_STFS | |
9027 | #define GEN_STF(name, stop, opc, type) \ | |
9028 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9029 | #define GEN_STUF(name, stop, opc, type) \ | |
9030 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9031 | #define GEN_STUXF(name, stop, opc, type) \ | |
9032 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
9033 | #define GEN_STXF(name, stop, opc2, opc3, type) \ | |
9034 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
9035 | #define GEN_STFS(name, stop, op, type) \ | |
9036 | GEN_STF(name, stop, op | 0x20, type) \ | |
9037 | GEN_STUF(name, stop, op | 0x21, type) \ | |
9038 | GEN_STUXF(name, stop, op | 0x01, type) \ | |
9039 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
9040 | ||
9041 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT) | |
9042 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT) | |
9043 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX) | |
9044 | ||
9045 | #undef GEN_CRLOGIC | |
9046 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
9047 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
9048 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
9049 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
9050 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
9051 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
9052 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
9053 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
9054 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
9055 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
9056 | ||
9057 | #undef GEN_MAC_HANDLER | |
9058 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
9059 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
9060 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
9061 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
9062 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
9063 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
9064 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
9065 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
9066 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
9067 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
9068 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
9069 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
9070 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
9071 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
9072 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
9073 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
9074 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
9075 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
9076 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
9077 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
9078 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
9079 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
9080 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
9081 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
9082 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
9083 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
9084 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
9085 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
9086 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
9087 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
9088 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
9089 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
9090 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
9091 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
9092 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
9093 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
9094 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
9095 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
9096 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
9097 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
9098 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
9099 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
9100 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
9101 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
9102 | ||
9103 | #undef GEN_VR_LDX | |
9104 | #undef GEN_VR_STX | |
9105 | #undef GEN_VR_LVE | |
9106 | #undef GEN_VR_STVE | |
9107 | #define GEN_VR_LDX(name, opc2, opc3) \ | |
9108 | GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9109 | #define GEN_VR_STX(name, opc2, opc3) \ | |
9110 | GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9111 | #define GEN_VR_LVE(name, opc2, opc3) \ | |
9112 | GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9113 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
9114 | GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9115 | GEN_VR_LDX(lvx, 0x07, 0x03), | |
9116 | GEN_VR_LDX(lvxl, 0x07, 0x0B), | |
9117 | GEN_VR_LVE(bx, 0x07, 0x00), | |
9118 | GEN_VR_LVE(hx, 0x07, 0x01), | |
9119 | GEN_VR_LVE(wx, 0x07, 0x02), | |
9120 | GEN_VR_STX(svx, 0x07, 0x07), | |
9121 | GEN_VR_STX(svxl, 0x07, 0x0F), | |
9122 | GEN_VR_STVE(bx, 0x07, 0x04), | |
9123 | GEN_VR_STVE(hx, 0x07, 0x05), | |
9124 | GEN_VR_STVE(wx, 0x07, 0x06), | |
9125 | ||
9126 | #undef GEN_VX_LOGICAL | |
9127 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
9128 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9129 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16), | |
9130 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17), | |
9131 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18), | |
9132 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19), | |
9133 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20), | |
9134 | ||
9135 | #undef GEN_VXFORM | |
9136 | #define GEN_VXFORM(name, opc2, opc3) \ | |
9137 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9138 | GEN_VXFORM(vaddubm, 0, 0), | |
9139 | GEN_VXFORM(vadduhm, 0, 1), | |
9140 | GEN_VXFORM(vadduwm, 0, 2), | |
9141 | GEN_VXFORM(vsububm, 0, 16), | |
9142 | GEN_VXFORM(vsubuhm, 0, 17), | |
9143 | GEN_VXFORM(vsubuwm, 0, 18), | |
9144 | GEN_VXFORM(vmaxub, 1, 0), | |
9145 | GEN_VXFORM(vmaxuh, 1, 1), | |
9146 | GEN_VXFORM(vmaxuw, 1, 2), | |
9147 | GEN_VXFORM(vmaxsb, 1, 4), | |
9148 | GEN_VXFORM(vmaxsh, 1, 5), | |
9149 | GEN_VXFORM(vmaxsw, 1, 6), | |
9150 | GEN_VXFORM(vminub, 1, 8), | |
9151 | GEN_VXFORM(vminuh, 1, 9), | |
9152 | GEN_VXFORM(vminuw, 1, 10), | |
9153 | GEN_VXFORM(vminsb, 1, 12), | |
9154 | GEN_VXFORM(vminsh, 1, 13), | |
9155 | GEN_VXFORM(vminsw, 1, 14), | |
9156 | GEN_VXFORM(vavgub, 1, 16), | |
9157 | GEN_VXFORM(vavguh, 1, 17), | |
9158 | GEN_VXFORM(vavguw, 1, 18), | |
9159 | GEN_VXFORM(vavgsb, 1, 20), | |
9160 | GEN_VXFORM(vavgsh, 1, 21), | |
9161 | GEN_VXFORM(vavgsw, 1, 22), | |
9162 | GEN_VXFORM(vmrghb, 6, 0), | |
9163 | GEN_VXFORM(vmrghh, 6, 1), | |
9164 | GEN_VXFORM(vmrghw, 6, 2), | |
9165 | GEN_VXFORM(vmrglb, 6, 4), | |
9166 | GEN_VXFORM(vmrglh, 6, 5), | |
9167 | GEN_VXFORM(vmrglw, 6, 6), | |
9168 | GEN_VXFORM(vmuloub, 4, 0), | |
9169 | GEN_VXFORM(vmulouh, 4, 1), | |
9170 | GEN_VXFORM(vmulosb, 4, 4), | |
9171 | GEN_VXFORM(vmulosh, 4, 5), | |
9172 | GEN_VXFORM(vmuleub, 4, 8), | |
9173 | GEN_VXFORM(vmuleuh, 4, 9), | |
9174 | GEN_VXFORM(vmulesb, 4, 12), | |
9175 | GEN_VXFORM(vmulesh, 4, 13), | |
9176 | GEN_VXFORM(vslb, 2, 4), | |
9177 | GEN_VXFORM(vslh, 2, 5), | |
9178 | GEN_VXFORM(vslw, 2, 6), | |
9179 | GEN_VXFORM(vsrb, 2, 8), | |
9180 | GEN_VXFORM(vsrh, 2, 9), | |
9181 | GEN_VXFORM(vsrw, 2, 10), | |
9182 | GEN_VXFORM(vsrab, 2, 12), | |
9183 | GEN_VXFORM(vsrah, 2, 13), | |
9184 | GEN_VXFORM(vsraw, 2, 14), | |
9185 | GEN_VXFORM(vslo, 6, 16), | |
9186 | GEN_VXFORM(vsro, 6, 17), | |
9187 | GEN_VXFORM(vaddcuw, 0, 6), | |
9188 | GEN_VXFORM(vsubcuw, 0, 22), | |
9189 | GEN_VXFORM(vaddubs, 0, 8), | |
9190 | GEN_VXFORM(vadduhs, 0, 9), | |
9191 | GEN_VXFORM(vadduws, 0, 10), | |
9192 | GEN_VXFORM(vaddsbs, 0, 12), | |
9193 | GEN_VXFORM(vaddshs, 0, 13), | |
9194 | GEN_VXFORM(vaddsws, 0, 14), | |
9195 | GEN_VXFORM(vsububs, 0, 24), | |
9196 | GEN_VXFORM(vsubuhs, 0, 25), | |
9197 | GEN_VXFORM(vsubuws, 0, 26), | |
9198 | GEN_VXFORM(vsubsbs, 0, 28), | |
9199 | GEN_VXFORM(vsubshs, 0, 29), | |
9200 | GEN_VXFORM(vsubsws, 0, 30), | |
9201 | GEN_VXFORM(vrlb, 2, 0), | |
9202 | GEN_VXFORM(vrlh, 2, 1), | |
9203 | GEN_VXFORM(vrlw, 2, 2), | |
9204 | GEN_VXFORM(vsl, 2, 7), | |
9205 | GEN_VXFORM(vsr, 2, 11), | |
9206 | GEN_VXFORM(vpkuhum, 7, 0), | |
9207 | GEN_VXFORM(vpkuwum, 7, 1), | |
9208 | GEN_VXFORM(vpkuhus, 7, 2), | |
9209 | GEN_VXFORM(vpkuwus, 7, 3), | |
9210 | GEN_VXFORM(vpkshus, 7, 4), | |
9211 | GEN_VXFORM(vpkswus, 7, 5), | |
9212 | GEN_VXFORM(vpkshss, 7, 6), | |
9213 | GEN_VXFORM(vpkswss, 7, 7), | |
9214 | GEN_VXFORM(vpkpx, 7, 12), | |
9215 | GEN_VXFORM(vsum4ubs, 4, 24), | |
9216 | GEN_VXFORM(vsum4sbs, 4, 28), | |
9217 | GEN_VXFORM(vsum4shs, 4, 25), | |
9218 | GEN_VXFORM(vsum2sws, 4, 26), | |
9219 | GEN_VXFORM(vsumsws, 4, 30), | |
9220 | GEN_VXFORM(vaddfp, 5, 0), | |
9221 | GEN_VXFORM(vsubfp, 5, 1), | |
9222 | GEN_VXFORM(vmaxfp, 5, 16), | |
9223 | GEN_VXFORM(vminfp, 5, 17), | |
9224 | ||
9225 | #undef GEN_VXRFORM1 | |
9226 | #undef GEN_VXRFORM | |
9227 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ | |
9228 | GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC), | |
9229 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
9230 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
9231 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
9232 | GEN_VXRFORM(vcmpequb, 3, 0) | |
9233 | GEN_VXRFORM(vcmpequh, 3, 1) | |
9234 | GEN_VXRFORM(vcmpequw, 3, 2) | |
9235 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
9236 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
9237 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
9238 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
9239 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
9240 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
9241 | GEN_VXRFORM(vcmpeqfp, 3, 3) | |
9242 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
9243 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
9244 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
9245 | ||
9246 | #undef GEN_VXFORM_SIMM | |
9247 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ | |
9248 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9249 | GEN_VXFORM_SIMM(vspltisb, 6, 12), | |
9250 | GEN_VXFORM_SIMM(vspltish, 6, 13), | |
9251 | GEN_VXFORM_SIMM(vspltisw, 6, 14), | |
9252 | ||
9253 | #undef GEN_VXFORM_NOA | |
9254 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ | |
9255 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) | |
9256 | GEN_VXFORM_NOA(vupkhsb, 7, 8), | |
9257 | GEN_VXFORM_NOA(vupkhsh, 7, 9), | |
9258 | GEN_VXFORM_NOA(vupklsb, 7, 10), | |
9259 | GEN_VXFORM_NOA(vupklsh, 7, 11), | |
9260 | GEN_VXFORM_NOA(vupkhpx, 7, 13), | |
9261 | GEN_VXFORM_NOA(vupklpx, 7, 15), | |
9262 | GEN_VXFORM_NOA(vrefp, 5, 4), | |
9263 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5), | |
0bffbc6c | 9264 | GEN_VXFORM_NOA(vexptefp, 5, 6), |
5c55ff99 BS |
9265 | GEN_VXFORM_NOA(vlogefp, 5, 7), |
9266 | GEN_VXFORM_NOA(vrfim, 5, 8), | |
9267 | GEN_VXFORM_NOA(vrfin, 5, 9), | |
9268 | GEN_VXFORM_NOA(vrfip, 5, 10), | |
9269 | GEN_VXFORM_NOA(vrfiz, 5, 11), | |
9270 | ||
9271 | #undef GEN_VXFORM_UIMM | |
9272 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ | |
9273 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9274 | GEN_VXFORM_UIMM(vspltb, 6, 8), | |
9275 | GEN_VXFORM_UIMM(vsplth, 6, 9), | |
9276 | GEN_VXFORM_UIMM(vspltw, 6, 10), | |
9277 | GEN_VXFORM_UIMM(vcfux, 5, 12), | |
9278 | GEN_VXFORM_UIMM(vcfsx, 5, 13), | |
9279 | GEN_VXFORM_UIMM(vctuxs, 5, 14), | |
9280 | GEN_VXFORM_UIMM(vctsxs, 5, 15), | |
9281 | ||
9282 | #undef GEN_VAFORM_PAIRED | |
9283 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ | |
9284 | GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) | |
9285 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16), | |
9286 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18), | |
9287 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19), | |
9288 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20), | |
9289 | GEN_VAFORM_PAIRED(vsel, vperm, 21), | |
9290 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23), | |
9291 | ||
9292 | #undef GEN_SPE | |
70560da7 FC |
9293 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
9294 | GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE) | |
9295 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9296 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9297 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9298 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9299 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9300 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9301 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9302 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE), | |
9303 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE), | |
9304 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9305 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9306 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9307 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9308 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9309 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9310 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE), | |
9311 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9312 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9313 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9314 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9315 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9316 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9317 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9318 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9319 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9320 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9321 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9322 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9323 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE), | |
9324 | ||
9325 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9326 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9327 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9328 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9329 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9330 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9331 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9332 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9333 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9334 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9335 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9336 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9337 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9338 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9339 | ||
9340 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9341 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9342 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9343 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9344 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9345 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE), | |
9346 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9347 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9348 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9349 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9350 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9351 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9352 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9353 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9354 | ||
9355 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9356 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9357 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE), | |
9358 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9359 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9360 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9361 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9362 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE), | |
9363 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9364 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9365 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9366 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9367 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9368 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9369 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9370 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
5c55ff99 BS |
9371 | |
9372 | #undef GEN_SPEOP_LDST | |
9373 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
9374 | GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) | |
9375 | GEN_SPEOP_LDST(evldd, 0x00, 3), | |
9376 | GEN_SPEOP_LDST(evldw, 0x01, 3), | |
9377 | GEN_SPEOP_LDST(evldh, 0x02, 3), | |
9378 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1), | |
9379 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1), | |
9380 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1), | |
9381 | GEN_SPEOP_LDST(evlwhe, 0x08, 2), | |
9382 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2), | |
9383 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2), | |
9384 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2), | |
9385 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2), | |
9386 | ||
9387 | GEN_SPEOP_LDST(evstdd, 0x10, 3), | |
9388 | GEN_SPEOP_LDST(evstdw, 0x11, 3), | |
9389 | GEN_SPEOP_LDST(evstdh, 0x12, 3), | |
9390 | GEN_SPEOP_LDST(evstwhe, 0x18, 2), | |
9391 | GEN_SPEOP_LDST(evstwho, 0x1A, 2), | |
9392 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2), | |
9393 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2), | |
9394 | }; | |
9395 | ||
0411a972 | 9396 | #include "helper_regs.h" |
a1389542 | 9397 | #include "translate_init.c" |
79aceca5 | 9398 | |
9a64fbe4 | 9399 | /*****************************************************************************/ |
3fc6c082 | 9400 | /* Misc PowerPC helpers */ |
1328c2bf | 9401 | void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf, |
36081602 | 9402 | int flags) |
79aceca5 | 9403 | { |
3fc6c082 FB |
9404 | #define RGPL 4 |
9405 | #define RFPL 4 | |
3fc6c082 | 9406 | |
79aceca5 FB |
9407 | int i; |
9408 | ||
29979a8d AG |
9409 | cpu_synchronize_state(env); |
9410 | ||
90e189ec | 9411 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
9a78eead SW |
9412 | TARGET_FMT_lx " XER " TARGET_FMT_lx "\n", |
9413 | env->nip, env->lr, env->ctr, env->xer); | |
90e189ec BS |
9414 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
9415 | TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0], | |
9416 | env->hflags, env->mmu_idx); | |
d9bce9d9 | 9417 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 9418 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 9419 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 9420 | " DECR %08" PRIu32 |
76a66253 JM |
9421 | #endif |
9422 | "\n", | |
077fc206 | 9423 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
9424 | #if !defined(CONFIG_USER_ONLY) |
9425 | , cpu_ppc_load_decr(env) | |
9426 | #endif | |
9427 | ); | |
077fc206 | 9428 | #endif |
76a66253 | 9429 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
9430 | if ((i & (RGPL - 1)) == 0) |
9431 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 9432 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 9433 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 9434 | cpu_fprintf(f, "\n"); |
76a66253 | 9435 | } |
3fc6c082 | 9436 | cpu_fprintf(f, "CR "); |
76a66253 | 9437 | for (i = 0; i < 8; i++) |
7fe48483 FB |
9438 | cpu_fprintf(f, "%01x", env->crf[i]); |
9439 | cpu_fprintf(f, " ["); | |
76a66253 JM |
9440 | for (i = 0; i < 8; i++) { |
9441 | char a = '-'; | |
9442 | if (env->crf[i] & 0x08) | |
9443 | a = 'L'; | |
9444 | else if (env->crf[i] & 0x04) | |
9445 | a = 'G'; | |
9446 | else if (env->crf[i] & 0x02) | |
9447 | a = 'E'; | |
7fe48483 | 9448 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 9449 | } |
90e189ec BS |
9450 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
9451 | env->reserve_addr); | |
3fc6c082 FB |
9452 | for (i = 0; i < 32; i++) { |
9453 | if ((i & (RFPL - 1)) == 0) | |
9454 | cpu_fprintf(f, "FPR%02d", i); | |
26a76461 | 9455 | cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); |
3fc6c082 | 9456 | if ((i & (RFPL - 1)) == (RFPL - 1)) |
7fe48483 | 9457 | cpu_fprintf(f, "\n"); |
79aceca5 | 9458 | } |
30304420 | 9459 | cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); |
f2e63a42 | 9460 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
9461 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
9462 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
9463 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
9464 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
9465 | ||
9466 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
9467 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
9468 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
9469 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
9470 | ||
9471 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
9472 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
9473 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
9474 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
9475 | ||
9476 | if (env->excp_model == POWERPC_EXCP_BOOKE) { | |
9477 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
9478 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
9479 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
9480 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
9481 | ||
9482 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
9483 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
9484 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
9485 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
9486 | ||
9487 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
9488 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
9489 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
9490 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
9491 | ||
9492 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
9493 | " EPR " TARGET_FMT_lx "\n", | |
9494 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
9495 | env->spr[SPR_BOOKE_EPR]); | |
9496 | ||
9497 | /* FSL-specific */ | |
9498 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
9499 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
9500 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
9501 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
9502 | ||
9503 | /* | |
9504 | * IVORs are left out as they are large and do not change often -- | |
9505 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
9506 | */ | |
9507 | } | |
9508 | ||
697ab892 DG |
9509 | #if defined(TARGET_PPC64) |
9510 | if (env->flags & POWERPC_FLAG_CFAR) { | |
9511 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
9512 | } | |
9513 | #endif | |
9514 | ||
90dc8812 SW |
9515 | switch (env->mmu_model) { |
9516 | case POWERPC_MMU_32B: | |
9517 | case POWERPC_MMU_601: | |
9518 | case POWERPC_MMU_SOFT_6xx: | |
9519 | case POWERPC_MMU_SOFT_74xx: | |
9520 | #if defined(TARGET_PPC64) | |
9521 | case POWERPC_MMU_620: | |
9522 | case POWERPC_MMU_64B: | |
9523 | #endif | |
9524 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]); | |
9525 | break; | |
01662f3e | 9526 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
9527 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
9528 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
9529 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
9530 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
9531 | ||
9532 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
9533 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
9534 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
9535 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
9536 | ||
9537 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
9538 | " TLB1CFG " TARGET_FMT_lx "\n", | |
9539 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
9540 | env->spr[SPR_BOOKE_TLB1CFG]); | |
9541 | break; | |
9542 | default: | |
9543 | break; | |
9544 | } | |
f2e63a42 | 9545 | #endif |
79aceca5 | 9546 | |
3fc6c082 FB |
9547 | #undef RGPL |
9548 | #undef RFPL | |
79aceca5 FB |
9549 | } |
9550 | ||
1328c2bf | 9551 | void cpu_dump_statistics (CPUPPCState *env, FILE*f, fprintf_function cpu_fprintf, |
76a66253 JM |
9552 | int flags) |
9553 | { | |
9554 | #if defined(DO_PPC_STATISTICS) | |
c227f099 | 9555 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
9556 | int op1, op2, op3; |
9557 | ||
9558 | t1 = env->opcodes; | |
9559 | for (op1 = 0; op1 < 64; op1++) { | |
9560 | handler = t1[op1]; | |
9561 | if (is_indirect_opcode(handler)) { | |
9562 | t2 = ind_table(handler); | |
9563 | for (op2 = 0; op2 < 32; op2++) { | |
9564 | handler = t2[op2]; | |
9565 | if (is_indirect_opcode(handler)) { | |
9566 | t3 = ind_table(handler); | |
9567 | for (op3 = 0; op3 < 32; op3++) { | |
9568 | handler = t3[op3]; | |
9569 | if (handler->count == 0) | |
9570 | continue; | |
9571 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9572 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9573 | op1, op2, op3, op1, (op3 << 5) | op2, |
9574 | handler->oname, | |
9575 | handler->count, handler->count); | |
9576 | } | |
9577 | } else { | |
9578 | if (handler->count == 0) | |
9579 | continue; | |
9580 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9581 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9582 | op1, op2, op1, op2, handler->oname, |
9583 | handler->count, handler->count); | |
9584 | } | |
9585 | } | |
9586 | } else { | |
9587 | if (handler->count == 0) | |
9588 | continue; | |
0bfcd599 BS |
9589 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
9590 | " %" PRId64 "\n", | |
76a66253 JM |
9591 | op1, op1, handler->oname, |
9592 | handler->count, handler->count); | |
9593 | } | |
9594 | } | |
9595 | #endif | |
9596 | } | |
9597 | ||
9a64fbe4 | 9598 | /*****************************************************************************/ |
1328c2bf | 9599 | static inline void gen_intermediate_code_internal(CPUPPCState *env, |
636aa200 BS |
9600 | TranslationBlock *tb, |
9601 | int search_pc) | |
79aceca5 | 9602 | { |
9fddaa0c | 9603 | DisasContext ctx, *ctxp = &ctx; |
c227f099 | 9604 | opc_handler_t **table, *handler; |
0fa85d43 | 9605 | target_ulong pc_start; |
79aceca5 | 9606 | uint16_t *gen_opc_end; |
a1d1bb31 | 9607 | CPUBreakpoint *bp; |
79aceca5 | 9608 | int j, lj = -1; |
2e70f6ef PB |
9609 | int num_insns; |
9610 | int max_insns; | |
79aceca5 FB |
9611 | |
9612 | pc_start = tb->pc; | |
92414b31 | 9613 | gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
046d6672 | 9614 | ctx.nip = pc_start; |
79aceca5 | 9615 | ctx.tb = tb; |
e1833e1f | 9616 | ctx.exception = POWERPC_EXCP_NONE; |
3fc6c082 | 9617 | ctx.spr_cb = env->spr_cb; |
76db3ba4 AJ |
9618 | ctx.mem_idx = env->mmu_idx; |
9619 | ctx.access_type = -1; | |
9620 | ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0; | |
d9bce9d9 | 9621 | #if defined(TARGET_PPC64) |
e42a61f1 | 9622 | ctx.sf_mode = msr_is_64bit(env, env->msr); |
697ab892 | 9623 | ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); |
9a64fbe4 | 9624 | #endif |
3cc62370 | 9625 | ctx.fpu_enabled = msr_fp; |
a9d9eb8f | 9626 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
d26bfc9a JM |
9627 | ctx.spe_enabled = msr_spe; |
9628 | else | |
9629 | ctx.spe_enabled = 0; | |
a9d9eb8f JM |
9630 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
9631 | ctx.altivec_enabled = msr_vr; | |
9632 | else | |
9633 | ctx.altivec_enabled = 0; | |
d26bfc9a | 9634 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
8cbcb4fa | 9635 | ctx.singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 9636 | else |
8cbcb4fa | 9637 | ctx.singlestep_enabled = 0; |
d26bfc9a | 9638 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
8cbcb4fa AJ |
9639 | ctx.singlestep_enabled |= CPU_BRANCH_STEP; |
9640 | if (unlikely(env->singlestep_enabled)) | |
9641 | ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP; | |
3fc6c082 | 9642 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
9643 | /* Single step trace mode */ |
9644 | msr_se = 1; | |
9645 | #endif | |
2e70f6ef PB |
9646 | num_insns = 0; |
9647 | max_insns = tb->cflags & CF_COUNT_MASK; | |
9648 | if (max_insns == 0) | |
9649 | max_insns = CF_COUNT_MASK; | |
9650 | ||
9651 | gen_icount_start(); | |
9a64fbe4 | 9652 | /* Set env in case of segfault during code fetch */ |
efd7f486 EV |
9653 | while (ctx.exception == POWERPC_EXCP_NONE |
9654 | && tcg_ctx.gen_opc_ptr < gen_opc_end) { | |
72cf2d4f BS |
9655 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { |
9656 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
a1d1bb31 | 9657 | if (bp->pc == ctx.nip) { |
e06fcd75 | 9658 | gen_debug_exception(ctxp); |
ea4e754f FB |
9659 | break; |
9660 | } | |
9661 | } | |
9662 | } | |
76a66253 | 9663 | if (unlikely(search_pc)) { |
92414b31 | 9664 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
79aceca5 FB |
9665 | if (lj < j) { |
9666 | lj++; | |
9667 | while (lj < j) | |
ab1103de | 9668 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
79aceca5 | 9669 | } |
25983cad | 9670 | tcg_ctx.gen_opc_pc[lj] = ctx.nip; |
ab1103de | 9671 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 9672 | tcg_ctx.gen_opc_icount[lj] = num_insns; |
79aceca5 | 9673 | } |
d12d51d5 | 9674 | LOG_DISAS("----------------\n"); |
90e189ec | 9675 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", |
d12d51d5 | 9676 | ctx.nip, ctx.mem_idx, (int)msr_ir); |
2e70f6ef PB |
9677 | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
9678 | gen_io_start(); | |
76db3ba4 | 9679 | if (unlikely(ctx.le_mode)) { |
2f5a189c | 9680 | ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip)); |
056401ea | 9681 | } else { |
2f5a189c | 9682 | ctx.opcode = cpu_ldl_code(env, ctx.nip); |
111bfab3 | 9683 | } |
d12d51d5 | 9684 | LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n", |
9a64fbe4 | 9685 | ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
476b6d16 | 9686 | opc3(ctx.opcode), ctx.le_mode ? "little" : "big"); |
fdefe51c | 9687 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { |
731c54f8 | 9688 | tcg_gen_debug_insn_start(ctx.nip); |
fdefe51c | 9689 | } |
046d6672 | 9690 | ctx.nip += 4; |
3fc6c082 | 9691 | table = env->opcodes; |
2e70f6ef | 9692 | num_insns++; |
79aceca5 FB |
9693 | handler = table[opc1(ctx.opcode)]; |
9694 | if (is_indirect_opcode(handler)) { | |
9695 | table = ind_table(handler); | |
9696 | handler = table[opc2(ctx.opcode)]; | |
9697 | if (is_indirect_opcode(handler)) { | |
9698 | table = ind_table(handler); | |
9699 | handler = table[opc3(ctx.opcode)]; | |
9700 | } | |
9701 | } | |
9702 | /* Is opcode *REALLY* valid ? */ | |
76a66253 | 9703 | if (unlikely(handler->handler == &gen_invalid)) { |
93fcfe39 AL |
9704 | if (qemu_log_enabled()) { |
9705 | qemu_log("invalid/unsupported opcode: " | |
90e189ec BS |
9706 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n", |
9707 | opc1(ctx.opcode), opc2(ctx.opcode), | |
9708 | opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir); | |
4b3686fa | 9709 | } |
76a66253 | 9710 | } else { |
70560da7 FC |
9711 | uint32_t inval; |
9712 | ||
9713 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) { | |
9714 | inval = handler->inval2; | |
9715 | } else { | |
9716 | inval = handler->inval1; | |
9717 | } | |
9718 | ||
9719 | if (unlikely((ctx.opcode & inval) != 0)) { | |
93fcfe39 AL |
9720 | if (qemu_log_enabled()) { |
9721 | qemu_log("invalid bits: %08x for opcode: " | |
90e189ec | 9722 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n", |
70560da7 | 9723 | ctx.opcode & inval, opc1(ctx.opcode), |
90e189ec BS |
9724 | opc2(ctx.opcode), opc3(ctx.opcode), |
9725 | ctx.opcode, ctx.nip - 4); | |
76a66253 | 9726 | } |
e06fcd75 | 9727 | gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL); |
4b3686fa | 9728 | break; |
79aceca5 | 9729 | } |
79aceca5 | 9730 | } |
4b3686fa | 9731 | (*(handler->handler))(&ctx); |
76a66253 JM |
9732 | #if defined(DO_PPC_STATISTICS) |
9733 | handler->count++; | |
9734 | #endif | |
9a64fbe4 | 9735 | /* Check trace mode exceptions */ |
8cbcb4fa AJ |
9736 | if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP && |
9737 | (ctx.nip <= 0x100 || ctx.nip > 0xF00) && | |
9738 | ctx.exception != POWERPC_SYSCALL && | |
9739 | ctx.exception != POWERPC_EXCP_TRAP && | |
9740 | ctx.exception != POWERPC_EXCP_BRANCH)) { | |
e06fcd75 | 9741 | gen_exception(ctxp, POWERPC_EXCP_TRACE); |
d26bfc9a | 9742 | } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
2e70f6ef | 9743 | (env->singlestep_enabled) || |
1b530a6d | 9744 | singlestep || |
2e70f6ef | 9745 | num_insns >= max_insns)) { |
d26bfc9a JM |
9746 | /* if we reach a page boundary or are single stepping, stop |
9747 | * generation | |
9748 | */ | |
8dd4983c | 9749 | break; |
76a66253 | 9750 | } |
3fc6c082 | 9751 | } |
2e70f6ef PB |
9752 | if (tb->cflags & CF_LAST_IO) |
9753 | gen_io_end(); | |
e1833e1f | 9754 | if (ctx.exception == POWERPC_EXCP_NONE) { |
c1942362 | 9755 | gen_goto_tb(&ctx, 0, ctx.nip); |
e1833e1f | 9756 | } else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
8cbcb4fa | 9757 | if (unlikely(env->singlestep_enabled)) { |
e06fcd75 | 9758 | gen_debug_exception(ctxp); |
8cbcb4fa | 9759 | } |
76a66253 | 9760 | /* Generate the return instruction */ |
57fec1fe | 9761 | tcg_gen_exit_tb(0); |
9a64fbe4 | 9762 | } |
2e70f6ef | 9763 | gen_icount_end(tb, num_insns); |
efd7f486 | 9764 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
76a66253 | 9765 | if (unlikely(search_pc)) { |
92414b31 | 9766 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
9a64fbe4 FB |
9767 | lj++; |
9768 | while (lj <= j) | |
ab1103de | 9769 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
9a64fbe4 | 9770 | } else { |
046d6672 | 9771 | tb->size = ctx.nip - pc_start; |
2e70f6ef | 9772 | tb->icount = num_insns; |
9a64fbe4 | 9773 | } |
d9bce9d9 | 9774 | #if defined(DEBUG_DISAS) |
8fec2b8c | 9775 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
76a66253 | 9776 | int flags; |
237c0af0 | 9777 | flags = env->bfd_mach; |
76db3ba4 | 9778 | flags |= ctx.le_mode << 16; |
93fcfe39 | 9779 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); |
f4359b9f | 9780 | log_target_disas(env, pc_start, ctx.nip - pc_start, flags); |
93fcfe39 | 9781 | qemu_log("\n"); |
9fddaa0c | 9782 | } |
79aceca5 | 9783 | #endif |
79aceca5 FB |
9784 | } |
9785 | ||
1328c2bf | 9786 | void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 9787 | { |
2cfc5f17 | 9788 | gen_intermediate_code_internal(env, tb, 0); |
79aceca5 FB |
9789 | } |
9790 | ||
1328c2bf | 9791 | void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 9792 | { |
2cfc5f17 | 9793 | gen_intermediate_code_internal(env, tb, 1); |
79aceca5 | 9794 | } |
d2856f1a | 9795 | |
1328c2bf | 9796 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos) |
d2856f1a | 9797 | { |
25983cad | 9798 | env->nip = tcg_ctx.gen_opc_pc[pc_pos]; |
d2856f1a | 9799 | } |