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" |
79aceca5 | 22 | #include "disas.h" |
57fec1fe | 23 | #include "tcg-op.h" |
0cfe11ea | 24 | #include "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 | |
2e70f6ef PB |
74 | #include "gen-icount.h" |
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 | { |
a7812ae4 | 1064 | TCGv_i64 t0, t1; |
74637406 | 1065 | |
a7812ae4 PB |
1066 | t0 = tcg_temp_new_i64(); |
1067 | t1 = tcg_temp_new_i64(); | |
74637406 AJ |
1068 | #if defined(TARGET_PPC64) |
1069 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
1070 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
1071 | tcg_gen_mul_i64(t0, t0, t1); | |
1072 | tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
1073 | #else | |
1074 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1075 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1076 | tcg_gen_mul_i64(t0, t0, t1); | |
1077 | tcg_gen_shri_i64(t0, t0, 32); | |
1078 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1079 | #endif | |
a7812ae4 PB |
1080 | tcg_temp_free_i64(t0); |
1081 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1082 | if (unlikely(Rc(ctx->opcode) != 0)) |
1083 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1084 | } |
99e300ef | 1085 | |
54623277 | 1086 | /* mulhwu mulhwu. */ |
99e300ef | 1087 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1088 | { |
a7812ae4 | 1089 | TCGv_i64 t0, t1; |
74637406 | 1090 | |
a7812ae4 PB |
1091 | t0 = tcg_temp_new_i64(); |
1092 | t1 = tcg_temp_new_i64(); | |
d9bce9d9 | 1093 | #if defined(TARGET_PPC64) |
74637406 AJ |
1094 | tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]); |
1095 | tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1096 | tcg_gen_mul_i64(t0, t0, t1); | |
1097 | tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
1098 | #else | |
1099 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1100 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1101 | tcg_gen_mul_i64(t0, t0, t1); | |
1102 | tcg_gen_shri_i64(t0, t0, 32); | |
1103 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1104 | #endif | |
a7812ae4 PB |
1105 | tcg_temp_free_i64(t0); |
1106 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1107 | if (unlikely(Rc(ctx->opcode) != 0)) |
1108 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1109 | } |
99e300ef | 1110 | |
54623277 | 1111 | /* mullw mullw. */ |
99e300ef | 1112 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1113 | { |
74637406 AJ |
1114 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1115 | cpu_gpr[rB(ctx->opcode)]); | |
1e4c090f | 1116 | tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]); |
74637406 AJ |
1117 | if (unlikely(Rc(ctx->opcode) != 0)) |
1118 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1119 | } |
99e300ef | 1120 | |
54623277 | 1121 | /* mullwo mullwo. */ |
99e300ef | 1122 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1123 | { |
74637406 | 1124 | int l1; |
a7812ae4 | 1125 | TCGv_i64 t0, t1; |
74637406 | 1126 | |
a7812ae4 PB |
1127 | t0 = tcg_temp_new_i64(); |
1128 | t1 = tcg_temp_new_i64(); | |
74637406 AJ |
1129 | l1 = gen_new_label(); |
1130 | /* Start with XER OV disabled, the most likely case */ | |
1131 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1132 | #if defined(TARGET_PPC64) | |
1133 | tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1134 | tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1135 | #else | |
1136 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1137 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
d9bce9d9 | 1138 | #endif |
74637406 AJ |
1139 | tcg_gen_mul_i64(t0, t0, t1); |
1140 | #if defined(TARGET_PPC64) | |
1141 | tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0); | |
1142 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1); | |
1143 | #else | |
1144 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1145 | tcg_gen_ext32s_i64(t1, t0); | |
1146 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
1147 | #endif | |
1148 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1149 | gen_set_label(l1); | |
a7812ae4 PB |
1150 | tcg_temp_free_i64(t0); |
1151 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1152 | if (unlikely(Rc(ctx->opcode) != 0)) |
1153 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1154 | } |
99e300ef | 1155 | |
54623277 | 1156 | /* mulli */ |
99e300ef | 1157 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1158 | { |
74637406 AJ |
1159 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1160 | SIMM(ctx->opcode)); | |
d9bce9d9 JM |
1161 | } |
1162 | #if defined(TARGET_PPC64) | |
74637406 | 1163 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ |
99e300ef | 1164 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1165 | { \ |
a7812ae4 | 1166 | gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \ |
74637406 AJ |
1167 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
1168 | if (unlikely(Rc(ctx->opcode) != 0)) \ | |
1169 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \ | |
d9bce9d9 | 1170 | } |
74637406 AJ |
1171 | /* mulhd mulhd. */ |
1172 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00); | |
1173 | /* mulhdu mulhdu. */ | |
1174 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02); | |
99e300ef | 1175 | |
54623277 | 1176 | /* mulld mulld. */ |
99e300ef | 1177 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1178 | { |
74637406 AJ |
1179 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1180 | cpu_gpr[rB(ctx->opcode)]); | |
1181 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1182 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1183 | } |
d15f74fb | 1184 | |
74637406 | 1185 | /* mulldo mulldo. */ |
d15f74fb BS |
1186 | static void gen_mulldo(DisasContext *ctx) |
1187 | { | |
1188 | gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env, | |
1189 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1190 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1191 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1192 | } | |
1193 | } | |
d9bce9d9 | 1194 | #endif |
74637406 AJ |
1195 | |
1196 | /* neg neg. nego nego. */ | |
636aa200 BS |
1197 | static inline void gen_op_arith_neg(DisasContext *ctx, TCGv ret, TCGv arg1, |
1198 | int ov_check) | |
d9bce9d9 | 1199 | { |
ec6469a3 AJ |
1200 | int l1 = gen_new_label(); |
1201 | int l2 = gen_new_label(); | |
a7812ae4 | 1202 | TCGv t0 = tcg_temp_local_new(); |
d9bce9d9 | 1203 | #if defined(TARGET_PPC64) |
74637406 | 1204 | if (ctx->sf_mode) { |
741a7444 | 1205 | tcg_gen_mov_tl(t0, arg1); |
ec6469a3 AJ |
1206 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1); |
1207 | } else | |
1208 | #endif | |
1209 | { | |
1210 | tcg_gen_ext32s_tl(t0, arg1); | |
74637406 AJ |
1211 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1); |
1212 | } | |
74637406 AJ |
1213 | tcg_gen_neg_tl(ret, arg1); |
1214 | if (ov_check) { | |
1215 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1216 | } | |
1217 | tcg_gen_br(l2); | |
1218 | gen_set_label(l1); | |
ec6469a3 | 1219 | tcg_gen_mov_tl(ret, t0); |
74637406 AJ |
1220 | if (ov_check) { |
1221 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1222 | } | |
1223 | gen_set_label(l2); | |
ec6469a3 | 1224 | tcg_temp_free(t0); |
74637406 AJ |
1225 | if (unlikely(Rc(ctx->opcode) != 0)) |
1226 | gen_set_Rc0(ctx, ret); | |
1227 | } | |
99e300ef BS |
1228 | |
1229 | static void gen_neg(DisasContext *ctx) | |
d9bce9d9 | 1230 | { |
ec6469a3 | 1231 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0); |
d9bce9d9 | 1232 | } |
99e300ef BS |
1233 | |
1234 | static void gen_nego(DisasContext *ctx) | |
79aceca5 | 1235 | { |
ec6469a3 | 1236 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1); |
79aceca5 | 1237 | } |
74637406 AJ |
1238 | |
1239 | /* Common subf function */ | |
636aa200 BS |
1240 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
1241 | TCGv arg2, int add_ca, int compute_ca, | |
1242 | int compute_ov) | |
79aceca5 | 1243 | { |
74637406 | 1244 | TCGv t0, t1; |
76a66253 | 1245 | |
74637406 | 1246 | if ((!compute_ca && !compute_ov) || |
a7812ae4 | 1247 | (!TCGV_EQUAL(ret, arg1) && !TCGV_EQUAL(ret, arg2))) { |
74637406 | 1248 | t0 = ret; |
e864cabd | 1249 | } else { |
a7812ae4 | 1250 | t0 = tcg_temp_local_new(); |
d9bce9d9 | 1251 | } |
76a66253 | 1252 | |
74637406 | 1253 | if (add_ca) { |
a7812ae4 | 1254 | t1 = tcg_temp_local_new(); |
74637406 AJ |
1255 | tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA)); |
1256 | tcg_gen_shri_tl(t1, t1, XER_CA); | |
d2e9fd8f | 1257 | } else { |
1258 | TCGV_UNUSED(t1); | |
d9bce9d9 | 1259 | } |
79aceca5 | 1260 | |
74637406 AJ |
1261 | if (compute_ca && compute_ov) { |
1262 | /* Start with XER CA and OV disabled, the most likely case */ | |
1263 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV))); | |
1264 | } else if (compute_ca) { | |
1265 | /* Start with XER CA disabled, the most likely case */ | |
1266 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
1267 | } else if (compute_ov) { | |
1268 | /* Start with XER OV disabled, the most likely case */ | |
1269 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1270 | } | |
1271 | ||
1272 | if (add_ca) { | |
1273 | tcg_gen_not_tl(t0, arg1); | |
1274 | tcg_gen_add_tl(t0, t0, arg2); | |
1275 | gen_op_arith_compute_ca(ctx, t0, arg2, 0); | |
1276 | tcg_gen_add_tl(t0, t0, t1); | |
1277 | gen_op_arith_compute_ca(ctx, t0, t1, 0); | |
1278 | tcg_temp_free(t1); | |
79aceca5 | 1279 | } else { |
74637406 AJ |
1280 | tcg_gen_sub_tl(t0, arg2, arg1); |
1281 | if (compute_ca) { | |
1282 | gen_op_arith_compute_ca(ctx, t0, arg2, 1); | |
1283 | } | |
1284 | } | |
1285 | if (compute_ov) { | |
1286 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1287 | } | |
1288 | ||
1289 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1290 | gen_set_Rc0(ctx, t0); | |
1291 | ||
a7812ae4 | 1292 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
1293 | tcg_gen_mov_tl(ret, t0); |
1294 | tcg_temp_free(t0); | |
79aceca5 | 1295 | } |
79aceca5 | 1296 | } |
74637406 AJ |
1297 | /* Sub functions with Two operands functions */ |
1298 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1299 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1300 | { \ |
1301 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1302 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1303 | add_ca, compute_ca, compute_ov); \ | |
1304 | } | |
1305 | /* Sub functions with one operand and one immediate */ | |
1306 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1307 | add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1308 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1309 | { \ |
1310 | TCGv t0 = tcg_const_local_tl(const_val); \ | |
1311 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1312 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
1313 | add_ca, compute_ca, compute_ov); \ | |
1314 | tcg_temp_free(t0); \ | |
1315 | } | |
1316 | /* subf subf. subfo subfo. */ | |
1317 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1318 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1319 | /* subfc subfc. subfco subfco. */ | |
1320 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1321 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1322 | /* subfe subfe. subfeo subfo. */ | |
1323 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1324 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1325 | /* subfme subfme. subfmeo subfmeo. */ | |
1326 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1327 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1328 | /* subfze subfze. subfzeo subfzeo.*/ | |
1329 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1330 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1331 | |
54623277 | 1332 | /* subfic */ |
99e300ef | 1333 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1334 | { |
74637406 AJ |
1335 | /* Start with XER CA and OV disabled, the most likely case */ |
1336 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
a7812ae4 | 1337 | TCGv t0 = tcg_temp_local_new(); |
74637406 AJ |
1338 | TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode)); |
1339 | tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]); | |
1340 | gen_op_arith_compute_ca(ctx, t0, t1, 1); | |
1341 | tcg_temp_free(t1); | |
1342 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1343 | tcg_temp_free(t0); | |
79aceca5 FB |
1344 | } |
1345 | ||
79aceca5 | 1346 | /*** Integer logical ***/ |
26d67362 | 1347 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1348 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1349 | { \ |
26d67362 AJ |
1350 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1351 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1352 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1353 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1354 | } |
79aceca5 | 1355 | |
26d67362 | 1356 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1357 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1358 | { \ |
26d67362 | 1359 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1360 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1361 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1362 | } |
1363 | ||
1364 | /* and & and. */ | |
26d67362 | 1365 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1366 | /* andc & andc. */ |
26d67362 | 1367 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1368 | |
54623277 | 1369 | /* andi. */ |
e8eaa2c0 | 1370 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1371 | { |
26d67362 AJ |
1372 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1373 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1374 | } |
e8eaa2c0 | 1375 | |
54623277 | 1376 | /* andis. */ |
e8eaa2c0 | 1377 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1378 | { |
26d67362 AJ |
1379 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1380 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1381 | } |
99e300ef | 1382 | |
54623277 | 1383 | /* cntlzw */ |
99e300ef | 1384 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1385 | { |
a7812ae4 | 1386 | gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 | 1387 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1388 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1389 | } |
79aceca5 | 1390 | /* eqv & eqv. */ |
26d67362 | 1391 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1392 | /* extsb & extsb. */ |
26d67362 | 1393 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1394 | /* extsh & extsh. */ |
26d67362 | 1395 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1396 | /* nand & nand. */ |
26d67362 | 1397 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1398 | /* nor & nor. */ |
26d67362 | 1399 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1400 | |
54623277 | 1401 | /* or & or. */ |
99e300ef | 1402 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1403 | { |
76a66253 JM |
1404 | int rs, ra, rb; |
1405 | ||
1406 | rs = rS(ctx->opcode); | |
1407 | ra = rA(ctx->opcode); | |
1408 | rb = rB(ctx->opcode); | |
1409 | /* Optimisation for mr. ri case */ | |
1410 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1411 | if (rs != rb) |
1412 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1413 | else | |
1414 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1415 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1416 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1417 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1418 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 JM |
1419 | #if defined(TARGET_PPC64) |
1420 | } else { | |
26d67362 AJ |
1421 | int prio = 0; |
1422 | ||
c80f84e3 JM |
1423 | switch (rs) { |
1424 | case 1: | |
1425 | /* Set process priority to low */ | |
26d67362 | 1426 | prio = 2; |
c80f84e3 JM |
1427 | break; |
1428 | case 6: | |
1429 | /* Set process priority to medium-low */ | |
26d67362 | 1430 | prio = 3; |
c80f84e3 JM |
1431 | break; |
1432 | case 2: | |
1433 | /* Set process priority to normal */ | |
26d67362 | 1434 | prio = 4; |
c80f84e3 | 1435 | break; |
be147d08 JM |
1436 | #if !defined(CONFIG_USER_ONLY) |
1437 | case 31: | |
76db3ba4 | 1438 | if (ctx->mem_idx > 0) { |
be147d08 | 1439 | /* Set process priority to very low */ |
26d67362 | 1440 | prio = 1; |
be147d08 JM |
1441 | } |
1442 | break; | |
1443 | case 5: | |
76db3ba4 | 1444 | if (ctx->mem_idx > 0) { |
be147d08 | 1445 | /* Set process priority to medium-hight */ |
26d67362 | 1446 | prio = 5; |
be147d08 JM |
1447 | } |
1448 | break; | |
1449 | case 3: | |
76db3ba4 | 1450 | if (ctx->mem_idx > 0) { |
be147d08 | 1451 | /* Set process priority to high */ |
26d67362 | 1452 | prio = 6; |
be147d08 JM |
1453 | } |
1454 | break; | |
be147d08 | 1455 | case 7: |
76db3ba4 | 1456 | if (ctx->mem_idx > 1) { |
be147d08 | 1457 | /* Set process priority to very high */ |
26d67362 | 1458 | prio = 7; |
be147d08 JM |
1459 | } |
1460 | break; | |
be147d08 | 1461 | #endif |
c80f84e3 JM |
1462 | default: |
1463 | /* nop */ | |
1464 | break; | |
1465 | } | |
26d67362 | 1466 | if (prio) { |
a7812ae4 | 1467 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1468 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1469 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1470 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1471 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1472 | tcg_temp_free(t0); |
26d67362 | 1473 | } |
c80f84e3 | 1474 | #endif |
9a64fbe4 | 1475 | } |
9a64fbe4 | 1476 | } |
79aceca5 | 1477 | /* orc & orc. */ |
26d67362 | 1478 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1479 | |
54623277 | 1480 | /* xor & xor. */ |
99e300ef | 1481 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1482 | { |
9a64fbe4 | 1483 | /* Optimisation for "set to zero" case */ |
26d67362 | 1484 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1485 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1486 | else |
1487 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1488 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1489 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1490 | } |
99e300ef | 1491 | |
54623277 | 1492 | /* ori */ |
99e300ef | 1493 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1494 | { |
76a66253 | 1495 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1496 | |
9a64fbe4 FB |
1497 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1498 | /* NOP */ | |
76a66253 | 1499 | /* XXX: should handle special NOPs for POWER series */ |
9a64fbe4 | 1500 | return; |
76a66253 | 1501 | } |
26d67362 | 1502 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1503 | } |
99e300ef | 1504 | |
54623277 | 1505 | /* oris */ |
99e300ef | 1506 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1507 | { |
76a66253 | 1508 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1509 | |
9a64fbe4 FB |
1510 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1511 | /* NOP */ | |
1512 | return; | |
76a66253 | 1513 | } |
26d67362 | 1514 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1515 | } |
99e300ef | 1516 | |
54623277 | 1517 | /* xori */ |
99e300ef | 1518 | static void gen_xori(DisasContext *ctx) |
79aceca5 | 1519 | { |
76a66253 | 1520 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1521 | |
1522 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1523 | /* NOP */ | |
1524 | return; | |
1525 | } | |
26d67362 | 1526 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1527 | } |
99e300ef | 1528 | |
54623277 | 1529 | /* xoris */ |
99e300ef | 1530 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1531 | { |
76a66253 | 1532 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1533 | |
1534 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1535 | /* NOP */ | |
1536 | return; | |
1537 | } | |
26d67362 | 1538 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1539 | } |
99e300ef | 1540 | |
54623277 | 1541 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1542 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1543 | { |
eaabeef2 DG |
1544 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1545 | } | |
1546 | ||
1547 | static void gen_popcntw(DisasContext *ctx) | |
1548 | { | |
1549 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1550 | } | |
1551 | ||
d9bce9d9 | 1552 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1553 | /* popcntd: PowerPC 2.06 specification */ |
1554 | static void gen_popcntd(DisasContext *ctx) | |
1555 | { | |
1556 | gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 1557 | } |
eaabeef2 | 1558 | #endif |
d9bce9d9 JM |
1559 | |
1560 | #if defined(TARGET_PPC64) | |
1561 | /* extsw & extsw. */ | |
26d67362 | 1562 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1563 | |
54623277 | 1564 | /* cntlzd */ |
99e300ef | 1565 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1566 | { |
a7812ae4 | 1567 | gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 AJ |
1568 | if (unlikely(Rc(ctx->opcode) != 0)) |
1569 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1570 | } | |
d9bce9d9 JM |
1571 | #endif |
1572 | ||
79aceca5 | 1573 | /*** Integer rotate ***/ |
99e300ef | 1574 | |
54623277 | 1575 | /* rlwimi & rlwimi. */ |
99e300ef | 1576 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1577 | { |
76a66253 | 1578 | uint32_t mb, me, sh; |
79aceca5 FB |
1579 | |
1580 | mb = MB(ctx->opcode); | |
1581 | me = ME(ctx->opcode); | |
76a66253 | 1582 | sh = SH(ctx->opcode); |
d03ef511 AJ |
1583 | if (likely(sh == 0 && mb == 0 && me == 31)) { |
1584 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1585 | } else { | |
d03ef511 | 1586 | target_ulong mask; |
a7812ae4 PB |
1587 | TCGv t1; |
1588 | TCGv t0 = tcg_temp_new(); | |
54843a58 | 1589 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1590 | TCGv_i32 t2 = tcg_temp_new_i32(); |
1591 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]); | |
1592 | tcg_gen_rotli_i32(t2, t2, sh); | |
1593 | tcg_gen_extu_i32_i64(t0, t2); | |
1594 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1595 | #else |
1596 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1597 | #endif | |
76a66253 | 1598 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1599 | mb += 32; |
1600 | me += 32; | |
76a66253 | 1601 | #endif |
d03ef511 | 1602 | mask = MASK(mb, me); |
a7812ae4 | 1603 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1604 | tcg_gen_andi_tl(t0, t0, mask); |
1605 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1606 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1607 | tcg_temp_free(t0); | |
1608 | tcg_temp_free(t1); | |
1609 | } | |
76a66253 | 1610 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1611 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1612 | } |
99e300ef | 1613 | |
54623277 | 1614 | /* rlwinm & rlwinm. */ |
99e300ef | 1615 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 FB |
1616 | { |
1617 | uint32_t mb, me, sh; | |
3b46e624 | 1618 | |
79aceca5 FB |
1619 | sh = SH(ctx->opcode); |
1620 | mb = MB(ctx->opcode); | |
1621 | me = ME(ctx->opcode); | |
d03ef511 AJ |
1622 | |
1623 | if (likely(mb == 0 && me == (31 - sh))) { | |
1624 | if (likely(sh == 0)) { | |
1625 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1626 | } else { | |
a7812ae4 | 1627 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1628 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1629 | tcg_gen_shli_tl(t0, t0, sh); | |
1630 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1631 | tcg_temp_free(t0); | |
79aceca5 | 1632 | } |
d03ef511 | 1633 | } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) { |
a7812ae4 | 1634 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1635 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1636 | tcg_gen_shri_tl(t0, t0, mb); | |
1637 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1638 | tcg_temp_free(t0); | |
1639 | } else { | |
a7812ae4 | 1640 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1641 | #if defined(TARGET_PPC64) |
a7812ae4 | 1642 | TCGv_i32 t1 = tcg_temp_new_i32(); |
54843a58 AJ |
1643 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1644 | tcg_gen_rotli_i32(t1, t1, sh); | |
1645 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 | 1646 | tcg_temp_free_i32(t1); |
54843a58 AJ |
1647 | #else |
1648 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1649 | #endif | |
76a66253 | 1650 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1651 | mb += 32; |
1652 | me += 32; | |
76a66253 | 1653 | #endif |
d03ef511 AJ |
1654 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1655 | tcg_temp_free(t0); | |
1656 | } | |
76a66253 | 1657 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1658 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1659 | } |
99e300ef | 1660 | |
54623277 | 1661 | /* rlwnm & rlwnm. */ |
99e300ef | 1662 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 FB |
1663 | { |
1664 | uint32_t mb, me; | |
54843a58 AJ |
1665 | TCGv t0; |
1666 | #if defined(TARGET_PPC64) | |
a7812ae4 | 1667 | TCGv_i32 t1, t2; |
54843a58 | 1668 | #endif |
79aceca5 FB |
1669 | |
1670 | mb = MB(ctx->opcode); | |
1671 | me = ME(ctx->opcode); | |
a7812ae4 | 1672 | t0 = tcg_temp_new(); |
d03ef511 | 1673 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f); |
54843a58 | 1674 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1675 | t1 = tcg_temp_new_i32(); |
1676 | t2 = tcg_temp_new_i32(); | |
54843a58 AJ |
1677 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1678 | tcg_gen_trunc_i64_i32(t2, t0); | |
1679 | tcg_gen_rotl_i32(t1, t1, t2); | |
1680 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 PB |
1681 | tcg_temp_free_i32(t1); |
1682 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1683 | #else |
1684 | tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1685 | #endif | |
76a66253 JM |
1686 | if (unlikely(mb != 0 || me != 31)) { |
1687 | #if defined(TARGET_PPC64) | |
1688 | mb += 32; | |
1689 | me += 32; | |
1690 | #endif | |
54843a58 | 1691 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
d03ef511 | 1692 | } else { |
54843a58 | 1693 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
79aceca5 | 1694 | } |
54843a58 | 1695 | tcg_temp_free(t0); |
76a66253 | 1696 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1697 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 FB |
1698 | } |
1699 | ||
d9bce9d9 JM |
1700 | #if defined(TARGET_PPC64) |
1701 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1702 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1703 | { \ |
1704 | gen_##name(ctx, 0); \ | |
1705 | } \ | |
e8eaa2c0 BS |
1706 | \ |
1707 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1708 | { \ |
1709 | gen_##name(ctx, 1); \ | |
1710 | } | |
1711 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1712 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1713 | { \ |
1714 | gen_##name(ctx, 0, 0); \ | |
1715 | } \ | |
e8eaa2c0 BS |
1716 | \ |
1717 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1718 | { \ |
1719 | gen_##name(ctx, 0, 1); \ | |
1720 | } \ | |
e8eaa2c0 BS |
1721 | \ |
1722 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1723 | { \ |
1724 | gen_##name(ctx, 1, 0); \ | |
1725 | } \ | |
e8eaa2c0 BS |
1726 | \ |
1727 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1728 | { \ |
1729 | gen_##name(ctx, 1, 1); \ | |
1730 | } | |
51789c41 | 1731 | |
636aa200 BS |
1732 | static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me, |
1733 | uint32_t sh) | |
51789c41 | 1734 | { |
d03ef511 AJ |
1735 | if (likely(sh != 0 && mb == 0 && me == (63 - sh))) { |
1736 | tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
1737 | } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) { | |
1738 | tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb); | |
1739 | } else { | |
a7812ae4 | 1740 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1741 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
d03ef511 | 1742 | if (likely(mb == 0 && me == 63)) { |
54843a58 | 1743 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
d03ef511 AJ |
1744 | } else { |
1745 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); | |
51789c41 | 1746 | } |
d03ef511 | 1747 | tcg_temp_free(t0); |
51789c41 | 1748 | } |
51789c41 | 1749 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1750 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
51789c41 | 1751 | } |
d9bce9d9 | 1752 | /* rldicl - rldicl. */ |
636aa200 | 1753 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1754 | { |
51789c41 | 1755 | uint32_t sh, mb; |
d9bce9d9 | 1756 | |
9d53c753 JM |
1757 | sh = SH(ctx->opcode) | (shn << 5); |
1758 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 1759 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 1760 | } |
51789c41 | 1761 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
d9bce9d9 | 1762 | /* rldicr - rldicr. */ |
636aa200 | 1763 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 1764 | { |
51789c41 | 1765 | uint32_t sh, me; |
d9bce9d9 | 1766 | |
9d53c753 JM |
1767 | sh = SH(ctx->opcode) | (shn << 5); |
1768 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 1769 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 1770 | } |
51789c41 | 1771 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
d9bce9d9 | 1772 | /* rldic - rldic. */ |
636aa200 | 1773 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1774 | { |
51789c41 | 1775 | uint32_t sh, mb; |
d9bce9d9 | 1776 | |
9d53c753 JM |
1777 | sh = SH(ctx->opcode) | (shn << 5); |
1778 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
1779 | gen_rldinm(ctx, mb, 63 - sh, sh); |
1780 | } | |
1781 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
1782 | ||
636aa200 | 1783 | static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me) |
51789c41 | 1784 | { |
54843a58 | 1785 | TCGv t0; |
d03ef511 AJ |
1786 | |
1787 | mb = MB(ctx->opcode); | |
1788 | me = ME(ctx->opcode); | |
a7812ae4 | 1789 | t0 = tcg_temp_new(); |
d03ef511 | 1790 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f); |
54843a58 | 1791 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); |
51789c41 | 1792 | if (unlikely(mb != 0 || me != 63)) { |
54843a58 AJ |
1793 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1794 | } else { | |
1795 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1796 | } | |
1797 | tcg_temp_free(t0); | |
51789c41 | 1798 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1799 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1800 | } |
51789c41 | 1801 | |
d9bce9d9 | 1802 | /* rldcl - rldcl. */ |
636aa200 | 1803 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 1804 | { |
51789c41 | 1805 | uint32_t mb; |
d9bce9d9 | 1806 | |
9d53c753 | 1807 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 1808 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 1809 | } |
36081602 | 1810 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
d9bce9d9 | 1811 | /* rldcr - rldcr. */ |
636aa200 | 1812 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 1813 | { |
51789c41 | 1814 | uint32_t me; |
d9bce9d9 | 1815 | |
9d53c753 | 1816 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 1817 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 1818 | } |
36081602 | 1819 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
d9bce9d9 | 1820 | /* rldimi - rldimi. */ |
636aa200 | 1821 | static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1822 | { |
271a916e | 1823 | uint32_t sh, mb, me; |
d9bce9d9 | 1824 | |
9d53c753 JM |
1825 | sh = SH(ctx->opcode) | (shn << 5); |
1826 | mb = MB(ctx->opcode) | (mbn << 5); | |
271a916e | 1827 | me = 63 - sh; |
d03ef511 AJ |
1828 | if (unlikely(sh == 0 && mb == 0)) { |
1829 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1830 | } else { | |
1831 | TCGv t0, t1; | |
1832 | target_ulong mask; | |
1833 | ||
a7812ae4 | 1834 | t0 = tcg_temp_new(); |
54843a58 | 1835 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
a7812ae4 | 1836 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1837 | mask = MASK(mb, me); |
1838 | tcg_gen_andi_tl(t0, t0, mask); | |
1839 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1840 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1841 | tcg_temp_free(t0); | |
1842 | tcg_temp_free(t1); | |
51789c41 | 1843 | } |
51789c41 | 1844 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1845 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1846 | } |
36081602 | 1847 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
1848 | #endif |
1849 | ||
79aceca5 | 1850 | /*** Integer shift ***/ |
99e300ef | 1851 | |
54623277 | 1852 | /* slw & slw. */ |
99e300ef | 1853 | static void gen_slw(DisasContext *ctx) |
26d67362 | 1854 | { |
7fd6bf7d | 1855 | TCGv t0, t1; |
26d67362 | 1856 | |
7fd6bf7d AJ |
1857 | t0 = tcg_temp_new(); |
1858 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1859 | #if defined(TARGET_PPC64) | |
1860 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1861 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1862 | #else | |
1863 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1864 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1865 | #endif | |
1866 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1867 | t1 = tcg_temp_new(); | |
1868 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
1869 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1870 | tcg_temp_free(t1); | |
fea0c503 | 1871 | tcg_temp_free(t0); |
7fd6bf7d | 1872 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
1873 | if (unlikely(Rc(ctx->opcode) != 0)) |
1874 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1875 | } | |
99e300ef | 1876 | |
54623277 | 1877 | /* sraw & sraw. */ |
99e300ef | 1878 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 1879 | { |
d15f74fb | 1880 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1881 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1882 | if (unlikely(Rc(ctx->opcode) != 0)) |
1883 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1884 | } | |
99e300ef | 1885 | |
54623277 | 1886 | /* srawi & srawi. */ |
99e300ef | 1887 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 1888 | { |
26d67362 AJ |
1889 | int sh = SH(ctx->opcode); |
1890 | if (sh != 0) { | |
1891 | int l1, l2; | |
fea0c503 | 1892 | TCGv t0; |
26d67362 AJ |
1893 | l1 = gen_new_label(); |
1894 | l2 = gen_new_label(); | |
a7812ae4 | 1895 | t0 = tcg_temp_local_new(); |
fea0c503 AJ |
1896 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1897 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
1898 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); | |
1899 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1900 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1901 | tcg_gen_br(l2); |
1902 | gen_set_label(l1); | |
269f3e95 | 1903 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1904 | gen_set_label(l2); |
fea0c503 AJ |
1905 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1906 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh); | |
1907 | tcg_temp_free(t0); | |
26d67362 AJ |
1908 | } else { |
1909 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1910 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1911 | } |
76a66253 | 1912 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1913 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1914 | } |
99e300ef | 1915 | |
54623277 | 1916 | /* srw & srw. */ |
99e300ef | 1917 | static void gen_srw(DisasContext *ctx) |
26d67362 | 1918 | { |
fea0c503 | 1919 | TCGv t0, t1; |
d9bce9d9 | 1920 | |
7fd6bf7d AJ |
1921 | t0 = tcg_temp_new(); |
1922 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1923 | #if defined(TARGET_PPC64) | |
1924 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1925 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1926 | #else | |
1927 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1928 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1929 | #endif | |
1930 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1931 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 1932 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
1933 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
1934 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 1935 | tcg_temp_free(t1); |
fea0c503 | 1936 | tcg_temp_free(t0); |
26d67362 AJ |
1937 | if (unlikely(Rc(ctx->opcode) != 0)) |
1938 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1939 | } | |
54623277 | 1940 | |
d9bce9d9 JM |
1941 | #if defined(TARGET_PPC64) |
1942 | /* sld & sld. */ | |
99e300ef | 1943 | static void gen_sld(DisasContext *ctx) |
26d67362 | 1944 | { |
7fd6bf7d | 1945 | TCGv t0, t1; |
26d67362 | 1946 | |
7fd6bf7d AJ |
1947 | t0 = tcg_temp_new(); |
1948 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
1949 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
1950 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1951 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1952 | t1 = tcg_temp_new(); | |
1953 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
1954 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1955 | tcg_temp_free(t1); | |
fea0c503 | 1956 | tcg_temp_free(t0); |
26d67362 AJ |
1957 | if (unlikely(Rc(ctx->opcode) != 0)) |
1958 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1959 | } | |
99e300ef | 1960 | |
54623277 | 1961 | /* srad & srad. */ |
99e300ef | 1962 | static void gen_srad(DisasContext *ctx) |
26d67362 | 1963 | { |
d15f74fb | 1964 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1965 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1966 | if (unlikely(Rc(ctx->opcode) != 0)) |
1967 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1968 | } | |
d9bce9d9 | 1969 | /* sradi & sradi. */ |
636aa200 | 1970 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 1971 | { |
26d67362 | 1972 | int sh = SH(ctx->opcode) + (n << 5); |
d9bce9d9 | 1973 | if (sh != 0) { |
26d67362 | 1974 | int l1, l2; |
fea0c503 | 1975 | TCGv t0; |
26d67362 AJ |
1976 | l1 = gen_new_label(); |
1977 | l2 = gen_new_label(); | |
a7812ae4 | 1978 | t0 = tcg_temp_local_new(); |
26d67362 | 1979 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); |
fea0c503 AJ |
1980 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); |
1981 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1982 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1983 | tcg_gen_br(l2); |
1984 | gen_set_label(l1); | |
269f3e95 | 1985 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1986 | gen_set_label(l2); |
a9730017 | 1987 | tcg_temp_free(t0); |
26d67362 AJ |
1988 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); |
1989 | } else { | |
1990 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1991 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1992 | } |
d9bce9d9 | 1993 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1994 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1995 | } |
e8eaa2c0 BS |
1996 | |
1997 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
1998 | { |
1999 | gen_sradi(ctx, 0); | |
2000 | } | |
e8eaa2c0 BS |
2001 | |
2002 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
2003 | { |
2004 | gen_sradi(ctx, 1); | |
2005 | } | |
99e300ef | 2006 | |
54623277 | 2007 | /* srd & srd. */ |
99e300ef | 2008 | static void gen_srd(DisasContext *ctx) |
26d67362 | 2009 | { |
7fd6bf7d | 2010 | TCGv t0, t1; |
26d67362 | 2011 | |
7fd6bf7d AJ |
2012 | t0 = tcg_temp_new(); |
2013 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2014 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2015 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2016 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2017 | t1 = tcg_temp_new(); | |
2018 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2019 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2020 | tcg_temp_free(t1); | |
fea0c503 | 2021 | tcg_temp_free(t0); |
26d67362 AJ |
2022 | if (unlikely(Rc(ctx->opcode) != 0)) |
2023 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2024 | } | |
d9bce9d9 | 2025 | #endif |
79aceca5 FB |
2026 | |
2027 | /*** Floating-Point arithmetic ***/ | |
7c58044c | 2028 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ |
99e300ef | 2029 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2030 | { \ |
76a66253 | 2031 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2032 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2033 | return; \ |
2034 | } \ | |
eb44b959 AJ |
2035 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2036 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2037 | gen_reset_fpstatus(); \ |
8e703949 BS |
2038 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2039 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2040 | cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2041 | if (isfloat) { \ |
8e703949 BS |
2042 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2043 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2044 | } \ |
af12906f AJ |
2045 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \ |
2046 | Rc(ctx->opcode) != 0); \ | |
9a64fbe4 FB |
2047 | } |
2048 | ||
7c58044c JM |
2049 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ |
2050 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \ | |
2051 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type); | |
9a64fbe4 | 2052 | |
7c58044c | 2053 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2054 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2055 | { \ |
76a66253 | 2056 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2057 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2058 | return; \ |
2059 | } \ | |
eb44b959 AJ |
2060 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2061 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2062 | gen_reset_fpstatus(); \ |
8e703949 BS |
2063 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2064 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2065 | cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2066 | if (isfloat) { \ |
8e703949 BS |
2067 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2068 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2069 | } \ |
af12906f AJ |
2070 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2071 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2072 | } |
7c58044c JM |
2073 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ |
2074 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2075 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2076 | |
7c58044c | 2077 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2078 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2079 | { \ |
76a66253 | 2080 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2081 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2082 | return; \ |
2083 | } \ | |
eb44b959 AJ |
2084 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2085 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2086 | gen_reset_fpstatus(); \ |
8e703949 BS |
2087 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2088 | cpu_fpr[rA(ctx->opcode)], \ | |
2089 | cpu_fpr[rC(ctx->opcode)]); \ | |
4ecc3190 | 2090 | if (isfloat) { \ |
8e703949 BS |
2091 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2092 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2093 | } \ |
af12906f AJ |
2094 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2095 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2096 | } |
7c58044c JM |
2097 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ |
2098 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2099 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2100 | |
7c58044c | 2101 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ |
99e300ef | 2102 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2103 | { \ |
76a66253 | 2104 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2105 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2106 | return; \ |
2107 | } \ | |
eb44b959 AJ |
2108 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2109 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2110 | gen_reset_fpstatus(); \ |
8e703949 BS |
2111 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2112 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2113 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2114 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2115 | } |
2116 | ||
7c58044c | 2117 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ |
99e300ef | 2118 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2119 | { \ |
76a66253 | 2120 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2121 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2122 | return; \ |
2123 | } \ | |
eb44b959 AJ |
2124 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2125 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2126 | gen_reset_fpstatus(); \ |
8e703949 BS |
2127 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2128 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2129 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2130 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2131 | } |
2132 | ||
9a64fbe4 | 2133 | /* fadd - fadds */ |
7c58044c | 2134 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2135 | /* fdiv - fdivs */ |
7c58044c | 2136 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2137 | /* fmul - fmuls */ |
7c58044c | 2138 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT); |
79aceca5 | 2139 | |
d7e4b87e | 2140 | /* fre */ |
7c58044c | 2141 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2142 | |
a750fc0b | 2143 | /* fres */ |
7c58044c | 2144 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES); |
79aceca5 | 2145 | |
a750fc0b | 2146 | /* frsqrte */ |
7c58044c JM |
2147 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE); |
2148 | ||
2149 | /* frsqrtes */ | |
99e300ef | 2150 | static void gen_frsqrtes(DisasContext *ctx) |
7c58044c | 2151 | { |
af12906f | 2152 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2153 | gen_exception(ctx, POWERPC_EXCP_FPU); |
af12906f AJ |
2154 | return; |
2155 | } | |
eb44b959 AJ |
2156 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2157 | gen_update_nip(ctx, ctx->nip - 4); | |
af12906f | 2158 | gen_reset_fpstatus(); |
8e703949 BS |
2159 | gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2160 | cpu_fpr[rB(ctx->opcode)]); | |
2161 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2162 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2163 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
7c58044c | 2164 | } |
79aceca5 | 2165 | |
a750fc0b | 2166 | /* fsel */ |
7c58044c | 2167 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL); |
4ecc3190 | 2168 | /* fsub - fsubs */ |
7c58044c | 2169 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT); |
79aceca5 | 2170 | /* Optional: */ |
99e300ef | 2171 | |
54623277 | 2172 | /* fsqrt */ |
99e300ef | 2173 | static void gen_fsqrt(DisasContext *ctx) |
c7d344af | 2174 | { |
76a66253 | 2175 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2176 | gen_exception(ctx, POWERPC_EXCP_FPU); |
c7d344af FB |
2177 | return; |
2178 | } | |
eb44b959 AJ |
2179 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2180 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2181 | gen_reset_fpstatus(); |
8e703949 BS |
2182 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2183 | cpu_fpr[rB(ctx->opcode)]); | |
af12906f | 2184 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
c7d344af | 2185 | } |
79aceca5 | 2186 | |
99e300ef | 2187 | static void gen_fsqrts(DisasContext *ctx) |
79aceca5 | 2188 | { |
76a66253 | 2189 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2190 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2191 | return; |
2192 | } | |
eb44b959 AJ |
2193 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2194 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2195 | gen_reset_fpstatus(); |
8e703949 BS |
2196 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2197 | cpu_fpr[rB(ctx->opcode)]); | |
2198 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2199 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2200 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2201 | } |
2202 | ||
2203 | /*** Floating-Point multiply-and-add ***/ | |
4ecc3190 | 2204 | /* fmadd - fmadds */ |
7c58044c | 2205 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT); |
4ecc3190 | 2206 | /* fmsub - fmsubs */ |
7c58044c | 2207 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT); |
4ecc3190 | 2208 | /* fnmadd - fnmadds */ |
7c58044c | 2209 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT); |
4ecc3190 | 2210 | /* fnmsub - fnmsubs */ |
7c58044c | 2211 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT); |
79aceca5 FB |
2212 | |
2213 | /*** Floating-Point round & convert ***/ | |
2214 | /* fctiw */ | |
7c58044c | 2215 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2216 | /* fctiwz */ |
7c58044c | 2217 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2218 | /* frsp */ |
7c58044c | 2219 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT); |
426613db JM |
2220 | #if defined(TARGET_PPC64) |
2221 | /* fcfid */ | |
7c58044c | 2222 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B); |
426613db | 2223 | /* fctid */ |
7c58044c | 2224 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B); |
426613db | 2225 | /* fctidz */ |
7c58044c | 2226 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B); |
426613db | 2227 | #endif |
79aceca5 | 2228 | |
d7e4b87e | 2229 | /* frin */ |
7c58044c | 2230 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2231 | /* friz */ |
7c58044c | 2232 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2233 | /* frip */ |
7c58044c | 2234 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2235 | /* frim */ |
7c58044c | 2236 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2237 | |
79aceca5 | 2238 | /*** Floating-Point compare ***/ |
99e300ef | 2239 | |
54623277 | 2240 | /* fcmpo */ |
99e300ef | 2241 | static void gen_fcmpo(DisasContext *ctx) |
79aceca5 | 2242 | { |
330c483b | 2243 | TCGv_i32 crf; |
76a66253 | 2244 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2245 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2246 | return; |
2247 | } | |
eb44b959 AJ |
2248 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2249 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2250 | gen_reset_fpstatus(); |
9a819377 | 2251 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2252 | gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2253 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2254 | tcg_temp_free_i32(crf); |
8e703949 | 2255 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2256 | } |
2257 | ||
2258 | /* fcmpu */ | |
99e300ef | 2259 | static void gen_fcmpu(DisasContext *ctx) |
79aceca5 | 2260 | { |
330c483b | 2261 | TCGv_i32 crf; |
76a66253 | 2262 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2263 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2264 | return; |
2265 | } | |
eb44b959 AJ |
2266 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2267 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2268 | gen_reset_fpstatus(); |
9a819377 | 2269 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2270 | gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2271 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2272 | tcg_temp_free_i32(crf); |
8e703949 | 2273 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2274 | } |
2275 | ||
9a64fbe4 FB |
2276 | /*** Floating-point move ***/ |
2277 | /* fabs */ | |
7c58044c JM |
2278 | /* XXX: beware that fabs never checks for NaNs nor update FPSCR */ |
2279 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT); | |
9a64fbe4 FB |
2280 | |
2281 | /* fmr - fmr. */ | |
7c58044c | 2282 | /* XXX: beware that fmr never checks for NaNs nor update FPSCR */ |
99e300ef | 2283 | static void gen_fmr(DisasContext *ctx) |
9a64fbe4 | 2284 | { |
76a66253 | 2285 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2286 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2287 | return; |
2288 | } | |
af12906f AJ |
2289 | tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2290 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
9a64fbe4 FB |
2291 | } |
2292 | ||
2293 | /* fnabs */ | |
7c58044c JM |
2294 | /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */ |
2295 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT); | |
9a64fbe4 | 2296 | /* fneg */ |
7c58044c JM |
2297 | /* XXX: beware that fneg never checks for NaNs nor update FPSCR */ |
2298 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT); | |
9a64fbe4 | 2299 | |
79aceca5 | 2300 | /*** Floating-Point status & ctrl register ***/ |
99e300ef | 2301 | |
54623277 | 2302 | /* mcrfs */ |
99e300ef | 2303 | static void gen_mcrfs(DisasContext *ctx) |
79aceca5 | 2304 | { |
30304420 | 2305 | TCGv tmp = tcg_temp_new(); |
7c58044c JM |
2306 | int bfa; |
2307 | ||
76a66253 | 2308 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2309 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2310 | return; |
2311 | } | |
7c58044c | 2312 | bfa = 4 * (7 - crfS(ctx->opcode)); |
30304420 DG |
2313 | tcg_gen_shri_tl(tmp, cpu_fpscr, bfa); |
2314 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp); | |
2315 | tcg_temp_free(tmp); | |
e1571908 | 2316 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf); |
30304420 | 2317 | tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); |
79aceca5 FB |
2318 | } |
2319 | ||
2320 | /* mffs */ | |
99e300ef | 2321 | static void gen_mffs(DisasContext *ctx) |
79aceca5 | 2322 | { |
76a66253 | 2323 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2324 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2325 | return; |
2326 | } | |
7c58044c | 2327 | gen_reset_fpstatus(); |
30304420 | 2328 | tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr); |
af12906f | 2329 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2330 | } |
2331 | ||
2332 | /* mtfsb0 */ | |
99e300ef | 2333 | static void gen_mtfsb0(DisasContext *ctx) |
79aceca5 | 2334 | { |
fb0eaffc | 2335 | uint8_t crb; |
3b46e624 | 2336 | |
76a66253 | 2337 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2338 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2339 | return; |
2340 | } | |
6e35d524 | 2341 | crb = 31 - crbD(ctx->opcode); |
7c58044c | 2342 | gen_reset_fpstatus(); |
6e35d524 | 2343 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) { |
eb44b959 AJ |
2344 | TCGv_i32 t0; |
2345 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2346 | gen_update_nip(ctx, ctx->nip - 4); | |
2347 | t0 = tcg_const_i32(crb); | |
8e703949 | 2348 | gen_helper_fpscr_clrbit(cpu_env, t0); |
6e35d524 AJ |
2349 | tcg_temp_free_i32(t0); |
2350 | } | |
7c58044c | 2351 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2352 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2353 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c | 2354 | } |
79aceca5 FB |
2355 | } |
2356 | ||
2357 | /* mtfsb1 */ | |
99e300ef | 2358 | static void gen_mtfsb1(DisasContext *ctx) |
79aceca5 | 2359 | { |
fb0eaffc | 2360 | uint8_t crb; |
3b46e624 | 2361 | |
76a66253 | 2362 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2363 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2364 | return; |
2365 | } | |
6e35d524 | 2366 | crb = 31 - crbD(ctx->opcode); |
7c58044c JM |
2367 | gen_reset_fpstatus(); |
2368 | /* XXX: we pretend we can only do IEEE floating-point computations */ | |
af12906f | 2369 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) { |
eb44b959 AJ |
2370 | TCGv_i32 t0; |
2371 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2372 | gen_update_nip(ctx, ctx->nip - 4); | |
2373 | t0 = tcg_const_i32(crb); | |
8e703949 | 2374 | gen_helper_fpscr_setbit(cpu_env, t0); |
0f2f39c2 | 2375 | tcg_temp_free_i32(t0); |
af12906f | 2376 | } |
7c58044c | 2377 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2378 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2379 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2380 | } |
2381 | /* We can raise a differed exception */ | |
8e703949 | 2382 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2383 | } |
2384 | ||
2385 | /* mtfsf */ | |
99e300ef | 2386 | static void gen_mtfsf(DisasContext *ctx) |
79aceca5 | 2387 | { |
0f2f39c2 | 2388 | TCGv_i32 t0; |
4911012d | 2389 | int L = ctx->opcode & 0x02000000; |
af12906f | 2390 | |
76a66253 | 2391 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2392 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2393 | return; |
2394 | } | |
eb44b959 AJ |
2395 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2396 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2397 | gen_reset_fpstatus(); |
4911012d BS |
2398 | if (L) |
2399 | t0 = tcg_const_i32(0xff); | |
2400 | else | |
2401 | t0 = tcg_const_i32(FM(ctx->opcode)); | |
8e703949 | 2402 | gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0); |
0f2f39c2 | 2403 | tcg_temp_free_i32(t0); |
7c58044c | 2404 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2405 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2406 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2407 | } |
2408 | /* We can raise a differed exception */ | |
8e703949 | 2409 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2410 | } |
2411 | ||
2412 | /* mtfsfi */ | |
99e300ef | 2413 | static void gen_mtfsfi(DisasContext *ctx) |
79aceca5 | 2414 | { |
7c58044c | 2415 | int bf, sh; |
0f2f39c2 AJ |
2416 | TCGv_i64 t0; |
2417 | TCGv_i32 t1; | |
7c58044c | 2418 | |
76a66253 | 2419 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2420 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2421 | return; |
2422 | } | |
7c58044c JM |
2423 | bf = crbD(ctx->opcode) >> 2; |
2424 | sh = 7 - bf; | |
eb44b959 AJ |
2425 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2426 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2427 | gen_reset_fpstatus(); |
0f2f39c2 | 2428 | t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh)); |
af12906f | 2429 | t1 = tcg_const_i32(1 << sh); |
8e703949 | 2430 | gen_helper_store_fpscr(cpu_env, t0, t1); |
0f2f39c2 AJ |
2431 | tcg_temp_free_i64(t0); |
2432 | tcg_temp_free_i32(t1); | |
7c58044c | 2433 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2434 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2435 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2436 | } |
2437 | /* We can raise a differed exception */ | |
8e703949 | 2438 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2439 | } |
2440 | ||
76a66253 JM |
2441 | /*** Addressing modes ***/ |
2442 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2443 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2444 | target_long maskl) | |
76a66253 JM |
2445 | { |
2446 | target_long simm = SIMM(ctx->opcode); | |
2447 | ||
be147d08 | 2448 | simm &= ~maskl; |
76db3ba4 AJ |
2449 | if (rA(ctx->opcode) == 0) { |
2450 | #if defined(TARGET_PPC64) | |
2451 | if (!ctx->sf_mode) { | |
2452 | tcg_gen_movi_tl(EA, (uint32_t)simm); | |
2453 | } else | |
2454 | #endif | |
e2be8d8d | 2455 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2456 | } else if (likely(simm != 0)) { |
e2be8d8d | 2457 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
76db3ba4 AJ |
2458 | #if defined(TARGET_PPC64) |
2459 | if (!ctx->sf_mode) { | |
2460 | tcg_gen_ext32u_tl(EA, EA); | |
2461 | } | |
2462 | #endif | |
2463 | } else { | |
2464 | #if defined(TARGET_PPC64) | |
2465 | if (!ctx->sf_mode) { | |
2466 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2467 | } else | |
2468 | #endif | |
e2be8d8d | 2469 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 | 2470 | } |
76a66253 JM |
2471 | } |
2472 | ||
636aa200 | 2473 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2474 | { |
76db3ba4 AJ |
2475 | if (rA(ctx->opcode) == 0) { |
2476 | #if defined(TARGET_PPC64) | |
2477 | if (!ctx->sf_mode) { | |
2478 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2479 | } else | |
2480 | #endif | |
e2be8d8d | 2481 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 | 2482 | } else { |
e2be8d8d | 2483 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 AJ |
2484 | #if defined(TARGET_PPC64) |
2485 | if (!ctx->sf_mode) { | |
2486 | tcg_gen_ext32u_tl(EA, EA); | |
2487 | } | |
2488 | #endif | |
2489 | } | |
76a66253 JM |
2490 | } |
2491 | ||
636aa200 | 2492 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2493 | { |
76db3ba4 | 2494 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2495 | tcg_gen_movi_tl(EA, 0); |
76db3ba4 AJ |
2496 | } else { |
2497 | #if defined(TARGET_PPC64) | |
2498 | if (!ctx->sf_mode) { | |
2499 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2500 | } else | |
2501 | #endif | |
2502 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2503 | } | |
2504 | } | |
2505 | ||
636aa200 BS |
2506 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2507 | target_long val) | |
76db3ba4 AJ |
2508 | { |
2509 | tcg_gen_addi_tl(ret, arg1, val); | |
2510 | #if defined(TARGET_PPC64) | |
2511 | if (!ctx->sf_mode) { | |
2512 | tcg_gen_ext32u_tl(ret, ret); | |
2513 | } | |
2514 | #endif | |
76a66253 JM |
2515 | } |
2516 | ||
636aa200 | 2517 | static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask) |
cf360a32 AJ |
2518 | { |
2519 | int l1 = gen_new_label(); | |
2520 | TCGv t0 = tcg_temp_new(); | |
2521 | TCGv_i32 t1, t2; | |
2522 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2523 | gen_update_nip(ctx, ctx->nip - 4); | |
2524 | tcg_gen_andi_tl(t0, EA, mask); | |
2525 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
2526 | t1 = tcg_const_i32(POWERPC_EXCP_ALIGN); | |
2527 | t2 = tcg_const_i32(0); | |
e5f17ac6 | 2528 | gen_helper_raise_exception_err(cpu_env, t1, t2); |
cf360a32 AJ |
2529 | tcg_temp_free_i32(t1); |
2530 | tcg_temp_free_i32(t2); | |
2531 | gen_set_label(l1); | |
2532 | tcg_temp_free(t0); | |
2533 | } | |
2534 | ||
7863667f | 2535 | /*** Integer load ***/ |
636aa200 | 2536 | static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2537 | { |
2538 | tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx); | |
2539 | } | |
2540 | ||
636aa200 | 2541 | static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2542 | { |
2543 | tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx); | |
2544 | } | |
2545 | ||
636aa200 | 2546 | static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2547 | { |
2548 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); | |
2549 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2550 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2551 | } |
b61f2753 AJ |
2552 | } |
2553 | ||
636aa200 | 2554 | static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2555 | { |
76db3ba4 | 2556 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2557 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
fa3966a3 | 2558 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2559 | tcg_gen_ext16s_tl(arg1, arg1); |
76db3ba4 AJ |
2560 | } else { |
2561 | tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx); | |
2562 | } | |
b61f2753 AJ |
2563 | } |
2564 | ||
636aa200 | 2565 | static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2566 | { |
76db3ba4 AJ |
2567 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2568 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2569 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2570 | } |
b61f2753 AJ |
2571 | } |
2572 | ||
76db3ba4 | 2573 | #if defined(TARGET_PPC64) |
636aa200 | 2574 | static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2575 | { |
a457e7ee | 2576 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2577 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
fa3966a3 AJ |
2578 | tcg_gen_bswap32_tl(arg1, arg1); |
2579 | tcg_gen_ext32s_tl(arg1, arg1); | |
b61f2753 | 2580 | } else |
76db3ba4 | 2581 | tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx); |
b61f2753 | 2582 | } |
76db3ba4 | 2583 | #endif |
b61f2753 | 2584 | |
636aa200 | 2585 | static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2586 | { |
76db3ba4 AJ |
2587 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); |
2588 | if (unlikely(ctx->le_mode)) { | |
66896cb8 | 2589 | tcg_gen_bswap64_i64(arg1, arg1); |
76db3ba4 | 2590 | } |
b61f2753 AJ |
2591 | } |
2592 | ||
636aa200 | 2593 | static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2594 | { |
76db3ba4 | 2595 | tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2596 | } |
2597 | ||
636aa200 | 2598 | static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2599 | { |
76db3ba4 | 2600 | if (unlikely(ctx->le_mode)) { |
76db3ba4 AJ |
2601 | TCGv t0 = tcg_temp_new(); |
2602 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2603 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2604 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2605 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2606 | } else { |
2607 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2608 | } | |
b61f2753 AJ |
2609 | } |
2610 | ||
636aa200 | 2611 | static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2612 | { |
76db3ba4 | 2613 | if (unlikely(ctx->le_mode)) { |
fa3966a3 AJ |
2614 | TCGv t0 = tcg_temp_new(); |
2615 | tcg_gen_ext32u_tl(t0, arg1); | |
2616 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2617 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2618 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2619 | } else { |
2620 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2621 | } | |
b61f2753 AJ |
2622 | } |
2623 | ||
636aa200 | 2624 | static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2625 | { |
76db3ba4 | 2626 | if (unlikely(ctx->le_mode)) { |
a7812ae4 | 2627 | TCGv_i64 t0 = tcg_temp_new_i64(); |
66896cb8 | 2628 | tcg_gen_bswap64_i64(t0, arg1); |
76db3ba4 | 2629 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); |
a7812ae4 | 2630 | tcg_temp_free_i64(t0); |
b61f2753 | 2631 | } else |
76db3ba4 | 2632 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2633 | } |
2634 | ||
0c8aacd4 | 2635 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2636 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2637 | { \ |
76db3ba4 AJ |
2638 | TCGv EA; \ |
2639 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2640 | EA = tcg_temp_new(); \ | |
2641 | gen_addr_imm_index(ctx, EA, 0); \ | |
2642 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2643 | tcg_temp_free(EA); \ |
79aceca5 FB |
2644 | } |
2645 | ||
0c8aacd4 | 2646 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2647 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2648 | { \ |
b61f2753 | 2649 | TCGv EA; \ |
76a66253 JM |
2650 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2651 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2652 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2653 | return; \ |
9a64fbe4 | 2654 | } \ |
76db3ba4 | 2655 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2656 | EA = tcg_temp_new(); \ |
9d53c753 | 2657 | if (type == PPC_64B) \ |
76db3ba4 | 2658 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2659 | else \ |
76db3ba4 AJ |
2660 | gen_addr_imm_index(ctx, EA, 0); \ |
2661 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2662 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2663 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2664 | } |
2665 | ||
0c8aacd4 | 2666 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2667 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2668 | { \ |
b61f2753 | 2669 | TCGv EA; \ |
76a66253 JM |
2670 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2671 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2672 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2673 | return; \ |
9a64fbe4 | 2674 | } \ |
76db3ba4 | 2675 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2676 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2677 | gen_addr_reg_index(ctx, EA); \ |
2678 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2679 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2680 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2681 | } |
2682 | ||
cd6e9320 | 2683 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
99e300ef | 2684 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2685 | { \ |
76db3ba4 AJ |
2686 | TCGv EA; \ |
2687 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2688 | EA = tcg_temp_new(); \ | |
2689 | gen_addr_reg_index(ctx, EA); \ | |
2690 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2691 | tcg_temp_free(EA); \ |
79aceca5 | 2692 | } |
cd6e9320 TH |
2693 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
2694 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2695 | |
0c8aacd4 AJ |
2696 | #define GEN_LDS(name, ldop, op, type) \ |
2697 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2698 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2699 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2700 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2701 | |
2702 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2703 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2704 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2705 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2706 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2707 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2708 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2709 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
d9bce9d9 | 2710 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2711 | /* lwaux */ |
0c8aacd4 | 2712 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2713 | /* lwax */ |
0c8aacd4 | 2714 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2715 | /* ldux */ |
0c8aacd4 | 2716 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2717 | /* ldx */ |
0c8aacd4 | 2718 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B); |
99e300ef BS |
2719 | |
2720 | static void gen_ld(DisasContext *ctx) | |
d9bce9d9 | 2721 | { |
b61f2753 | 2722 | TCGv EA; |
d9bce9d9 JM |
2723 | if (Rc(ctx->opcode)) { |
2724 | if (unlikely(rA(ctx->opcode) == 0 || | |
2725 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2726 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2727 | return; |
2728 | } | |
2729 | } | |
76db3ba4 | 2730 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2731 | EA = tcg_temp_new(); |
76db3ba4 | 2732 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2733 | if (ctx->opcode & 0x02) { |
2734 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2735 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2736 | } else { |
2737 | /* ld - ldu */ | |
76db3ba4 | 2738 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2739 | } |
d9bce9d9 | 2740 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2741 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2742 | tcg_temp_free(EA); | |
d9bce9d9 | 2743 | } |
99e300ef | 2744 | |
54623277 | 2745 | /* lq */ |
99e300ef | 2746 | static void gen_lq(DisasContext *ctx) |
be147d08 JM |
2747 | { |
2748 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2749 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2750 | #else |
2751 | int ra, rd; | |
b61f2753 | 2752 | TCGv EA; |
be147d08 JM |
2753 | |
2754 | /* Restore CPU state */ | |
76db3ba4 | 2755 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2756 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2757 | return; |
2758 | } | |
2759 | ra = rA(ctx->opcode); | |
2760 | rd = rD(ctx->opcode); | |
2761 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2762 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2763 | return; |
2764 | } | |
76db3ba4 | 2765 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2766 | /* Little-endian mode is not handled */ |
e06fcd75 | 2767 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2768 | return; |
2769 | } | |
76db3ba4 | 2770 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2771 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2772 | gen_addr_imm_index(ctx, EA, 0x0F); |
2773 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2774 | gen_addr_add(ctx, EA, EA, 8); | |
2775 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
b61f2753 | 2776 | tcg_temp_free(EA); |
be147d08 JM |
2777 | #endif |
2778 | } | |
d9bce9d9 | 2779 | #endif |
79aceca5 FB |
2780 | |
2781 | /*** Integer store ***/ | |
0c8aacd4 | 2782 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2783 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2784 | { \ |
76db3ba4 AJ |
2785 | TCGv EA; \ |
2786 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2787 | EA = tcg_temp_new(); \ | |
2788 | gen_addr_imm_index(ctx, EA, 0); \ | |
2789 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2790 | tcg_temp_free(EA); \ |
79aceca5 FB |
2791 | } |
2792 | ||
0c8aacd4 | 2793 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2794 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2795 | { \ |
b61f2753 | 2796 | TCGv EA; \ |
76a66253 | 2797 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2798 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2799 | return; \ |
9a64fbe4 | 2800 | } \ |
76db3ba4 | 2801 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2802 | EA = tcg_temp_new(); \ |
9d53c753 | 2803 | if (type == PPC_64B) \ |
76db3ba4 | 2804 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2805 | else \ |
76db3ba4 AJ |
2806 | gen_addr_imm_index(ctx, EA, 0); \ |
2807 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2808 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2809 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2810 | } |
2811 | ||
0c8aacd4 | 2812 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2813 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2814 | { \ |
b61f2753 | 2815 | TCGv EA; \ |
76a66253 | 2816 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2817 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2818 | return; \ |
9a64fbe4 | 2819 | } \ |
76db3ba4 | 2820 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2821 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2822 | gen_addr_reg_index(ctx, EA); \ |
2823 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2824 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2825 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2826 | } |
2827 | ||
cd6e9320 TH |
2828 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
2829 | static void glue(gen_, name##x)(DisasContext *ctx) \ | |
79aceca5 | 2830 | { \ |
76db3ba4 AJ |
2831 | TCGv EA; \ |
2832 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2833 | EA = tcg_temp_new(); \ | |
2834 | gen_addr_reg_index(ctx, EA); \ | |
2835 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2836 | tcg_temp_free(EA); \ |
79aceca5 | 2837 | } |
cd6e9320 TH |
2838 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
2839 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2840 | |
0c8aacd4 AJ |
2841 | #define GEN_STS(name, stop, op, type) \ |
2842 | GEN_ST(name, stop, op | 0x20, type); \ | |
2843 | GEN_STU(name, stop, op | 0x21, type); \ | |
2844 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2845 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2846 | |
2847 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2848 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2849 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2850 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2851 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2852 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
d9bce9d9 | 2853 | #if defined(TARGET_PPC64) |
0c8aacd4 AJ |
2854 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B); |
2855 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B); | |
99e300ef BS |
2856 | |
2857 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 2858 | { |
be147d08 | 2859 | int rs; |
b61f2753 | 2860 | TCGv EA; |
be147d08 JM |
2861 | |
2862 | rs = rS(ctx->opcode); | |
2863 | if ((ctx->opcode & 0x3) == 0x2) { | |
2864 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2865 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2866 | #else |
2867 | /* stq */ | |
76db3ba4 | 2868 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2869 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2870 | return; |
2871 | } | |
2872 | if (unlikely(rs & 1)) { | |
e06fcd75 | 2873 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2874 | return; |
2875 | } | |
76db3ba4 | 2876 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2877 | /* Little-endian mode is not handled */ |
e06fcd75 | 2878 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2879 | return; |
2880 | } | |
76db3ba4 | 2881 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2882 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2883 | gen_addr_imm_index(ctx, EA, 0x03); |
2884 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
2885 | gen_addr_add(ctx, EA, EA, 8); | |
2886 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
b61f2753 | 2887 | tcg_temp_free(EA); |
be147d08 JM |
2888 | #endif |
2889 | } else { | |
2890 | /* std / stdu */ | |
2891 | if (Rc(ctx->opcode)) { | |
2892 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 2893 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2894 | return; |
2895 | } | |
2896 | } | |
76db3ba4 | 2897 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2898 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2899 | gen_addr_imm_index(ctx, EA, 0x03); |
2900 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
be147d08 | 2901 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2902 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2903 | tcg_temp_free(EA); | |
d9bce9d9 | 2904 | } |
d9bce9d9 JM |
2905 | } |
2906 | #endif | |
79aceca5 FB |
2907 | /*** Integer load and store with byte reverse ***/ |
2908 | /* lhbrx */ | |
86178a57 | 2909 | static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2910 | { |
76db3ba4 AJ |
2911 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
2912 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2913 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2914 | } |
b61f2753 | 2915 | } |
0c8aacd4 | 2916 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 2917 | |
79aceca5 | 2918 | /* lwbrx */ |
86178a57 | 2919 | static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2920 | { |
76db3ba4 AJ |
2921 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2922 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2923 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2924 | } |
b61f2753 | 2925 | } |
0c8aacd4 | 2926 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 2927 | |
cd6e9320 TH |
2928 | #if defined(TARGET_PPC64) |
2929 | /* ldbrx */ | |
2930 | static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
2931 | { | |
2932 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); | |
2933 | if (likely(!ctx->le_mode)) { | |
2934 | tcg_gen_bswap64_tl(arg1, arg1); | |
2935 | } | |
2936 | } | |
2937 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX); | |
2938 | #endif /* TARGET_PPC64 */ | |
2939 | ||
79aceca5 | 2940 | /* sthbrx */ |
86178a57 | 2941 | static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2942 | { |
76db3ba4 | 2943 | if (likely(!ctx->le_mode)) { |
76db3ba4 AJ |
2944 | TCGv t0 = tcg_temp_new(); |
2945 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2946 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2947 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2948 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2949 | } else { |
2950 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2951 | } | |
b61f2753 | 2952 | } |
0c8aacd4 | 2953 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
b61f2753 | 2954 | |
79aceca5 | 2955 | /* stwbrx */ |
86178a57 | 2956 | static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2957 | { |
76db3ba4 | 2958 | if (likely(!ctx->le_mode)) { |
fa3966a3 AJ |
2959 | TCGv t0 = tcg_temp_new(); |
2960 | tcg_gen_ext32u_tl(t0, arg1); | |
2961 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2962 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2963 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2964 | } else { |
2965 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2966 | } | |
b61f2753 | 2967 | } |
0c8aacd4 | 2968 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 | 2969 | |
cd6e9320 TH |
2970 | #if defined(TARGET_PPC64) |
2971 | /* stdbrx */ | |
2972 | static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
2973 | { | |
2974 | if (likely(!ctx->le_mode)) { | |
2975 | TCGv t0 = tcg_temp_new(); | |
2976 | tcg_gen_bswap64_tl(t0, arg1); | |
2977 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); | |
2978 | tcg_temp_free(t0); | |
2979 | } else { | |
2980 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); | |
2981 | } | |
2982 | } | |
2983 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX); | |
2984 | #endif /* TARGET_PPC64 */ | |
2985 | ||
79aceca5 | 2986 | /*** Integer load and store multiple ***/ |
99e300ef | 2987 | |
54623277 | 2988 | /* lmw */ |
99e300ef | 2989 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 2990 | { |
76db3ba4 AJ |
2991 | TCGv t0; |
2992 | TCGv_i32 t1; | |
2993 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 2994 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 2995 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
2996 | t0 = tcg_temp_new(); |
2997 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
2998 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 2999 | gen_helper_lmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3000 | tcg_temp_free(t0); |
3001 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3002 | } |
3003 | ||
3004 | /* stmw */ | |
99e300ef | 3005 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 3006 | { |
76db3ba4 AJ |
3007 | TCGv t0; |
3008 | TCGv_i32 t1; | |
3009 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3010 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3011 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3012 | t0 = tcg_temp_new(); |
3013 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
3014 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3015 | gen_helper_stmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3016 | tcg_temp_free(t0); |
3017 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3018 | } |
3019 | ||
3020 | /*** Integer load and store strings ***/ | |
54623277 | 3021 | |
79aceca5 | 3022 | /* lswi */ |
3fc6c082 | 3023 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
3024 | * rA is in the range of registers to be loaded. |
3025 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
3026 | * For now, I'll follow the spec... | |
3027 | */ | |
99e300ef | 3028 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 3029 | { |
dfbc799d AJ |
3030 | TCGv t0; |
3031 | TCGv_i32 t1, t2; | |
79aceca5 FB |
3032 | int nb = NB(ctx->opcode); |
3033 | int start = rD(ctx->opcode); | |
9a64fbe4 | 3034 | int ra = rA(ctx->opcode); |
79aceca5 FB |
3035 | int nr; |
3036 | ||
3037 | if (nb == 0) | |
3038 | nb = 32; | |
3039 | nr = nb / 4; | |
76a66253 JM |
3040 | if (unlikely(((start + nr) > 32 && |
3041 | start <= ra && (start + nr - 32) > ra) || | |
3042 | ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) { | |
e06fcd75 | 3043 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 3044 | return; |
297d8e62 | 3045 | } |
76db3ba4 | 3046 | gen_set_access_type(ctx, ACCESS_INT); |
8dd4983c | 3047 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3048 | gen_update_nip(ctx, ctx->nip - 4); |
dfbc799d | 3049 | t0 = tcg_temp_new(); |
76db3ba4 | 3050 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
3051 | t1 = tcg_const_i32(nb); |
3052 | t2 = tcg_const_i32(start); | |
2f5a189c | 3053 | gen_helper_lsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3054 | tcg_temp_free(t0); |
3055 | tcg_temp_free_i32(t1); | |
3056 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3057 | } |
3058 | ||
3059 | /* lswx */ | |
99e300ef | 3060 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 3061 | { |
76db3ba4 AJ |
3062 | TCGv t0; |
3063 | TCGv_i32 t1, t2, t3; | |
3064 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3065 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3066 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3067 | t0 = tcg_temp_new(); |
3068 | gen_addr_reg_index(ctx, t0); | |
3069 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3070 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
3071 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
2f5a189c | 3072 | gen_helper_lswx(cpu_env, t0, t1, t2, t3); |
dfbc799d AJ |
3073 | tcg_temp_free(t0); |
3074 | tcg_temp_free_i32(t1); | |
3075 | tcg_temp_free_i32(t2); | |
3076 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
3077 | } |
3078 | ||
3079 | /* stswi */ | |
99e300ef | 3080 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 3081 | { |
76db3ba4 AJ |
3082 | TCGv t0; |
3083 | TCGv_i32 t1, t2; | |
4b3686fa | 3084 | int nb = NB(ctx->opcode); |
76db3ba4 | 3085 | gen_set_access_type(ctx, ACCESS_INT); |
76a66253 | 3086 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3087 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3088 | t0 = tcg_temp_new(); |
3089 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
3090 | if (nb == 0) |
3091 | nb = 32; | |
dfbc799d | 3092 | t1 = tcg_const_i32(nb); |
76db3ba4 | 3093 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3094 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3095 | tcg_temp_free(t0); |
3096 | tcg_temp_free_i32(t1); | |
3097 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3098 | } |
3099 | ||
3100 | /* stswx */ | |
99e300ef | 3101 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3102 | { |
76db3ba4 AJ |
3103 | TCGv t0; |
3104 | TCGv_i32 t1, t2; | |
3105 | gen_set_access_type(ctx, ACCESS_INT); | |
8dd4983c | 3106 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5fafdf24 | 3107 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3108 | t0 = tcg_temp_new(); |
3109 | gen_addr_reg_index(ctx, t0); | |
3110 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3111 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3112 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3113 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3114 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3115 | tcg_temp_free(t0); |
3116 | tcg_temp_free_i32(t1); | |
3117 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3118 | } |
3119 | ||
3120 | /*** Memory synchronisation ***/ | |
3121 | /* eieio */ | |
99e300ef | 3122 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3123 | { |
79aceca5 FB |
3124 | } |
3125 | ||
3126 | /* isync */ | |
99e300ef | 3127 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3128 | { |
e06fcd75 | 3129 | gen_stop_exception(ctx); |
79aceca5 FB |
3130 | } |
3131 | ||
111bfab3 | 3132 | /* lwarx */ |
99e300ef | 3133 | static void gen_lwarx(DisasContext *ctx) |
79aceca5 | 3134 | { |
76db3ba4 | 3135 | TCGv t0; |
18b21a2f | 3136 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3137 | gen_set_access_type(ctx, ACCESS_RES); |
3138 | t0 = tcg_temp_local_new(); | |
3139 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3140 | gen_check_align(ctx, t0, 0x03); |
18b21a2f | 3141 | gen_qemu_ld32u(ctx, gpr, t0); |
cf360a32 | 3142 | tcg_gen_mov_tl(cpu_reserve, t0); |
1328c2bf | 3143 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); |
cf360a32 | 3144 | tcg_temp_free(t0); |
79aceca5 FB |
3145 | } |
3146 | ||
4425265b NF |
3147 | #if defined(CONFIG_USER_ONLY) |
3148 | static void gen_conditional_store (DisasContext *ctx, TCGv EA, | |
3149 | int reg, int size) | |
3150 | { | |
3151 | TCGv t0 = tcg_temp_new(); | |
3152 | uint32_t save_exception = ctx->exception; | |
3153 | ||
1328c2bf | 3154 | tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea)); |
4425265b | 3155 | tcg_gen_movi_tl(t0, (size << 5) | reg); |
1328c2bf | 3156 | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info)); |
4425265b NF |
3157 | tcg_temp_free(t0); |
3158 | gen_update_nip(ctx, ctx->nip-4); | |
3159 | ctx->exception = POWERPC_EXCP_BRANCH; | |
3160 | gen_exception(ctx, POWERPC_EXCP_STCX); | |
3161 | ctx->exception = save_exception; | |
3162 | } | |
3163 | #endif | |
3164 | ||
79aceca5 | 3165 | /* stwcx. */ |
e8eaa2c0 | 3166 | static void gen_stwcx_(DisasContext *ctx) |
79aceca5 | 3167 | { |
76db3ba4 AJ |
3168 | TCGv t0; |
3169 | gen_set_access_type(ctx, ACCESS_RES); | |
3170 | t0 = tcg_temp_local_new(); | |
3171 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3172 | gen_check_align(ctx, t0, 0x03); |
4425265b NF |
3173 | #if defined(CONFIG_USER_ONLY) |
3174 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 4); | |
3175 | #else | |
3176 | { | |
3177 | int l1; | |
3178 | ||
3179 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3180 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3181 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3182 | l1 = gen_new_label(); | |
3183 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3184 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3185 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3186 | gen_set_label(l1); | |
3187 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3188 | } | |
3189 | #endif | |
cf360a32 | 3190 | tcg_temp_free(t0); |
79aceca5 FB |
3191 | } |
3192 | ||
426613db | 3193 | #if defined(TARGET_PPC64) |
426613db | 3194 | /* ldarx */ |
99e300ef | 3195 | static void gen_ldarx(DisasContext *ctx) |
426613db | 3196 | { |
76db3ba4 | 3197 | TCGv t0; |
18b21a2f | 3198 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3199 | gen_set_access_type(ctx, ACCESS_RES); |
3200 | t0 = tcg_temp_local_new(); | |
3201 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3202 | gen_check_align(ctx, t0, 0x07); |
18b21a2f | 3203 | gen_qemu_ld64(ctx, gpr, t0); |
cf360a32 | 3204 | tcg_gen_mov_tl(cpu_reserve, t0); |
1328c2bf | 3205 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); |
cf360a32 | 3206 | tcg_temp_free(t0); |
426613db JM |
3207 | } |
3208 | ||
3209 | /* stdcx. */ | |
e8eaa2c0 | 3210 | static void gen_stdcx_(DisasContext *ctx) |
426613db | 3211 | { |
76db3ba4 AJ |
3212 | TCGv t0; |
3213 | gen_set_access_type(ctx, ACCESS_RES); | |
3214 | t0 = tcg_temp_local_new(); | |
3215 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3216 | gen_check_align(ctx, t0, 0x07); |
4425265b NF |
3217 | #if defined(CONFIG_USER_ONLY) |
3218 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 8); | |
3219 | #else | |
3220 | { | |
3221 | int l1; | |
3222 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3223 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3224 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3225 | l1 = gen_new_label(); | |
3226 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3227 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3228 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3229 | gen_set_label(l1); | |
3230 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3231 | } | |
3232 | #endif | |
cf360a32 | 3233 | tcg_temp_free(t0); |
426613db JM |
3234 | } |
3235 | #endif /* defined(TARGET_PPC64) */ | |
3236 | ||
79aceca5 | 3237 | /* sync */ |
99e300ef | 3238 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3239 | { |
79aceca5 FB |
3240 | } |
3241 | ||
0db1b20e | 3242 | /* wait */ |
99e300ef | 3243 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3244 | { |
931ff272 | 3245 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1328c2bf | 3246 | tcg_gen_st_i32(t0, cpu_env, offsetof(CPUPPCState, halted)); |
931ff272 | 3247 | tcg_temp_free_i32(t0); |
0db1b20e | 3248 | /* Stop translation, as the CPU is supposed to sleep from now */ |
e06fcd75 | 3249 | gen_exception_err(ctx, EXCP_HLT, 1); |
0db1b20e JM |
3250 | } |
3251 | ||
79aceca5 | 3252 | /*** Floating-point load ***/ |
a0d7d5a7 | 3253 | #define GEN_LDF(name, ldop, opc, type) \ |
99e300ef | 3254 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3255 | { \ |
a0d7d5a7 | 3256 | TCGv EA; \ |
76a66253 | 3257 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3258 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3259 | return; \ |
3260 | } \ | |
76db3ba4 | 3261 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3262 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3263 | gen_addr_imm_index(ctx, EA, 0); \ |
3264 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3265 | tcg_temp_free(EA); \ |
79aceca5 FB |
3266 | } |
3267 | ||
a0d7d5a7 | 3268 | #define GEN_LDUF(name, ldop, opc, type) \ |
99e300ef | 3269 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3270 | { \ |
a0d7d5a7 | 3271 | TCGv EA; \ |
76a66253 | 3272 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3273 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3274 | return; \ |
3275 | } \ | |
76a66253 | 3276 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3277 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3278 | return; \ |
9a64fbe4 | 3279 | } \ |
76db3ba4 | 3280 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3281 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3282 | gen_addr_imm_index(ctx, EA, 0); \ |
3283 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3284 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3285 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3286 | } |
3287 | ||
a0d7d5a7 | 3288 | #define GEN_LDUXF(name, ldop, opc, type) \ |
99e300ef | 3289 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3290 | { \ |
a0d7d5a7 | 3291 | TCGv EA; \ |
76a66253 | 3292 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3293 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3294 | return; \ |
3295 | } \ | |
76a66253 | 3296 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3297 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3298 | return; \ |
9a64fbe4 | 3299 | } \ |
76db3ba4 | 3300 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3301 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3302 | gen_addr_reg_index(ctx, EA); \ |
3303 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3304 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3305 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3306 | } |
3307 | ||
a0d7d5a7 | 3308 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ |
99e300ef | 3309 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3310 | { \ |
a0d7d5a7 | 3311 | TCGv EA; \ |
76a66253 | 3312 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3313 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3314 | return; \ |
3315 | } \ | |
76db3ba4 | 3316 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3317 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3318 | gen_addr_reg_index(ctx, EA); \ |
3319 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3320 | tcg_temp_free(EA); \ |
79aceca5 FB |
3321 | } |
3322 | ||
a0d7d5a7 AJ |
3323 | #define GEN_LDFS(name, ldop, op, type) \ |
3324 | GEN_LDF(name, ldop, op | 0x20, type); \ | |
3325 | GEN_LDUF(name, ldop, op | 0x21, type); \ | |
3326 | GEN_LDUXF(name, ldop, op | 0x01, type); \ | |
3327 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
3328 | ||
636aa200 | 3329 | static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3330 | { |
3331 | TCGv t0 = tcg_temp_new(); | |
3332 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
76db3ba4 | 3333 | gen_qemu_ld32u(ctx, t0, arg2); |
a0d7d5a7 AJ |
3334 | tcg_gen_trunc_tl_i32(t1, t0); |
3335 | tcg_temp_free(t0); | |
8e703949 | 3336 | gen_helper_float32_to_float64(arg1, cpu_env, t1); |
a0d7d5a7 AJ |
3337 | tcg_temp_free_i32(t1); |
3338 | } | |
79aceca5 | 3339 | |
a0d7d5a7 AJ |
3340 | /* lfd lfdu lfdux lfdx */ |
3341 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT); | |
3342 | /* lfs lfsu lfsux lfsx */ | |
3343 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT); | |
79aceca5 FB |
3344 | |
3345 | /*** Floating-point store ***/ | |
a0d7d5a7 | 3346 | #define GEN_STF(name, stop, opc, type) \ |
99e300ef | 3347 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3348 | { \ |
a0d7d5a7 | 3349 | TCGv EA; \ |
76a66253 | 3350 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3351 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3352 | return; \ |
3353 | } \ | |
76db3ba4 | 3354 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3355 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3356 | gen_addr_imm_index(ctx, EA, 0); \ |
3357 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3358 | tcg_temp_free(EA); \ |
79aceca5 FB |
3359 | } |
3360 | ||
a0d7d5a7 | 3361 | #define GEN_STUF(name, stop, opc, type) \ |
99e300ef | 3362 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3363 | { \ |
a0d7d5a7 | 3364 | TCGv EA; \ |
76a66253 | 3365 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3366 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3367 | return; \ |
3368 | } \ | |
76a66253 | 3369 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3370 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3371 | return; \ |
9a64fbe4 | 3372 | } \ |
76db3ba4 | 3373 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3374 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3375 | gen_addr_imm_index(ctx, EA, 0); \ |
3376 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3377 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3378 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3379 | } |
3380 | ||
a0d7d5a7 | 3381 | #define GEN_STUXF(name, stop, opc, type) \ |
99e300ef | 3382 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3383 | { \ |
a0d7d5a7 | 3384 | TCGv EA; \ |
76a66253 | 3385 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3386 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3387 | return; \ |
3388 | } \ | |
76a66253 | 3389 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3390 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3391 | return; \ |
9a64fbe4 | 3392 | } \ |
76db3ba4 | 3393 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3394 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3395 | gen_addr_reg_index(ctx, EA); \ |
3396 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3397 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3398 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3399 | } |
3400 | ||
a0d7d5a7 | 3401 | #define GEN_STXF(name, stop, opc2, opc3, type) \ |
99e300ef | 3402 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3403 | { \ |
a0d7d5a7 | 3404 | TCGv EA; \ |
76a66253 | 3405 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3406 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3407 | return; \ |
3408 | } \ | |
76db3ba4 | 3409 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3410 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3411 | gen_addr_reg_index(ctx, EA); \ |
3412 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3413 | tcg_temp_free(EA); \ |
79aceca5 FB |
3414 | } |
3415 | ||
a0d7d5a7 AJ |
3416 | #define GEN_STFS(name, stop, op, type) \ |
3417 | GEN_STF(name, stop, op | 0x20, type); \ | |
3418 | GEN_STUF(name, stop, op | 0x21, type); \ | |
3419 | GEN_STUXF(name, stop, op | 0x01, type); \ | |
3420 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
3421 | ||
636aa200 | 3422 | static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3423 | { |
3424 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
3425 | TCGv t1 = tcg_temp_new(); | |
8e703949 | 3426 | gen_helper_float64_to_float32(t0, cpu_env, arg1); |
a0d7d5a7 AJ |
3427 | tcg_gen_extu_i32_tl(t1, t0); |
3428 | tcg_temp_free_i32(t0); | |
76db3ba4 | 3429 | gen_qemu_st32(ctx, t1, arg2); |
a0d7d5a7 AJ |
3430 | tcg_temp_free(t1); |
3431 | } | |
79aceca5 FB |
3432 | |
3433 | /* stfd stfdu stfdux stfdx */ | |
a0d7d5a7 | 3434 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT); |
79aceca5 | 3435 | /* stfs stfsu stfsux stfsx */ |
a0d7d5a7 | 3436 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT); |
79aceca5 FB |
3437 | |
3438 | /* Optional: */ | |
636aa200 | 3439 | static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3440 | { |
3441 | TCGv t0 = tcg_temp_new(); | |
3442 | tcg_gen_trunc_i64_tl(t0, arg1), | |
76db3ba4 | 3443 | gen_qemu_st32(ctx, t0, arg2); |
a0d7d5a7 AJ |
3444 | tcg_temp_free(t0); |
3445 | } | |
79aceca5 | 3446 | /* stfiwx */ |
a0d7d5a7 | 3447 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
79aceca5 | 3448 | |
697ab892 DG |
3449 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3450 | { | |
3451 | #if defined(TARGET_PPC64) | |
3452 | if (ctx->has_cfar) | |
3453 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3454 | #endif | |
3455 | } | |
3456 | ||
79aceca5 | 3457 | /*** Branch ***/ |
636aa200 | 3458 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 FB |
3459 | { |
3460 | TranslationBlock *tb; | |
3461 | tb = ctx->tb; | |
a2ffb812 AJ |
3462 | #if defined(TARGET_PPC64) |
3463 | if (!ctx->sf_mode) | |
3464 | dest = (uint32_t) dest; | |
3465 | #endif | |
57fec1fe | 3466 | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && |
8cbcb4fa | 3467 | likely(!ctx->singlestep_enabled)) { |
57fec1fe | 3468 | tcg_gen_goto_tb(n); |
a2ffb812 | 3469 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
4b4a72e5 | 3470 | tcg_gen_exit_tb((tcg_target_long)tb + n); |
c1942362 | 3471 | } else { |
a2ffb812 | 3472 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cbcb4fa AJ |
3473 | if (unlikely(ctx->singlestep_enabled)) { |
3474 | if ((ctx->singlestep_enabled & | |
bdc4e053 | 3475 | (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) && |
f0cc4aa8 JG |
3476 | (ctx->exception == POWERPC_EXCP_BRANCH || |
3477 | ctx->exception == POWERPC_EXCP_TRACE)) { | |
8cbcb4fa AJ |
3478 | target_ulong tmp = ctx->nip; |
3479 | ctx->nip = dest; | |
e06fcd75 | 3480 | gen_exception(ctx, POWERPC_EXCP_TRACE); |
8cbcb4fa AJ |
3481 | ctx->nip = tmp; |
3482 | } | |
3483 | if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) { | |
e06fcd75 | 3484 | gen_debug_exception(ctx); |
8cbcb4fa AJ |
3485 | } |
3486 | } | |
57fec1fe | 3487 | tcg_gen_exit_tb(0); |
c1942362 | 3488 | } |
c53be334 FB |
3489 | } |
3490 | ||
636aa200 | 3491 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f JM |
3492 | { |
3493 | #if defined(TARGET_PPC64) | |
a2ffb812 AJ |
3494 | if (ctx->sf_mode == 0) |
3495 | tcg_gen_movi_tl(cpu_lr, (uint32_t)nip); | |
e1833e1f JM |
3496 | else |
3497 | #endif | |
a2ffb812 | 3498 | tcg_gen_movi_tl(cpu_lr, nip); |
e1833e1f JM |
3499 | } |
3500 | ||
79aceca5 | 3501 | /* b ba bl bla */ |
99e300ef | 3502 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3503 | { |
76a66253 | 3504 | target_ulong li, target; |
38a64f9d | 3505 | |
8cbcb4fa | 3506 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3507 | /* sign extend LI */ |
76a66253 | 3508 | #if defined(TARGET_PPC64) |
d9bce9d9 JM |
3509 | if (ctx->sf_mode) |
3510 | li = ((int64_t)LI(ctx->opcode) << 38) >> 38; | |
3511 | else | |
76a66253 | 3512 | #endif |
d9bce9d9 | 3513 | li = ((int32_t)LI(ctx->opcode) << 6) >> 6; |
76a66253 | 3514 | if (likely(AA(ctx->opcode) == 0)) |
046d6672 | 3515 | target = ctx->nip + li - 4; |
79aceca5 | 3516 | else |
9a64fbe4 | 3517 | target = li; |
e1833e1f JM |
3518 | if (LK(ctx->opcode)) |
3519 | gen_setlr(ctx, ctx->nip); | |
697ab892 | 3520 | gen_update_cfar(ctx, ctx->nip); |
c1942362 | 3521 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3522 | } |
3523 | ||
e98a6e40 FB |
3524 | #define BCOND_IM 0 |
3525 | #define BCOND_LR 1 | |
3526 | #define BCOND_CTR 2 | |
3527 | ||
636aa200 | 3528 | static inline void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3529 | { |
d9bce9d9 | 3530 | uint32_t bo = BO(ctx->opcode); |
05f92404 | 3531 | int l1; |
a2ffb812 | 3532 | TCGv target; |
e98a6e40 | 3533 | |
8cbcb4fa | 3534 | ctx->exception = POWERPC_EXCP_BRANCH; |
a2ffb812 | 3535 | if (type == BCOND_LR || type == BCOND_CTR) { |
a7812ae4 | 3536 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3537 | if (type == BCOND_CTR) |
3538 | tcg_gen_mov_tl(target, cpu_ctr); | |
3539 | else | |
3540 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3541 | } else { |
3542 | TCGV_UNUSED(target); | |
e98a6e40 | 3543 | } |
e1833e1f JM |
3544 | if (LK(ctx->opcode)) |
3545 | gen_setlr(ctx, ctx->nip); | |
a2ffb812 AJ |
3546 | l1 = gen_new_label(); |
3547 | if ((bo & 0x4) == 0) { | |
3548 | /* Decrement and test CTR */ | |
a7812ae4 | 3549 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3550 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3551 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3552 | return; |
3553 | } | |
3554 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
d9bce9d9 | 3555 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3556 | if (!ctx->sf_mode) |
3557 | tcg_gen_ext32u_tl(temp, cpu_ctr); | |
3558 | else | |
d9bce9d9 | 3559 | #endif |
a2ffb812 AJ |
3560 | tcg_gen_mov_tl(temp, cpu_ctr); |
3561 | if (bo & 0x2) { | |
3562 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3563 | } else { | |
3564 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3565 | } |
a7812ae4 | 3566 | tcg_temp_free(temp); |
a2ffb812 AJ |
3567 | } |
3568 | if ((bo & 0x10) == 0) { | |
3569 | /* Test CR */ | |
3570 | uint32_t bi = BI(ctx->opcode); | |
3571 | uint32_t mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 3572 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3573 | |
d9bce9d9 | 3574 | if (bo & 0x8) { |
a2ffb812 AJ |
3575 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3576 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3577 | } else { |
a2ffb812 AJ |
3578 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3579 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3580 | } |
a7812ae4 | 3581 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3582 | } |
697ab892 | 3583 | gen_update_cfar(ctx, ctx->nip); |
e98a6e40 | 3584 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3585 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3586 | if (likely(AA(ctx->opcode) == 0)) { | |
3587 | gen_goto_tb(ctx, 0, ctx->nip + li - 4); | |
3588 | } else { | |
3589 | gen_goto_tb(ctx, 0, li); | |
3590 | } | |
c53be334 | 3591 | gen_set_label(l1); |
c1942362 | 3592 | gen_goto_tb(ctx, 1, ctx->nip); |
e98a6e40 | 3593 | } else { |
d9bce9d9 | 3594 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3595 | if (!(ctx->sf_mode)) |
3596 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); | |
3597 | else | |
3598 | #endif | |
3599 | tcg_gen_andi_tl(cpu_nip, target, ~3); | |
3600 | tcg_gen_exit_tb(0); | |
3601 | gen_set_label(l1); | |
3602 | #if defined(TARGET_PPC64) | |
3603 | if (!(ctx->sf_mode)) | |
3604 | tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip); | |
d9bce9d9 JM |
3605 | else |
3606 | #endif | |
a2ffb812 | 3607 | tcg_gen_movi_tl(cpu_nip, ctx->nip); |
57fec1fe | 3608 | tcg_gen_exit_tb(0); |
08e46e54 | 3609 | } |
e98a6e40 FB |
3610 | } |
3611 | ||
99e300ef | 3612 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3613 | { |
e98a6e40 FB |
3614 | gen_bcond(ctx, BCOND_IM); |
3615 | } | |
3616 | ||
99e300ef | 3617 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3618 | { |
e98a6e40 FB |
3619 | gen_bcond(ctx, BCOND_CTR); |
3620 | } | |
3621 | ||
99e300ef | 3622 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3623 | { |
e98a6e40 FB |
3624 | gen_bcond(ctx, BCOND_LR); |
3625 | } | |
79aceca5 FB |
3626 | |
3627 | /*** Condition register logical ***/ | |
e1571908 | 3628 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3629 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3630 | { \ |
fc0d441e JM |
3631 | uint8_t bitmask; \ |
3632 | int sh; \ | |
a7812ae4 | 3633 | TCGv_i32 t0, t1; \ |
fc0d441e | 3634 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3635 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3636 | if (sh > 0) \ |
fea0c503 | 3637 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3638 | else if (sh < 0) \ |
fea0c503 | 3639 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3640 | else \ |
fea0c503 | 3641 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3642 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3643 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3644 | if (sh > 0) \ | |
fea0c503 | 3645 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3646 | else if (sh < 0) \ |
fea0c503 | 3647 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3648 | else \ |
fea0c503 AJ |
3649 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3650 | tcg_op(t0, t0, t1); \ | |
fc0d441e | 3651 | bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \ |
fea0c503 AJ |
3652 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3653 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3654 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3655 | tcg_temp_free_i32(t0); \ |
3656 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3657 | } |
3658 | ||
3659 | /* crand */ | |
e1571908 | 3660 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3661 | /* crandc */ |
e1571908 | 3662 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3663 | /* creqv */ |
e1571908 | 3664 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3665 | /* crnand */ |
e1571908 | 3666 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3667 | /* crnor */ |
e1571908 | 3668 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3669 | /* cror */ |
e1571908 | 3670 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3671 | /* crorc */ |
e1571908 | 3672 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3673 | /* crxor */ |
e1571908 | 3674 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3675 | |
54623277 | 3676 | /* mcrf */ |
99e300ef | 3677 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3678 | { |
47e4661c | 3679 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3680 | } |
3681 | ||
3682 | /*** System linkage ***/ | |
99e300ef | 3683 | |
54623277 | 3684 | /* rfi (mem_idx only) */ |
99e300ef | 3685 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 3686 | { |
9a64fbe4 | 3687 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3688 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 FB |
3689 | #else |
3690 | /* Restore CPU state */ | |
76db3ba4 | 3691 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3692 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 3693 | return; |
9a64fbe4 | 3694 | } |
697ab892 | 3695 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3696 | gen_helper_rfi(cpu_env); |
e06fcd75 | 3697 | gen_sync_exception(ctx); |
9a64fbe4 | 3698 | #endif |
79aceca5 FB |
3699 | } |
3700 | ||
426613db | 3701 | #if defined(TARGET_PPC64) |
99e300ef | 3702 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
3703 | { |
3704 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3705 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3706 | #else |
3707 | /* Restore CPU state */ | |
76db3ba4 | 3708 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3709 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3710 | return; |
3711 | } | |
697ab892 | 3712 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3713 | gen_helper_rfid(cpu_env); |
e06fcd75 | 3714 | gen_sync_exception(ctx); |
426613db JM |
3715 | #endif |
3716 | } | |
426613db | 3717 | |
99e300ef | 3718 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
3719 | { |
3720 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3721 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3722 | #else |
3723 | /* Restore CPU state */ | |
76db3ba4 | 3724 | if (unlikely(ctx->mem_idx <= 1)) { |
e06fcd75 | 3725 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3726 | return; |
3727 | } | |
e5f17ac6 | 3728 | gen_helper_hrfid(cpu_env); |
e06fcd75 | 3729 | gen_sync_exception(ctx); |
be147d08 JM |
3730 | #endif |
3731 | } | |
3732 | #endif | |
3733 | ||
79aceca5 | 3734 | /* sc */ |
417bf010 JM |
3735 | #if defined(CONFIG_USER_ONLY) |
3736 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
3737 | #else | |
3738 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
3739 | #endif | |
99e300ef | 3740 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 3741 | { |
e1833e1f JM |
3742 | uint32_t lev; |
3743 | ||
3744 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 3745 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
3746 | } |
3747 | ||
3748 | /*** Trap ***/ | |
99e300ef | 3749 | |
54623277 | 3750 | /* tw */ |
99e300ef | 3751 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 3752 | { |
cab3bee2 | 3753 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3754 | /* Update the nip since this might generate a trap exception */ |
3755 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3756 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3757 | t0); | |
cab3bee2 | 3758 | tcg_temp_free_i32(t0); |
79aceca5 FB |
3759 | } |
3760 | ||
3761 | /* twi */ | |
99e300ef | 3762 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 3763 | { |
cab3bee2 AJ |
3764 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3765 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3766 | /* Update the nip since this might generate a trap exception */ |
3767 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3768 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3769 | tcg_temp_free(t0); |
3770 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3771 | } |
3772 | ||
d9bce9d9 JM |
3773 | #if defined(TARGET_PPC64) |
3774 | /* td */ | |
99e300ef | 3775 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 3776 | { |
cab3bee2 | 3777 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3778 | /* Update the nip since this might generate a trap exception */ |
3779 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3780 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3781 | t0); | |
cab3bee2 | 3782 | tcg_temp_free_i32(t0); |
d9bce9d9 JM |
3783 | } |
3784 | ||
3785 | /* tdi */ | |
99e300ef | 3786 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 3787 | { |
cab3bee2 AJ |
3788 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3789 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3790 | /* Update the nip since this might generate a trap exception */ |
3791 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3792 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3793 | tcg_temp_free(t0); |
3794 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
3795 | } |
3796 | #endif | |
3797 | ||
79aceca5 | 3798 | /*** Processor control ***/ |
99e300ef | 3799 | |
54623277 | 3800 | /* mcrxr */ |
99e300ef | 3801 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 3802 | { |
3d7b417e AJ |
3803 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer); |
3804 | tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA); | |
269f3e95 | 3805 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA)); |
79aceca5 FB |
3806 | } |
3807 | ||
0cfe11ea | 3808 | /* mfcr mfocrf */ |
99e300ef | 3809 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 3810 | { |
76a66253 | 3811 | uint32_t crm, crn; |
3b46e624 | 3812 | |
76a66253 JM |
3813 | if (likely(ctx->opcode & 0x00100000)) { |
3814 | crm = CRM(ctx->opcode); | |
8dd640e4 | 3815 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 3816 | crn = ctz32 (crm); |
e1571908 | 3817 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
3818 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
3819 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 3820 | } |
d9bce9d9 | 3821 | } else { |
651721b2 AJ |
3822 | TCGv_i32 t0 = tcg_temp_new_i32(); |
3823 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
3824 | tcg_gen_shli_i32(t0, t0, 4); | |
3825 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
3826 | tcg_gen_shli_i32(t0, t0, 4); | |
3827 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
3828 | tcg_gen_shli_i32(t0, t0, 4); | |
3829 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
3830 | tcg_gen_shli_i32(t0, t0, 4); | |
3831 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
3832 | tcg_gen_shli_i32(t0, t0, 4); | |
3833 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
3834 | tcg_gen_shli_i32(t0, t0, 4); | |
3835 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
3836 | tcg_gen_shli_i32(t0, t0, 4); | |
3837 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
3838 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
3839 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 3840 | } |
79aceca5 FB |
3841 | } |
3842 | ||
3843 | /* mfmsr */ | |
99e300ef | 3844 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 3845 | { |
9a64fbe4 | 3846 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3847 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3848 | #else |
76db3ba4 | 3849 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3850 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3851 | return; |
9a64fbe4 | 3852 | } |
6527f6ea | 3853 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
9a64fbe4 | 3854 | #endif |
79aceca5 FB |
3855 | } |
3856 | ||
7b13448f | 3857 | static void spr_noaccess(void *opaque, int gprn, int sprn) |
3fc6c082 | 3858 | { |
7b13448f | 3859 | #if 0 |
3fc6c082 FB |
3860 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
3861 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 3862 | #endif |
3fc6c082 FB |
3863 | } |
3864 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 3865 | |
79aceca5 | 3866 | /* mfspr */ |
636aa200 | 3867 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 3868 | { |
45d827d2 | 3869 | void (*read_cb)(void *opaque, int gprn, int sprn); |
79aceca5 FB |
3870 | uint32_t sprn = SPR(ctx->opcode); |
3871 | ||
3fc6c082 | 3872 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 3873 | if (ctx->mem_idx == 2) |
be147d08 | 3874 | read_cb = ctx->spr_cb[sprn].hea_read; |
76db3ba4 | 3875 | else if (ctx->mem_idx) |
3fc6c082 FB |
3876 | read_cb = ctx->spr_cb[sprn].oea_read; |
3877 | else | |
9a64fbe4 | 3878 | #endif |
3fc6c082 | 3879 | read_cb = ctx->spr_cb[sprn].uea_read; |
76a66253 JM |
3880 | if (likely(read_cb != NULL)) { |
3881 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 3882 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
3883 | } else { |
3884 | /* Privilege exception */ | |
9fceefa7 JM |
3885 | /* This is a hack to avoid warnings when running Linux: |
3886 | * this OS breaks the PowerPC virtualisation model, | |
3887 | * allowing userland application to read the PVR | |
3888 | */ | |
3889 | if (sprn != SPR_PVR) { | |
93fcfe39 | 3890 | qemu_log("Trying to read privileged spr %d %03x at " |
90e189ec BS |
3891 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3892 | printf("Trying to read privileged spr %d %03x at " | |
3893 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); | |
f24e5695 | 3894 | } |
e06fcd75 | 3895 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 3896 | } |
3fc6c082 FB |
3897 | } else { |
3898 | /* Not defined */ | |
93fcfe39 | 3899 | qemu_log("Trying to read invalid spr %d %03x at " |
90e189ec BS |
3900 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3901 | printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 3902 | sprn, sprn, ctx->nip); |
e06fcd75 | 3903 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 3904 | } |
79aceca5 FB |
3905 | } |
3906 | ||
99e300ef | 3907 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 3908 | { |
3fc6c082 | 3909 | gen_op_mfspr(ctx); |
76a66253 | 3910 | } |
3fc6c082 FB |
3911 | |
3912 | /* mftb */ | |
99e300ef | 3913 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
3914 | { |
3915 | gen_op_mfspr(ctx); | |
79aceca5 FB |
3916 | } |
3917 | ||
0cfe11ea | 3918 | /* mtcrf mtocrf*/ |
99e300ef | 3919 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 3920 | { |
76a66253 | 3921 | uint32_t crm, crn; |
3b46e624 | 3922 | |
76a66253 | 3923 | crm = CRM(ctx->opcode); |
8dd640e4 | 3924 | if (likely((ctx->opcode & 0x00100000))) { |
3925 | if (crm && ((crm & (crm - 1)) == 0)) { | |
3926 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 3927 | crn = ctz32 (crm); |
8dd640e4 | 3928 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
3929 | tcg_gen_shri_i32(temp, temp, crn * 4); |
3930 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 3931 | tcg_temp_free_i32(temp); |
3932 | } | |
76a66253 | 3933 | } else { |
651721b2 AJ |
3934 | TCGv_i32 temp = tcg_temp_new_i32(); |
3935 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
3936 | for (crn = 0 ; crn < 8 ; crn++) { | |
3937 | if (crm & (1 << crn)) { | |
3938 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
3939 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
3940 | } | |
3941 | } | |
a7812ae4 | 3942 | tcg_temp_free_i32(temp); |
76a66253 | 3943 | } |
79aceca5 FB |
3944 | } |
3945 | ||
3946 | /* mtmsr */ | |
426613db | 3947 | #if defined(TARGET_PPC64) |
99e300ef | 3948 | static void gen_mtmsrd(DisasContext *ctx) |
426613db JM |
3949 | { |
3950 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3951 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db | 3952 | #else |
76db3ba4 | 3953 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3954 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db JM |
3955 | return; |
3956 | } | |
be147d08 JM |
3957 | if (ctx->opcode & 0x00010000) { |
3958 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3959 | TCGv t0 = tcg_temp_new(); |
3960 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3961 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3962 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3963 | tcg_temp_free(t0); | |
be147d08 | 3964 | } else { |
056b05f8 JM |
3965 | /* XXX: we need to update nip before the store |
3966 | * if we enter power saving mode, we will exit the loop | |
3967 | * directly from ppc_store_msr | |
3968 | */ | |
be147d08 | 3969 | gen_update_nip(ctx, ctx->nip); |
e5f17ac6 | 3970 | gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
3971 | /* Must stop the translation as machine state (may have) changed */ |
3972 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 3973 | gen_stop_exception(ctx); |
be147d08 | 3974 | } |
426613db JM |
3975 | #endif |
3976 | } | |
3977 | #endif | |
3978 | ||
99e300ef | 3979 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 3980 | { |
9a64fbe4 | 3981 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3982 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3983 | #else |
76db3ba4 | 3984 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3985 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3986 | return; |
9a64fbe4 | 3987 | } |
be147d08 JM |
3988 | if (ctx->opcode & 0x00010000) { |
3989 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3990 | TCGv t0 = tcg_temp_new(); |
3991 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3992 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3993 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3994 | tcg_temp_free(t0); | |
be147d08 | 3995 | } else { |
8018dc63 AG |
3996 | TCGv msr = tcg_temp_new(); |
3997 | ||
056b05f8 JM |
3998 | /* XXX: we need to update nip before the store |
3999 | * if we enter power saving mode, we will exit the loop | |
4000 | * directly from ppc_store_msr | |
4001 | */ | |
be147d08 | 4002 | gen_update_nip(ctx, ctx->nip); |
d9bce9d9 | 4003 | #if defined(TARGET_PPC64) |
8018dc63 AG |
4004 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
4005 | #else | |
4006 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 4007 | #endif |
e5f17ac6 | 4008 | gen_helper_store_msr(cpu_env, msr); |
be147d08 | 4009 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 4010 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 4011 | gen_stop_exception(ctx); |
be147d08 | 4012 | } |
9a64fbe4 | 4013 | #endif |
79aceca5 FB |
4014 | } |
4015 | ||
4016 | /* mtspr */ | |
99e300ef | 4017 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 4018 | { |
45d827d2 | 4019 | void (*write_cb)(void *opaque, int sprn, int gprn); |
79aceca5 FB |
4020 | uint32_t sprn = SPR(ctx->opcode); |
4021 | ||
3fc6c082 | 4022 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4023 | if (ctx->mem_idx == 2) |
be147d08 | 4024 | write_cb = ctx->spr_cb[sprn].hea_write; |
76db3ba4 | 4025 | else if (ctx->mem_idx) |
3fc6c082 FB |
4026 | write_cb = ctx->spr_cb[sprn].oea_write; |
4027 | else | |
9a64fbe4 | 4028 | #endif |
3fc6c082 | 4029 | write_cb = ctx->spr_cb[sprn].uea_write; |
76a66253 JM |
4030 | if (likely(write_cb != NULL)) { |
4031 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 4032 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
4033 | } else { |
4034 | /* Privilege exception */ | |
93fcfe39 | 4035 | qemu_log("Trying to write privileged spr %d %03x at " |
90e189ec BS |
4036 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
4037 | printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx | |
4038 | "\n", sprn, sprn, ctx->nip); | |
e06fcd75 | 4039 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 4040 | } |
3fc6c082 FB |
4041 | } else { |
4042 | /* Not defined */ | |
93fcfe39 | 4043 | qemu_log("Trying to write invalid spr %d %03x at " |
90e189ec BS |
4044 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
4045 | printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 4046 | sprn, sprn, ctx->nip); |
e06fcd75 | 4047 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4048 | } |
79aceca5 FB |
4049 | } |
4050 | ||
4051 | /*** Cache management ***/ | |
99e300ef | 4052 | |
54623277 | 4053 | /* dcbf */ |
99e300ef | 4054 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 4055 | { |
dac454af | 4056 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
4057 | TCGv t0; |
4058 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4059 | t0 = tcg_temp_new(); | |
4060 | gen_addr_reg_index(ctx, t0); | |
4061 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4062 | tcg_temp_free(t0); |
79aceca5 FB |
4063 | } |
4064 | ||
4065 | /* dcbi (Supervisor only) */ | |
99e300ef | 4066 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4067 | { |
a541f297 | 4068 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4069 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a541f297 | 4070 | #else |
b61f2753 | 4071 | TCGv EA, val; |
76db3ba4 | 4072 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4073 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4074 | return; |
9a64fbe4 | 4075 | } |
a7812ae4 | 4076 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4077 | gen_set_access_type(ctx, ACCESS_CACHE); |
4078 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4079 | val = tcg_temp_new(); |
76a66253 | 4080 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4081 | gen_qemu_ld8u(ctx, val, EA); |
4082 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4083 | tcg_temp_free(val); |
4084 | tcg_temp_free(EA); | |
a541f297 | 4085 | #endif |
79aceca5 FB |
4086 | } |
4087 | ||
4088 | /* dcdst */ | |
99e300ef | 4089 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4090 | { |
76a66253 | 4091 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4092 | TCGv t0; |
4093 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4094 | t0 = tcg_temp_new(); | |
4095 | gen_addr_reg_index(ctx, t0); | |
4096 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4097 | tcg_temp_free(t0); |
79aceca5 FB |
4098 | } |
4099 | ||
4100 | /* dcbt */ | |
99e300ef | 4101 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4102 | { |
0db1b20e | 4103 | /* interpreted as no-op */ |
76a66253 JM |
4104 | /* XXX: specification say this is treated as a load by the MMU |
4105 | * but does not generate any exception | |
4106 | */ | |
79aceca5 FB |
4107 | } |
4108 | ||
4109 | /* dcbtst */ | |
99e300ef | 4110 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4111 | { |
0db1b20e | 4112 | /* interpreted as no-op */ |
76a66253 JM |
4113 | /* XXX: specification say this is treated as a load by the MMU |
4114 | * but does not generate any exception | |
4115 | */ | |
79aceca5 FB |
4116 | } |
4117 | ||
4118 | /* dcbz */ | |
99e300ef | 4119 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4120 | { |
76db3ba4 AJ |
4121 | TCGv t0; |
4122 | gen_set_access_type(ctx, ACCESS_CACHE); | |
799a8c8d AJ |
4123 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4124 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4125 | t0 = tcg_temp_new(); |
4126 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4127 | gen_helper_dcbz(cpu_env, t0); |
799a8c8d | 4128 | tcg_temp_free(t0); |
d63001d1 JM |
4129 | } |
4130 | ||
e8eaa2c0 | 4131 | static void gen_dcbz_970(DisasContext *ctx) |
d63001d1 | 4132 | { |
76db3ba4 AJ |
4133 | TCGv t0; |
4134 | gen_set_access_type(ctx, ACCESS_CACHE); | |
799a8c8d AJ |
4135 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4136 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4137 | t0 = tcg_temp_new(); |
4138 | gen_addr_reg_index(ctx, t0); | |
d63001d1 | 4139 | if (ctx->opcode & 0x00200000) |
2f5a189c | 4140 | gen_helper_dcbz(cpu_env, t0); |
d63001d1 | 4141 | else |
2f5a189c | 4142 | gen_helper_dcbz_970(cpu_env, t0); |
799a8c8d | 4143 | tcg_temp_free(t0); |
79aceca5 FB |
4144 | } |
4145 | ||
ae1c1a3d | 4146 | /* dst / dstt */ |
99e300ef | 4147 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4148 | { |
4149 | if (rA(ctx->opcode) == 0) { | |
4150 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4151 | } else { | |
4152 | /* interpreted as no-op */ | |
4153 | } | |
4154 | } | |
4155 | ||
4156 | /* dstst /dststt */ | |
99e300ef | 4157 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4158 | { |
4159 | if (rA(ctx->opcode) == 0) { | |
4160 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4161 | } else { | |
4162 | /* interpreted as no-op */ | |
4163 | } | |
4164 | ||
4165 | } | |
4166 | ||
4167 | /* dss / dssall */ | |
99e300ef | 4168 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4169 | { |
4170 | /* interpreted as no-op */ | |
4171 | } | |
4172 | ||
79aceca5 | 4173 | /* icbi */ |
99e300ef | 4174 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4175 | { |
76db3ba4 AJ |
4176 | TCGv t0; |
4177 | gen_set_access_type(ctx, ACCESS_CACHE); | |
30032c94 JM |
4178 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4179 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4180 | t0 = tcg_temp_new(); |
4181 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4182 | gen_helper_icbi(cpu_env, t0); |
37d269df | 4183 | tcg_temp_free(t0); |
79aceca5 FB |
4184 | } |
4185 | ||
4186 | /* Optional: */ | |
4187 | /* dcba */ | |
99e300ef | 4188 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4189 | { |
0db1b20e JM |
4190 | /* interpreted as no-op */ |
4191 | /* XXX: specification say this is treated as a store by the MMU | |
4192 | * but does not generate any exception | |
4193 | */ | |
79aceca5 FB |
4194 | } |
4195 | ||
4196 | /*** Segment register manipulation ***/ | |
4197 | /* Supervisor only: */ | |
99e300ef | 4198 | |
54623277 | 4199 | /* mfsr */ |
99e300ef | 4200 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4201 | { |
9a64fbe4 | 4202 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4203 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4204 | #else |
74d37793 | 4205 | TCGv t0; |
76db3ba4 | 4206 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4207 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4208 | return; |
9a64fbe4 | 4209 | } |
74d37793 | 4210 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4211 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4212 | tcg_temp_free(t0); |
9a64fbe4 | 4213 | #endif |
79aceca5 FB |
4214 | } |
4215 | ||
4216 | /* mfsrin */ | |
99e300ef | 4217 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4218 | { |
9a64fbe4 | 4219 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4220 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4221 | #else |
74d37793 | 4222 | TCGv t0; |
76db3ba4 | 4223 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4224 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4225 | return; |
9a64fbe4 | 4226 | } |
74d37793 AJ |
4227 | t0 = tcg_temp_new(); |
4228 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4229 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4230 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4231 | tcg_temp_free(t0); |
9a64fbe4 | 4232 | #endif |
79aceca5 FB |
4233 | } |
4234 | ||
4235 | /* mtsr */ | |
99e300ef | 4236 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4237 | { |
9a64fbe4 | 4238 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4239 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4240 | #else |
74d37793 | 4241 | TCGv t0; |
76db3ba4 | 4242 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4243 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4244 | return; |
9a64fbe4 | 4245 | } |
74d37793 | 4246 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4247 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4248 | tcg_temp_free(t0); |
9a64fbe4 | 4249 | #endif |
79aceca5 FB |
4250 | } |
4251 | ||
4252 | /* mtsrin */ | |
99e300ef | 4253 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4254 | { |
9a64fbe4 | 4255 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4256 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4257 | #else |
74d37793 | 4258 | TCGv t0; |
76db3ba4 | 4259 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4260 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4261 | return; |
9a64fbe4 | 4262 | } |
74d37793 AJ |
4263 | t0 = tcg_temp_new(); |
4264 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4265 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4266 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); |
74d37793 | 4267 | tcg_temp_free(t0); |
9a64fbe4 | 4268 | #endif |
79aceca5 FB |
4269 | } |
4270 | ||
12de9a39 JM |
4271 | #if defined(TARGET_PPC64) |
4272 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4273 | |
54623277 | 4274 | /* mfsr */ |
e8eaa2c0 | 4275 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4276 | { |
4277 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4278 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4279 | #else |
74d37793 | 4280 | TCGv t0; |
76db3ba4 | 4281 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4282 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4283 | return; |
4284 | } | |
74d37793 | 4285 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4286 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4287 | tcg_temp_free(t0); |
12de9a39 JM |
4288 | #endif |
4289 | } | |
4290 | ||
4291 | /* mfsrin */ | |
e8eaa2c0 | 4292 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4293 | { |
4294 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4295 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4296 | #else |
74d37793 | 4297 | TCGv t0; |
76db3ba4 | 4298 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4299 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4300 | return; |
4301 | } | |
74d37793 AJ |
4302 | t0 = tcg_temp_new(); |
4303 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4304 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4305 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4306 | tcg_temp_free(t0); |
12de9a39 JM |
4307 | #endif |
4308 | } | |
4309 | ||
4310 | /* mtsr */ | |
e8eaa2c0 | 4311 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4312 | { |
4313 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4314 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4315 | #else |
74d37793 | 4316 | TCGv t0; |
76db3ba4 | 4317 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4318 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4319 | return; |
4320 | } | |
74d37793 | 4321 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4322 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4323 | tcg_temp_free(t0); |
12de9a39 JM |
4324 | #endif |
4325 | } | |
4326 | ||
4327 | /* mtsrin */ | |
e8eaa2c0 | 4328 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4329 | { |
4330 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4331 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4332 | #else |
74d37793 | 4333 | TCGv t0; |
76db3ba4 | 4334 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4335 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4336 | return; |
4337 | } | |
74d37793 AJ |
4338 | t0 = tcg_temp_new(); |
4339 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4340 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4341 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4342 | tcg_temp_free(t0); |
12de9a39 JM |
4343 | #endif |
4344 | } | |
f6b868fc BS |
4345 | |
4346 | /* slbmte */ | |
e8eaa2c0 | 4347 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
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 BS |
4356 | gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)], |
4357 | cpu_gpr[rS(ctx->opcode)]); | |
f6b868fc BS |
4358 | #endif |
4359 | } | |
4360 | ||
efdef95f DG |
4361 | static void gen_slbmfee(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_esid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4371 | cpu_gpr[rB(ctx->opcode)]); |
4372 | #endif | |
4373 | } | |
4374 | ||
4375 | static void gen_slbmfev(DisasContext *ctx) | |
4376 | { | |
4377 | #if defined(CONFIG_USER_ONLY) | |
4378 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4379 | #else | |
4380 | if (unlikely(!ctx->mem_idx)) { | |
4381 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4382 | return; | |
4383 | } | |
c6c7cf05 | 4384 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4385 | cpu_gpr[rB(ctx->opcode)]); |
4386 | #endif | |
4387 | } | |
12de9a39 JM |
4388 | #endif /* defined(TARGET_PPC64) */ |
4389 | ||
79aceca5 | 4390 | /*** Lookaside buffer management ***/ |
76db3ba4 | 4391 | /* Optional & mem_idx only: */ |
99e300ef | 4392 | |
54623277 | 4393 | /* tlbia */ |
99e300ef | 4394 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4395 | { |
9a64fbe4 | 4396 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4397 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4398 | #else |
76db3ba4 | 4399 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4400 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4401 | return; |
9a64fbe4 | 4402 | } |
c6c7cf05 | 4403 | gen_helper_tlbia(cpu_env); |
9a64fbe4 | 4404 | #endif |
79aceca5 FB |
4405 | } |
4406 | ||
bf14b1ce | 4407 | /* tlbiel */ |
99e300ef | 4408 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4409 | { |
4410 | #if defined(CONFIG_USER_ONLY) | |
4411 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4412 | #else | |
4413 | if (unlikely(!ctx->mem_idx)) { | |
4414 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4415 | return; | |
4416 | } | |
c6c7cf05 | 4417 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
bf14b1ce BS |
4418 | #endif |
4419 | } | |
4420 | ||
79aceca5 | 4421 | /* tlbie */ |
99e300ef | 4422 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4423 | { |
9a64fbe4 | 4424 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4425 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4426 | #else |
76db3ba4 | 4427 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4428 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4429 | return; |
9a64fbe4 | 4430 | } |
d9bce9d9 | 4431 | #if defined(TARGET_PPC64) |
74d37793 AJ |
4432 | if (!ctx->sf_mode) { |
4433 | TCGv t0 = tcg_temp_new(); | |
4434 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 4435 | gen_helper_tlbie(cpu_env, t0); |
74d37793 AJ |
4436 | tcg_temp_free(t0); |
4437 | } else | |
d9bce9d9 | 4438 | #endif |
c6c7cf05 | 4439 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9a64fbe4 | 4440 | #endif |
79aceca5 FB |
4441 | } |
4442 | ||
4443 | /* tlbsync */ | |
99e300ef | 4444 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4445 | { |
9a64fbe4 | 4446 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4447 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4448 | #else |
76db3ba4 | 4449 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4450 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4451 | return; |
9a64fbe4 FB |
4452 | } |
4453 | /* This has no effect: it should ensure that all previous | |
4454 | * tlbie have completed | |
4455 | */ | |
e06fcd75 | 4456 | gen_stop_exception(ctx); |
9a64fbe4 | 4457 | #endif |
79aceca5 FB |
4458 | } |
4459 | ||
426613db JM |
4460 | #if defined(TARGET_PPC64) |
4461 | /* slbia */ | |
99e300ef | 4462 | static void gen_slbia(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_slbia(cpu_env); |
426613db JM |
4472 | #endif |
4473 | } | |
4474 | ||
4475 | /* slbie */ | |
99e300ef | 4476 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4477 | { |
4478 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4479 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4480 | #else |
76db3ba4 | 4481 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4482 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4483 | return; |
4484 | } | |
c6c7cf05 | 4485 | gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
426613db JM |
4486 | #endif |
4487 | } | |
4488 | #endif | |
4489 | ||
79aceca5 FB |
4490 | /*** External control ***/ |
4491 | /* Optional: */ | |
99e300ef | 4492 | |
54623277 | 4493 | /* eciwx */ |
99e300ef | 4494 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4495 | { |
76db3ba4 | 4496 | TCGv t0; |
fa407c03 | 4497 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4498 | gen_set_access_type(ctx, ACCESS_EXT); |
4499 | t0 = tcg_temp_new(); | |
4500 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4501 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4502 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4503 | tcg_temp_free(t0); |
76a66253 JM |
4504 | } |
4505 | ||
4506 | /* ecowx */ | |
99e300ef | 4507 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4508 | { |
76db3ba4 | 4509 | TCGv t0; |
fa407c03 | 4510 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4511 | gen_set_access_type(ctx, ACCESS_EXT); |
4512 | t0 = tcg_temp_new(); | |
4513 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4514 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4515 | gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4516 | tcg_temp_free(t0); |
76a66253 JM |
4517 | } |
4518 | ||
4519 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4520 | |
54623277 | 4521 | /* abs - abs. */ |
99e300ef | 4522 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4523 | { |
22e0e173 AJ |
4524 | int l1 = gen_new_label(); |
4525 | int l2 = gen_new_label(); | |
4526 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4527 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4528 | tcg_gen_br(l2); | |
4529 | gen_set_label(l1); | |
4530 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4531 | gen_set_label(l2); | |
76a66253 | 4532 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4533 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4534 | } |
4535 | ||
4536 | /* abso - abso. */ | |
99e300ef | 4537 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4538 | { |
22e0e173 AJ |
4539 | int l1 = gen_new_label(); |
4540 | int l2 = gen_new_label(); | |
4541 | int l3 = gen_new_label(); | |
4542 | /* Start with XER OV disabled, the most likely case */ | |
4543 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4544 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); | |
4545 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
4546 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4547 | tcg_gen_br(l2); | |
4548 | gen_set_label(l1); | |
4549 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4550 | tcg_gen_br(l3); | |
4551 | gen_set_label(l2); | |
4552 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4553 | gen_set_label(l3); | |
76a66253 | 4554 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4555 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4556 | } |
4557 | ||
4558 | /* clcs */ | |
99e300ef | 4559 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 4560 | { |
22e0e173 | 4561 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
d523dd00 | 4562 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 4563 | tcg_temp_free_i32(t0); |
c7697e1f | 4564 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
4565 | } |
4566 | ||
4567 | /* div - div. */ | |
99e300ef | 4568 | static void gen_div(DisasContext *ctx) |
76a66253 | 4569 | { |
d15f74fb BS |
4570 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4571 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4572 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4573 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4574 | } |
4575 | ||
4576 | /* divo - divo. */ | |
99e300ef | 4577 | static void gen_divo(DisasContext *ctx) |
76a66253 | 4578 | { |
d15f74fb BS |
4579 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4580 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4581 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4582 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4583 | } |
4584 | ||
4585 | /* divs - divs. */ | |
99e300ef | 4586 | static void gen_divs(DisasContext *ctx) |
76a66253 | 4587 | { |
d15f74fb BS |
4588 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4589 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4590 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4591 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4592 | } |
4593 | ||
4594 | /* divso - divso. */ | |
99e300ef | 4595 | static void gen_divso(DisasContext *ctx) |
76a66253 | 4596 | { |
d15f74fb BS |
4597 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env, |
4598 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4599 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4600 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4601 | } |
4602 | ||
4603 | /* doz - doz. */ | |
99e300ef | 4604 | static void gen_doz(DisasContext *ctx) |
76a66253 | 4605 | { |
22e0e173 AJ |
4606 | int l1 = gen_new_label(); |
4607 | int l2 = gen_new_label(); | |
4608 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4609 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4610 | tcg_gen_br(l2); | |
4611 | gen_set_label(l1); | |
4612 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4613 | gen_set_label(l2); | |
76a66253 | 4614 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4615 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4616 | } |
4617 | ||
4618 | /* dozo - dozo. */ | |
99e300ef | 4619 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 4620 | { |
22e0e173 AJ |
4621 | int l1 = gen_new_label(); |
4622 | int l2 = gen_new_label(); | |
4623 | TCGv t0 = tcg_temp_new(); | |
4624 | TCGv t1 = tcg_temp_new(); | |
4625 | TCGv t2 = tcg_temp_new(); | |
4626 | /* Start with XER OV disabled, the most likely case */ | |
4627 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4628 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4629 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4630 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4631 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
4632 | tcg_gen_andc_tl(t1, t1, t2); | |
4633 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4634 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
4635 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4636 | tcg_gen_br(l2); | |
4637 | gen_set_label(l1); | |
4638 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4639 | gen_set_label(l2); | |
4640 | tcg_temp_free(t0); | |
4641 | tcg_temp_free(t1); | |
4642 | tcg_temp_free(t2); | |
76a66253 | 4643 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4644 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4645 | } |
4646 | ||
4647 | /* dozi */ | |
99e300ef | 4648 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 4649 | { |
22e0e173 AJ |
4650 | target_long simm = SIMM(ctx->opcode); |
4651 | int l1 = gen_new_label(); | |
4652 | int l2 = gen_new_label(); | |
4653 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); | |
4654 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
4655 | tcg_gen_br(l2); | |
4656 | gen_set_label(l1); | |
4657 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4658 | gen_set_label(l2); | |
4659 | if (unlikely(Rc(ctx->opcode) != 0)) | |
4660 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
4661 | } |
4662 | ||
76a66253 | 4663 | /* lscbx - lscbx. */ |
99e300ef | 4664 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 4665 | { |
bdb4b689 AJ |
4666 | TCGv t0 = tcg_temp_new(); |
4667 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
4668 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
4669 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 4670 | |
76db3ba4 | 4671 | gen_addr_reg_index(ctx, t0); |
76a66253 | 4672 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 4673 | gen_update_nip(ctx, ctx->nip - 4); |
2f5a189c | 4674 | gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3); |
bdb4b689 AJ |
4675 | tcg_temp_free_i32(t1); |
4676 | tcg_temp_free_i32(t2); | |
4677 | tcg_temp_free_i32(t3); | |
3d7b417e | 4678 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 4679 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 4680 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
4681 | gen_set_Rc0(ctx, t0); |
4682 | tcg_temp_free(t0); | |
76a66253 JM |
4683 | } |
4684 | ||
4685 | /* maskg - maskg. */ | |
99e300ef | 4686 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 4687 | { |
22e0e173 AJ |
4688 | int l1 = gen_new_label(); |
4689 | TCGv t0 = tcg_temp_new(); | |
4690 | TCGv t1 = tcg_temp_new(); | |
4691 | TCGv t2 = tcg_temp_new(); | |
4692 | TCGv t3 = tcg_temp_new(); | |
4693 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
4694 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4695 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
4696 | tcg_gen_addi_tl(t2, t0, 1); | |
4697 | tcg_gen_shr_tl(t2, t3, t2); | |
4698 | tcg_gen_shr_tl(t3, t3, t1); | |
4699 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
4700 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
4701 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4702 | gen_set_label(l1); | |
4703 | tcg_temp_free(t0); | |
4704 | tcg_temp_free(t1); | |
4705 | tcg_temp_free(t2); | |
4706 | tcg_temp_free(t3); | |
76a66253 | 4707 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4708 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4709 | } |
4710 | ||
4711 | /* maskir - maskir. */ | |
99e300ef | 4712 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 4713 | { |
22e0e173 AJ |
4714 | TCGv t0 = tcg_temp_new(); |
4715 | TCGv t1 = tcg_temp_new(); | |
4716 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4717 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4718 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4719 | tcg_temp_free(t0); | |
4720 | tcg_temp_free(t1); | |
76a66253 | 4721 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4722 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4723 | } |
4724 | ||
4725 | /* mul - mul. */ | |
99e300ef | 4726 | static void gen_mul(DisasContext *ctx) |
76a66253 | 4727 | { |
22e0e173 AJ |
4728 | TCGv_i64 t0 = tcg_temp_new_i64(); |
4729 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4730 | TCGv t2 = tcg_temp_new(); | |
4731 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4732 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4733 | tcg_gen_mul_i64(t0, t0, t1); | |
4734 | tcg_gen_trunc_i64_tl(t2, t0); | |
4735 | gen_store_spr(SPR_MQ, t2); | |
4736 | tcg_gen_shri_i64(t1, t0, 32); | |
4737 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4738 | tcg_temp_free_i64(t0); | |
4739 | tcg_temp_free_i64(t1); | |
4740 | tcg_temp_free(t2); | |
76a66253 | 4741 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4742 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4743 | } |
4744 | ||
4745 | /* mulo - mulo. */ | |
99e300ef | 4746 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 4747 | { |
22e0e173 AJ |
4748 | int l1 = gen_new_label(); |
4749 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
4750 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4751 | TCGv t2 = tcg_temp_new(); | |
4752 | /* Start with XER OV disabled, the most likely case */ | |
4753 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4754 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4755 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4756 | tcg_gen_mul_i64(t0, t0, t1); | |
4757 | tcg_gen_trunc_i64_tl(t2, t0); | |
4758 | gen_store_spr(SPR_MQ, t2); | |
4759 | tcg_gen_shri_i64(t1, t0, 32); | |
4760 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4761 | tcg_gen_ext32s_i64(t1, t0); | |
4762 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
4763 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4764 | gen_set_label(l1); | |
4765 | tcg_temp_free_i64(t0); | |
4766 | tcg_temp_free_i64(t1); | |
4767 | tcg_temp_free(t2); | |
76a66253 | 4768 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4769 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4770 | } |
4771 | ||
4772 | /* nabs - nabs. */ | |
99e300ef | 4773 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 4774 | { |
22e0e173 AJ |
4775 | int l1 = gen_new_label(); |
4776 | int l2 = gen_new_label(); | |
4777 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4778 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4779 | tcg_gen_br(l2); | |
4780 | gen_set_label(l1); | |
4781 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4782 | gen_set_label(l2); | |
76a66253 | 4783 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4784 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4785 | } |
4786 | ||
4787 | /* nabso - nabso. */ | |
99e300ef | 4788 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 4789 | { |
22e0e173 AJ |
4790 | int l1 = gen_new_label(); |
4791 | int l2 = gen_new_label(); | |
4792 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4793 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4794 | tcg_gen_br(l2); | |
4795 | gen_set_label(l1); | |
4796 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4797 | gen_set_label(l2); | |
4798 | /* nabs never overflows */ | |
4799 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
76a66253 | 4800 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4801 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4802 | } |
4803 | ||
4804 | /* rlmi - rlmi. */ | |
99e300ef | 4805 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 4806 | { |
7487953d AJ |
4807 | uint32_t mb = MB(ctx->opcode); |
4808 | uint32_t me = ME(ctx->opcode); | |
4809 | TCGv t0 = tcg_temp_new(); | |
4810 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4811 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4812 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
4813 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
4814 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
4815 | tcg_temp_free(t0); | |
76a66253 | 4816 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4817 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4818 | } |
4819 | ||
4820 | /* rrib - rrib. */ | |
99e300ef | 4821 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 4822 | { |
7487953d AJ |
4823 | TCGv t0 = tcg_temp_new(); |
4824 | TCGv t1 = tcg_temp_new(); | |
4825 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4826 | tcg_gen_movi_tl(t1, 0x80000000); | |
4827 | tcg_gen_shr_tl(t1, t1, t0); | |
4828 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4829 | tcg_gen_and_tl(t0, t0, t1); | |
4830 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
4831 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4832 | tcg_temp_free(t0); | |
4833 | tcg_temp_free(t1); | |
76a66253 | 4834 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4835 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4836 | } |
4837 | ||
4838 | /* sle - sle. */ | |
99e300ef | 4839 | static void gen_sle(DisasContext *ctx) |
76a66253 | 4840 | { |
7487953d AJ |
4841 | TCGv t0 = tcg_temp_new(); |
4842 | TCGv t1 = tcg_temp_new(); | |
4843 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4844 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4845 | tcg_gen_subfi_tl(t1, 32, t1); | |
4846 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4847 | tcg_gen_or_tl(t1, t0, t1); | |
4848 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4849 | gen_store_spr(SPR_MQ, t1); | |
4850 | tcg_temp_free(t0); | |
4851 | tcg_temp_free(t1); | |
76a66253 | 4852 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4853 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4854 | } |
4855 | ||
4856 | /* sleq - sleq. */ | |
99e300ef | 4857 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 4858 | { |
7487953d AJ |
4859 | TCGv t0 = tcg_temp_new(); |
4860 | TCGv t1 = tcg_temp_new(); | |
4861 | TCGv t2 = tcg_temp_new(); | |
4862 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4863 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
4864 | tcg_gen_shl_tl(t2, t2, t0); | |
4865 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4866 | gen_load_spr(t1, SPR_MQ); | |
4867 | gen_store_spr(SPR_MQ, t0); | |
4868 | tcg_gen_and_tl(t0, t0, t2); | |
4869 | tcg_gen_andc_tl(t1, t1, t2); | |
4870 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4871 | tcg_temp_free(t0); | |
4872 | tcg_temp_free(t1); | |
4873 | tcg_temp_free(t2); | |
76a66253 | 4874 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4875 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4876 | } |
4877 | ||
4878 | /* sliq - sliq. */ | |
99e300ef | 4879 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 4880 | { |
7487953d AJ |
4881 | int sh = SH(ctx->opcode); |
4882 | TCGv t0 = tcg_temp_new(); | |
4883 | TCGv t1 = tcg_temp_new(); | |
4884 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4885 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4886 | tcg_gen_or_tl(t1, t0, t1); | |
4887 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4888 | gen_store_spr(SPR_MQ, t1); | |
4889 | tcg_temp_free(t0); | |
4890 | tcg_temp_free(t1); | |
76a66253 | 4891 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4892 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4893 | } |
4894 | ||
4895 | /* slliq - slliq. */ | |
99e300ef | 4896 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 4897 | { |
7487953d AJ |
4898 | int sh = SH(ctx->opcode); |
4899 | TCGv t0 = tcg_temp_new(); | |
4900 | TCGv t1 = tcg_temp_new(); | |
4901 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4902 | gen_load_spr(t1, SPR_MQ); | |
4903 | gen_store_spr(SPR_MQ, t0); | |
4904 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
4905 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
4906 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4907 | tcg_temp_free(t0); | |
4908 | tcg_temp_free(t1); | |
76a66253 | 4909 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4910 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4911 | } |
4912 | ||
4913 | /* sllq - sllq. */ | |
99e300ef | 4914 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 4915 | { |
7487953d AJ |
4916 | int l1 = gen_new_label(); |
4917 | int l2 = gen_new_label(); | |
4918 | TCGv t0 = tcg_temp_local_new(); | |
4919 | TCGv t1 = tcg_temp_local_new(); | |
4920 | TCGv t2 = tcg_temp_local_new(); | |
4921 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4922 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
4923 | tcg_gen_shl_tl(t1, t1, t2); | |
4924 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4925 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
4926 | gen_load_spr(t0, SPR_MQ); | |
4927 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4928 | tcg_gen_br(l2); | |
4929 | gen_set_label(l1); | |
4930 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4931 | gen_load_spr(t2, SPR_MQ); | |
4932 | tcg_gen_andc_tl(t1, t2, t1); | |
4933 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4934 | gen_set_label(l2); | |
4935 | tcg_temp_free(t0); | |
4936 | tcg_temp_free(t1); | |
4937 | tcg_temp_free(t2); | |
76a66253 | 4938 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4939 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4940 | } |
4941 | ||
4942 | /* slq - slq. */ | |
99e300ef | 4943 | static void gen_slq(DisasContext *ctx) |
76a66253 | 4944 | { |
7487953d AJ |
4945 | int l1 = gen_new_label(); |
4946 | TCGv t0 = tcg_temp_new(); | |
4947 | TCGv t1 = tcg_temp_new(); | |
4948 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4949 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4950 | tcg_gen_subfi_tl(t1, 32, t1); | |
4951 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4952 | tcg_gen_or_tl(t1, t0, t1); | |
4953 | gen_store_spr(SPR_MQ, t1); | |
4954 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4955 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4956 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4957 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
4958 | gen_set_label(l1); | |
4959 | tcg_temp_free(t0); | |
4960 | tcg_temp_free(t1); | |
76a66253 | 4961 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4962 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4963 | } |
4964 | ||
d9bce9d9 | 4965 | /* sraiq - sraiq. */ |
99e300ef | 4966 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 4967 | { |
7487953d AJ |
4968 | int sh = SH(ctx->opcode); |
4969 | int l1 = gen_new_label(); | |
4970 | TCGv t0 = tcg_temp_new(); | |
4971 | TCGv t1 = tcg_temp_new(); | |
4972 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4973 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4974 | tcg_gen_or_tl(t0, t0, t1); | |
4975 | gen_store_spr(SPR_MQ, t0); | |
4976 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
4977 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4978 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
4979 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
4980 | gen_set_label(l1); | |
4981 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
4982 | tcg_temp_free(t0); | |
4983 | tcg_temp_free(t1); | |
76a66253 | 4984 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4985 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4986 | } |
4987 | ||
4988 | /* sraq - sraq. */ | |
99e300ef | 4989 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 4990 | { |
7487953d AJ |
4991 | int l1 = gen_new_label(); |
4992 | int l2 = gen_new_label(); | |
4993 | TCGv t0 = tcg_temp_new(); | |
4994 | TCGv t1 = tcg_temp_local_new(); | |
4995 | TCGv t2 = tcg_temp_local_new(); | |
4996 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4997 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4998 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
4999 | tcg_gen_subfi_tl(t2, 32, t2); | |
5000 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
5001 | tcg_gen_or_tl(t0, t0, t2); | |
5002 | gen_store_spr(SPR_MQ, t0); | |
5003 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5004 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
5005 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
5006 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
5007 | gen_set_label(l1); | |
5008 | tcg_temp_free(t0); | |
5009 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
5010 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
5011 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
5012 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
5013 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
5014 | gen_set_label(l2); | |
5015 | tcg_temp_free(t1); | |
5016 | tcg_temp_free(t2); | |
76a66253 | 5017 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5018 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5019 | } |
5020 | ||
5021 | /* sre - sre. */ | |
99e300ef | 5022 | static void gen_sre(DisasContext *ctx) |
76a66253 | 5023 | { |
7487953d AJ |
5024 | TCGv t0 = tcg_temp_new(); |
5025 | TCGv t1 = tcg_temp_new(); | |
5026 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5027 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5028 | tcg_gen_subfi_tl(t1, 32, t1); | |
5029 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5030 | tcg_gen_or_tl(t1, t0, t1); | |
5031 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5032 | gen_store_spr(SPR_MQ, t1); | |
5033 | tcg_temp_free(t0); | |
5034 | tcg_temp_free(t1); | |
76a66253 | 5035 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5036 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5037 | } |
5038 | ||
5039 | /* srea - srea. */ | |
99e300ef | 5040 | static void gen_srea(DisasContext *ctx) |
76a66253 | 5041 | { |
7487953d AJ |
5042 | TCGv t0 = tcg_temp_new(); |
5043 | TCGv t1 = tcg_temp_new(); | |
5044 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5045 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5046 | gen_store_spr(SPR_MQ, t0); | |
5047 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
5048 | tcg_temp_free(t0); | |
5049 | tcg_temp_free(t1); | |
76a66253 | 5050 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5051 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5052 | } |
5053 | ||
5054 | /* sreq */ | |
99e300ef | 5055 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 5056 | { |
7487953d AJ |
5057 | TCGv t0 = tcg_temp_new(); |
5058 | TCGv t1 = tcg_temp_new(); | |
5059 | TCGv t2 = tcg_temp_new(); | |
5060 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5061 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5062 | tcg_gen_shr_tl(t1, t1, t0); | |
5063 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5064 | gen_load_spr(t2, SPR_MQ); | |
5065 | gen_store_spr(SPR_MQ, t0); | |
5066 | tcg_gen_and_tl(t0, t0, t1); | |
5067 | tcg_gen_andc_tl(t2, t2, t1); | |
5068 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5069 | tcg_temp_free(t0); | |
5070 | tcg_temp_free(t1); | |
5071 | tcg_temp_free(t2); | |
76a66253 | 5072 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5073 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5074 | } |
5075 | ||
5076 | /* sriq */ | |
99e300ef | 5077 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5078 | { |
7487953d AJ |
5079 | int sh = SH(ctx->opcode); |
5080 | TCGv t0 = tcg_temp_new(); | |
5081 | TCGv t1 = tcg_temp_new(); | |
5082 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5083 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5084 | tcg_gen_or_tl(t1, t0, t1); | |
5085 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5086 | gen_store_spr(SPR_MQ, t1); | |
5087 | tcg_temp_free(t0); | |
5088 | tcg_temp_free(t1); | |
76a66253 | 5089 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5090 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5091 | } |
5092 | ||
5093 | /* srliq */ | |
99e300ef | 5094 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5095 | { |
7487953d AJ |
5096 | int sh = SH(ctx->opcode); |
5097 | TCGv t0 = tcg_temp_new(); | |
5098 | TCGv t1 = tcg_temp_new(); | |
5099 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5100 | gen_load_spr(t1, SPR_MQ); | |
5101 | gen_store_spr(SPR_MQ, t0); | |
5102 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5103 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5104 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5105 | tcg_temp_free(t0); | |
5106 | tcg_temp_free(t1); | |
76a66253 | 5107 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5108 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5109 | } |
5110 | ||
5111 | /* srlq */ | |
99e300ef | 5112 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5113 | { |
7487953d AJ |
5114 | int l1 = gen_new_label(); |
5115 | int l2 = gen_new_label(); | |
5116 | TCGv t0 = tcg_temp_local_new(); | |
5117 | TCGv t1 = tcg_temp_local_new(); | |
5118 | TCGv t2 = tcg_temp_local_new(); | |
5119 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5120 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5121 | tcg_gen_shr_tl(t2, t1, t2); | |
5122 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5123 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5124 | gen_load_spr(t0, SPR_MQ); | |
5125 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5126 | tcg_gen_br(l2); | |
5127 | gen_set_label(l1); | |
5128 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5129 | tcg_gen_and_tl(t0, t0, t2); | |
5130 | gen_load_spr(t1, SPR_MQ); | |
5131 | tcg_gen_andc_tl(t1, t1, t2); | |
5132 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5133 | gen_set_label(l2); | |
5134 | tcg_temp_free(t0); | |
5135 | tcg_temp_free(t1); | |
5136 | tcg_temp_free(t2); | |
76a66253 | 5137 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5138 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5139 | } |
5140 | ||
5141 | /* srq */ | |
99e300ef | 5142 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5143 | { |
7487953d AJ |
5144 | int l1 = gen_new_label(); |
5145 | TCGv t0 = tcg_temp_new(); | |
5146 | TCGv t1 = tcg_temp_new(); | |
5147 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5148 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5149 | tcg_gen_subfi_tl(t1, 32, t1); | |
5150 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5151 | tcg_gen_or_tl(t1, t0, t1); | |
5152 | gen_store_spr(SPR_MQ, t1); | |
5153 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5154 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5155 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5156 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5157 | gen_set_label(l1); | |
5158 | tcg_temp_free(t0); | |
5159 | tcg_temp_free(t1); | |
76a66253 | 5160 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5161 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5162 | } |
5163 | ||
5164 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5165 | |
54623277 | 5166 | /* dsa */ |
99e300ef | 5167 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5168 | { |
5169 | /* XXX: TODO */ | |
e06fcd75 | 5170 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5171 | } |
5172 | ||
5173 | /* esa */ | |
99e300ef | 5174 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5175 | { |
5176 | /* XXX: TODO */ | |
e06fcd75 | 5177 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5178 | } |
5179 | ||
5180 | /* mfrom */ | |
99e300ef | 5181 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5182 | { |
5183 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5184 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5185 | #else |
76db3ba4 | 5186 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5187 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5188 | return; |
5189 | } | |
cf02a65c | 5190 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5191 | #endif |
5192 | } | |
5193 | ||
5194 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5195 | |
54623277 | 5196 | /* tlbld */ |
e8eaa2c0 | 5197 | static void gen_tlbld_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_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5207 | #endif |
5208 | } | |
5209 | ||
5210 | /* tlbli */ | |
e8eaa2c0 | 5211 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5212 | { |
5213 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5214 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5215 | #else |
76db3ba4 | 5216 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5217 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5218 | return; |
5219 | } | |
c6c7cf05 | 5220 | gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5221 | #endif |
5222 | } | |
5223 | ||
7dbe11ac | 5224 | /* 74xx TLB management */ |
e8eaa2c0 | 5225 | |
54623277 | 5226 | /* tlbld */ |
e8eaa2c0 | 5227 | static void gen_tlbld_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_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5237 | #endif |
5238 | } | |
5239 | ||
5240 | /* tlbli */ | |
e8eaa2c0 | 5241 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5242 | { |
5243 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5244 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5245 | #else |
76db3ba4 | 5246 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5247 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5248 | return; |
5249 | } | |
c6c7cf05 | 5250 | gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5251 | #endif |
5252 | } | |
5253 | ||
76a66253 | 5254 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5255 | |
54623277 | 5256 | /* clf */ |
99e300ef | 5257 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5258 | { |
5259 | /* Cache line flush: implemented as no-op */ | |
5260 | } | |
5261 | ||
5262 | /* cli */ | |
99e300ef | 5263 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5264 | { |
7f75ffd3 | 5265 | /* Cache line invalidate: privileged and treated as no-op */ |
76a66253 | 5266 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5267 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5268 | #else |
76db3ba4 | 5269 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5270 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5271 | return; |
5272 | } | |
5273 | #endif | |
5274 | } | |
5275 | ||
5276 | /* dclst */ | |
99e300ef | 5277 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5278 | { |
5279 | /* Data cache line store: treated as no-op */ | |
5280 | } | |
5281 | ||
99e300ef | 5282 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5283 | { |
5284 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5285 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5286 | #else |
74d37793 AJ |
5287 | int ra = rA(ctx->opcode); |
5288 | int rd = rD(ctx->opcode); | |
5289 | TCGv t0; | |
76db3ba4 | 5290 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5291 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5292 | return; |
5293 | } | |
74d37793 | 5294 | t0 = tcg_temp_new(); |
76db3ba4 | 5295 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5296 | tcg_gen_shri_tl(t0, t0, 28); |
5297 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 5298 | gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0); |
74d37793 | 5299 | tcg_temp_free(t0); |
76a66253 | 5300 | if (ra != 0 && ra != rd) |
74d37793 | 5301 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
76a66253 JM |
5302 | #endif |
5303 | } | |
5304 | ||
99e300ef | 5305 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5306 | { |
5307 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5308 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5309 | #else |
22e0e173 | 5310 | TCGv t0; |
76db3ba4 | 5311 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5312 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5313 | return; |
5314 | } | |
22e0e173 | 5315 | t0 = tcg_temp_new(); |
76db3ba4 | 5316 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5317 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5318 | tcg_temp_free(t0); |
76a66253 JM |
5319 | #endif |
5320 | } | |
5321 | ||
99e300ef | 5322 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5323 | { |
5324 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5325 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5326 | #else |
76db3ba4 | 5327 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5328 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5329 | return; |
5330 | } | |
e5f17ac6 | 5331 | gen_helper_rfsvc(cpu_env); |
e06fcd75 | 5332 | gen_sync_exception(ctx); |
76a66253 JM |
5333 | #endif |
5334 | } | |
5335 | ||
5336 | /* svc is not implemented for now */ | |
5337 | ||
5338 | /* POWER2 specific instructions */ | |
5339 | /* Quad manipulation (load/store two floats at a time) */ | |
76a66253 JM |
5340 | |
5341 | /* lfq */ | |
99e300ef | 5342 | static void gen_lfq(DisasContext *ctx) |
76a66253 | 5343 | { |
01a4afeb | 5344 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5345 | TCGv t0; |
5346 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5347 | t0 = tcg_temp_new(); | |
5348 | gen_addr_imm_index(ctx, t0, 0); | |
5349 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5350 | gen_addr_add(ctx, t0, t0, 8); | |
5351 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5352 | tcg_temp_free(t0); |
76a66253 JM |
5353 | } |
5354 | ||
5355 | /* lfqu */ | |
99e300ef | 5356 | static void gen_lfqu(DisasContext *ctx) |
76a66253 JM |
5357 | { |
5358 | int ra = rA(ctx->opcode); | |
01a4afeb | 5359 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5360 | TCGv t0, t1; |
5361 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5362 | t0 = tcg_temp_new(); | |
5363 | t1 = tcg_temp_new(); | |
5364 | gen_addr_imm_index(ctx, t0, 0); | |
5365 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5366 | gen_addr_add(ctx, t1, t0, 8); | |
5367 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
76a66253 | 5368 | if (ra != 0) |
01a4afeb AJ |
5369 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5370 | tcg_temp_free(t0); | |
5371 | tcg_temp_free(t1); | |
76a66253 JM |
5372 | } |
5373 | ||
5374 | /* lfqux */ | |
99e300ef | 5375 | static void gen_lfqux(DisasContext *ctx) |
76a66253 JM |
5376 | { |
5377 | int ra = rA(ctx->opcode); | |
01a4afeb | 5378 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5379 | gen_set_access_type(ctx, ACCESS_FLOAT); |
5380 | TCGv t0, t1; | |
5381 | t0 = tcg_temp_new(); | |
5382 | gen_addr_reg_index(ctx, t0); | |
5383 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5384 | t1 = tcg_temp_new(); | |
5385 | gen_addr_add(ctx, t1, t0, 8); | |
5386 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5387 | tcg_temp_free(t1); | |
76a66253 | 5388 | if (ra != 0) |
01a4afeb AJ |
5389 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5390 | tcg_temp_free(t0); | |
76a66253 JM |
5391 | } |
5392 | ||
5393 | /* lfqx */ | |
99e300ef | 5394 | static void gen_lfqx(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_reg_index(ctx, t0); | |
5401 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5402 | gen_addr_add(ctx, t0, t0, 8); | |
5403 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5404 | tcg_temp_free(t0); |
76a66253 JM |
5405 | } |
5406 | ||
5407 | /* stfq */ | |
99e300ef | 5408 | static void gen_stfq(DisasContext *ctx) |
76a66253 | 5409 | { |
01a4afeb | 5410 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5411 | TCGv t0; |
5412 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5413 | t0 = tcg_temp_new(); | |
5414 | gen_addr_imm_index(ctx, t0, 0); | |
5415 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5416 | gen_addr_add(ctx, t0, t0, 8); | |
5417 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5418 | tcg_temp_free(t0); |
76a66253 JM |
5419 | } |
5420 | ||
5421 | /* stfqu */ | |
99e300ef | 5422 | static void gen_stfqu(DisasContext *ctx) |
76a66253 JM |
5423 | { |
5424 | int ra = rA(ctx->opcode); | |
01a4afeb | 5425 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5426 | TCGv t0, t1; |
5427 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5428 | t0 = tcg_temp_new(); | |
5429 | gen_addr_imm_index(ctx, t0, 0); | |
5430 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5431 | t1 = tcg_temp_new(); | |
5432 | gen_addr_add(ctx, t1, t0, 8); | |
5433 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5434 | tcg_temp_free(t1); | |
76a66253 | 5435 | if (ra != 0) |
01a4afeb AJ |
5436 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5437 | tcg_temp_free(t0); | |
76a66253 JM |
5438 | } |
5439 | ||
5440 | /* stfqux */ | |
99e300ef | 5441 | static void gen_stfqux(DisasContext *ctx) |
76a66253 JM |
5442 | { |
5443 | int ra = rA(ctx->opcode); | |
01a4afeb | 5444 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5445 | TCGv t0, t1; |
5446 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5447 | t0 = tcg_temp_new(); | |
5448 | gen_addr_reg_index(ctx, t0); | |
5449 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5450 | t1 = tcg_temp_new(); | |
5451 | gen_addr_add(ctx, t1, t0, 8); | |
5452 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5453 | tcg_temp_free(t1); | |
76a66253 | 5454 | if (ra != 0) |
01a4afeb AJ |
5455 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5456 | tcg_temp_free(t0); | |
76a66253 JM |
5457 | } |
5458 | ||
5459 | /* stfqx */ | |
99e300ef | 5460 | static void gen_stfqx(DisasContext *ctx) |
76a66253 | 5461 | { |
01a4afeb | 5462 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5463 | TCGv t0; |
5464 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5465 | t0 = tcg_temp_new(); | |
5466 | gen_addr_reg_index(ctx, t0); | |
5467 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5468 | gen_addr_add(ctx, t0, t0, 8); | |
5469 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5470 | tcg_temp_free(t0); |
76a66253 JM |
5471 | } |
5472 | ||
5473 | /* BookE specific instructions */ | |
99e300ef | 5474 | |
54623277 | 5475 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5476 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5477 | { |
5478 | /* XXX: TODO */ | |
e06fcd75 | 5479 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5480 | } |
5481 | ||
2662a059 | 5482 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5483 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5484 | { |
5485 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5486 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5487 | #else |
74d37793 | 5488 | TCGv t0; |
76db3ba4 | 5489 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5490 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5491 | return; |
5492 | } | |
ec72e276 | 5493 | t0 = tcg_temp_new(); |
76db3ba4 | 5494 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5495 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
74d37793 | 5496 | tcg_temp_free(t0); |
76a66253 JM |
5497 | #endif |
5498 | } | |
5499 | ||
5500 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5501 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5502 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5503 | { |
182608d4 AJ |
5504 | TCGv t0, t1; |
5505 | ||
a7812ae4 PB |
5506 | t0 = tcg_temp_local_new(); |
5507 | t1 = tcg_temp_local_new(); | |
182608d4 | 5508 | |
76a66253 JM |
5509 | switch (opc3 & 0x0D) { |
5510 | case 0x05: | |
5511 | /* macchw - macchw. - macchwo - macchwo. */ | |
5512 | /* macchws - macchws. - macchwso - macchwso. */ | |
5513 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5514 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5515 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5516 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5517 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5518 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5519 | break; |
5520 | case 0x04: | |
5521 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5522 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5523 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5524 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5525 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5526 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5527 | break; |
5528 | case 0x01: | |
5529 | /* machhw - machhw. - machhwo - machhwo. */ | |
5530 | /* machhws - machhws. - machhwso - machhwso. */ | |
5531 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5532 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5533 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5534 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5535 | tcg_gen_ext16s_tl(t0, t0); | |
5536 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5537 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5538 | break; |
5539 | case 0x00: | |
5540 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5541 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5542 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5543 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5544 | tcg_gen_ext16u_tl(t0, t0); | |
5545 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5546 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5547 | break; |
5548 | case 0x0D: | |
5549 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5550 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5551 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5552 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5553 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5554 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5555 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5556 | break; |
5557 | case 0x0C: | |
5558 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5559 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5560 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5561 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5562 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5563 | break; |
5564 | } | |
76a66253 | 5565 | if (opc2 & 0x04) { |
182608d4 AJ |
5566 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5567 | tcg_gen_mul_tl(t1, t0, t1); | |
5568 | if (opc2 & 0x02) { | |
5569 | /* nmultiply-and-accumulate (0x0E) */ | |
5570 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5571 | } else { | |
5572 | /* multiply-and-accumulate (0x0C) */ | |
5573 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5574 | } | |
5575 | ||
5576 | if (opc3 & 0x12) { | |
5577 | /* Check overflow and/or saturate */ | |
5578 | int l1 = gen_new_label(); | |
5579 | ||
5580 | if (opc3 & 0x10) { | |
5581 | /* Start with XER OV disabled, the most likely case */ | |
5582 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
5583 | } | |
5584 | if (opc3 & 0x01) { | |
5585 | /* Signed */ | |
5586 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5587 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5588 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5589 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5590 | if (opc3 & 0x02) { |
182608d4 AJ |
5591 | /* Saturate */ |
5592 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5593 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5594 | } | |
5595 | } else { | |
5596 | /* Unsigned */ | |
5597 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5598 | if (opc3 & 0x02) { |
182608d4 AJ |
5599 | /* Saturate */ |
5600 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5601 | } | |
5602 | } | |
5603 | if (opc3 & 0x10) { | |
5604 | /* Check overflow */ | |
5605 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
5606 | } | |
5607 | gen_set_label(l1); | |
5608 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5609 | } | |
5610 | } else { | |
5611 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5612 | } |
182608d4 AJ |
5613 | tcg_temp_free(t0); |
5614 | tcg_temp_free(t1); | |
76a66253 JM |
5615 | if (unlikely(Rc) != 0) { |
5616 | /* Update Rc0 */ | |
182608d4 | 5617 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5618 | } |
5619 | } | |
5620 | ||
a750fc0b | 5621 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5622 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5623 | { \ |
5624 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5625 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5626 | } | |
5627 | ||
5628 | /* macchw - macchw. */ | |
a750fc0b | 5629 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5630 | /* macchwo - macchwo. */ |
a750fc0b | 5631 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5632 | /* macchws - macchws. */ |
a750fc0b | 5633 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5634 | /* macchwso - macchwso. */ |
a750fc0b | 5635 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5636 | /* macchwsu - macchwsu. */ |
a750fc0b | 5637 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5638 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5639 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5640 | /* macchwu - macchwu. */ |
a750fc0b | 5641 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5642 | /* macchwuo - macchwuo. */ |
a750fc0b | 5643 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 5644 | /* machhw - machhw. */ |
a750fc0b | 5645 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 5646 | /* machhwo - machhwo. */ |
a750fc0b | 5647 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 5648 | /* machhws - machhws. */ |
a750fc0b | 5649 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 5650 | /* machhwso - machhwso. */ |
a750fc0b | 5651 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 5652 | /* machhwsu - machhwsu. */ |
a750fc0b | 5653 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 5654 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 5655 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 5656 | /* machhwu - machhwu. */ |
a750fc0b | 5657 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 5658 | /* machhwuo - machhwuo. */ |
a750fc0b | 5659 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 5660 | /* maclhw - maclhw. */ |
a750fc0b | 5661 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 5662 | /* maclhwo - maclhwo. */ |
a750fc0b | 5663 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 5664 | /* maclhws - maclhws. */ |
a750fc0b | 5665 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 5666 | /* maclhwso - maclhwso. */ |
a750fc0b | 5667 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 5668 | /* maclhwu - maclhwu. */ |
a750fc0b | 5669 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 5670 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 5671 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 5672 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 5673 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 5674 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 5675 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 5676 | /* nmacchw - nmacchw. */ |
a750fc0b | 5677 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 5678 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 5679 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 5680 | /* nmacchws - nmacchws. */ |
a750fc0b | 5681 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 5682 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 5683 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 5684 | /* nmachhw - nmachhw. */ |
a750fc0b | 5685 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 5686 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 5687 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 5688 | /* nmachhws - nmachhws. */ |
a750fc0b | 5689 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 5690 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 5691 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 5692 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 5693 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 5694 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 5695 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 5696 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 5697 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 5698 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 5699 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
5700 | |
5701 | /* mulchw - mulchw. */ | |
a750fc0b | 5702 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 5703 | /* mulchwu - mulchwu. */ |
a750fc0b | 5704 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 5705 | /* mulhhw - mulhhw. */ |
a750fc0b | 5706 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 5707 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 5708 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 5709 | /* mullhw - mullhw. */ |
a750fc0b | 5710 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 5711 | /* mullhwu - mullhwu. */ |
a750fc0b | 5712 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
5713 | |
5714 | /* mfdcr */ | |
99e300ef | 5715 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
5716 | { |
5717 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5718 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5719 | #else |
06dca6a7 | 5720 | TCGv dcrn; |
76db3ba4 | 5721 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5722 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5723 | return; |
5724 | } | |
06dca6a7 AJ |
5725 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5726 | gen_update_nip(ctx, ctx->nip - 4); | |
5727 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5728 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn); |
06dca6a7 | 5729 | tcg_temp_free(dcrn); |
76a66253 JM |
5730 | #endif |
5731 | } | |
5732 | ||
5733 | /* mtdcr */ | |
99e300ef | 5734 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
5735 | { |
5736 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5737 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5738 | #else |
06dca6a7 | 5739 | TCGv dcrn; |
76db3ba4 | 5740 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5741 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5742 | return; |
5743 | } | |
06dca6a7 AJ |
5744 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5745 | gen_update_nip(ctx, ctx->nip - 4); | |
5746 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5747 | gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]); |
06dca6a7 | 5748 | tcg_temp_free(dcrn); |
a42bd6cc JM |
5749 | #endif |
5750 | } | |
5751 | ||
5752 | /* mfdcrx */ | |
2662a059 | 5753 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5754 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
5755 | { |
5756 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5757 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5758 | #else |
76db3ba4 | 5759 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5760 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5761 | return; |
5762 | } | |
06dca6a7 AJ |
5763 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5764 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5765 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5766 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 5767 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
a42bd6cc JM |
5768 | #endif |
5769 | } | |
5770 | ||
5771 | /* mtdcrx */ | |
2662a059 | 5772 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5773 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
5774 | { |
5775 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5776 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5777 | #else |
76db3ba4 | 5778 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5779 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5780 | return; |
5781 | } | |
06dca6a7 AJ |
5782 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5783 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5784 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
5785 | cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 5786 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
76a66253 JM |
5787 | #endif |
5788 | } | |
5789 | ||
a750fc0b | 5790 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 5791 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 5792 | { |
06dca6a7 AJ |
5793 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5794 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
5795 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5796 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
5797 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5798 | } | |
5799 | ||
5800 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 5801 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 5802 | { |
06dca6a7 AJ |
5803 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5804 | gen_update_nip(ctx, ctx->nip - 4); | |
975e5463 | 5805 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
d0f1562d | 5806 | cpu_gpr[rS(ctx->opcode)]); |
a750fc0b JM |
5807 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5808 | } | |
5809 | ||
76a66253 | 5810 | /* dccci */ |
99e300ef | 5811 | static void gen_dccci(DisasContext *ctx) |
76a66253 JM |
5812 | { |
5813 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5814 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5815 | #else |
76db3ba4 | 5816 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5817 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5818 | return; |
5819 | } | |
5820 | /* interpreted as no-op */ | |
5821 | #endif | |
5822 | } | |
5823 | ||
5824 | /* dcread */ | |
99e300ef | 5825 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
5826 | { |
5827 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5828 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5829 | #else |
b61f2753 | 5830 | TCGv EA, val; |
76db3ba4 | 5831 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5832 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5833 | return; |
5834 | } | |
76db3ba4 | 5835 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 5836 | EA = tcg_temp_new(); |
76db3ba4 | 5837 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 5838 | val = tcg_temp_new(); |
76db3ba4 | 5839 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
5840 | tcg_temp_free(val); |
5841 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
5842 | tcg_temp_free(EA); | |
76a66253 JM |
5843 | #endif |
5844 | } | |
5845 | ||
5846 | /* icbt */ | |
e8eaa2c0 | 5847 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
5848 | { |
5849 | /* interpreted as no-op */ | |
5850 | /* XXX: specification say this is treated as a load by the MMU | |
5851 | * but does not generate any exception | |
5852 | */ | |
5853 | } | |
5854 | ||
5855 | /* iccci */ | |
99e300ef | 5856 | static void gen_iccci(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 | ||
5869 | /* icread */ | |
99e300ef | 5870 | static void gen_icread(DisasContext *ctx) |
76a66253 JM |
5871 | { |
5872 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5873 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5874 | #else |
76db3ba4 | 5875 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5876 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5877 | return; |
5878 | } | |
5879 | /* interpreted as no-op */ | |
5880 | #endif | |
5881 | } | |
5882 | ||
76db3ba4 | 5883 | /* rfci (mem_idx only) */ |
e8eaa2c0 | 5884 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
5885 | { |
5886 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5887 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5888 | #else |
76db3ba4 | 5889 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5890 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5891 | return; |
5892 | } | |
5893 | /* Restore CPU state */ | |
e5f17ac6 | 5894 | gen_helper_40x_rfci(cpu_env); |
e06fcd75 | 5895 | gen_sync_exception(ctx); |
a42bd6cc JM |
5896 | #endif |
5897 | } | |
5898 | ||
99e300ef | 5899 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
5900 | { |
5901 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5902 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5903 | #else |
76db3ba4 | 5904 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5905 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5906 | return; |
5907 | } | |
5908 | /* Restore CPU state */ | |
e5f17ac6 | 5909 | gen_helper_rfci(cpu_env); |
e06fcd75 | 5910 | gen_sync_exception(ctx); |
a42bd6cc JM |
5911 | #endif |
5912 | } | |
5913 | ||
5914 | /* BookE specific */ | |
99e300ef | 5915 | |
54623277 | 5916 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5917 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
5918 | { |
5919 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5920 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5921 | #else |
76db3ba4 | 5922 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5923 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5924 | return; |
5925 | } | |
5926 | /* Restore CPU state */ | |
e5f17ac6 | 5927 | gen_helper_rfdi(cpu_env); |
e06fcd75 | 5928 | gen_sync_exception(ctx); |
76a66253 JM |
5929 | #endif |
5930 | } | |
5931 | ||
2662a059 | 5932 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5933 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
5934 | { |
5935 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5936 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5937 | #else |
76db3ba4 | 5938 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5939 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5940 | return; |
5941 | } | |
5942 | /* Restore CPU state */ | |
e5f17ac6 | 5943 | gen_helper_rfmci(cpu_env); |
e06fcd75 | 5944 | gen_sync_exception(ctx); |
a42bd6cc JM |
5945 | #endif |
5946 | } | |
5eb7995e | 5947 | |
d9bce9d9 | 5948 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 5949 | |
54623277 | 5950 | /* tlbre */ |
e8eaa2c0 | 5951 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
5952 | { |
5953 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5954 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5955 | #else |
76db3ba4 | 5956 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5957 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5958 | return; |
5959 | } | |
5960 | switch (rB(ctx->opcode)) { | |
5961 | case 0: | |
c6c7cf05 BS |
5962 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5963 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
5964 | break; |
5965 | case 1: | |
c6c7cf05 BS |
5966 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5967 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
5968 | break; |
5969 | default: | |
e06fcd75 | 5970 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 5971 | break; |
9a64fbe4 | 5972 | } |
76a66253 JM |
5973 | #endif |
5974 | } | |
5975 | ||
d9bce9d9 | 5976 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 5977 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
5978 | { |
5979 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5980 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5981 | #else |
74d37793 | 5982 | TCGv t0; |
76db3ba4 | 5983 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5984 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5985 | return; |
5986 | } | |
74d37793 | 5987 | t0 = tcg_temp_new(); |
76db3ba4 | 5988 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5989 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
5990 | tcg_temp_free(t0); |
5991 | if (Rc(ctx->opcode)) { | |
5992 | int l1 = gen_new_label(); | |
5993 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
5994 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
5995 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
5996 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
5997 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
5998 | gen_set_label(l1); | |
5999 | } | |
76a66253 | 6000 | #endif |
79aceca5 FB |
6001 | } |
6002 | ||
76a66253 | 6003 | /* tlbwe */ |
e8eaa2c0 | 6004 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 6005 | { |
76a66253 | 6006 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 6007 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6008 | #else |
76db3ba4 | 6009 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6010 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6011 | return; |
6012 | } | |
6013 | switch (rB(ctx->opcode)) { | |
6014 | case 0: | |
c6c7cf05 BS |
6015 | gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6016 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6017 | break; |
6018 | case 1: | |
c6c7cf05 BS |
6019 | gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6020 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6021 | break; |
6022 | default: | |
e06fcd75 | 6023 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6024 | break; |
9a64fbe4 | 6025 | } |
76a66253 JM |
6026 | #endif |
6027 | } | |
6028 | ||
a4bb6c3e | 6029 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 6030 | |
54623277 | 6031 | /* tlbre */ |
e8eaa2c0 | 6032 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
6033 | { |
6034 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6035 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6036 | #else |
76db3ba4 | 6037 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6038 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6039 | return; |
6040 | } | |
6041 | switch (rB(ctx->opcode)) { | |
6042 | case 0: | |
5eb7995e | 6043 | case 1: |
5eb7995e | 6044 | case 2: |
74d37793 AJ |
6045 | { |
6046 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6047 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6048 | t0, cpu_gpr[rA(ctx->opcode)]); | |
74d37793 AJ |
6049 | tcg_temp_free_i32(t0); |
6050 | } | |
5eb7995e JM |
6051 | break; |
6052 | default: | |
e06fcd75 | 6053 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6054 | break; |
6055 | } | |
6056 | #endif | |
6057 | } | |
6058 | ||
6059 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 6060 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
6061 | { |
6062 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6063 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6064 | #else |
74d37793 | 6065 | TCGv t0; |
76db3ba4 | 6066 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6067 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6068 | return; |
6069 | } | |
74d37793 | 6070 | t0 = tcg_temp_new(); |
76db3ba4 | 6071 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6072 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6073 | tcg_temp_free(t0); |
6074 | if (Rc(ctx->opcode)) { | |
6075 | int l1 = gen_new_label(); | |
6076 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
6077 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
6078 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
6079 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
6080 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6081 | gen_set_label(l1); | |
6082 | } | |
5eb7995e JM |
6083 | #endif |
6084 | } | |
6085 | ||
6086 | /* tlbwe */ | |
e8eaa2c0 | 6087 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6088 | { |
6089 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6090 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6091 | #else |
76db3ba4 | 6092 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6093 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6094 | return; |
6095 | } | |
6096 | switch (rB(ctx->opcode)) { | |
6097 | case 0: | |
5eb7995e | 6098 | case 1: |
5eb7995e | 6099 | case 2: |
74d37793 AJ |
6100 | { |
6101 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6102 | gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)], |
6103 | cpu_gpr[rS(ctx->opcode)]); | |
74d37793 AJ |
6104 | tcg_temp_free_i32(t0); |
6105 | } | |
5eb7995e JM |
6106 | break; |
6107 | default: | |
e06fcd75 | 6108 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6109 | break; |
6110 | } | |
6111 | #endif | |
6112 | } | |
6113 | ||
01662f3e AG |
6114 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6115 | ||
6116 | /* tlbre */ | |
6117 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6118 | { | |
6119 | #if defined(CONFIG_USER_ONLY) | |
6120 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6121 | #else | |
6122 | if (unlikely(!ctx->mem_idx)) { | |
6123 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6124 | return; | |
6125 | } | |
6126 | ||
c6c7cf05 | 6127 | gen_helper_booke206_tlbre(cpu_env); |
01662f3e AG |
6128 | #endif |
6129 | } | |
6130 | ||
6131 | /* tlbsx - tlbsx. */ | |
6132 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6133 | { | |
6134 | #if defined(CONFIG_USER_ONLY) | |
6135 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6136 | #else | |
6137 | TCGv t0; | |
6138 | if (unlikely(!ctx->mem_idx)) { | |
6139 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6140 | return; | |
6141 | } | |
6142 | ||
6143 | if (rA(ctx->opcode)) { | |
6144 | t0 = tcg_temp_new(); | |
6145 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6146 | } else { | |
6147 | t0 = tcg_const_tl(0); | |
6148 | } | |
6149 | ||
6150 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 6151 | gen_helper_booke206_tlbsx(cpu_env, t0); |
01662f3e AG |
6152 | #endif |
6153 | } | |
6154 | ||
6155 | /* tlbwe */ | |
6156 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6157 | { | |
6158 | #if defined(CONFIG_USER_ONLY) | |
6159 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6160 | #else | |
6161 | if (unlikely(!ctx->mem_idx)) { | |
6162 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6163 | return; | |
6164 | } | |
3f162d11 | 6165 | gen_update_nip(ctx, ctx->nip - 4); |
c6c7cf05 | 6166 | gen_helper_booke206_tlbwe(cpu_env); |
01662f3e AG |
6167 | #endif |
6168 | } | |
6169 | ||
6170 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6171 | { | |
6172 | #if defined(CONFIG_USER_ONLY) | |
6173 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6174 | #else | |
6175 | TCGv t0; | |
6176 | if (unlikely(!ctx->mem_idx)) { | |
6177 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6178 | return; | |
6179 | } | |
6180 | ||
6181 | t0 = tcg_temp_new(); | |
6182 | gen_addr_reg_index(ctx, t0); | |
6183 | ||
c6c7cf05 | 6184 | gen_helper_booke206_tlbivax(cpu_env, t0); |
01662f3e AG |
6185 | #endif |
6186 | } | |
6187 | ||
6d3db821 AG |
6188 | static void gen_tlbilx_booke206(DisasContext *ctx) |
6189 | { | |
6190 | #if defined(CONFIG_USER_ONLY) | |
6191 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6192 | #else | |
6193 | TCGv t0; | |
6194 | if (unlikely(!ctx->mem_idx)) { | |
6195 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6196 | return; | |
6197 | } | |
6198 | ||
6199 | t0 = tcg_temp_new(); | |
6200 | gen_addr_reg_index(ctx, t0); | |
6201 | ||
6202 | switch((ctx->opcode >> 21) & 0x3) { | |
6203 | case 0: | |
c6c7cf05 | 6204 | gen_helper_booke206_tlbilx0(cpu_env, t0); |
6d3db821 AG |
6205 | break; |
6206 | case 1: | |
c6c7cf05 | 6207 | gen_helper_booke206_tlbilx1(cpu_env, t0); |
6d3db821 AG |
6208 | break; |
6209 | case 3: | |
c6c7cf05 | 6210 | gen_helper_booke206_tlbilx3(cpu_env, t0); |
6d3db821 AG |
6211 | break; |
6212 | default: | |
6213 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6214 | break; | |
6215 | } | |
6216 | ||
6217 | tcg_temp_free(t0); | |
6218 | #endif | |
6219 | } | |
6220 | ||
01662f3e | 6221 | |
76a66253 | 6222 | /* wrtee */ |
99e300ef | 6223 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6224 | { |
6225 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6226 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6227 | #else |
6527f6ea | 6228 | TCGv t0; |
76db3ba4 | 6229 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6230 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6231 | return; |
6232 | } | |
6527f6ea AJ |
6233 | t0 = tcg_temp_new(); |
6234 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6235 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6236 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6237 | tcg_temp_free(t0); | |
dee96f6c JM |
6238 | /* Stop translation to have a chance to raise an exception |
6239 | * if we just set msr_ee to 1 | |
6240 | */ | |
e06fcd75 | 6241 | gen_stop_exception(ctx); |
76a66253 JM |
6242 | #endif |
6243 | } | |
6244 | ||
6245 | /* wrteei */ | |
99e300ef | 6246 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6247 | { |
6248 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6249 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6250 | #else |
76db3ba4 | 6251 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6252 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6253 | return; |
6254 | } | |
fbe73008 | 6255 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6256 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6257 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6258 | gen_stop_exception(ctx); |
6527f6ea | 6259 | } else { |
1b6e5f99 | 6260 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6261 | } |
76a66253 JM |
6262 | #endif |
6263 | } | |
6264 | ||
08e46e54 | 6265 | /* PowerPC 440 specific instructions */ |
99e300ef | 6266 | |
54623277 | 6267 | /* dlmzb */ |
99e300ef | 6268 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6269 | { |
ef0d51af | 6270 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
d15f74fb BS |
6271 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env, |
6272 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); | |
ef0d51af | 6273 | tcg_temp_free_i32(t0); |
76a66253 JM |
6274 | } |
6275 | ||
6276 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6277 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6278 | { |
6279 | /* interpreted as no-op */ | |
6280 | } | |
6281 | ||
6282 | /* msync replaces sync on 440 */ | |
dcb2b9e1 | 6283 | static void gen_msync_4xx(DisasContext *ctx) |
76a66253 JM |
6284 | { |
6285 | /* interpreted as no-op */ | |
6286 | } | |
6287 | ||
6288 | /* icbt */ | |
e8eaa2c0 | 6289 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6290 | { |
6291 | /* interpreted as no-op */ | |
6292 | /* XXX: specification say this is treated as a load by the MMU | |
6293 | * but does not generate any exception | |
6294 | */ | |
79aceca5 FB |
6295 | } |
6296 | ||
9e0b5cb1 AG |
6297 | /* Embedded.Processor Control */ |
6298 | ||
6299 | static void gen_msgclr(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 | ||
e5f17ac6 | 6309 | gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9e0b5cb1 AG |
6310 | #endif |
6311 | } | |
6312 | ||
d5d11a39 AG |
6313 | static void gen_msgsnd(DisasContext *ctx) |
6314 | { | |
6315 | #if defined(CONFIG_USER_ONLY) | |
6316 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6317 | #else | |
6318 | if (unlikely(ctx->mem_idx == 0)) { | |
6319 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6320 | return; | |
6321 | } | |
6322 | ||
6323 | gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6324 | #endif | |
6325 | } | |
6326 | ||
a9d9eb8f JM |
6327 | /*** Altivec vector extension ***/ |
6328 | /* Altivec registers moves */ | |
a9d9eb8f | 6329 | |
636aa200 | 6330 | static inline TCGv_ptr gen_avr_ptr(int reg) |
564e571a | 6331 | { |
e4704b3b | 6332 | TCGv_ptr r = tcg_temp_new_ptr(); |
564e571a AJ |
6333 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg])); |
6334 | return r; | |
6335 | } | |
6336 | ||
a9d9eb8f | 6337 | #define GEN_VR_LDX(name, opc2, opc3) \ |
99e300ef | 6338 | static void glue(gen_, name)(DisasContext *ctx) \ |
a9d9eb8f | 6339 | { \ |
fe1e5c53 | 6340 | TCGv EA; \ |
a9d9eb8f | 6341 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6342 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6343 | return; \ |
6344 | } \ | |
76db3ba4 | 6345 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6346 | EA = tcg_temp_new(); \ |
76db3ba4 | 6347 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6348 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6349 | if (ctx->le_mode) { \ |
6350 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6351 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6352 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6353 | } else { \ |
76db3ba4 | 6354 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6355 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6356 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6357 | } \ |
6358 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6359 | } |
6360 | ||
6361 | #define GEN_VR_STX(name, opc2, opc3) \ | |
99e300ef | 6362 | static void gen_st##name(DisasContext *ctx) \ |
a9d9eb8f | 6363 | { \ |
fe1e5c53 | 6364 | TCGv EA; \ |
a9d9eb8f | 6365 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6366 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6367 | return; \ |
6368 | } \ | |
76db3ba4 | 6369 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6370 | EA = tcg_temp_new(); \ |
76db3ba4 | 6371 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6372 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6373 | if (ctx->le_mode) { \ |
6374 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6375 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6376 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6377 | } else { \ |
76db3ba4 | 6378 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6379 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6380 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6381 | } \ |
6382 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6383 | } |
6384 | ||
cbfb6ae9 | 6385 | #define GEN_VR_LVE(name, opc2, opc3) \ |
99e300ef | 6386 | static void gen_lve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6387 | { \ |
6388 | TCGv EA; \ | |
6389 | TCGv_ptr rs; \ | |
6390 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6391 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6392 | return; \ | |
6393 | } \ | |
6394 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6395 | EA = tcg_temp_new(); \ | |
6396 | gen_addr_reg_index(ctx, EA); \ | |
6397 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6398 | gen_helper_lve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6399 | tcg_temp_free(EA); \ |
6400 | tcg_temp_free_ptr(rs); \ | |
6401 | } | |
6402 | ||
6403 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
99e300ef | 6404 | static void gen_stve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6405 | { \ |
6406 | TCGv EA; \ | |
6407 | TCGv_ptr rs; \ | |
6408 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6409 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6410 | return; \ | |
6411 | } \ | |
6412 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6413 | EA = tcg_temp_new(); \ | |
6414 | gen_addr_reg_index(ctx, EA); \ | |
6415 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6416 | gen_helper_stve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6417 | tcg_temp_free(EA); \ |
6418 | tcg_temp_free_ptr(rs); \ | |
6419 | } | |
6420 | ||
fe1e5c53 | 6421 | GEN_VR_LDX(lvx, 0x07, 0x03); |
a9d9eb8f | 6422 | /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */ |
fe1e5c53 | 6423 | GEN_VR_LDX(lvxl, 0x07, 0x0B); |
a9d9eb8f | 6424 | |
cbfb6ae9 AJ |
6425 | GEN_VR_LVE(bx, 0x07, 0x00); |
6426 | GEN_VR_LVE(hx, 0x07, 0x01); | |
6427 | GEN_VR_LVE(wx, 0x07, 0x02); | |
6428 | ||
fe1e5c53 | 6429 | GEN_VR_STX(svx, 0x07, 0x07); |
a9d9eb8f | 6430 | /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */ |
fe1e5c53 | 6431 | GEN_VR_STX(svxl, 0x07, 0x0F); |
a9d9eb8f | 6432 | |
cbfb6ae9 AJ |
6433 | GEN_VR_STVE(bx, 0x07, 0x04); |
6434 | GEN_VR_STVE(hx, 0x07, 0x05); | |
6435 | GEN_VR_STVE(wx, 0x07, 0x06); | |
6436 | ||
99e300ef | 6437 | static void gen_lvsl(DisasContext *ctx) |
bf8d8ded AJ |
6438 | { |
6439 | TCGv_ptr rd; | |
6440 | TCGv EA; | |
6441 | if (unlikely(!ctx->altivec_enabled)) { | |
6442 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6443 | return; | |
6444 | } | |
6445 | EA = tcg_temp_new(); | |
6446 | gen_addr_reg_index(ctx, EA); | |
6447 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6448 | gen_helper_lvsl(rd, EA); | |
6449 | tcg_temp_free(EA); | |
6450 | tcg_temp_free_ptr(rd); | |
6451 | } | |
6452 | ||
99e300ef | 6453 | static void gen_lvsr(DisasContext *ctx) |
bf8d8ded AJ |
6454 | { |
6455 | TCGv_ptr rd; | |
6456 | TCGv EA; | |
6457 | if (unlikely(!ctx->altivec_enabled)) { | |
6458 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6459 | return; | |
6460 | } | |
6461 | EA = tcg_temp_new(); | |
6462 | gen_addr_reg_index(ctx, EA); | |
6463 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6464 | gen_helper_lvsr(rd, EA); | |
6465 | tcg_temp_free(EA); | |
6466 | tcg_temp_free_ptr(rd); | |
6467 | } | |
6468 | ||
99e300ef | 6469 | static void gen_mfvscr(DisasContext *ctx) |
785f451b AJ |
6470 | { |
6471 | TCGv_i32 t; | |
6472 | if (unlikely(!ctx->altivec_enabled)) { | |
6473 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6474 | return; | |
6475 | } | |
6476 | tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0); | |
6477 | t = tcg_temp_new_i32(); | |
1328c2bf | 6478 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr)); |
785f451b | 6479 | tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t); |
fce5ecb7 | 6480 | tcg_temp_free_i32(t); |
785f451b AJ |
6481 | } |
6482 | ||
99e300ef | 6483 | static void gen_mtvscr(DisasContext *ctx) |
785f451b | 6484 | { |
6e87b7c7 | 6485 | TCGv_ptr p; |
785f451b AJ |
6486 | if (unlikely(!ctx->altivec_enabled)) { |
6487 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6488 | return; | |
6489 | } | |
6e87b7c7 | 6490 | p = gen_avr_ptr(rD(ctx->opcode)); |
d15f74fb | 6491 | gen_helper_mtvscr(cpu_env, p); |
6e87b7c7 | 6492 | tcg_temp_free_ptr(p); |
785f451b AJ |
6493 | } |
6494 | ||
7a9b96cf AJ |
6495 | /* Logical operations */ |
6496 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
99e300ef | 6497 | static void glue(gen_, name)(DisasContext *ctx) \ |
7a9b96cf AJ |
6498 | { \ |
6499 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6500 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6501 | return; \ | |
6502 | } \ | |
6503 | tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \ | |
6504 | tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \ | |
6505 | } | |
6506 | ||
6507 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16); | |
6508 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17); | |
6509 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18); | |
6510 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19); | |
6511 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20); | |
6512 | ||
8e27dd6f | 6513 | #define GEN_VXFORM(name, opc2, opc3) \ |
99e300ef | 6514 | static void glue(gen_, name)(DisasContext *ctx) \ |
8e27dd6f AJ |
6515 | { \ |
6516 | TCGv_ptr ra, rb, rd; \ | |
6517 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6518 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6519 | return; \ | |
6520 | } \ | |
6521 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6522 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6523 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6524 | gen_helper_##name (rd, ra, rb); \ | |
6525 | tcg_temp_free_ptr(ra); \ | |
6526 | tcg_temp_free_ptr(rb); \ | |
6527 | tcg_temp_free_ptr(rd); \ | |
6528 | } | |
6529 | ||
d15f74fb BS |
6530 | #define GEN_VXFORM_ENV(name, opc2, opc3) \ |
6531 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6532 | { \ | |
6533 | TCGv_ptr ra, rb, rd; \ | |
6534 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6535 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6536 | return; \ | |
6537 | } \ | |
6538 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6539 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6540 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
54cddd21 | 6541 | gen_helper_##name(cpu_env, rd, ra, rb); \ |
d15f74fb BS |
6542 | tcg_temp_free_ptr(ra); \ |
6543 | tcg_temp_free_ptr(rb); \ | |
6544 | tcg_temp_free_ptr(rd); \ | |
6545 | } | |
6546 | ||
7872c51c AJ |
6547 | GEN_VXFORM(vaddubm, 0, 0); |
6548 | GEN_VXFORM(vadduhm, 0, 1); | |
6549 | GEN_VXFORM(vadduwm, 0, 2); | |
6550 | GEN_VXFORM(vsububm, 0, 16); | |
6551 | GEN_VXFORM(vsubuhm, 0, 17); | |
6552 | GEN_VXFORM(vsubuwm, 0, 18); | |
e4039339 AJ |
6553 | GEN_VXFORM(vmaxub, 1, 0); |
6554 | GEN_VXFORM(vmaxuh, 1, 1); | |
6555 | GEN_VXFORM(vmaxuw, 1, 2); | |
6556 | GEN_VXFORM(vmaxsb, 1, 4); | |
6557 | GEN_VXFORM(vmaxsh, 1, 5); | |
6558 | GEN_VXFORM(vmaxsw, 1, 6); | |
6559 | GEN_VXFORM(vminub, 1, 8); | |
6560 | GEN_VXFORM(vminuh, 1, 9); | |
6561 | GEN_VXFORM(vminuw, 1, 10); | |
6562 | GEN_VXFORM(vminsb, 1, 12); | |
6563 | GEN_VXFORM(vminsh, 1, 13); | |
6564 | GEN_VXFORM(vminsw, 1, 14); | |
fab3cbe9 AJ |
6565 | GEN_VXFORM(vavgub, 1, 16); |
6566 | GEN_VXFORM(vavguh, 1, 17); | |
6567 | GEN_VXFORM(vavguw, 1, 18); | |
6568 | GEN_VXFORM(vavgsb, 1, 20); | |
6569 | GEN_VXFORM(vavgsh, 1, 21); | |
6570 | GEN_VXFORM(vavgsw, 1, 22); | |
3b430048 AJ |
6571 | GEN_VXFORM(vmrghb, 6, 0); |
6572 | GEN_VXFORM(vmrghh, 6, 1); | |
6573 | GEN_VXFORM(vmrghw, 6, 2); | |
6574 | GEN_VXFORM(vmrglb, 6, 4); | |
6575 | GEN_VXFORM(vmrglh, 6, 5); | |
6576 | GEN_VXFORM(vmrglw, 6, 6); | |
2c277908 AJ |
6577 | GEN_VXFORM(vmuloub, 4, 0); |
6578 | GEN_VXFORM(vmulouh, 4, 1); | |
6579 | GEN_VXFORM(vmulosb, 4, 4); | |
6580 | GEN_VXFORM(vmulosh, 4, 5); | |
6581 | GEN_VXFORM(vmuleub, 4, 8); | |
6582 | GEN_VXFORM(vmuleuh, 4, 9); | |
6583 | GEN_VXFORM(vmulesb, 4, 12); | |
6584 | GEN_VXFORM(vmulesh, 4, 13); | |
d79f0809 AJ |
6585 | GEN_VXFORM(vslb, 2, 4); |
6586 | GEN_VXFORM(vslh, 2, 5); | |
6587 | GEN_VXFORM(vslw, 2, 6); | |
07ef34c3 AJ |
6588 | GEN_VXFORM(vsrb, 2, 8); |
6589 | GEN_VXFORM(vsrh, 2, 9); | |
6590 | GEN_VXFORM(vsrw, 2, 10); | |
6591 | GEN_VXFORM(vsrab, 2, 12); | |
6592 | GEN_VXFORM(vsrah, 2, 13); | |
6593 | GEN_VXFORM(vsraw, 2, 14); | |
7b239bec AJ |
6594 | GEN_VXFORM(vslo, 6, 16); |
6595 | GEN_VXFORM(vsro, 6, 17); | |
e343da72 AJ |
6596 | GEN_VXFORM(vaddcuw, 0, 6); |
6597 | GEN_VXFORM(vsubcuw, 0, 22); | |
d15f74fb BS |
6598 | GEN_VXFORM_ENV(vaddubs, 0, 8); |
6599 | GEN_VXFORM_ENV(vadduhs, 0, 9); | |
6600 | GEN_VXFORM_ENV(vadduws, 0, 10); | |
6601 | GEN_VXFORM_ENV(vaddsbs, 0, 12); | |
6602 | GEN_VXFORM_ENV(vaddshs, 0, 13); | |
6603 | GEN_VXFORM_ENV(vaddsws, 0, 14); | |
6604 | GEN_VXFORM_ENV(vsububs, 0, 24); | |
6605 | GEN_VXFORM_ENV(vsubuhs, 0, 25); | |
6606 | GEN_VXFORM_ENV(vsubuws, 0, 26); | |
6607 | GEN_VXFORM_ENV(vsubsbs, 0, 28); | |
6608 | GEN_VXFORM_ENV(vsubshs, 0, 29); | |
6609 | GEN_VXFORM_ENV(vsubsws, 0, 30); | |
5e1d0985 AJ |
6610 | GEN_VXFORM(vrlb, 2, 0); |
6611 | GEN_VXFORM(vrlh, 2, 1); | |
6612 | GEN_VXFORM(vrlw, 2, 2); | |
d9430add AJ |
6613 | GEN_VXFORM(vsl, 2, 7); |
6614 | GEN_VXFORM(vsr, 2, 11); | |
d15f74fb BS |
6615 | GEN_VXFORM_ENV(vpkuhum, 7, 0); |
6616 | GEN_VXFORM_ENV(vpkuwum, 7, 1); | |
6617 | GEN_VXFORM_ENV(vpkuhus, 7, 2); | |
6618 | GEN_VXFORM_ENV(vpkuwus, 7, 3); | |
6619 | GEN_VXFORM_ENV(vpkshus, 7, 4); | |
6620 | GEN_VXFORM_ENV(vpkswus, 7, 5); | |
6621 | GEN_VXFORM_ENV(vpkshss, 7, 6); | |
6622 | GEN_VXFORM_ENV(vpkswss, 7, 7); | |
1dd9ffb9 | 6623 | GEN_VXFORM(vpkpx, 7, 12); |
d15f74fb BS |
6624 | GEN_VXFORM_ENV(vsum4ubs, 4, 24); |
6625 | GEN_VXFORM_ENV(vsum4sbs, 4, 28); | |
6626 | GEN_VXFORM_ENV(vsum4shs, 4, 25); | |
6627 | GEN_VXFORM_ENV(vsum2sws, 4, 26); | |
6628 | GEN_VXFORM_ENV(vsumsws, 4, 30); | |
6629 | GEN_VXFORM_ENV(vaddfp, 5, 0); | |
6630 | GEN_VXFORM_ENV(vsubfp, 5, 1); | |
6631 | GEN_VXFORM_ENV(vmaxfp, 5, 16); | |
6632 | GEN_VXFORM_ENV(vminfp, 5, 17); | |
fab3cbe9 | 6633 | |
0cbcd906 | 6634 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ |
e8eaa2c0 | 6635 | static void glue(gen_, name)(DisasContext *ctx) \ |
0cbcd906 AJ |
6636 | { \ |
6637 | TCGv_ptr ra, rb, rd; \ | |
6638 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6639 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6640 | return; \ | |
6641 | } \ | |
6642 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6643 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6644 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
d15f74fb | 6645 | gen_helper_##opname(cpu_env, rd, ra, rb); \ |
0cbcd906 AJ |
6646 | tcg_temp_free_ptr(ra); \ |
6647 | tcg_temp_free_ptr(rb); \ | |
6648 | tcg_temp_free_ptr(rd); \ | |
6649 | } | |
6650 | ||
6651 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
6652 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
6653 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
6654 | ||
1add6e23 AJ |
6655 | GEN_VXRFORM(vcmpequb, 3, 0) |
6656 | GEN_VXRFORM(vcmpequh, 3, 1) | |
6657 | GEN_VXRFORM(vcmpequw, 3, 2) | |
6658 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
6659 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
6660 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
6661 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
6662 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
6663 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
819ca121 AJ |
6664 | GEN_VXRFORM(vcmpeqfp, 3, 3) |
6665 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
6666 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
6667 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
1add6e23 | 6668 | |
c026766b | 6669 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6670 | static void glue(gen_, name)(DisasContext *ctx) \ |
c026766b AJ |
6671 | { \ |
6672 | TCGv_ptr rd; \ | |
6673 | TCGv_i32 simm; \ | |
6674 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6675 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6676 | return; \ | |
6677 | } \ | |
6678 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6679 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6680 | gen_helper_##name (rd, simm); \ | |
6681 | tcg_temp_free_i32(simm); \ | |
6682 | tcg_temp_free_ptr(rd); \ | |
6683 | } | |
6684 | ||
6685 | GEN_VXFORM_SIMM(vspltisb, 6, 12); | |
6686 | GEN_VXFORM_SIMM(vspltish, 6, 13); | |
6687 | GEN_VXFORM_SIMM(vspltisw, 6, 14); | |
6688 | ||
de5f2484 | 6689 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ |
99e300ef | 6690 | static void glue(gen_, name)(DisasContext *ctx) \ |
de5f2484 AJ |
6691 | { \ |
6692 | TCGv_ptr rb, rd; \ | |
6693 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6694 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6695 | return; \ | |
6696 | } \ | |
6697 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6698 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6699 | gen_helper_##name (rd, rb); \ | |
6700 | tcg_temp_free_ptr(rb); \ | |
6701 | tcg_temp_free_ptr(rd); \ | |
6702 | } | |
6703 | ||
d15f74fb BS |
6704 | #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \ |
6705 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6706 | { \ | |
6707 | TCGv_ptr rb, rd; \ | |
6708 | \ | |
6709 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6710 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6711 | return; \ | |
6712 | } \ | |
6713 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6714 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6715 | gen_helper_##name(cpu_env, rd, rb); \ | |
6716 | tcg_temp_free_ptr(rb); \ | |
6717 | tcg_temp_free_ptr(rd); \ | |
6718 | } | |
6719 | ||
6cf1c6e5 AJ |
6720 | GEN_VXFORM_NOA(vupkhsb, 7, 8); |
6721 | GEN_VXFORM_NOA(vupkhsh, 7, 9); | |
6722 | GEN_VXFORM_NOA(vupklsb, 7, 10); | |
6723 | GEN_VXFORM_NOA(vupklsh, 7, 11); | |
79f85c3a AJ |
6724 | GEN_VXFORM_NOA(vupkhpx, 7, 13); |
6725 | GEN_VXFORM_NOA(vupklpx, 7, 15); | |
d15f74fb BS |
6726 | GEN_VXFORM_NOA_ENV(vrefp, 5, 4); |
6727 | GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5); | |
6728 | GEN_VXFORM_NOA_ENV(vexptefp, 5, 6); | |
6729 | GEN_VXFORM_NOA_ENV(vlogefp, 5, 7); | |
6730 | GEN_VXFORM_NOA_ENV(vrfim, 5, 8); | |
6731 | GEN_VXFORM_NOA_ENV(vrfin, 5, 9); | |
6732 | GEN_VXFORM_NOA_ENV(vrfip, 5, 10); | |
6733 | GEN_VXFORM_NOA_ENV(vrfiz, 5, 11); | |
79f85c3a | 6734 | |
21d21583 | 6735 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6736 | static void glue(gen_, name)(DisasContext *ctx) \ |
21d21583 AJ |
6737 | { \ |
6738 | TCGv_ptr rd; \ | |
6739 | TCGv_i32 simm; \ | |
6740 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6741 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6742 | return; \ | |
6743 | } \ | |
6744 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6745 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6746 | gen_helper_##name (rd, simm); \ | |
6747 | tcg_temp_free_i32(simm); \ | |
6748 | tcg_temp_free_ptr(rd); \ | |
6749 | } | |
6750 | ||
27a4edb3 | 6751 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ |
99e300ef | 6752 | static void glue(gen_, name)(DisasContext *ctx) \ |
27a4edb3 AJ |
6753 | { \ |
6754 | TCGv_ptr rb, rd; \ | |
6755 | TCGv_i32 uimm; \ | |
6756 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6757 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6758 | return; \ | |
6759 | } \ | |
6760 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6761 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6762 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6763 | gen_helper_##name (rd, rb, uimm); \ | |
6764 | tcg_temp_free_i32(uimm); \ | |
6765 | tcg_temp_free_ptr(rb); \ | |
6766 | tcg_temp_free_ptr(rd); \ | |
6767 | } | |
6768 | ||
d15f74fb BS |
6769 | #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \ |
6770 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6771 | { \ | |
6772 | TCGv_ptr rb, rd; \ | |
6773 | TCGv_i32 uimm; \ | |
6774 | \ | |
6775 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6776 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6777 | return; \ | |
6778 | } \ | |
6779 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6780 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6781 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6782 | gen_helper_##name(cpu_env, rd, rb, uimm); \ | |
6783 | tcg_temp_free_i32(uimm); \ | |
6784 | tcg_temp_free_ptr(rb); \ | |
6785 | tcg_temp_free_ptr(rd); \ | |
6786 | } | |
6787 | ||
e4e6bee7 AJ |
6788 | GEN_VXFORM_UIMM(vspltb, 6, 8); |
6789 | GEN_VXFORM_UIMM(vsplth, 6, 9); | |
6790 | GEN_VXFORM_UIMM(vspltw, 6, 10); | |
d15f74fb BS |
6791 | GEN_VXFORM_UIMM_ENV(vcfux, 5, 12); |
6792 | GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13); | |
6793 | GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14); | |
6794 | GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15); | |
e4e6bee7 | 6795 | |
99e300ef | 6796 | static void gen_vsldoi(DisasContext *ctx) |
cd633b10 AJ |
6797 | { |
6798 | TCGv_ptr ra, rb, rd; | |
fce5ecb7 | 6799 | TCGv_i32 sh; |
cd633b10 AJ |
6800 | if (unlikely(!ctx->altivec_enabled)) { |
6801 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6802 | return; | |
6803 | } | |
6804 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6805 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6806 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6807 | sh = tcg_const_i32(VSH(ctx->opcode)); | |
6808 | gen_helper_vsldoi (rd, ra, rb, sh); | |
6809 | tcg_temp_free_ptr(ra); | |
6810 | tcg_temp_free_ptr(rb); | |
6811 | tcg_temp_free_ptr(rd); | |
fce5ecb7 | 6812 | tcg_temp_free_i32(sh); |
cd633b10 AJ |
6813 | } |
6814 | ||
707cec33 | 6815 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ |
d15f74fb | 6816 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
707cec33 AJ |
6817 | { \ |
6818 | TCGv_ptr ra, rb, rc, rd; \ | |
6819 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6820 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6821 | return; \ | |
6822 | } \ | |
6823 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6824 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6825 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
6826 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6827 | if (Rc(ctx->opcode)) { \ | |
d15f74fb | 6828 | gen_helper_##name1(cpu_env, rd, ra, rb, rc); \ |
707cec33 | 6829 | } else { \ |
d15f74fb | 6830 | gen_helper_##name0(cpu_env, rd, ra, rb, rc); \ |
707cec33 AJ |
6831 | } \ |
6832 | tcg_temp_free_ptr(ra); \ | |
6833 | tcg_temp_free_ptr(rb); \ | |
6834 | tcg_temp_free_ptr(rc); \ | |
6835 | tcg_temp_free_ptr(rd); \ | |
6836 | } | |
6837 | ||
b161ae27 AJ |
6838 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16) |
6839 | ||
99e300ef | 6840 | static void gen_vmladduhm(DisasContext *ctx) |
bcd2ee23 AJ |
6841 | { |
6842 | TCGv_ptr ra, rb, rc, rd; | |
6843 | if (unlikely(!ctx->altivec_enabled)) { | |
6844 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6845 | return; | |
6846 | } | |
6847 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6848 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6849 | rc = gen_avr_ptr(rC(ctx->opcode)); | |
6850 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6851 | gen_helper_vmladduhm(rd, ra, rb, rc); | |
6852 | tcg_temp_free_ptr(ra); | |
6853 | tcg_temp_free_ptr(rb); | |
6854 | tcg_temp_free_ptr(rc); | |
6855 | tcg_temp_free_ptr(rd); | |
6856 | } | |
6857 | ||
b04ae981 | 6858 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18) |
4d9903b6 | 6859 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19) |
eae07261 | 6860 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20) |
d1258698 | 6861 | GEN_VAFORM_PAIRED(vsel, vperm, 21) |
35cf7c7e | 6862 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23) |
b04ae981 | 6863 | |
0487d6a8 | 6864 | /*** SPE extension ***/ |
0487d6a8 | 6865 | /* Register moves */ |
3cd7d1dd | 6866 | |
a0e13900 FC |
6867 | |
6868 | static inline void gen_evmra(DisasContext *ctx) | |
6869 | { | |
6870 | ||
6871 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 6872 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
6873 | return; |
6874 | } | |
6875 | ||
6876 | #if defined(TARGET_PPC64) | |
6877 | /* rD := rA */ | |
6878 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6879 | ||
6880 | /* spe_acc := rA */ | |
6881 | tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)], | |
6882 | cpu_env, | |
1328c2bf | 6883 | offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
6884 | #else |
6885 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
6886 | ||
6887 | /* tmp := rA_lo + rA_hi << 32 */ | |
6888 | tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6889 | ||
6890 | /* spe_acc := tmp */ | |
1328c2bf | 6891 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
6892 | tcg_temp_free_i64(tmp); |
6893 | ||
6894 | /* rD := rA */ | |
6895 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6896 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6897 | #endif | |
6898 | } | |
6899 | ||
636aa200 BS |
6900 | static inline void gen_load_gpr64(TCGv_i64 t, int reg) |
6901 | { | |
f78fb44e AJ |
6902 | #if defined(TARGET_PPC64) |
6903 | tcg_gen_mov_i64(t, cpu_gpr[reg]); | |
6904 | #else | |
36aa55dc | 6905 | tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]); |
3cd7d1dd | 6906 | #endif |
f78fb44e | 6907 | } |
3cd7d1dd | 6908 | |
636aa200 BS |
6909 | static inline void gen_store_gpr64(int reg, TCGv_i64 t) |
6910 | { | |
f78fb44e AJ |
6911 | #if defined(TARGET_PPC64) |
6912 | tcg_gen_mov_i64(cpu_gpr[reg], t); | |
6913 | #else | |
a7812ae4 | 6914 | TCGv_i64 tmp = tcg_temp_new_i64(); |
f78fb44e | 6915 | tcg_gen_trunc_i64_i32(cpu_gpr[reg], t); |
f78fb44e AJ |
6916 | tcg_gen_shri_i64(tmp, t, 32); |
6917 | tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp); | |
a7812ae4 | 6918 | tcg_temp_free_i64(tmp); |
3cd7d1dd | 6919 | #endif |
f78fb44e | 6920 | } |
3cd7d1dd | 6921 | |
70560da7 | 6922 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
99e300ef | 6923 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
0487d6a8 JM |
6924 | { \ |
6925 | if (Rc(ctx->opcode)) \ | |
6926 | gen_##name1(ctx); \ | |
6927 | else \ | |
6928 | gen_##name0(ctx); \ | |
6929 | } | |
6930 | ||
6931 | /* Handler for undefined SPE opcodes */ | |
636aa200 | 6932 | static inline void gen_speundef(DisasContext *ctx) |
0487d6a8 | 6933 | { |
e06fcd75 | 6934 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
0487d6a8 JM |
6935 | } |
6936 | ||
57951c27 AJ |
6937 | /* SPE logic */ |
6938 | #if defined(TARGET_PPC64) | |
6939 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6940 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6941 | { \ |
6942 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6943 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6944 | return; \ |
6945 | } \ | |
57951c27 AJ |
6946 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6947 | cpu_gpr[rB(ctx->opcode)]); \ | |
6948 | } | |
6949 | #else | |
6950 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6951 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
6952 | { \ |
6953 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6954 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
6955 | return; \ |
6956 | } \ | |
6957 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ | |
6958 | cpu_gpr[rB(ctx->opcode)]); \ | |
6959 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6960 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 6961 | } |
57951c27 AJ |
6962 | #endif |
6963 | ||
6964 | GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl); | |
6965 | GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl); | |
6966 | GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl); | |
6967 | GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl); | |
6968 | GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl); | |
6969 | GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl); | |
6970 | GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl); | |
6971 | GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl); | |
0487d6a8 | 6972 | |
57951c27 AJ |
6973 | /* SPE logic immediate */ |
6974 | #if defined(TARGET_PPC64) | |
6975 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6976 | static inline void gen_##name(DisasContext *ctx) \ |
3d3a6a0a AJ |
6977 | { \ |
6978 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6979 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
3d3a6a0a AJ |
6980 | return; \ |
6981 | } \ | |
a7812ae4 PB |
6982 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
6983 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
6984 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
6985 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
6986 | tcg_opi(t0, t0, rB(ctx->opcode)); \ | |
6987 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
6988 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 6989 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
6990 | tcg_opi(t1, t1, rB(ctx->opcode)); \ |
6991 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
6992 | tcg_temp_free_i32(t0); \ |
6993 | tcg_temp_free_i32(t1); \ | |
3d3a6a0a | 6994 | } |
57951c27 AJ |
6995 | #else |
6996 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6997 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6998 | { \ |
6999 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7000 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7001 | return; \ |
7002 | } \ | |
57951c27 AJ |
7003 | tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7004 | rB(ctx->opcode)); \ | |
7005 | tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
7006 | rB(ctx->opcode)); \ | |
0487d6a8 | 7007 | } |
57951c27 AJ |
7008 | #endif |
7009 | GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32); | |
7010 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32); | |
7011 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32); | |
7012 | GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32); | |
0487d6a8 | 7013 | |
57951c27 AJ |
7014 | /* SPE arithmetic */ |
7015 | #if defined(TARGET_PPC64) | |
7016 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ | |
636aa200 | 7017 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7018 | { \ |
7019 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7020 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7021 | return; \ |
7022 | } \ | |
a7812ae4 PB |
7023 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7024 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7025 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7026 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7027 | tcg_op(t0, t0); \ | |
7028 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7029 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7030 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7031 | tcg_op(t1, t1); \ |
7032 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7033 | tcg_temp_free_i32(t0); \ |
7034 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 7035 | } |
57951c27 | 7036 | #else |
a7812ae4 | 7037 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ |
636aa200 | 7038 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7039 | { \ |
7040 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7041 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7042 | return; \ |
7043 | } \ | |
7044 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \ | |
7045 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \ | |
7046 | } | |
7047 | #endif | |
0487d6a8 | 7048 | |
636aa200 | 7049 | static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1) |
57951c27 AJ |
7050 | { |
7051 | int l1 = gen_new_label(); | |
7052 | int l2 = gen_new_label(); | |
0487d6a8 | 7053 | |
57951c27 AJ |
7054 | tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1); |
7055 | tcg_gen_neg_i32(ret, arg1); | |
7056 | tcg_gen_br(l2); | |
7057 | gen_set_label(l1); | |
a7812ae4 | 7058 | tcg_gen_mov_i32(ret, arg1); |
57951c27 AJ |
7059 | gen_set_label(l2); |
7060 | } | |
7061 | GEN_SPEOP_ARITH1(evabs, gen_op_evabs); | |
7062 | GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32); | |
7063 | GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32); | |
7064 | GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32); | |
636aa200 | 7065 | static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1) |
0487d6a8 | 7066 | { |
57951c27 AJ |
7067 | tcg_gen_addi_i32(ret, arg1, 0x8000); |
7068 | tcg_gen_ext16u_i32(ret, ret); | |
7069 | } | |
7070 | GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw); | |
a7812ae4 PB |
7071 | GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32); |
7072 | GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32); | |
0487d6a8 | 7073 | |
57951c27 AJ |
7074 | #if defined(TARGET_PPC64) |
7075 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 7076 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7077 | { \ |
7078 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7079 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7080 | return; \ |
7081 | } \ | |
a7812ae4 PB |
7082 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7083 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7084 | TCGv_i32 t2 = tcg_temp_local_new_i32(); \ | |
501e23c4 | 7085 | TCGv_i64 t3 = tcg_temp_local_new_i64(); \ |
57951c27 AJ |
7086 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7087 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \ | |
7088 | tcg_op(t0, t0, t2); \ | |
7089 | tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7090 | tcg_gen_trunc_i64_i32(t1, t3); \ | |
7091 | tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7092 | tcg_gen_trunc_i64_i32(t2, t3); \ | |
a7812ae4 | 7093 | tcg_temp_free_i64(t3); \ |
57951c27 | 7094 | tcg_op(t1, t1, t2); \ |
a7812ae4 | 7095 | tcg_temp_free_i32(t2); \ |
57951c27 | 7096 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ |
a7812ae4 PB |
7097 | tcg_temp_free_i32(t0); \ |
7098 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 7099 | } |
57951c27 AJ |
7100 | #else |
7101 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 7102 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7103 | { \ |
7104 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7105 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7106 | return; \ |
7107 | } \ | |
57951c27 AJ |
7108 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7109 | cpu_gpr[rB(ctx->opcode)]); \ | |
7110 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
7111 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 7112 | } |
57951c27 | 7113 | #endif |
0487d6a8 | 7114 | |
636aa200 | 7115 | static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7116 | { |
a7812ae4 | 7117 | TCGv_i32 t0; |
57951c27 | 7118 | int l1, l2; |
0487d6a8 | 7119 | |
57951c27 AJ |
7120 | l1 = gen_new_label(); |
7121 | l2 = gen_new_label(); | |
a7812ae4 | 7122 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7123 | /* No error here: 6 bits are used */ |
7124 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7125 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7126 | tcg_gen_shr_i32(ret, arg1, t0); | |
7127 | tcg_gen_br(l2); | |
7128 | gen_set_label(l1); | |
7129 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 7130 | gen_set_label(l2); |
a7812ae4 | 7131 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7132 | } |
7133 | GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu); | |
636aa200 | 7134 | static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7135 | { |
a7812ae4 | 7136 | TCGv_i32 t0; |
57951c27 AJ |
7137 | int l1, l2; |
7138 | ||
7139 | l1 = gen_new_label(); | |
7140 | l2 = gen_new_label(); | |
a7812ae4 | 7141 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7142 | /* No error here: 6 bits are used */ |
7143 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7144 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7145 | tcg_gen_sar_i32(ret, arg1, t0); | |
7146 | tcg_gen_br(l2); | |
7147 | gen_set_label(l1); | |
7148 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 7149 | gen_set_label(l2); |
a7812ae4 | 7150 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7151 | } |
7152 | GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws); | |
636aa200 | 7153 | static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7154 | { |
a7812ae4 | 7155 | TCGv_i32 t0; |
57951c27 AJ |
7156 | int l1, l2; |
7157 | ||
7158 | l1 = gen_new_label(); | |
7159 | l2 = gen_new_label(); | |
a7812ae4 | 7160 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
7161 | /* No error here: 6 bits are used */ |
7162 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
7163 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
7164 | tcg_gen_shl_i32(ret, arg1, t0); | |
7165 | tcg_gen_br(l2); | |
7166 | gen_set_label(l1); | |
7167 | tcg_gen_movi_i32(ret, 0); | |
e29ef9fa | 7168 | gen_set_label(l2); |
a7812ae4 | 7169 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7170 | } |
7171 | GEN_SPEOP_ARITH2(evslw, gen_op_evslw); | |
636aa200 | 7172 | static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 7173 | { |
a7812ae4 | 7174 | TCGv_i32 t0 = tcg_temp_new_i32(); |
57951c27 AJ |
7175 | tcg_gen_andi_i32(t0, arg2, 0x1F); |
7176 | tcg_gen_rotl_i32(ret, arg1, t0); | |
a7812ae4 | 7177 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7178 | } |
7179 | GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw); | |
636aa200 | 7180 | static inline void gen_evmergehi(DisasContext *ctx) |
57951c27 AJ |
7181 | { |
7182 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7183 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7184 | return; |
7185 | } | |
7186 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7187 | TCGv t0 = tcg_temp_new(); |
7188 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
7189 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
7190 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); | |
7191 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7192 | tcg_temp_free(t0); | |
7193 | tcg_temp_free(t1); | |
7194 | #else | |
7195 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7196 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7197 | #endif | |
7198 | } | |
7199 | GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32); | |
636aa200 | 7200 | static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
0487d6a8 | 7201 | { |
57951c27 AJ |
7202 | tcg_gen_sub_i32(ret, arg2, arg1); |
7203 | } | |
7204 | GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf); | |
0487d6a8 | 7205 | |
57951c27 AJ |
7206 | /* SPE arithmetic immediate */ |
7207 | #if defined(TARGET_PPC64) | |
7208 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 7209 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7210 | { \ |
7211 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7212 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7213 | return; \ |
7214 | } \ | |
a7812ae4 PB |
7215 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7216 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7217 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7218 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ |
7219 | tcg_op(t0, t0, rA(ctx->opcode)); \ | |
7220 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7221 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
e06fcd75 | 7222 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7223 | tcg_op(t1, t1, rA(ctx->opcode)); \ |
7224 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7225 | tcg_temp_free_i32(t0); \ |
7226 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
7227 | } |
7228 | #else | |
7229 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 7230 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7231 | { \ |
7232 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7233 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7234 | return; \ |
7235 | } \ | |
7236 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
7237 | rA(ctx->opcode)); \ | |
7238 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \ | |
7239 | rA(ctx->opcode)); \ | |
7240 | } | |
7241 | #endif | |
7242 | GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32); | |
7243 | GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32); | |
7244 | ||
7245 | /* SPE comparison */ | |
7246 | #if defined(TARGET_PPC64) | |
7247 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7248 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7249 | { \ |
7250 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7251 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7252 | return; \ |
7253 | } \ | |
7254 | int l1 = gen_new_label(); \ | |
7255 | int l2 = gen_new_label(); \ | |
7256 | int l3 = gen_new_label(); \ | |
7257 | int l4 = gen_new_label(); \ | |
a7812ae4 PB |
7258 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7259 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7260 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7261 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7262 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
7263 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \ | |
a7812ae4 | 7264 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \ |
57951c27 AJ |
7265 | tcg_gen_br(l2); \ |
7266 | gen_set_label(l1); \ | |
7267 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7268 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7269 | gen_set_label(l2); \ | |
7270 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7271 | tcg_gen_trunc_i64_i32(t0, t2); \ | |
7272 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7273 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7274 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7275 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \ |
7276 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7277 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7278 | tcg_gen_br(l4); \ | |
7279 | gen_set_label(l3); \ | |
7280 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7281 | CRF_CH | CRF_CH_OR_CL); \ | |
7282 | gen_set_label(l4); \ | |
a7812ae4 PB |
7283 | tcg_temp_free_i32(t0); \ |
7284 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
7285 | } |
7286 | #else | |
7287 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7288 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7289 | { \ |
7290 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7291 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7292 | return; \ |
7293 | } \ | |
7294 | int l1 = gen_new_label(); \ | |
7295 | int l2 = gen_new_label(); \ | |
7296 | int l3 = gen_new_label(); \ | |
7297 | int l4 = gen_new_label(); \ | |
7298 | \ | |
7299 | tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \ | |
7300 | cpu_gpr[rB(ctx->opcode)], l1); \ | |
7301 | tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \ | |
7302 | tcg_gen_br(l2); \ | |
7303 | gen_set_label(l1); \ | |
7304 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7305 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7306 | gen_set_label(l2); \ | |
7307 | tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \ | |
7308 | cpu_gprh[rB(ctx->opcode)], l3); \ | |
7309 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7310 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7311 | tcg_gen_br(l4); \ | |
7312 | gen_set_label(l3); \ | |
7313 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7314 | CRF_CH | CRF_CH_OR_CL); \ | |
7315 | gen_set_label(l4); \ | |
7316 | } | |
7317 | #endif | |
7318 | GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU); | |
7319 | GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT); | |
7320 | GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU); | |
7321 | GEN_SPEOP_COMP(evcmplts, TCG_COND_LT); | |
7322 | GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ); | |
7323 | ||
7324 | /* SPE misc */ | |
636aa200 | 7325 | static inline void gen_brinc(DisasContext *ctx) |
57951c27 AJ |
7326 | { |
7327 | /* Note: brinc is usable even if SPE is disabled */ | |
a7812ae4 PB |
7328 | gen_helper_brinc(cpu_gpr[rD(ctx->opcode)], |
7329 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
0487d6a8 | 7330 | } |
636aa200 | 7331 | static inline void gen_evmergelo(DisasContext *ctx) |
57951c27 AJ |
7332 | { |
7333 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7334 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7335 | return; |
7336 | } | |
7337 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7338 | TCGv t0 = tcg_temp_new(); |
7339 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7340 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7341 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); |
7342 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7343 | tcg_temp_free(t0); | |
7344 | tcg_temp_free(t1); | |
7345 | #else | |
57951c27 | 7346 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
33890b3e | 7347 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7348 | #endif |
7349 | } | |
636aa200 | 7350 | static inline void gen_evmergehilo(DisasContext *ctx) |
57951c27 AJ |
7351 | { |
7352 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7353 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7354 | return; |
7355 | } | |
7356 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7357 | TCGv t0 = tcg_temp_new(); |
7358 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7359 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7360 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); |
7361 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7362 | tcg_temp_free(t0); | |
7363 | tcg_temp_free(t1); | |
7364 | #else | |
7365 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7366 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7367 | #endif | |
7368 | } | |
636aa200 | 7369 | static inline void gen_evmergelohi(DisasContext *ctx) |
57951c27 AJ |
7370 | { |
7371 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7372 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7373 | return; |
7374 | } | |
7375 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7376 | TCGv t0 = tcg_temp_new(); |
7377 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
7378 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
7379 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); | |
7380 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7381 | tcg_temp_free(t0); | |
7382 | tcg_temp_free(t1); | |
7383 | #else | |
33890b3e NF |
7384 | if (rD(ctx->opcode) == rA(ctx->opcode)) { |
7385 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
7386 | tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); | |
7387 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7388 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp); | |
7389 | tcg_temp_free_i32(tmp); | |
7390 | } else { | |
7391 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7392 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7393 | } | |
57951c27 AJ |
7394 | #endif |
7395 | } | |
636aa200 | 7396 | static inline void gen_evsplati(DisasContext *ctx) |
57951c27 | 7397 | { |
ae01847f | 7398 | uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27; |
0487d6a8 | 7399 | |
57951c27 | 7400 | #if defined(TARGET_PPC64) |
38d14952 | 7401 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7402 | #else |
7403 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7404 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7405 | #endif | |
7406 | } | |
636aa200 | 7407 | static inline void gen_evsplatfi(DisasContext *ctx) |
0487d6a8 | 7408 | { |
ae01847f | 7409 | uint64_t imm = rA(ctx->opcode) << 27; |
0487d6a8 | 7410 | |
57951c27 | 7411 | #if defined(TARGET_PPC64) |
38d14952 | 7412 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7413 | #else |
7414 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7415 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7416 | #endif | |
0487d6a8 JM |
7417 | } |
7418 | ||
636aa200 | 7419 | static inline void gen_evsel(DisasContext *ctx) |
57951c27 AJ |
7420 | { |
7421 | int l1 = gen_new_label(); | |
7422 | int l2 = gen_new_label(); | |
7423 | int l3 = gen_new_label(); | |
7424 | int l4 = gen_new_label(); | |
a7812ae4 | 7425 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
57951c27 | 7426 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
7427 | TCGv t1 = tcg_temp_local_new(); |
7428 | TCGv t2 = tcg_temp_local_new(); | |
57951c27 AJ |
7429 | #endif |
7430 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | |
7431 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
7432 | #if defined(TARGET_PPC64) | |
7433 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7434 | #else | |
7435 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7436 | #endif | |
7437 | tcg_gen_br(l2); | |
7438 | gen_set_label(l1); | |
7439 | #if defined(TARGET_PPC64) | |
7440 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7441 | #else | |
7442 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7443 | #endif | |
7444 | gen_set_label(l2); | |
7445 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2); | |
7446 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3); | |
7447 | #if defined(TARGET_PPC64) | |
17d9b3af | 7448 | tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]); |
57951c27 AJ |
7449 | #else |
7450 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7451 | #endif | |
7452 | tcg_gen_br(l4); | |
7453 | gen_set_label(l3); | |
7454 | #if defined(TARGET_PPC64) | |
17d9b3af | 7455 | tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7456 | #else |
7457 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7458 | #endif | |
7459 | gen_set_label(l4); | |
a7812ae4 | 7460 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7461 | #if defined(TARGET_PPC64) |
7462 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2); | |
7463 | tcg_temp_free(t1); | |
7464 | tcg_temp_free(t2); | |
7465 | #endif | |
7466 | } | |
e8eaa2c0 BS |
7467 | |
7468 | static void gen_evsel0(DisasContext *ctx) | |
57951c27 AJ |
7469 | { |
7470 | gen_evsel(ctx); | |
7471 | } | |
e8eaa2c0 BS |
7472 | |
7473 | static void gen_evsel1(DisasContext *ctx) | |
57951c27 AJ |
7474 | { |
7475 | gen_evsel(ctx); | |
7476 | } | |
e8eaa2c0 BS |
7477 | |
7478 | static void gen_evsel2(DisasContext *ctx) | |
57951c27 AJ |
7479 | { |
7480 | gen_evsel(ctx); | |
7481 | } | |
e8eaa2c0 BS |
7482 | |
7483 | static void gen_evsel3(DisasContext *ctx) | |
57951c27 AJ |
7484 | { |
7485 | gen_evsel(ctx); | |
7486 | } | |
0487d6a8 | 7487 | |
a0e13900 FC |
7488 | /* Multiply */ |
7489 | ||
7490 | static inline void gen_evmwumi(DisasContext *ctx) | |
7491 | { | |
7492 | TCGv_i64 t0, t1; | |
7493 | ||
7494 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7495 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7496 | return; |
7497 | } | |
7498 | ||
7499 | t0 = tcg_temp_new_i64(); | |
7500 | t1 = tcg_temp_new_i64(); | |
7501 | ||
7502 | /* t0 := rA; t1 := rB */ | |
7503 | #if defined(TARGET_PPC64) | |
7504 | tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7505 | tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7506 | #else | |
7507 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7508 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7509 | #endif | |
7510 | ||
7511 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7512 | ||
7513 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7514 | ||
7515 | tcg_temp_free_i64(t0); | |
7516 | tcg_temp_free_i64(t1); | |
7517 | } | |
7518 | ||
7519 | static inline void gen_evmwumia(DisasContext *ctx) | |
7520 | { | |
7521 | TCGv_i64 tmp; | |
7522 | ||
7523 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7524 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7525 | return; |
7526 | } | |
7527 | ||
7528 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7529 | ||
7530 | tmp = tcg_temp_new_i64(); | |
7531 | ||
7532 | /* acc := rD */ | |
7533 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 7534 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7535 | tcg_temp_free_i64(tmp); |
7536 | } | |
7537 | ||
7538 | static inline void gen_evmwumiaa(DisasContext *ctx) | |
7539 | { | |
7540 | TCGv_i64 acc; | |
7541 | TCGv_i64 tmp; | |
7542 | ||
7543 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7544 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7545 | return; |
7546 | } | |
7547 | ||
7548 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7549 | ||
7550 | acc = tcg_temp_new_i64(); | |
7551 | tmp = tcg_temp_new_i64(); | |
7552 | ||
7553 | /* tmp := rD */ | |
7554 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7555 | ||
7556 | /* Load acc */ | |
1328c2bf | 7557 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7558 | |
7559 | /* acc := tmp + acc */ | |
7560 | tcg_gen_add_i64(acc, acc, tmp); | |
7561 | ||
7562 | /* Store acc */ | |
1328c2bf | 7563 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7564 | |
7565 | /* rD := acc */ | |
7566 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7567 | ||
7568 | tcg_temp_free_i64(acc); | |
7569 | tcg_temp_free_i64(tmp); | |
7570 | } | |
7571 | ||
7572 | static inline void gen_evmwsmi(DisasContext *ctx) | |
7573 | { | |
7574 | TCGv_i64 t0, t1; | |
7575 | ||
7576 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7577 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7578 | return; |
7579 | } | |
7580 | ||
7581 | t0 = tcg_temp_new_i64(); | |
7582 | t1 = tcg_temp_new_i64(); | |
7583 | ||
7584 | /* t0 := rA; t1 := rB */ | |
7585 | #if defined(TARGET_PPC64) | |
7586 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7587 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7588 | #else | |
7589 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7590 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7591 | #endif | |
7592 | ||
7593 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7594 | ||
7595 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7596 | ||
7597 | tcg_temp_free_i64(t0); | |
7598 | tcg_temp_free_i64(t1); | |
7599 | } | |
7600 | ||
7601 | static inline void gen_evmwsmia(DisasContext *ctx) | |
7602 | { | |
7603 | TCGv_i64 tmp; | |
7604 | ||
7605 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7606 | ||
7607 | tmp = tcg_temp_new_i64(); | |
7608 | ||
7609 | /* acc := rD */ | |
7610 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 7611 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7612 | |
7613 | tcg_temp_free_i64(tmp); | |
7614 | } | |
7615 | ||
7616 | static inline void gen_evmwsmiaa(DisasContext *ctx) | |
7617 | { | |
7618 | TCGv_i64 acc = tcg_temp_new_i64(); | |
7619 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
7620 | ||
7621 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7622 | ||
7623 | acc = tcg_temp_new_i64(); | |
7624 | tmp = tcg_temp_new_i64(); | |
7625 | ||
7626 | /* tmp := rD */ | |
7627 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7628 | ||
7629 | /* Load acc */ | |
1328c2bf | 7630 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7631 | |
7632 | /* acc := tmp + acc */ | |
7633 | tcg_gen_add_i64(acc, acc, tmp); | |
7634 | ||
7635 | /* Store acc */ | |
1328c2bf | 7636 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7637 | |
7638 | /* rD := acc */ | |
7639 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7640 | ||
7641 | tcg_temp_free_i64(acc); | |
7642 | tcg_temp_free_i64(tmp); | |
7643 | } | |
7644 | ||
70560da7 FC |
7645 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// |
7646 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7647 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7648 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7649 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7650 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7651 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7652 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); // | |
7653 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE); | |
7654 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7655 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7656 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7657 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7658 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7659 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7660 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
7661 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7662 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7663 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7664 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE); | |
7665 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7666 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7667 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); // | |
7668 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE); | |
7669 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7670 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7671 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7672 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7673 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); //// | |
0487d6a8 | 7674 | |
6a6ae23f | 7675 | /* SPE load and stores */ |
636aa200 | 7676 | static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh) |
6a6ae23f AJ |
7677 | { |
7678 | target_ulong uimm = rB(ctx->opcode); | |
7679 | ||
76db3ba4 | 7680 | if (rA(ctx->opcode) == 0) { |
6a6ae23f | 7681 | tcg_gen_movi_tl(EA, uimm << sh); |
76db3ba4 | 7682 | } else { |
6a6ae23f | 7683 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh); |
76db3ba4 AJ |
7684 | #if defined(TARGET_PPC64) |
7685 | if (!ctx->sf_mode) { | |
7686 | tcg_gen_ext32u_tl(EA, EA); | |
7687 | } | |
7688 | #endif | |
7689 | } | |
0487d6a8 | 7690 | } |
6a6ae23f | 7691 | |
636aa200 | 7692 | static inline void gen_op_evldd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7693 | { |
7694 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7695 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
6a6ae23f AJ |
7696 | #else |
7697 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
76db3ba4 | 7698 | gen_qemu_ld64(ctx, t0, addr); |
6a6ae23f AJ |
7699 | tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0); |
7700 | tcg_gen_shri_i64(t0, t0, 32); | |
7701 | tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0); | |
7702 | tcg_temp_free_i64(t0); | |
7703 | #endif | |
0487d6a8 | 7704 | } |
6a6ae23f | 7705 | |
636aa200 | 7706 | static inline void gen_op_evldw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7707 | { |
0487d6a8 | 7708 | #if defined(TARGET_PPC64) |
6a6ae23f | 7709 | TCGv t0 = tcg_temp_new(); |
76db3ba4 | 7710 | gen_qemu_ld32u(ctx, t0, addr); |
6a6ae23f | 7711 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
76db3ba4 AJ |
7712 | gen_addr_add(ctx, addr, addr, 4); |
7713 | gen_qemu_ld32u(ctx, t0, addr); | |
6a6ae23f AJ |
7714 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7715 | tcg_temp_free(t0); | |
7716 | #else | |
76db3ba4 AJ |
7717 | gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7718 | gen_addr_add(ctx, addr, addr, 4); | |
7719 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f | 7720 | #endif |
0487d6a8 | 7721 | } |
6a6ae23f | 7722 | |
636aa200 | 7723 | static inline void gen_op_evldh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7724 | { |
7725 | TCGv t0 = tcg_temp_new(); | |
7726 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7727 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7728 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7729 | gen_addr_add(ctx, addr, addr, 2); |
7730 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7731 | tcg_gen_shli_tl(t0, t0, 32); |
7732 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7733 | gen_addr_add(ctx, addr, addr, 2); |
7734 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7735 | tcg_gen_shli_tl(t0, t0, 16); |
7736 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7737 | gen_addr_add(ctx, addr, addr, 2); |
7738 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7739 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7740 | #else |
76db3ba4 | 7741 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7742 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7743 | gen_addr_add(ctx, addr, addr, 2); |
7744 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7745 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7746 | gen_addr_add(ctx, addr, addr, 2); |
7747 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7748 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7749 | gen_addr_add(ctx, addr, addr, 2); |
7750 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7751 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7752 | #endif |
6a6ae23f | 7753 | tcg_temp_free(t0); |
0487d6a8 JM |
7754 | } |
7755 | ||
636aa200 | 7756 | static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7757 | { |
7758 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7759 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7760 | #if defined(TARGET_PPC64) |
7761 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); | |
7762 | tcg_gen_shli_tl(t0, t0, 16); | |
7763 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7764 | #else | |
7765 | tcg_gen_shli_tl(t0, t0, 16); | |
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_evlhhousplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7773 | { |
7774 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7775 | gen_qemu_ld16u(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_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7779 | #else | |
7780 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7781 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7782 | #endif | |
7783 | tcg_temp_free(t0); | |
0487d6a8 JM |
7784 | } |
7785 | ||
636aa200 | 7786 | static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7787 | { |
7788 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7789 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f AJ |
7790 | #if defined(TARGET_PPC64) |
7791 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
7792 | tcg_gen_ext32u_tl(t0, t0); | |
7793 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7794 | #else | |
7795 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7796 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7797 | #endif | |
7798 | tcg_temp_free(t0); | |
7799 | } | |
7800 | ||
636aa200 | 7801 | static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7802 | { |
7803 | TCGv t0 = tcg_temp_new(); | |
7804 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7805 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7806 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7807 | gen_addr_add(ctx, addr, addr, 2); |
7808 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7809 | tcg_gen_shli_tl(t0, t0, 16); |
7810 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7811 | #else | |
76db3ba4 | 7812 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7813 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7814 | gen_addr_add(ctx, addr, addr, 2); |
7815 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7816 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7817 | #endif | |
7818 | tcg_temp_free(t0); | |
7819 | } | |
7820 | ||
636aa200 | 7821 | static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7822 | { |
7823 | #if defined(TARGET_PPC64) | |
7824 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 AJ |
7825 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
7826 | gen_addr_add(ctx, addr, addr, 2); | |
7827 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7828 | tcg_gen_shli_tl(t0, t0, 32); |
7829 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7830 | tcg_temp_free(t0); | |
7831 | #else | |
76db3ba4 AJ |
7832 | gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7833 | gen_addr_add(ctx, addr, addr, 2); | |
7834 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7835 | #endif |
7836 | } | |
7837 | ||
636aa200 | 7838 | static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7839 | { |
7840 | #if defined(TARGET_PPC64) | |
7841 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7842 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f | 7843 | tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7844 | gen_addr_add(ctx, addr, addr, 2); |
7845 | gen_qemu_ld16s(ctx, t0, addr); | |
6a6ae23f AJ |
7846 | tcg_gen_shli_tl(t0, t0, 32); |
7847 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7848 | tcg_temp_free(t0); | |
7849 | #else | |
76db3ba4 AJ |
7850 | gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7851 | gen_addr_add(ctx, addr, addr, 2); | |
7852 | gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7853 | #endif |
7854 | } | |
7855 | ||
636aa200 | 7856 | static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7857 | { |
7858 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7859 | gen_qemu_ld32u(ctx, t0, addr); |
0487d6a8 | 7860 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7861 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
7862 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7863 | #else | |
7864 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7865 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7866 | #endif | |
7867 | tcg_temp_free(t0); | |
7868 | } | |
7869 | ||
636aa200 | 7870 | static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7871 | { |
7872 | TCGv t0 = tcg_temp_new(); | |
7873 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7874 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7875 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
7876 | tcg_gen_shli_tl(t0, t0, 32); | |
7877 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7878 | gen_addr_add(ctx, addr, addr, 2); |
7879 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7880 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7881 | tcg_gen_shli_tl(t0, t0, 16); | |
7882 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7883 | #else | |
76db3ba4 | 7884 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7885 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
7886 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7887 | gen_addr_add(ctx, addr, addr, 2); |
7888 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7889 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7890 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
0487d6a8 | 7891 | #endif |
6a6ae23f AJ |
7892 | tcg_temp_free(t0); |
7893 | } | |
7894 | ||
636aa200 | 7895 | static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7896 | { |
7897 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7898 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
0487d6a8 | 7899 | #else |
6a6ae23f AJ |
7900 | TCGv_i64 t0 = tcg_temp_new_i64(); |
7901 | tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]); | |
76db3ba4 | 7902 | gen_qemu_st64(ctx, t0, addr); |
6a6ae23f AJ |
7903 | tcg_temp_free_i64(t0); |
7904 | #endif | |
7905 | } | |
7906 | ||
636aa200 | 7907 | static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7908 | { |
0487d6a8 | 7909 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7910 | TCGv t0 = tcg_temp_new(); |
7911 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7912 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7913 | tcg_temp_free(t0); |
7914 | #else | |
76db3ba4 | 7915 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7916 | #endif |
76db3ba4 AJ |
7917 | gen_addr_add(ctx, addr, addr, 4); |
7918 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7919 | } |
7920 | ||
636aa200 | 7921 | static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7922 | { |
7923 | TCGv t0 = tcg_temp_new(); | |
7924 | #if defined(TARGET_PPC64) | |
7925 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7926 | #else | |
7927 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7928 | #endif | |
76db3ba4 AJ |
7929 | gen_qemu_st16(ctx, t0, addr); |
7930 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f AJ |
7931 | #if defined(TARGET_PPC64) |
7932 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7933 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7934 | #else |
76db3ba4 | 7935 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7936 | #endif |
76db3ba4 | 7937 | gen_addr_add(ctx, addr, addr, 2); |
6a6ae23f | 7938 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7939 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7940 | tcg_temp_free(t0); |
76db3ba4 AJ |
7941 | gen_addr_add(ctx, addr, addr, 2); |
7942 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7943 | } |
7944 | ||
636aa200 | 7945 | static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7946 | { |
7947 | TCGv t0 = tcg_temp_new(); | |
7948 | #if defined(TARGET_PPC64) | |
7949 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7950 | #else | |
7951 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7952 | #endif | |
76db3ba4 AJ |
7953 | gen_qemu_st16(ctx, t0, addr); |
7954 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f | 7955 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7956 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
7957 | tcg_temp_free(t0); |
7958 | } | |
7959 | ||
636aa200 | 7960 | static inline void gen_op_evstwho(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_st16(ctx, t0, addr); |
6a6ae23f AJ |
7966 | tcg_temp_free(t0); |
7967 | #else | |
76db3ba4 | 7968 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7969 | #endif |
76db3ba4 AJ |
7970 | gen_addr_add(ctx, addr, addr, 2); |
7971 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7972 | } |
7973 | ||
636aa200 | 7974 | static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7975 | { |
7976 | #if defined(TARGET_PPC64) | |
7977 | TCGv t0 = tcg_temp_new(); | |
7978 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7979 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7980 | tcg_temp_free(t0); |
7981 | #else | |
76db3ba4 | 7982 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7983 | #endif |
7984 | } | |
7985 | ||
636aa200 | 7986 | static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7987 | { |
76db3ba4 | 7988 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7989 | } |
7990 | ||
7991 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
99e300ef | 7992 | static void glue(gen_, name)(DisasContext *ctx) \ |
6a6ae23f AJ |
7993 | { \ |
7994 | TCGv t0; \ | |
7995 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7996 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
6a6ae23f AJ |
7997 | return; \ |
7998 | } \ | |
76db3ba4 | 7999 | gen_set_access_type(ctx, ACCESS_INT); \ |
6a6ae23f AJ |
8000 | t0 = tcg_temp_new(); \ |
8001 | if (Rc(ctx->opcode)) { \ | |
76db3ba4 | 8002 | gen_addr_spe_imm_index(ctx, t0, sh); \ |
6a6ae23f | 8003 | } else { \ |
76db3ba4 | 8004 | gen_addr_reg_index(ctx, t0); \ |
6a6ae23f AJ |
8005 | } \ |
8006 | gen_op_##name(ctx, t0); \ | |
8007 | tcg_temp_free(t0); \ | |
8008 | } | |
8009 | ||
8010 | GEN_SPEOP_LDST(evldd, 0x00, 3); | |
8011 | GEN_SPEOP_LDST(evldw, 0x01, 3); | |
8012 | GEN_SPEOP_LDST(evldh, 0x02, 3); | |
8013 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1); | |
8014 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1); | |
8015 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1); | |
8016 | GEN_SPEOP_LDST(evlwhe, 0x08, 2); | |
8017 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2); | |
8018 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2); | |
8019 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2); | |
8020 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2); | |
8021 | ||
8022 | GEN_SPEOP_LDST(evstdd, 0x10, 3); | |
8023 | GEN_SPEOP_LDST(evstdw, 0x11, 3); | |
8024 | GEN_SPEOP_LDST(evstdh, 0x12, 3); | |
8025 | GEN_SPEOP_LDST(evstwhe, 0x18, 2); | |
8026 | GEN_SPEOP_LDST(evstwho, 0x1A, 2); | |
8027 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2); | |
8028 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2); | |
0487d6a8 JM |
8029 | |
8030 | /* Multiply and add - TODO */ | |
8031 | #if 0 | |
70560da7 FC |
8032 | GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);// |
8033 | GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8034 | GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8035 | GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8036 | GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8037 | GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8038 | GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8039 | GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8040 | GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8041 | GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8042 | GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8043 | GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8044 | ||
8045 | GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8046 | GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8047 | GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8048 | GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8049 | GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8050 | GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8051 | GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8052 | GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8053 | GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8054 | GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8055 | GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8056 | GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8057 | ||
8058 | GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8059 | GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8060 | GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8061 | GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8062 | GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE); | |
8063 | ||
8064 | GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8065 | GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8066 | GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8067 | GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8068 | GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8069 | GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8070 | GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8071 | GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8072 | GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8073 | GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8074 | GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8075 | GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8076 | ||
8077 | GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
8078 | GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
8079 | GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8080 | GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8081 | ||
8082 | GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8083 | GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8084 | GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8085 | GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8086 | GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8087 | GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8088 | GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8089 | GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8090 | GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8091 | GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8092 | GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
8093 | GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8094 | ||
8095 | GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8096 | GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8097 | GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8098 | GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
8099 | GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
0487d6a8 JM |
8100 | #endif |
8101 | ||
8102 | /*** SPE floating-point extension ***/ | |
1c97856d AJ |
8103 | #if defined(TARGET_PPC64) |
8104 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 8105 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 | 8106 | { \ |
1c97856d AJ |
8107 | TCGv_i32 t0; \ |
8108 | TCGv t1; \ | |
8109 | t0 = tcg_temp_new_i32(); \ | |
8110 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8111 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
8112 | t1 = tcg_temp_new(); \ |
8113 | tcg_gen_extu_i32_tl(t1, t0); \ | |
8114 | tcg_temp_free_i32(t0); \ | |
8115 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8116 | 0xFFFFFFFF00000000ULL); \ | |
8117 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
8118 | tcg_temp_free(t1); \ | |
0487d6a8 | 8119 | } |
1c97856d | 8120 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 8121 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8122 | { \ |
8123 | TCGv_i32 t0; \ | |
8124 | TCGv t1; \ | |
8125 | t0 = tcg_temp_new_i32(); \ | |
8e703949 | 8126 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
8127 | t1 = tcg_temp_new(); \ |
8128 | tcg_gen_extu_i32_tl(t1, t0); \ | |
8129 | tcg_temp_free_i32(t0); \ | |
8130 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8131 | 0xFFFFFFFF00000000ULL); \ | |
8132 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
8133 | tcg_temp_free(t1); \ | |
8134 | } | |
8135 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 8136 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8137 | { \ |
8138 | TCGv_i32 t0 = tcg_temp_new_i32(); \ | |
8139 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8140 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
8141 | tcg_temp_free_i32(t0); \ |
8142 | } | |
8143 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 8144 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 8145 | { \ |
8e703949 BS |
8146 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8147 | cpu_gpr[rB(ctx->opcode)]); \ | |
1c97856d AJ |
8148 | } |
8149 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 8150 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 8151 | { \ |
1c97856d AJ |
8152 | TCGv_i32 t0, t1; \ |
8153 | TCGv_i64 t2; \ | |
57951c27 | 8154 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 8155 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8156 | return; \ |
8157 | } \ | |
1c97856d AJ |
8158 | t0 = tcg_temp_new_i32(); \ |
8159 | t1 = tcg_temp_new_i32(); \ | |
8160 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
8161 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8162 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
8163 | tcg_temp_free_i32(t1); \ |
8164 | t2 = tcg_temp_new(); \ | |
8165 | tcg_gen_extu_i32_tl(t2, t0); \ | |
8166 | tcg_temp_free_i32(t0); \ | |
8167 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
8168 | 0xFFFFFFFF00000000ULL); \ | |
8169 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \ | |
8170 | tcg_temp_free(t2); \ | |
57951c27 | 8171 | } |
1c97856d | 8172 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ |
636aa200 | 8173 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8174 | { \ |
8175 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8176 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8177 | return; \ |
8178 | } \ | |
8e703949 BS |
8179 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8180 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 8181 | } |
1c97856d | 8182 | #define GEN_SPEFPUOP_COMP_32(name) \ |
636aa200 | 8183 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 8184 | { \ |
1c97856d | 8185 | TCGv_i32 t0, t1; \ |
57951c27 | 8186 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 8187 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8188 | return; \ |
8189 | } \ | |
1c97856d AJ |
8190 | t0 = tcg_temp_new_i32(); \ |
8191 | t1 = tcg_temp_new_i32(); \ | |
8192 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
8193 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 8194 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
8195 | tcg_temp_free_i32(t0); \ |
8196 | tcg_temp_free_i32(t1); \ | |
8197 | } | |
8198 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8199 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8200 | { \ |
8201 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8202 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8203 | return; \ |
8204 | } \ | |
8e703949 | 8205 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8206 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8207 | } | |
8208 | #else | |
8209 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 8210 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 8211 | { \ |
8e703949 BS |
8212 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
8213 | cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 8214 | } |
1c97856d | 8215 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 8216 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8217 | { \ |
8218 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8219 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 8220 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
8221 | tcg_temp_free_i64(t0); \ |
8222 | } | |
8223 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 8224 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8225 | { \ |
8226 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8e703949 | 8227 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
8228 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8229 | tcg_temp_free_i64(t0); \ | |
8230 | } | |
8231 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 8232 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8233 | { \ |
8234 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8235 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 8236 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
8237 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8238 | tcg_temp_free_i64(t0); \ | |
8239 | } | |
8240 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 8241 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8242 | { \ |
8243 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8244 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8245 | return; \ |
8246 | } \ | |
8e703949 | 8247 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8248 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8249 | } | |
8250 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ | |
636aa200 | 8251 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8252 | { \ |
8253 | TCGv_i64 t0, t1; \ | |
8254 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8255 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8256 | return; \ |
8257 | } \ | |
8258 | t0 = tcg_temp_new_i64(); \ | |
8259 | t1 = tcg_temp_new_i64(); \ | |
8260 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8261 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 8262 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
8263 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
8264 | tcg_temp_free_i64(t0); \ | |
8265 | tcg_temp_free_i64(t1); \ | |
8266 | } | |
8267 | #define GEN_SPEFPUOP_COMP_32(name) \ | |
636aa200 | 8268 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8269 | { \ |
8270 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8271 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8272 | return; \ |
8273 | } \ | |
8e703949 | 8274 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
8275 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
8276 | } | |
8277 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8278 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8279 | { \ |
8280 | TCGv_i64 t0, t1; \ | |
8281 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8282 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8283 | return; \ |
8284 | } \ | |
8285 | t0 = tcg_temp_new_i64(); \ | |
8286 | t1 = tcg_temp_new_i64(); \ | |
8287 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8288 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 8289 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
8290 | tcg_temp_free_i64(t0); \ |
8291 | tcg_temp_free_i64(t1); \ | |
8292 | } | |
8293 | #endif | |
57951c27 | 8294 | |
0487d6a8 JM |
8295 | /* Single precision floating-point vectors operations */ |
8296 | /* Arithmetic */ | |
1c97856d AJ |
8297 | GEN_SPEFPUOP_ARITH2_64_64(evfsadd); |
8298 | GEN_SPEFPUOP_ARITH2_64_64(evfssub); | |
8299 | GEN_SPEFPUOP_ARITH2_64_64(evfsmul); | |
8300 | GEN_SPEFPUOP_ARITH2_64_64(evfsdiv); | |
636aa200 | 8301 | static inline void gen_evfsabs(DisasContext *ctx) |
1c97856d AJ |
8302 | { |
8303 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8304 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8305 | return; |
8306 | } | |
8307 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8308 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL); |
1c97856d | 8309 | #else |
6d5c34fa MP |
8310 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000); |
8311 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8312 | #endif |
8313 | } | |
636aa200 | 8314 | static inline void gen_evfsnabs(DisasContext *ctx) |
1c97856d AJ |
8315 | { |
8316 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8317 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8318 | return; |
8319 | } | |
8320 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8321 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8322 | #else |
6d5c34fa MP |
8323 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8324 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8325 | #endif |
8326 | } | |
636aa200 | 8327 | static inline void gen_evfsneg(DisasContext *ctx) |
1c97856d AJ |
8328 | { |
8329 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8330 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8331 | return; |
8332 | } | |
8333 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8334 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8335 | #else |
6d5c34fa MP |
8336 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8337 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8338 | #endif |
8339 | } | |
8340 | ||
0487d6a8 | 8341 | /* Conversion */ |
1c97856d AJ |
8342 | GEN_SPEFPUOP_CONV_64_64(evfscfui); |
8343 | GEN_SPEFPUOP_CONV_64_64(evfscfsi); | |
8344 | GEN_SPEFPUOP_CONV_64_64(evfscfuf); | |
8345 | GEN_SPEFPUOP_CONV_64_64(evfscfsf); | |
8346 | GEN_SPEFPUOP_CONV_64_64(evfsctui); | |
8347 | GEN_SPEFPUOP_CONV_64_64(evfsctsi); | |
8348 | GEN_SPEFPUOP_CONV_64_64(evfsctuf); | |
8349 | GEN_SPEFPUOP_CONV_64_64(evfsctsf); | |
8350 | GEN_SPEFPUOP_CONV_64_64(evfsctuiz); | |
8351 | GEN_SPEFPUOP_CONV_64_64(evfsctsiz); | |
8352 | ||
0487d6a8 | 8353 | /* Comparison */ |
1c97856d AJ |
8354 | GEN_SPEFPUOP_COMP_64(evfscmpgt); |
8355 | GEN_SPEFPUOP_COMP_64(evfscmplt); | |
8356 | GEN_SPEFPUOP_COMP_64(evfscmpeq); | |
8357 | GEN_SPEFPUOP_COMP_64(evfststgt); | |
8358 | GEN_SPEFPUOP_COMP_64(evfststlt); | |
8359 | GEN_SPEFPUOP_COMP_64(evfststeq); | |
0487d6a8 JM |
8360 | |
8361 | /* Opcodes definitions */ | |
70560da7 FC |
8362 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8363 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8364 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8365 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8366 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8367 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8368 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8369 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8370 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8371 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8372 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8373 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8374 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8375 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8376 | |
8377 | /* Single precision floating-point operations */ | |
8378 | /* Arithmetic */ | |
1c97856d AJ |
8379 | GEN_SPEFPUOP_ARITH2_32_32(efsadd); |
8380 | GEN_SPEFPUOP_ARITH2_32_32(efssub); | |
8381 | GEN_SPEFPUOP_ARITH2_32_32(efsmul); | |
8382 | GEN_SPEFPUOP_ARITH2_32_32(efsdiv); | |
636aa200 | 8383 | static inline void gen_efsabs(DisasContext *ctx) |
1c97856d AJ |
8384 | { |
8385 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8386 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8387 | return; |
8388 | } | |
6d5c34fa | 8389 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL); |
1c97856d | 8390 | } |
636aa200 | 8391 | static inline void gen_efsnabs(DisasContext *ctx) |
1c97856d AJ |
8392 | { |
8393 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8394 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8395 | return; |
8396 | } | |
6d5c34fa | 8397 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d | 8398 | } |
636aa200 | 8399 | static inline void gen_efsneg(DisasContext *ctx) |
1c97856d AJ |
8400 | { |
8401 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8402 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8403 | return; |
8404 | } | |
6d5c34fa | 8405 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d AJ |
8406 | } |
8407 | ||
0487d6a8 | 8408 | /* Conversion */ |
1c97856d AJ |
8409 | GEN_SPEFPUOP_CONV_32_32(efscfui); |
8410 | GEN_SPEFPUOP_CONV_32_32(efscfsi); | |
8411 | GEN_SPEFPUOP_CONV_32_32(efscfuf); | |
8412 | GEN_SPEFPUOP_CONV_32_32(efscfsf); | |
8413 | GEN_SPEFPUOP_CONV_32_32(efsctui); | |
8414 | GEN_SPEFPUOP_CONV_32_32(efsctsi); | |
8415 | GEN_SPEFPUOP_CONV_32_32(efsctuf); | |
8416 | GEN_SPEFPUOP_CONV_32_32(efsctsf); | |
8417 | GEN_SPEFPUOP_CONV_32_32(efsctuiz); | |
8418 | GEN_SPEFPUOP_CONV_32_32(efsctsiz); | |
8419 | GEN_SPEFPUOP_CONV_32_64(efscfd); | |
8420 | ||
0487d6a8 | 8421 | /* Comparison */ |
1c97856d AJ |
8422 | GEN_SPEFPUOP_COMP_32(efscmpgt); |
8423 | GEN_SPEFPUOP_COMP_32(efscmplt); | |
8424 | GEN_SPEFPUOP_COMP_32(efscmpeq); | |
8425 | GEN_SPEFPUOP_COMP_32(efststgt); | |
8426 | GEN_SPEFPUOP_COMP_32(efststlt); | |
8427 | GEN_SPEFPUOP_COMP_32(efststeq); | |
0487d6a8 JM |
8428 | |
8429 | /* Opcodes definitions */ | |
70560da7 FC |
8430 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8431 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8432 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8433 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8434 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8435 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); // | |
8436 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8437 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8438 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8439 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8440 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8441 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8442 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8443 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8444 | |
8445 | /* Double precision floating-point operations */ | |
8446 | /* Arithmetic */ | |
1c97856d AJ |
8447 | GEN_SPEFPUOP_ARITH2_64_64(efdadd); |
8448 | GEN_SPEFPUOP_ARITH2_64_64(efdsub); | |
8449 | GEN_SPEFPUOP_ARITH2_64_64(efdmul); | |
8450 | GEN_SPEFPUOP_ARITH2_64_64(efddiv); | |
636aa200 | 8451 | static inline void gen_efdabs(DisasContext *ctx) |
1c97856d AJ |
8452 | { |
8453 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8454 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8455 | return; |
8456 | } | |
8457 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8458 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL); |
1c97856d | 8459 | #else |
6d5c34fa MP |
8460 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8461 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8462 | #endif |
8463 | } | |
636aa200 | 8464 | static inline void gen_efdnabs(DisasContext *ctx) |
1c97856d AJ |
8465 | { |
8466 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8467 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8468 | return; |
8469 | } | |
8470 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8471 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8472 | #else |
6d5c34fa MP |
8473 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8474 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8475 | #endif |
8476 | } | |
636aa200 | 8477 | static inline void gen_efdneg(DisasContext *ctx) |
1c97856d AJ |
8478 | { |
8479 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8480 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8481 | return; |
8482 | } | |
8483 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8484 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8485 | #else |
6d5c34fa MP |
8486 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8487 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8488 | #endif |
8489 | } | |
8490 | ||
0487d6a8 | 8491 | /* Conversion */ |
1c97856d AJ |
8492 | GEN_SPEFPUOP_CONV_64_32(efdcfui); |
8493 | GEN_SPEFPUOP_CONV_64_32(efdcfsi); | |
8494 | GEN_SPEFPUOP_CONV_64_32(efdcfuf); | |
8495 | GEN_SPEFPUOP_CONV_64_32(efdcfsf); | |
8496 | GEN_SPEFPUOP_CONV_32_64(efdctui); | |
8497 | GEN_SPEFPUOP_CONV_32_64(efdctsi); | |
8498 | GEN_SPEFPUOP_CONV_32_64(efdctuf); | |
8499 | GEN_SPEFPUOP_CONV_32_64(efdctsf); | |
8500 | GEN_SPEFPUOP_CONV_32_64(efdctuiz); | |
8501 | GEN_SPEFPUOP_CONV_32_64(efdctsiz); | |
8502 | GEN_SPEFPUOP_CONV_64_32(efdcfs); | |
8503 | GEN_SPEFPUOP_CONV_64_64(efdcfuid); | |
8504 | GEN_SPEFPUOP_CONV_64_64(efdcfsid); | |
8505 | GEN_SPEFPUOP_CONV_64_64(efdctuidz); | |
8506 | GEN_SPEFPUOP_CONV_64_64(efdctsidz); | |
0487d6a8 | 8507 | |
0487d6a8 | 8508 | /* Comparison */ |
1c97856d AJ |
8509 | GEN_SPEFPUOP_COMP_64(efdcmpgt); |
8510 | GEN_SPEFPUOP_COMP_64(efdcmplt); | |
8511 | GEN_SPEFPUOP_COMP_64(efdcmpeq); | |
8512 | GEN_SPEFPUOP_COMP_64(efdtstgt); | |
8513 | GEN_SPEFPUOP_COMP_64(efdtstlt); | |
8514 | GEN_SPEFPUOP_COMP_64(efdtsteq); | |
0487d6a8 JM |
8515 | |
8516 | /* Opcodes definitions */ | |
70560da7 FC |
8517 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // |
8518 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8519 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); // | |
8520 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8521 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // | |
8522 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8523 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8524 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); // | |
8525 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8526 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8527 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8528 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8529 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8530 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8531 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8532 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
0487d6a8 | 8533 | |
c227f099 | 8534 | static opcode_t opcodes[] = { |
5c55ff99 BS |
8535 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
8536 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
8537 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8538 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER), | |
8539 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8540 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), | |
8541 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8542 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8543 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8544 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8545 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), | |
8546 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
8547 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
8548 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
8549 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8550 | #if defined(TARGET_PPC64) | |
8551 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
8552 | #endif | |
8553 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
8554 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
8555 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8556 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8557 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8558 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
8559 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), | |
8560 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
8561 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8562 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8563 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8564 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8565 | GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), | |
eaabeef2 | 8566 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 8567 | #if defined(TARGET_PPC64) |
eaabeef2 | 8568 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 BS |
8569 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
8570 | #endif | |
8571 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8572 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8573 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8574 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
8575 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
8576 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
8577 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
8578 | #if defined(TARGET_PPC64) | |
8579 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
8580 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
8581 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
8582 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
8583 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
8584 | #endif | |
8585 | GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES), | |
8586 | GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8587 | GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8588 | GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT), | |
8589 | GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT), | |
8590 | GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT), | |
8591 | GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT), | |
8592 | GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT), | |
8593 | GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT), | |
8594 | GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT), | |
8595 | GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT), | |
8596 | GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT), | |
8597 | #if defined(TARGET_PPC64) | |
8598 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8599 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
8600 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8601 | #endif | |
8602 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8603 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8604 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
8605 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
8606 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
8607 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
8608 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO), | |
8609 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), | |
f844c817 | 8610 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
5c55ff99 BS |
8611 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
8612 | #if defined(TARGET_PPC64) | |
f844c817 | 8613 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
5c55ff99 BS |
8614 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
8615 | #endif | |
8616 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
8617 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
8618 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8619 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8620 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
8621 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
8622 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), | |
8623 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
8624 | #if defined(TARGET_PPC64) | |
8625 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
8626 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), | |
8627 | #endif | |
8628 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
8629 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
8630 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8631 | #if defined(TARGET_PPC64) | |
8632 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
8633 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8634 | #endif | |
8635 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
8636 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
8637 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
8638 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
8639 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
8640 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
8641 | #if defined(TARGET_PPC64) | |
8642 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
8643 | #endif | |
8644 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC), | |
8645 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC), | |
8646 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), | |
8647 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), | |
8648 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
8649 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE), | |
8650 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE), | |
8651 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ), | |
8652 | GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT), | |
8653 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), | |
8654 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC), | |
8655 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), | |
8656 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
8657 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), | |
8658 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
8659 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
8660 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
8661 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
8662 | #if defined(TARGET_PPC64) | |
8663 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
8664 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
8665 | PPC_SEGMENT_64B), | |
8666 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
8667 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
8668 | PPC_SEGMENT_64B), | |
efdef95f DG |
8669 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
8670 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
8671 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
5c55ff99 BS |
8672 | #endif |
8673 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
8674 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE), | |
8675 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE), | |
8676 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), | |
8677 | #if defined(TARGET_PPC64) | |
8678 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI), | |
8679 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), | |
8680 | #endif | |
8681 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
8682 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
8683 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
8684 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
8685 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
8686 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
8687 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
8688 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
8689 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
8690 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
8691 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
8692 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8693 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
8694 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
8695 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
8696 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
8697 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
8698 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
8699 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
8700 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8701 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
8702 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
8703 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
8704 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
8705 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
8706 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
8707 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
8708 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
8709 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
8710 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
8711 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
8712 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
8713 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
8714 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
8715 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
8716 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
8717 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
8718 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
8719 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
8720 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
8721 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
8722 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
8723 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
8724 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
8725 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
8726 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
8727 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
8728 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
8729 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
8730 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8731 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8732 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
8733 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
8734 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8735 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8736 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
8737 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
8738 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
8739 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
8740 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
8741 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
8742 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
8743 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
8744 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
8745 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
8746 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
8747 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
8748 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
8749 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
8750 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
8751 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 8752 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
8753 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
8754 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
8755 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
8756 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
8757 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
8758 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
8759 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
8760 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
8761 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
8762 | PPC_NONE, PPC2_BOOKE206), | |
8763 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
8764 | PPC_NONE, PPC2_BOOKE206), | |
8765 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
8766 | PPC_NONE, PPC2_BOOKE206), | |
8767 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
8768 | PPC_NONE, PPC2_BOOKE206), | |
6d3db821 AG |
8769 | GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001, |
8770 | PPC_NONE, PPC2_BOOKE206), | |
d5d11a39 AG |
8771 | GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001, |
8772 | PPC_NONE, PPC2_PRCNTL), | |
9e0b5cb1 AG |
8773 | GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001, |
8774 | PPC_NONE, PPC2_PRCNTL), | |
5c55ff99 | 8775 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 8776 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 8777 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
8778 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
8779 | PPC_BOOKE, PPC2_BOOKE206), | |
dcb2b9e1 | 8780 | GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE), |
01662f3e AG |
8781 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, |
8782 | PPC_BOOKE, PPC2_BOOKE206), | |
5c55ff99 BS |
8783 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
8784 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
8785 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
8786 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
8787 | GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC), | |
8788 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), | |
8789 | GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE), | |
8790 | GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE), | |
8791 | GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE), | |
8792 | GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE), | |
8793 | ||
8794 | #undef GEN_INT_ARITH_ADD | |
8795 | #undef GEN_INT_ARITH_ADD_CONST | |
8796 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8797 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
8798 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
8799 | add_ca, compute_ca, compute_ov) \ | |
8800 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
8801 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
8802 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
8803 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
8804 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
8805 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
8806 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
8807 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
8808 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
8809 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
8810 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
8811 | ||
8812 | #undef GEN_INT_ARITH_DIVW | |
8813 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
8814 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
8815 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
8816 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
8817 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
8818 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
8819 | ||
8820 | #if defined(TARGET_PPC64) | |
8821 | #undef GEN_INT_ARITH_DIVD | |
8822 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
8823 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8824 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
8825 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
8826 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
8827 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
8828 | ||
8829 | #undef GEN_INT_ARITH_MUL_HELPER | |
8830 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
8831 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8832 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
8833 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
8834 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
8835 | #endif | |
8836 | ||
8837 | #undef GEN_INT_ARITH_SUBF | |
8838 | #undef GEN_INT_ARITH_SUBF_CONST | |
8839 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8840 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
8841 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
8842 | add_ca, compute_ca, compute_ov) \ | |
8843 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
8844 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
8845 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
8846 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
8847 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
8848 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
8849 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
8850 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
8851 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
8852 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
8853 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
8854 | ||
8855 | #undef GEN_LOGICAL1 | |
8856 | #undef GEN_LOGICAL2 | |
8857 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
8858 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
8859 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
8860 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
8861 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
8862 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
8863 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
8864 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
8865 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
8866 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
8867 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
8868 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
8869 | #if defined(TARGET_PPC64) | |
8870 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
8871 | #endif | |
8872 | ||
8873 | #if defined(TARGET_PPC64) | |
8874 | #undef GEN_PPC64_R2 | |
8875 | #undef GEN_PPC64_R4 | |
8876 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
8877 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8878 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8879 | PPC_64B) | |
8880 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
8881 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8882 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
8883 | PPC_64B), \ | |
8884 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8885 | PPC_64B), \ | |
8886 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
8887 | PPC_64B) | |
8888 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
8889 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
8890 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
8891 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
8892 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
8893 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
8894 | #endif | |
8895 | ||
8896 | #undef _GEN_FLOAT_ACB | |
8897 | #undef GEN_FLOAT_ACB | |
8898 | #undef _GEN_FLOAT_AB | |
8899 | #undef GEN_FLOAT_AB | |
8900 | #undef _GEN_FLOAT_AC | |
8901 | #undef GEN_FLOAT_AC | |
8902 | #undef GEN_FLOAT_B | |
8903 | #undef GEN_FLOAT_BS | |
8904 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ | |
8905 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) | |
8906 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ | |
8907 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \ | |
8908 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type) | |
8909 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8910 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8911 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ | |
8912 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8913 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8914 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8915 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8916 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ | |
8917 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8918 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8919 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ | |
8920 | GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) | |
8921 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ | |
8922 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) | |
8923 | ||
8924 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT), | |
8925 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT), | |
8926 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT), | |
8927 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT), | |
8928 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES), | |
8929 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE), | |
8930 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL), | |
8931 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT), | |
8932 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT), | |
8933 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT), | |
8934 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT), | |
8935 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT), | |
8936 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT), | |
8937 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT), | |
8938 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT), | |
8939 | #if defined(TARGET_PPC64) | |
8940 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B), | |
8941 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B), | |
8942 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B), | |
8943 | #endif | |
8944 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT), | |
8945 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT), | |
8946 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT), | |
8947 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), | |
8948 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT), | |
8949 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT), | |
8950 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT), | |
8951 | ||
8952 | #undef GEN_LD | |
8953 | #undef GEN_LDU | |
8954 | #undef GEN_LDUX | |
cd6e9320 | 8955 | #undef GEN_LDX_E |
5c55ff99 BS |
8956 | #undef GEN_LDS |
8957 | #define GEN_LD(name, ldop, opc, type) \ | |
8958 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8959 | #define GEN_LDU(name, ldop, opc, type) \ | |
8960 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8961 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
8962 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
8963 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
8964 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
8965 | #define GEN_LDS(name, ldop, op, type) \ |
8966 | GEN_LD(name, ldop, op | 0x20, type) \ | |
8967 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
8968 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
8969 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
8970 | ||
8971 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
8972 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
8973 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
8974 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
8975 | #if defined(TARGET_PPC64) | |
8976 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
8977 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
8978 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B) | |
8979 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B) | |
cd6e9320 | 8980 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
8981 | #endif |
8982 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
8983 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
8984 | ||
8985 | #undef GEN_ST | |
8986 | #undef GEN_STU | |
8987 | #undef GEN_STUX | |
cd6e9320 | 8988 | #undef GEN_STX_E |
5c55ff99 BS |
8989 | #undef GEN_STS |
8990 | #define GEN_ST(name, stop, opc, type) \ | |
8991 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8992 | #define GEN_STU(name, stop, opc, type) \ | |
8993 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8994 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
8995 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
8996 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
8997 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
8998 | #define GEN_STS(name, stop, op, type) \ |
8999 | GEN_ST(name, stop, op | 0x20, type) \ | |
9000 | GEN_STU(name, stop, op | 0x21, type) \ | |
9001 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
9002 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
9003 | ||
9004 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
9005 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
9006 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
9007 | #if defined(TARGET_PPC64) | |
9008 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B) | |
9009 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B) | |
cd6e9320 | 9010 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
9011 | #endif |
9012 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
9013 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
9014 | ||
9015 | #undef GEN_LDF | |
9016 | #undef GEN_LDUF | |
9017 | #undef GEN_LDUXF | |
9018 | #undef GEN_LDXF | |
9019 | #undef GEN_LDFS | |
9020 | #define GEN_LDF(name, ldop, opc, type) \ | |
9021 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9022 | #define GEN_LDUF(name, ldop, opc, type) \ | |
9023 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9024 | #define GEN_LDUXF(name, ldop, opc, type) \ | |
9025 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
9026 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ | |
9027 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
9028 | #define GEN_LDFS(name, ldop, op, type) \ | |
9029 | GEN_LDF(name, ldop, op | 0x20, type) \ | |
9030 | GEN_LDUF(name, ldop, op | 0x21, type) \ | |
9031 | GEN_LDUXF(name, ldop, op | 0x01, type) \ | |
9032 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
9033 | ||
9034 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT) | |
9035 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT) | |
9036 | ||
9037 | #undef GEN_STF | |
9038 | #undef GEN_STUF | |
9039 | #undef GEN_STUXF | |
9040 | #undef GEN_STXF | |
9041 | #undef GEN_STFS | |
9042 | #define GEN_STF(name, stop, opc, type) \ | |
9043 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9044 | #define GEN_STUF(name, stop, opc, type) \ | |
9045 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9046 | #define GEN_STUXF(name, stop, opc, type) \ | |
9047 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
9048 | #define GEN_STXF(name, stop, opc2, opc3, type) \ | |
9049 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
9050 | #define GEN_STFS(name, stop, op, type) \ | |
9051 | GEN_STF(name, stop, op | 0x20, type) \ | |
9052 | GEN_STUF(name, stop, op | 0x21, type) \ | |
9053 | GEN_STUXF(name, stop, op | 0x01, type) \ | |
9054 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
9055 | ||
9056 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT) | |
9057 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT) | |
9058 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX) | |
9059 | ||
9060 | #undef GEN_CRLOGIC | |
9061 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
9062 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
9063 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
9064 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
9065 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
9066 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
9067 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
9068 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
9069 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
9070 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
9071 | ||
9072 | #undef GEN_MAC_HANDLER | |
9073 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
9074 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
9075 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
9076 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
9077 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
9078 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
9079 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
9080 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
9081 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
9082 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
9083 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
9084 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
9085 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
9086 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
9087 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
9088 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
9089 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
9090 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
9091 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
9092 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
9093 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
9094 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
9095 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
9096 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
9097 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
9098 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
9099 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
9100 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
9101 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
9102 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
9103 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
9104 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
9105 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
9106 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
9107 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
9108 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
9109 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
9110 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
9111 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
9112 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
9113 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
9114 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
9115 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
9116 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
9117 | ||
9118 | #undef GEN_VR_LDX | |
9119 | #undef GEN_VR_STX | |
9120 | #undef GEN_VR_LVE | |
9121 | #undef GEN_VR_STVE | |
9122 | #define GEN_VR_LDX(name, opc2, opc3) \ | |
9123 | GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9124 | #define GEN_VR_STX(name, opc2, opc3) \ | |
9125 | GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9126 | #define GEN_VR_LVE(name, opc2, opc3) \ | |
9127 | GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9128 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
9129 | GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
9130 | GEN_VR_LDX(lvx, 0x07, 0x03), | |
9131 | GEN_VR_LDX(lvxl, 0x07, 0x0B), | |
9132 | GEN_VR_LVE(bx, 0x07, 0x00), | |
9133 | GEN_VR_LVE(hx, 0x07, 0x01), | |
9134 | GEN_VR_LVE(wx, 0x07, 0x02), | |
9135 | GEN_VR_STX(svx, 0x07, 0x07), | |
9136 | GEN_VR_STX(svxl, 0x07, 0x0F), | |
9137 | GEN_VR_STVE(bx, 0x07, 0x04), | |
9138 | GEN_VR_STVE(hx, 0x07, 0x05), | |
9139 | GEN_VR_STVE(wx, 0x07, 0x06), | |
9140 | ||
9141 | #undef GEN_VX_LOGICAL | |
9142 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
9143 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9144 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16), | |
9145 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17), | |
9146 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18), | |
9147 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19), | |
9148 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20), | |
9149 | ||
9150 | #undef GEN_VXFORM | |
9151 | #define GEN_VXFORM(name, opc2, opc3) \ | |
9152 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9153 | GEN_VXFORM(vaddubm, 0, 0), | |
9154 | GEN_VXFORM(vadduhm, 0, 1), | |
9155 | GEN_VXFORM(vadduwm, 0, 2), | |
9156 | GEN_VXFORM(vsububm, 0, 16), | |
9157 | GEN_VXFORM(vsubuhm, 0, 17), | |
9158 | GEN_VXFORM(vsubuwm, 0, 18), | |
9159 | GEN_VXFORM(vmaxub, 1, 0), | |
9160 | GEN_VXFORM(vmaxuh, 1, 1), | |
9161 | GEN_VXFORM(vmaxuw, 1, 2), | |
9162 | GEN_VXFORM(vmaxsb, 1, 4), | |
9163 | GEN_VXFORM(vmaxsh, 1, 5), | |
9164 | GEN_VXFORM(vmaxsw, 1, 6), | |
9165 | GEN_VXFORM(vminub, 1, 8), | |
9166 | GEN_VXFORM(vminuh, 1, 9), | |
9167 | GEN_VXFORM(vminuw, 1, 10), | |
9168 | GEN_VXFORM(vminsb, 1, 12), | |
9169 | GEN_VXFORM(vminsh, 1, 13), | |
9170 | GEN_VXFORM(vminsw, 1, 14), | |
9171 | GEN_VXFORM(vavgub, 1, 16), | |
9172 | GEN_VXFORM(vavguh, 1, 17), | |
9173 | GEN_VXFORM(vavguw, 1, 18), | |
9174 | GEN_VXFORM(vavgsb, 1, 20), | |
9175 | GEN_VXFORM(vavgsh, 1, 21), | |
9176 | GEN_VXFORM(vavgsw, 1, 22), | |
9177 | GEN_VXFORM(vmrghb, 6, 0), | |
9178 | GEN_VXFORM(vmrghh, 6, 1), | |
9179 | GEN_VXFORM(vmrghw, 6, 2), | |
9180 | GEN_VXFORM(vmrglb, 6, 4), | |
9181 | GEN_VXFORM(vmrglh, 6, 5), | |
9182 | GEN_VXFORM(vmrglw, 6, 6), | |
9183 | GEN_VXFORM(vmuloub, 4, 0), | |
9184 | GEN_VXFORM(vmulouh, 4, 1), | |
9185 | GEN_VXFORM(vmulosb, 4, 4), | |
9186 | GEN_VXFORM(vmulosh, 4, 5), | |
9187 | GEN_VXFORM(vmuleub, 4, 8), | |
9188 | GEN_VXFORM(vmuleuh, 4, 9), | |
9189 | GEN_VXFORM(vmulesb, 4, 12), | |
9190 | GEN_VXFORM(vmulesh, 4, 13), | |
9191 | GEN_VXFORM(vslb, 2, 4), | |
9192 | GEN_VXFORM(vslh, 2, 5), | |
9193 | GEN_VXFORM(vslw, 2, 6), | |
9194 | GEN_VXFORM(vsrb, 2, 8), | |
9195 | GEN_VXFORM(vsrh, 2, 9), | |
9196 | GEN_VXFORM(vsrw, 2, 10), | |
9197 | GEN_VXFORM(vsrab, 2, 12), | |
9198 | GEN_VXFORM(vsrah, 2, 13), | |
9199 | GEN_VXFORM(vsraw, 2, 14), | |
9200 | GEN_VXFORM(vslo, 6, 16), | |
9201 | GEN_VXFORM(vsro, 6, 17), | |
9202 | GEN_VXFORM(vaddcuw, 0, 6), | |
9203 | GEN_VXFORM(vsubcuw, 0, 22), | |
9204 | GEN_VXFORM(vaddubs, 0, 8), | |
9205 | GEN_VXFORM(vadduhs, 0, 9), | |
9206 | GEN_VXFORM(vadduws, 0, 10), | |
9207 | GEN_VXFORM(vaddsbs, 0, 12), | |
9208 | GEN_VXFORM(vaddshs, 0, 13), | |
9209 | GEN_VXFORM(vaddsws, 0, 14), | |
9210 | GEN_VXFORM(vsububs, 0, 24), | |
9211 | GEN_VXFORM(vsubuhs, 0, 25), | |
9212 | GEN_VXFORM(vsubuws, 0, 26), | |
9213 | GEN_VXFORM(vsubsbs, 0, 28), | |
9214 | GEN_VXFORM(vsubshs, 0, 29), | |
9215 | GEN_VXFORM(vsubsws, 0, 30), | |
9216 | GEN_VXFORM(vrlb, 2, 0), | |
9217 | GEN_VXFORM(vrlh, 2, 1), | |
9218 | GEN_VXFORM(vrlw, 2, 2), | |
9219 | GEN_VXFORM(vsl, 2, 7), | |
9220 | GEN_VXFORM(vsr, 2, 11), | |
9221 | GEN_VXFORM(vpkuhum, 7, 0), | |
9222 | GEN_VXFORM(vpkuwum, 7, 1), | |
9223 | GEN_VXFORM(vpkuhus, 7, 2), | |
9224 | GEN_VXFORM(vpkuwus, 7, 3), | |
9225 | GEN_VXFORM(vpkshus, 7, 4), | |
9226 | GEN_VXFORM(vpkswus, 7, 5), | |
9227 | GEN_VXFORM(vpkshss, 7, 6), | |
9228 | GEN_VXFORM(vpkswss, 7, 7), | |
9229 | GEN_VXFORM(vpkpx, 7, 12), | |
9230 | GEN_VXFORM(vsum4ubs, 4, 24), | |
9231 | GEN_VXFORM(vsum4sbs, 4, 28), | |
9232 | GEN_VXFORM(vsum4shs, 4, 25), | |
9233 | GEN_VXFORM(vsum2sws, 4, 26), | |
9234 | GEN_VXFORM(vsumsws, 4, 30), | |
9235 | GEN_VXFORM(vaddfp, 5, 0), | |
9236 | GEN_VXFORM(vsubfp, 5, 1), | |
9237 | GEN_VXFORM(vmaxfp, 5, 16), | |
9238 | GEN_VXFORM(vminfp, 5, 17), | |
9239 | ||
9240 | #undef GEN_VXRFORM1 | |
9241 | #undef GEN_VXRFORM | |
9242 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ | |
9243 | GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC), | |
9244 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
9245 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
9246 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
9247 | GEN_VXRFORM(vcmpequb, 3, 0) | |
9248 | GEN_VXRFORM(vcmpequh, 3, 1) | |
9249 | GEN_VXRFORM(vcmpequw, 3, 2) | |
9250 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
9251 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
9252 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
9253 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
9254 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
9255 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
9256 | GEN_VXRFORM(vcmpeqfp, 3, 3) | |
9257 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
9258 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
9259 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
9260 | ||
9261 | #undef GEN_VXFORM_SIMM | |
9262 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ | |
9263 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9264 | GEN_VXFORM_SIMM(vspltisb, 6, 12), | |
9265 | GEN_VXFORM_SIMM(vspltish, 6, 13), | |
9266 | GEN_VXFORM_SIMM(vspltisw, 6, 14), | |
9267 | ||
9268 | #undef GEN_VXFORM_NOA | |
9269 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ | |
9270 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) | |
9271 | GEN_VXFORM_NOA(vupkhsb, 7, 8), | |
9272 | GEN_VXFORM_NOA(vupkhsh, 7, 9), | |
9273 | GEN_VXFORM_NOA(vupklsb, 7, 10), | |
9274 | GEN_VXFORM_NOA(vupklsh, 7, 11), | |
9275 | GEN_VXFORM_NOA(vupkhpx, 7, 13), | |
9276 | GEN_VXFORM_NOA(vupklpx, 7, 15), | |
9277 | GEN_VXFORM_NOA(vrefp, 5, 4), | |
9278 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5), | |
0bffbc6c | 9279 | GEN_VXFORM_NOA(vexptefp, 5, 6), |
5c55ff99 BS |
9280 | GEN_VXFORM_NOA(vlogefp, 5, 7), |
9281 | GEN_VXFORM_NOA(vrfim, 5, 8), | |
9282 | GEN_VXFORM_NOA(vrfin, 5, 9), | |
9283 | GEN_VXFORM_NOA(vrfip, 5, 10), | |
9284 | GEN_VXFORM_NOA(vrfiz, 5, 11), | |
9285 | ||
9286 | #undef GEN_VXFORM_UIMM | |
9287 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ | |
9288 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9289 | GEN_VXFORM_UIMM(vspltb, 6, 8), | |
9290 | GEN_VXFORM_UIMM(vsplth, 6, 9), | |
9291 | GEN_VXFORM_UIMM(vspltw, 6, 10), | |
9292 | GEN_VXFORM_UIMM(vcfux, 5, 12), | |
9293 | GEN_VXFORM_UIMM(vcfsx, 5, 13), | |
9294 | GEN_VXFORM_UIMM(vctuxs, 5, 14), | |
9295 | GEN_VXFORM_UIMM(vctsxs, 5, 15), | |
9296 | ||
9297 | #undef GEN_VAFORM_PAIRED | |
9298 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ | |
9299 | GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) | |
9300 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16), | |
9301 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18), | |
9302 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19), | |
9303 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20), | |
9304 | GEN_VAFORM_PAIRED(vsel, vperm, 21), | |
9305 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23), | |
9306 | ||
9307 | #undef GEN_SPE | |
70560da7 FC |
9308 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
9309 | GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE) | |
9310 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9311 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9312 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9313 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9314 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9315 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9316 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9317 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE), | |
9318 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE), | |
9319 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9320 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9321 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9322 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9323 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9324 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9325 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE), | |
9326 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9327 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9328 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9329 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9330 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9331 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9332 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9333 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9334 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9335 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9336 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9337 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9338 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE), | |
9339 | ||
9340 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9341 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9342 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9343 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9344 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9345 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9346 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9347 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9348 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9349 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9350 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9351 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9352 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9353 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9354 | ||
9355 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9356 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9357 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9358 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9359 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9360 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE), | |
9361 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9362 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9363 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9364 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9365 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9366 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9367 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9368 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9369 | ||
9370 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9371 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9372 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE), | |
9373 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9374 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9375 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9376 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9377 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE), | |
9378 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9379 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9380 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9381 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9382 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9383 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9384 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9385 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
5c55ff99 BS |
9386 | |
9387 | #undef GEN_SPEOP_LDST | |
9388 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
9389 | GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) | |
9390 | GEN_SPEOP_LDST(evldd, 0x00, 3), | |
9391 | GEN_SPEOP_LDST(evldw, 0x01, 3), | |
9392 | GEN_SPEOP_LDST(evldh, 0x02, 3), | |
9393 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1), | |
9394 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1), | |
9395 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1), | |
9396 | GEN_SPEOP_LDST(evlwhe, 0x08, 2), | |
9397 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2), | |
9398 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2), | |
9399 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2), | |
9400 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2), | |
9401 | ||
9402 | GEN_SPEOP_LDST(evstdd, 0x10, 3), | |
9403 | GEN_SPEOP_LDST(evstdw, 0x11, 3), | |
9404 | GEN_SPEOP_LDST(evstdh, 0x12, 3), | |
9405 | GEN_SPEOP_LDST(evstwhe, 0x18, 2), | |
9406 | GEN_SPEOP_LDST(evstwho, 0x1A, 2), | |
9407 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2), | |
9408 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2), | |
9409 | }; | |
9410 | ||
0411a972 | 9411 | #include "helper_regs.h" |
a1389542 | 9412 | #include "translate_init.c" |
79aceca5 | 9413 | |
9a64fbe4 | 9414 | /*****************************************************************************/ |
3fc6c082 | 9415 | /* Misc PowerPC helpers */ |
1328c2bf | 9416 | void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf, |
36081602 | 9417 | int flags) |
79aceca5 | 9418 | { |
3fc6c082 FB |
9419 | #define RGPL 4 |
9420 | #define RFPL 4 | |
3fc6c082 | 9421 | |
79aceca5 FB |
9422 | int i; |
9423 | ||
29979a8d AG |
9424 | cpu_synchronize_state(env); |
9425 | ||
90e189ec | 9426 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
9a78eead SW |
9427 | TARGET_FMT_lx " XER " TARGET_FMT_lx "\n", |
9428 | env->nip, env->lr, env->ctr, env->xer); | |
90e189ec BS |
9429 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
9430 | TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0], | |
9431 | env->hflags, env->mmu_idx); | |
d9bce9d9 | 9432 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 9433 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 9434 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 9435 | " DECR %08" PRIu32 |
76a66253 JM |
9436 | #endif |
9437 | "\n", | |
077fc206 | 9438 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
9439 | #if !defined(CONFIG_USER_ONLY) |
9440 | , cpu_ppc_load_decr(env) | |
9441 | #endif | |
9442 | ); | |
077fc206 | 9443 | #endif |
76a66253 | 9444 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
9445 | if ((i & (RGPL - 1)) == 0) |
9446 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 9447 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 9448 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 9449 | cpu_fprintf(f, "\n"); |
76a66253 | 9450 | } |
3fc6c082 | 9451 | cpu_fprintf(f, "CR "); |
76a66253 | 9452 | for (i = 0; i < 8; i++) |
7fe48483 FB |
9453 | cpu_fprintf(f, "%01x", env->crf[i]); |
9454 | cpu_fprintf(f, " ["); | |
76a66253 JM |
9455 | for (i = 0; i < 8; i++) { |
9456 | char a = '-'; | |
9457 | if (env->crf[i] & 0x08) | |
9458 | a = 'L'; | |
9459 | else if (env->crf[i] & 0x04) | |
9460 | a = 'G'; | |
9461 | else if (env->crf[i] & 0x02) | |
9462 | a = 'E'; | |
7fe48483 | 9463 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 9464 | } |
90e189ec BS |
9465 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
9466 | env->reserve_addr); | |
3fc6c082 FB |
9467 | for (i = 0; i < 32; i++) { |
9468 | if ((i & (RFPL - 1)) == 0) | |
9469 | cpu_fprintf(f, "FPR%02d", i); | |
26a76461 | 9470 | cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); |
3fc6c082 | 9471 | if ((i & (RFPL - 1)) == (RFPL - 1)) |
7fe48483 | 9472 | cpu_fprintf(f, "\n"); |
79aceca5 | 9473 | } |
30304420 | 9474 | cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); |
f2e63a42 | 9475 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
9476 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
9477 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
9478 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
9479 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
9480 | ||
9481 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
9482 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
9483 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
9484 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
9485 | ||
9486 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
9487 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
9488 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
9489 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
9490 | ||
9491 | if (env->excp_model == POWERPC_EXCP_BOOKE) { | |
9492 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
9493 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
9494 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
9495 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
9496 | ||
9497 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
9498 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
9499 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
9500 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
9501 | ||
9502 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
9503 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
9504 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
9505 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
9506 | ||
9507 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
9508 | " EPR " TARGET_FMT_lx "\n", | |
9509 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
9510 | env->spr[SPR_BOOKE_EPR]); | |
9511 | ||
9512 | /* FSL-specific */ | |
9513 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
9514 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
9515 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
9516 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
9517 | ||
9518 | /* | |
9519 | * IVORs are left out as they are large and do not change often -- | |
9520 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
9521 | */ | |
9522 | } | |
9523 | ||
697ab892 DG |
9524 | #if defined(TARGET_PPC64) |
9525 | if (env->flags & POWERPC_FLAG_CFAR) { | |
9526 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
9527 | } | |
9528 | #endif | |
9529 | ||
90dc8812 SW |
9530 | switch (env->mmu_model) { |
9531 | case POWERPC_MMU_32B: | |
9532 | case POWERPC_MMU_601: | |
9533 | case POWERPC_MMU_SOFT_6xx: | |
9534 | case POWERPC_MMU_SOFT_74xx: | |
9535 | #if defined(TARGET_PPC64) | |
9536 | case POWERPC_MMU_620: | |
9537 | case POWERPC_MMU_64B: | |
9538 | #endif | |
9539 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]); | |
9540 | break; | |
01662f3e | 9541 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
9542 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
9543 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
9544 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
9545 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
9546 | ||
9547 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
9548 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
9549 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
9550 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
9551 | ||
9552 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
9553 | " TLB1CFG " TARGET_FMT_lx "\n", | |
9554 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
9555 | env->spr[SPR_BOOKE_TLB1CFG]); | |
9556 | break; | |
9557 | default: | |
9558 | break; | |
9559 | } | |
f2e63a42 | 9560 | #endif |
79aceca5 | 9561 | |
3fc6c082 FB |
9562 | #undef RGPL |
9563 | #undef RFPL | |
79aceca5 FB |
9564 | } |
9565 | ||
1328c2bf | 9566 | void cpu_dump_statistics (CPUPPCState *env, FILE*f, fprintf_function cpu_fprintf, |
76a66253 JM |
9567 | int flags) |
9568 | { | |
9569 | #if defined(DO_PPC_STATISTICS) | |
c227f099 | 9570 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
9571 | int op1, op2, op3; |
9572 | ||
9573 | t1 = env->opcodes; | |
9574 | for (op1 = 0; op1 < 64; op1++) { | |
9575 | handler = t1[op1]; | |
9576 | if (is_indirect_opcode(handler)) { | |
9577 | t2 = ind_table(handler); | |
9578 | for (op2 = 0; op2 < 32; op2++) { | |
9579 | handler = t2[op2]; | |
9580 | if (is_indirect_opcode(handler)) { | |
9581 | t3 = ind_table(handler); | |
9582 | for (op3 = 0; op3 < 32; op3++) { | |
9583 | handler = t3[op3]; | |
9584 | if (handler->count == 0) | |
9585 | continue; | |
9586 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9587 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9588 | op1, op2, op3, op1, (op3 << 5) | op2, |
9589 | handler->oname, | |
9590 | handler->count, handler->count); | |
9591 | } | |
9592 | } else { | |
9593 | if (handler->count == 0) | |
9594 | continue; | |
9595 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9596 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9597 | op1, op2, op1, op2, handler->oname, |
9598 | handler->count, handler->count); | |
9599 | } | |
9600 | } | |
9601 | } else { | |
9602 | if (handler->count == 0) | |
9603 | continue; | |
0bfcd599 BS |
9604 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
9605 | " %" PRId64 "\n", | |
76a66253 JM |
9606 | op1, op1, handler->oname, |
9607 | handler->count, handler->count); | |
9608 | } | |
9609 | } | |
9610 | #endif | |
9611 | } | |
9612 | ||
9a64fbe4 | 9613 | /*****************************************************************************/ |
1328c2bf | 9614 | static inline void gen_intermediate_code_internal(CPUPPCState *env, |
636aa200 BS |
9615 | TranslationBlock *tb, |
9616 | int search_pc) | |
79aceca5 | 9617 | { |
9fddaa0c | 9618 | DisasContext ctx, *ctxp = &ctx; |
c227f099 | 9619 | opc_handler_t **table, *handler; |
0fa85d43 | 9620 | target_ulong pc_start; |
79aceca5 | 9621 | uint16_t *gen_opc_end; |
a1d1bb31 | 9622 | CPUBreakpoint *bp; |
79aceca5 | 9623 | int j, lj = -1; |
2e70f6ef PB |
9624 | int num_insns; |
9625 | int max_insns; | |
79aceca5 FB |
9626 | |
9627 | pc_start = tb->pc; | |
92414b31 | 9628 | gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
046d6672 | 9629 | ctx.nip = pc_start; |
79aceca5 | 9630 | ctx.tb = tb; |
e1833e1f | 9631 | ctx.exception = POWERPC_EXCP_NONE; |
3fc6c082 | 9632 | ctx.spr_cb = env->spr_cb; |
76db3ba4 AJ |
9633 | ctx.mem_idx = env->mmu_idx; |
9634 | ctx.access_type = -1; | |
9635 | ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0; | |
d9bce9d9 | 9636 | #if defined(TARGET_PPC64) |
e42a61f1 | 9637 | ctx.sf_mode = msr_is_64bit(env, env->msr); |
697ab892 | 9638 | ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); |
9a64fbe4 | 9639 | #endif |
3cc62370 | 9640 | ctx.fpu_enabled = msr_fp; |
a9d9eb8f | 9641 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
d26bfc9a JM |
9642 | ctx.spe_enabled = msr_spe; |
9643 | else | |
9644 | ctx.spe_enabled = 0; | |
a9d9eb8f JM |
9645 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
9646 | ctx.altivec_enabled = msr_vr; | |
9647 | else | |
9648 | ctx.altivec_enabled = 0; | |
d26bfc9a | 9649 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
8cbcb4fa | 9650 | ctx.singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 9651 | else |
8cbcb4fa | 9652 | ctx.singlestep_enabled = 0; |
d26bfc9a | 9653 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
8cbcb4fa AJ |
9654 | ctx.singlestep_enabled |= CPU_BRANCH_STEP; |
9655 | if (unlikely(env->singlestep_enabled)) | |
9656 | ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP; | |
3fc6c082 | 9657 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
9658 | /* Single step trace mode */ |
9659 | msr_se = 1; | |
9660 | #endif | |
2e70f6ef PB |
9661 | num_insns = 0; |
9662 | max_insns = tb->cflags & CF_COUNT_MASK; | |
9663 | if (max_insns == 0) | |
9664 | max_insns = CF_COUNT_MASK; | |
9665 | ||
9666 | gen_icount_start(); | |
9a64fbe4 | 9667 | /* Set env in case of segfault during code fetch */ |
efd7f486 EV |
9668 | while (ctx.exception == POWERPC_EXCP_NONE |
9669 | && tcg_ctx.gen_opc_ptr < gen_opc_end) { | |
72cf2d4f BS |
9670 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { |
9671 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
a1d1bb31 | 9672 | if (bp->pc == ctx.nip) { |
e06fcd75 | 9673 | gen_debug_exception(ctxp); |
ea4e754f FB |
9674 | break; |
9675 | } | |
9676 | } | |
9677 | } | |
76a66253 | 9678 | if (unlikely(search_pc)) { |
92414b31 | 9679 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
79aceca5 FB |
9680 | if (lj < j) { |
9681 | lj++; | |
9682 | while (lj < j) | |
ab1103de | 9683 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
79aceca5 | 9684 | } |
25983cad | 9685 | tcg_ctx.gen_opc_pc[lj] = ctx.nip; |
ab1103de | 9686 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 9687 | tcg_ctx.gen_opc_icount[lj] = num_insns; |
79aceca5 | 9688 | } |
d12d51d5 | 9689 | LOG_DISAS("----------------\n"); |
90e189ec | 9690 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", |
d12d51d5 | 9691 | ctx.nip, ctx.mem_idx, (int)msr_ir); |
2e70f6ef PB |
9692 | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
9693 | gen_io_start(); | |
76db3ba4 | 9694 | if (unlikely(ctx.le_mode)) { |
2f5a189c | 9695 | ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip)); |
056401ea | 9696 | } else { |
2f5a189c | 9697 | ctx.opcode = cpu_ldl_code(env, ctx.nip); |
111bfab3 | 9698 | } |
d12d51d5 | 9699 | LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n", |
9a64fbe4 | 9700 | ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
056401ea | 9701 | opc3(ctx.opcode), little_endian ? "little" : "big"); |
fdefe51c | 9702 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { |
731c54f8 | 9703 | tcg_gen_debug_insn_start(ctx.nip); |
fdefe51c | 9704 | } |
046d6672 | 9705 | ctx.nip += 4; |
3fc6c082 | 9706 | table = env->opcodes; |
2e70f6ef | 9707 | num_insns++; |
79aceca5 FB |
9708 | handler = table[opc1(ctx.opcode)]; |
9709 | if (is_indirect_opcode(handler)) { | |
9710 | table = ind_table(handler); | |
9711 | handler = table[opc2(ctx.opcode)]; | |
9712 | if (is_indirect_opcode(handler)) { | |
9713 | table = ind_table(handler); | |
9714 | handler = table[opc3(ctx.opcode)]; | |
9715 | } | |
9716 | } | |
9717 | /* Is opcode *REALLY* valid ? */ | |
76a66253 | 9718 | if (unlikely(handler->handler == &gen_invalid)) { |
93fcfe39 AL |
9719 | if (qemu_log_enabled()) { |
9720 | qemu_log("invalid/unsupported opcode: " | |
90e189ec BS |
9721 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n", |
9722 | opc1(ctx.opcode), opc2(ctx.opcode), | |
9723 | opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir); | |
4b3686fa | 9724 | } |
76a66253 | 9725 | } else { |
70560da7 FC |
9726 | uint32_t inval; |
9727 | ||
9728 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) { | |
9729 | inval = handler->inval2; | |
9730 | } else { | |
9731 | inval = handler->inval1; | |
9732 | } | |
9733 | ||
9734 | if (unlikely((ctx.opcode & inval) != 0)) { | |
93fcfe39 AL |
9735 | if (qemu_log_enabled()) { |
9736 | qemu_log("invalid bits: %08x for opcode: " | |
90e189ec | 9737 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n", |
70560da7 | 9738 | ctx.opcode & inval, opc1(ctx.opcode), |
90e189ec BS |
9739 | opc2(ctx.opcode), opc3(ctx.opcode), |
9740 | ctx.opcode, ctx.nip - 4); | |
76a66253 | 9741 | } |
e06fcd75 | 9742 | gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL); |
4b3686fa | 9743 | break; |
79aceca5 | 9744 | } |
79aceca5 | 9745 | } |
4b3686fa | 9746 | (*(handler->handler))(&ctx); |
76a66253 JM |
9747 | #if defined(DO_PPC_STATISTICS) |
9748 | handler->count++; | |
9749 | #endif | |
9a64fbe4 | 9750 | /* Check trace mode exceptions */ |
8cbcb4fa AJ |
9751 | if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP && |
9752 | (ctx.nip <= 0x100 || ctx.nip > 0xF00) && | |
9753 | ctx.exception != POWERPC_SYSCALL && | |
9754 | ctx.exception != POWERPC_EXCP_TRAP && | |
9755 | ctx.exception != POWERPC_EXCP_BRANCH)) { | |
e06fcd75 | 9756 | gen_exception(ctxp, POWERPC_EXCP_TRACE); |
d26bfc9a | 9757 | } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
2e70f6ef | 9758 | (env->singlestep_enabled) || |
1b530a6d | 9759 | singlestep || |
2e70f6ef | 9760 | num_insns >= max_insns)) { |
d26bfc9a JM |
9761 | /* if we reach a page boundary or are single stepping, stop |
9762 | * generation | |
9763 | */ | |
8dd4983c | 9764 | break; |
76a66253 | 9765 | } |
3fc6c082 | 9766 | } |
2e70f6ef PB |
9767 | if (tb->cflags & CF_LAST_IO) |
9768 | gen_io_end(); | |
e1833e1f | 9769 | if (ctx.exception == POWERPC_EXCP_NONE) { |
c1942362 | 9770 | gen_goto_tb(&ctx, 0, ctx.nip); |
e1833e1f | 9771 | } else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
8cbcb4fa | 9772 | if (unlikely(env->singlestep_enabled)) { |
e06fcd75 | 9773 | gen_debug_exception(ctxp); |
8cbcb4fa | 9774 | } |
76a66253 | 9775 | /* Generate the return instruction */ |
57fec1fe | 9776 | tcg_gen_exit_tb(0); |
9a64fbe4 | 9777 | } |
2e70f6ef | 9778 | gen_icount_end(tb, num_insns); |
efd7f486 | 9779 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
76a66253 | 9780 | if (unlikely(search_pc)) { |
92414b31 | 9781 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
9a64fbe4 FB |
9782 | lj++; |
9783 | while (lj <= j) | |
ab1103de | 9784 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
9a64fbe4 | 9785 | } else { |
046d6672 | 9786 | tb->size = ctx.nip - pc_start; |
2e70f6ef | 9787 | tb->icount = num_insns; |
9a64fbe4 | 9788 | } |
d9bce9d9 | 9789 | #if defined(DEBUG_DISAS) |
8fec2b8c | 9790 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
76a66253 | 9791 | int flags; |
237c0af0 | 9792 | flags = env->bfd_mach; |
76db3ba4 | 9793 | flags |= ctx.le_mode << 16; |
93fcfe39 | 9794 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); |
f4359b9f | 9795 | log_target_disas(env, pc_start, ctx.nip - pc_start, flags); |
93fcfe39 | 9796 | qemu_log("\n"); |
9fddaa0c | 9797 | } |
79aceca5 | 9798 | #endif |
79aceca5 FB |
9799 | } |
9800 | ||
1328c2bf | 9801 | void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 9802 | { |
2cfc5f17 | 9803 | gen_intermediate_code_internal(env, tb, 0); |
79aceca5 FB |
9804 | } |
9805 | ||
1328c2bf | 9806 | void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 9807 | { |
2cfc5f17 | 9808 | gen_intermediate_code_internal(env, tb, 1); |
79aceca5 | 9809 | } |
d2856f1a | 9810 | |
1328c2bf | 9811 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos) |
d2856f1a | 9812 | { |
25983cad | 9813 | env->nip = tcg_ctx.gen_opc_pc[pc_pos]; |
d2856f1a | 9814 | } |