]>
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 FB |
20 | #include <stdarg.h> |
21 | #include <stdlib.h> | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | #include <inttypes.h> | |
25 | ||
79aceca5 | 26 | #include "cpu.h" |
79aceca5 | 27 | #include "disas.h" |
57fec1fe | 28 | #include "tcg-op.h" |
ca10f867 | 29 | #include "qemu-common.h" |
0cfe11ea | 30 | #include "host-utils.h" |
79aceca5 | 31 | |
a7812ae4 PB |
32 | #include "helper.h" |
33 | #define GEN_HELPER 1 | |
34 | #include "helper.h" | |
35 | ||
8cbcb4fa AJ |
36 | #define CPU_SINGLE_STEP 0x1 |
37 | #define CPU_BRANCH_STEP 0x2 | |
38 | #define GDBSTUB_SINGLE_STEP 0x4 | |
39 | ||
a750fc0b | 40 | /* Include definitions for instructions classes and implementations flags */ |
9fddaa0c | 41 | //#define PPC_DEBUG_DISAS |
76a66253 | 42 | //#define DO_PPC_STATISTICS |
79aceca5 | 43 | |
d12d51d5 | 44 | #ifdef PPC_DEBUG_DISAS |
93fcfe39 | 45 | # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) |
d12d51d5 AL |
46 | #else |
47 | # define LOG_DISAS(...) do { } while (0) | |
48 | #endif | |
a750fc0b JM |
49 | /*****************************************************************************/ |
50 | /* Code translation helpers */ | |
c53be334 | 51 | |
f78fb44e | 52 | /* global register indexes */ |
a7812ae4 | 53 | static TCGv_ptr cpu_env; |
1d542695 | 54 | static char cpu_reg_names[10*3 + 22*4 /* GPR */ |
f78fb44e | 55 | #if !defined(TARGET_PPC64) |
1d542695 | 56 | + 10*4 + 22*5 /* SPE GPRh */ |
f78fb44e | 57 | #endif |
a5e26afa | 58 | + 10*4 + 22*5 /* FPR */ |
47e4661c AJ |
59 | + 2*(10*6 + 22*7) /* AVRh, AVRl */ |
60 | + 8*5 /* CRF */]; | |
f78fb44e AJ |
61 | static TCGv cpu_gpr[32]; |
62 | #if !defined(TARGET_PPC64) | |
63 | static TCGv cpu_gprh[32]; | |
64 | #endif | |
a7812ae4 PB |
65 | static TCGv_i64 cpu_fpr[32]; |
66 | static TCGv_i64 cpu_avrh[32], cpu_avrl[32]; | |
67 | static TCGv_i32 cpu_crf[8]; | |
bd568f18 | 68 | static TCGv cpu_nip; |
6527f6ea | 69 | static TCGv cpu_msr; |
cfdcd37a AJ |
70 | static TCGv cpu_ctr; |
71 | static TCGv cpu_lr; | |
697ab892 DG |
72 | #if defined(TARGET_PPC64) |
73 | static TCGv cpu_cfar; | |
74 | #endif | |
3d7b417e | 75 | static TCGv cpu_xer; |
cf360a32 | 76 | static TCGv cpu_reserve; |
a7812ae4 | 77 | static TCGv_i32 cpu_fpscr; |
a7859e89 | 78 | static TCGv_i32 cpu_access_type; |
f78fb44e | 79 | |
2e70f6ef PB |
80 | #include "gen-icount.h" |
81 | ||
82 | void ppc_translate_init(void) | |
83 | { | |
f78fb44e AJ |
84 | int i; |
85 | char* p; | |
2dc766da | 86 | size_t cpu_reg_names_size; |
b2437bf2 | 87 | static int done_init = 0; |
f78fb44e | 88 | |
2e70f6ef PB |
89 | if (done_init) |
90 | return; | |
f78fb44e | 91 | |
a7812ae4 | 92 | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); |
a7812ae4 | 93 | |
f78fb44e | 94 | p = cpu_reg_names; |
2dc766da | 95 | cpu_reg_names_size = sizeof(cpu_reg_names); |
47e4661c AJ |
96 | |
97 | for (i = 0; i < 8; i++) { | |
2dc766da | 98 | snprintf(p, cpu_reg_names_size, "crf%d", i); |
a7812ae4 PB |
99 | cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0, |
100 | offsetof(CPUState, crf[i]), p); | |
47e4661c | 101 | p += 5; |
2dc766da | 102 | cpu_reg_names_size -= 5; |
47e4661c AJ |
103 | } |
104 | ||
f78fb44e | 105 | for (i = 0; i < 32; i++) { |
2dc766da | 106 | snprintf(p, cpu_reg_names_size, "r%d", i); |
a7812ae4 | 107 | cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0, |
f78fb44e AJ |
108 | offsetof(CPUState, gpr[i]), p); |
109 | p += (i < 10) ? 3 : 4; | |
2dc766da | 110 | cpu_reg_names_size -= (i < 10) ? 3 : 4; |
f78fb44e | 111 | #if !defined(TARGET_PPC64) |
2dc766da | 112 | snprintf(p, cpu_reg_names_size, "r%dH", i); |
a7812ae4 PB |
113 | cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0, |
114 | offsetof(CPUState, gprh[i]), p); | |
f78fb44e | 115 | p += (i < 10) ? 4 : 5; |
2dc766da | 116 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
f78fb44e | 117 | #endif |
1d542695 | 118 | |
2dc766da | 119 | snprintf(p, cpu_reg_names_size, "fp%d", i); |
a7812ae4 PB |
120 | cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0, |
121 | offsetof(CPUState, fpr[i]), p); | |
ec1ac72d | 122 | p += (i < 10) ? 4 : 5; |
2dc766da | 123 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
a5e26afa | 124 | |
2dc766da | 125 | snprintf(p, cpu_reg_names_size, "avr%dH", i); |
e2542fe2 | 126 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 AJ |
127 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
128 | offsetof(CPUState, avr[i].u64[0]), p); | |
129 | #else | |
a7812ae4 | 130 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
fe1e5c53 AJ |
131 | offsetof(CPUState, avr[i].u64[1]), p); |
132 | #endif | |
1d542695 | 133 | p += (i < 10) ? 6 : 7; |
2dc766da | 134 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
ec1ac72d | 135 | |
2dc766da | 136 | snprintf(p, cpu_reg_names_size, "avr%dL", i); |
e2542fe2 | 137 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 AJ |
138 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
139 | offsetof(CPUState, avr[i].u64[1]), p); | |
140 | #else | |
a7812ae4 | 141 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
fe1e5c53 AJ |
142 | offsetof(CPUState, avr[i].u64[0]), p); |
143 | #endif | |
1d542695 | 144 | p += (i < 10) ? 6 : 7; |
2dc766da | 145 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
f78fb44e | 146 | } |
f10dc08e | 147 | |
a7812ae4 | 148 | cpu_nip = tcg_global_mem_new(TCG_AREG0, |
bd568f18 AJ |
149 | offsetof(CPUState, nip), "nip"); |
150 | ||
6527f6ea AJ |
151 | cpu_msr = tcg_global_mem_new(TCG_AREG0, |
152 | offsetof(CPUState, msr), "msr"); | |
153 | ||
a7812ae4 | 154 | cpu_ctr = tcg_global_mem_new(TCG_AREG0, |
cfdcd37a AJ |
155 | offsetof(CPUState, ctr), "ctr"); |
156 | ||
a7812ae4 | 157 | cpu_lr = tcg_global_mem_new(TCG_AREG0, |
cfdcd37a AJ |
158 | offsetof(CPUState, lr), "lr"); |
159 | ||
697ab892 DG |
160 | #if defined(TARGET_PPC64) |
161 | cpu_cfar = tcg_global_mem_new(TCG_AREG0, | |
162 | offsetof(CPUState, cfar), "cfar"); | |
163 | #endif | |
164 | ||
a7812ae4 | 165 | cpu_xer = tcg_global_mem_new(TCG_AREG0, |
3d7b417e AJ |
166 | offsetof(CPUState, xer), "xer"); |
167 | ||
cf360a32 | 168 | cpu_reserve = tcg_global_mem_new(TCG_AREG0, |
18b21a2f NF |
169 | offsetof(CPUState, reserve_addr), |
170 | "reserve_addr"); | |
cf360a32 | 171 | |
a7812ae4 PB |
172 | cpu_fpscr = tcg_global_mem_new_i32(TCG_AREG0, |
173 | offsetof(CPUState, fpscr), "fpscr"); | |
e1571908 | 174 | |
a7859e89 AJ |
175 | cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0, |
176 | offsetof(CPUState, access_type), "access_type"); | |
177 | ||
f10dc08e | 178 | /* register helpers */ |
a7812ae4 | 179 | #define GEN_HELPER 2 |
f10dc08e AJ |
180 | #include "helper.h" |
181 | ||
2e70f6ef PB |
182 | done_init = 1; |
183 | } | |
184 | ||
79aceca5 FB |
185 | /* internal defines */ |
186 | typedef struct DisasContext { | |
187 | struct TranslationBlock *tb; | |
0fa85d43 | 188 | target_ulong nip; |
79aceca5 | 189 | uint32_t opcode; |
9a64fbe4 | 190 | uint32_t exception; |
3cc62370 FB |
191 | /* Routine used to access memory */ |
192 | int mem_idx; | |
76db3ba4 | 193 | int access_type; |
3cc62370 | 194 | /* Translation flags */ |
76db3ba4 | 195 | int le_mode; |
d9bce9d9 JM |
196 | #if defined(TARGET_PPC64) |
197 | int sf_mode; | |
697ab892 | 198 | int has_cfar; |
9a64fbe4 | 199 | #endif |
3cc62370 | 200 | int fpu_enabled; |
a9d9eb8f | 201 | int altivec_enabled; |
0487d6a8 | 202 | int spe_enabled; |
c227f099 | 203 | ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ |
ea4e754f | 204 | int singlestep_enabled; |
79aceca5 FB |
205 | } DisasContext; |
206 | ||
c227f099 | 207 | struct opc_handler_t { |
70560da7 FC |
208 | /* invalid bits for instruction 1 (Rc(opcode) == 0) */ |
209 | uint32_t inval1; | |
210 | /* invalid bits for instruction 2 (Rc(opcode) == 1) */ | |
211 | uint32_t inval2; | |
9a64fbe4 | 212 | /* instruction type */ |
0487d6a8 | 213 | uint64_t type; |
a5858d7a AG |
214 | /* extended instruction type */ |
215 | uint64_t type2; | |
79aceca5 FB |
216 | /* handler */ |
217 | void (*handler)(DisasContext *ctx); | |
a750fc0b | 218 | #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU) |
b55266b5 | 219 | const char *oname; |
a750fc0b JM |
220 | #endif |
221 | #if defined(DO_PPC_STATISTICS) | |
76a66253 JM |
222 | uint64_t count; |
223 | #endif | |
3fc6c082 | 224 | }; |
79aceca5 | 225 | |
636aa200 | 226 | static inline void gen_reset_fpstatus(void) |
7c58044c | 227 | { |
a44d2ce1 | 228 | gen_helper_reset_fpstatus(); |
7c58044c JM |
229 | } |
230 | ||
636aa200 | 231 | static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc) |
7c58044c | 232 | { |
0f2f39c2 | 233 | TCGv_i32 t0 = tcg_temp_new_i32(); |
af12906f | 234 | |
7c58044c JM |
235 | if (set_fprf != 0) { |
236 | /* This case might be optimized later */ | |
0f2f39c2 | 237 | tcg_gen_movi_i32(t0, 1); |
af12906f | 238 | gen_helper_compute_fprf(t0, arg, t0); |
a7812ae4 | 239 | if (unlikely(set_rc)) { |
0f2f39c2 | 240 | tcg_gen_mov_i32(cpu_crf[1], t0); |
a7812ae4 | 241 | } |
af12906f | 242 | gen_helper_float_check_status(); |
7c58044c JM |
243 | } else if (unlikely(set_rc)) { |
244 | /* We always need to compute fpcc */ | |
0f2f39c2 | 245 | tcg_gen_movi_i32(t0, 0); |
af12906f | 246 | gen_helper_compute_fprf(t0, arg, t0); |
0f2f39c2 | 247 | tcg_gen_mov_i32(cpu_crf[1], t0); |
7c58044c | 248 | } |
af12906f | 249 | |
0f2f39c2 | 250 | tcg_temp_free_i32(t0); |
7c58044c JM |
251 | } |
252 | ||
636aa200 | 253 | static inline void gen_set_access_type(DisasContext *ctx, int access_type) |
a7859e89 | 254 | { |
76db3ba4 AJ |
255 | if (ctx->access_type != access_type) { |
256 | tcg_gen_movi_i32(cpu_access_type, access_type); | |
257 | ctx->access_type = access_type; | |
258 | } | |
a7859e89 AJ |
259 | } |
260 | ||
636aa200 | 261 | static inline void gen_update_nip(DisasContext *ctx, target_ulong nip) |
d9bce9d9 JM |
262 | { |
263 | #if defined(TARGET_PPC64) | |
264 | if (ctx->sf_mode) | |
bd568f18 | 265 | tcg_gen_movi_tl(cpu_nip, nip); |
d9bce9d9 JM |
266 | else |
267 | #endif | |
bd568f18 | 268 | tcg_gen_movi_tl(cpu_nip, (uint32_t)nip); |
d9bce9d9 JM |
269 | } |
270 | ||
636aa200 | 271 | static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error) |
e06fcd75 AJ |
272 | { |
273 | TCGv_i32 t0, t1; | |
274 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
275 | gen_update_nip(ctx, ctx->nip); | |
276 | } | |
277 | t0 = tcg_const_i32(excp); | |
278 | t1 = tcg_const_i32(error); | |
279 | gen_helper_raise_exception_err(t0, t1); | |
280 | tcg_temp_free_i32(t0); | |
281 | tcg_temp_free_i32(t1); | |
282 | ctx->exception = (excp); | |
283 | } | |
e1833e1f | 284 | |
636aa200 | 285 | static inline void gen_exception(DisasContext *ctx, uint32_t excp) |
e06fcd75 AJ |
286 | { |
287 | TCGv_i32 t0; | |
288 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
289 | gen_update_nip(ctx, ctx->nip); | |
290 | } | |
291 | t0 = tcg_const_i32(excp); | |
292 | gen_helper_raise_exception(t0); | |
293 | tcg_temp_free_i32(t0); | |
294 | ctx->exception = (excp); | |
295 | } | |
e1833e1f | 296 | |
636aa200 | 297 | static inline void gen_debug_exception(DisasContext *ctx) |
e06fcd75 AJ |
298 | { |
299 | TCGv_i32 t0; | |
5518f3a6 BS |
300 | |
301 | if (ctx->exception != POWERPC_EXCP_BRANCH) | |
302 | gen_update_nip(ctx, ctx->nip); | |
e06fcd75 AJ |
303 | t0 = tcg_const_i32(EXCP_DEBUG); |
304 | gen_helper_raise_exception(t0); | |
305 | tcg_temp_free_i32(t0); | |
306 | } | |
9a64fbe4 | 307 | |
636aa200 | 308 | static inline void gen_inval_exception(DisasContext *ctx, uint32_t error) |
e06fcd75 AJ |
309 | { |
310 | gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error); | |
311 | } | |
a9d9eb8f | 312 | |
f24e5695 | 313 | /* Stop translation */ |
636aa200 | 314 | static inline void gen_stop_exception(DisasContext *ctx) |
3fc6c082 | 315 | { |
d9bce9d9 | 316 | gen_update_nip(ctx, ctx->nip); |
e1833e1f | 317 | ctx->exception = POWERPC_EXCP_STOP; |
3fc6c082 FB |
318 | } |
319 | ||
f24e5695 | 320 | /* No need to update nip here, as execution flow will change */ |
636aa200 | 321 | static inline void gen_sync_exception(DisasContext *ctx) |
2be0071f | 322 | { |
e1833e1f | 323 | ctx->exception = POWERPC_EXCP_SYNC; |
2be0071f FB |
324 | } |
325 | ||
79aceca5 | 326 | #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
327 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE) |
328 | ||
329 | #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \ | |
330 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2) | |
79aceca5 | 331 | |
c7697e1f | 332 | #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
333 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) |
334 | ||
335 | #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \ | |
336 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2) | |
c7697e1f | 337 | |
c227f099 | 338 | typedef struct opcode_t { |
79aceca5 | 339 | unsigned char opc1, opc2, opc3; |
1235fc06 | 340 | #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */ |
18fba28c FB |
341 | unsigned char pad[5]; |
342 | #else | |
343 | unsigned char pad[1]; | |
344 | #endif | |
c227f099 | 345 | opc_handler_t handler; |
b55266b5 | 346 | const char *oname; |
c227f099 | 347 | } opcode_t; |
79aceca5 | 348 | |
a750fc0b | 349 | /*****************************************************************************/ |
79aceca5 FB |
350 | /*** Instruction decoding ***/ |
351 | #define EXTRACT_HELPER(name, shift, nb) \ | |
636aa200 | 352 | static inline uint32_t name(uint32_t opcode) \ |
79aceca5 FB |
353 | { \ |
354 | return (opcode >> (shift)) & ((1 << (nb)) - 1); \ | |
355 | } | |
356 | ||
357 | #define EXTRACT_SHELPER(name, shift, nb) \ | |
636aa200 | 358 | static inline int32_t name(uint32_t opcode) \ |
79aceca5 | 359 | { \ |
18fba28c | 360 | return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \ |
79aceca5 FB |
361 | } |
362 | ||
363 | /* Opcode part 1 */ | |
364 | EXTRACT_HELPER(opc1, 26, 6); | |
365 | /* Opcode part 2 */ | |
366 | EXTRACT_HELPER(opc2, 1, 5); | |
367 | /* Opcode part 3 */ | |
368 | EXTRACT_HELPER(opc3, 6, 5); | |
369 | /* Update Cr0 flags */ | |
370 | EXTRACT_HELPER(Rc, 0, 1); | |
371 | /* Destination */ | |
372 | EXTRACT_HELPER(rD, 21, 5); | |
373 | /* Source */ | |
374 | EXTRACT_HELPER(rS, 21, 5); | |
375 | /* First operand */ | |
376 | EXTRACT_HELPER(rA, 16, 5); | |
377 | /* Second operand */ | |
378 | EXTRACT_HELPER(rB, 11, 5); | |
379 | /* Third operand */ | |
380 | EXTRACT_HELPER(rC, 6, 5); | |
381 | /*** Get CRn ***/ | |
382 | EXTRACT_HELPER(crfD, 23, 3); | |
383 | EXTRACT_HELPER(crfS, 18, 3); | |
384 | EXTRACT_HELPER(crbD, 21, 5); | |
385 | EXTRACT_HELPER(crbA, 16, 5); | |
386 | EXTRACT_HELPER(crbB, 11, 5); | |
387 | /* SPR / TBL */ | |
3fc6c082 | 388 | EXTRACT_HELPER(_SPR, 11, 10); |
636aa200 | 389 | static inline uint32_t SPR(uint32_t opcode) |
3fc6c082 FB |
390 | { |
391 | uint32_t sprn = _SPR(opcode); | |
392 | ||
393 | return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); | |
394 | } | |
79aceca5 FB |
395 | /*** Get constants ***/ |
396 | EXTRACT_HELPER(IMM, 12, 8); | |
397 | /* 16 bits signed immediate value */ | |
398 | EXTRACT_SHELPER(SIMM, 0, 16); | |
399 | /* 16 bits unsigned immediate value */ | |
400 | EXTRACT_HELPER(UIMM, 0, 16); | |
21d21583 AJ |
401 | /* 5 bits signed immediate value */ |
402 | EXTRACT_HELPER(SIMM5, 16, 5); | |
27a4edb3 AJ |
403 | /* 5 bits signed immediate value */ |
404 | EXTRACT_HELPER(UIMM5, 16, 5); | |
79aceca5 FB |
405 | /* Bit count */ |
406 | EXTRACT_HELPER(NB, 11, 5); | |
407 | /* Shift count */ | |
408 | EXTRACT_HELPER(SH, 11, 5); | |
cd633b10 AJ |
409 | /* Vector shift count */ |
410 | EXTRACT_HELPER(VSH, 6, 4); | |
79aceca5 FB |
411 | /* Mask start */ |
412 | EXTRACT_HELPER(MB, 6, 5); | |
413 | /* Mask end */ | |
414 | EXTRACT_HELPER(ME, 1, 5); | |
fb0eaffc FB |
415 | /* Trap operand */ |
416 | EXTRACT_HELPER(TO, 21, 5); | |
79aceca5 FB |
417 | |
418 | EXTRACT_HELPER(CRM, 12, 8); | |
419 | EXTRACT_HELPER(FM, 17, 8); | |
420 | EXTRACT_HELPER(SR, 16, 4); | |
e4bb997e | 421 | EXTRACT_HELPER(FPIMM, 12, 4); |
fb0eaffc | 422 | |
79aceca5 FB |
423 | /*** Jump target decoding ***/ |
424 | /* Displacement */ | |
425 | EXTRACT_SHELPER(d, 0, 16); | |
426 | /* Immediate address */ | |
636aa200 | 427 | static inline target_ulong LI(uint32_t opcode) |
79aceca5 FB |
428 | { |
429 | return (opcode >> 0) & 0x03FFFFFC; | |
430 | } | |
431 | ||
636aa200 | 432 | static inline uint32_t BD(uint32_t opcode) |
79aceca5 FB |
433 | { |
434 | return (opcode >> 0) & 0xFFFC; | |
435 | } | |
436 | ||
437 | EXTRACT_HELPER(BO, 21, 5); | |
438 | EXTRACT_HELPER(BI, 16, 5); | |
439 | /* Absolute/relative address */ | |
440 | EXTRACT_HELPER(AA, 1, 1); | |
441 | /* Link */ | |
442 | EXTRACT_HELPER(LK, 0, 1); | |
443 | ||
444 | /* Create a mask between <start> and <end> bits */ | |
636aa200 | 445 | static inline target_ulong MASK(uint32_t start, uint32_t end) |
79aceca5 | 446 | { |
76a66253 | 447 | target_ulong ret; |
79aceca5 | 448 | |
76a66253 JM |
449 | #if defined(TARGET_PPC64) |
450 | if (likely(start == 0)) { | |
6f2d8978 | 451 | ret = UINT64_MAX << (63 - end); |
76a66253 | 452 | } else if (likely(end == 63)) { |
6f2d8978 | 453 | ret = UINT64_MAX >> start; |
76a66253 JM |
454 | } |
455 | #else | |
456 | if (likely(start == 0)) { | |
6f2d8978 | 457 | ret = UINT32_MAX << (31 - end); |
76a66253 | 458 | } else if (likely(end == 31)) { |
6f2d8978 | 459 | ret = UINT32_MAX >> start; |
76a66253 JM |
460 | } |
461 | #endif | |
462 | else { | |
463 | ret = (((target_ulong)(-1ULL)) >> (start)) ^ | |
464 | (((target_ulong)(-1ULL) >> (end)) >> 1); | |
465 | if (unlikely(start > end)) | |
466 | return ~ret; | |
467 | } | |
79aceca5 FB |
468 | |
469 | return ret; | |
470 | } | |
471 | ||
a750fc0b | 472 | /*****************************************************************************/ |
a750fc0b | 473 | /* PowerPC instructions table */ |
933dc6eb | 474 | |
76a66253 | 475 | #if defined(DO_PPC_STATISTICS) |
a5858d7a | 476 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 477 | { \ |
79aceca5 FB |
478 | .opc1 = op1, \ |
479 | .opc2 = op2, \ | |
480 | .opc3 = op3, \ | |
18fba28c | 481 | .pad = { 0, }, \ |
79aceca5 | 482 | .handler = { \ |
70560da7 FC |
483 | .inval1 = invl, \ |
484 | .type = _typ, \ | |
485 | .type2 = _typ2, \ | |
486 | .handler = &gen_##name, \ | |
487 | .oname = stringify(name), \ | |
488 | }, \ | |
489 | .oname = stringify(name), \ | |
490 | } | |
491 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
492 | { \ | |
493 | .opc1 = op1, \ | |
494 | .opc2 = op2, \ | |
495 | .opc3 = op3, \ | |
496 | .pad = { 0, }, \ | |
497 | .handler = { \ | |
498 | .inval1 = invl1, \ | |
499 | .inval2 = invl2, \ | |
9a64fbe4 | 500 | .type = _typ, \ |
a5858d7a | 501 | .type2 = _typ2, \ |
79aceca5 | 502 | .handler = &gen_##name, \ |
76a66253 | 503 | .oname = stringify(name), \ |
79aceca5 | 504 | }, \ |
3fc6c082 | 505 | .oname = stringify(name), \ |
79aceca5 | 506 | } |
a5858d7a | 507 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 508 | { \ |
c7697e1f JM |
509 | .opc1 = op1, \ |
510 | .opc2 = op2, \ | |
511 | .opc3 = op3, \ | |
512 | .pad = { 0, }, \ | |
513 | .handler = { \ | |
70560da7 | 514 | .inval1 = invl, \ |
c7697e1f | 515 | .type = _typ, \ |
a5858d7a | 516 | .type2 = _typ2, \ |
c7697e1f JM |
517 | .handler = &gen_##name, \ |
518 | .oname = onam, \ | |
519 | }, \ | |
520 | .oname = onam, \ | |
521 | } | |
76a66253 | 522 | #else |
a5858d7a | 523 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 524 | { \ |
c7697e1f JM |
525 | .opc1 = op1, \ |
526 | .opc2 = op2, \ | |
527 | .opc3 = op3, \ | |
528 | .pad = { 0, }, \ | |
529 | .handler = { \ | |
70560da7 FC |
530 | .inval1 = invl, \ |
531 | .type = _typ, \ | |
532 | .type2 = _typ2, \ | |
533 | .handler = &gen_##name, \ | |
534 | }, \ | |
535 | .oname = stringify(name), \ | |
536 | } | |
537 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
538 | { \ | |
539 | .opc1 = op1, \ | |
540 | .opc2 = op2, \ | |
541 | .opc3 = op3, \ | |
542 | .pad = { 0, }, \ | |
543 | .handler = { \ | |
544 | .inval1 = invl1, \ | |
545 | .inval2 = invl2, \ | |
c7697e1f | 546 | .type = _typ, \ |
a5858d7a | 547 | .type2 = _typ2, \ |
c7697e1f | 548 | .handler = &gen_##name, \ |
5c55ff99 BS |
549 | }, \ |
550 | .oname = stringify(name), \ | |
551 | } | |
a5858d7a | 552 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 BS |
553 | { \ |
554 | .opc1 = op1, \ | |
555 | .opc2 = op2, \ | |
556 | .opc3 = op3, \ | |
557 | .pad = { 0, }, \ | |
558 | .handler = { \ | |
70560da7 | 559 | .inval1 = invl, \ |
5c55ff99 | 560 | .type = _typ, \ |
a5858d7a | 561 | .type2 = _typ2, \ |
5c55ff99 BS |
562 | .handler = &gen_##name, \ |
563 | }, \ | |
564 | .oname = onam, \ | |
565 | } | |
566 | #endif | |
2e610050 | 567 | |
5c55ff99 | 568 | /* SPR load/store helpers */ |
636aa200 | 569 | static inline void gen_load_spr(TCGv t, int reg) |
5c55ff99 BS |
570 | { |
571 | tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, spr[reg])); | |
572 | } | |
2e610050 | 573 | |
636aa200 | 574 | static inline void gen_store_spr(int reg, TCGv t) |
5c55ff99 BS |
575 | { |
576 | tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, spr[reg])); | |
577 | } | |
2e610050 | 578 | |
54623277 | 579 | /* Invalid instruction */ |
99e300ef | 580 | static void gen_invalid(DisasContext *ctx) |
9a64fbe4 | 581 | { |
e06fcd75 | 582 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
9a64fbe4 FB |
583 | } |
584 | ||
c227f099 | 585 | static opc_handler_t invalid_handler = { |
70560da7 FC |
586 | .inval1 = 0xFFFFFFFF, |
587 | .inval2 = 0xFFFFFFFF, | |
9a64fbe4 | 588 | .type = PPC_NONE, |
a5858d7a | 589 | .type2 = PPC_NONE, |
79aceca5 FB |
590 | .handler = gen_invalid, |
591 | }; | |
592 | ||
e1571908 AJ |
593 | /*** Integer comparison ***/ |
594 | ||
636aa200 | 595 | static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 AJ |
596 | { |
597 | int l1, l2, l3; | |
598 | ||
269f3e95 AJ |
599 | tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer); |
600 | tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO); | |
e1571908 AJ |
601 | tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1); |
602 | ||
603 | l1 = gen_new_label(); | |
604 | l2 = gen_new_label(); | |
605 | l3 = gen_new_label(); | |
606 | if (s) { | |
ea363694 AJ |
607 | tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1); |
608 | tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2); | |
e1571908 | 609 | } else { |
ea363694 AJ |
610 | tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1); |
611 | tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2); | |
e1571908 AJ |
612 | } |
613 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ); | |
614 | tcg_gen_br(l3); | |
615 | gen_set_label(l1); | |
616 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT); | |
617 | tcg_gen_br(l3); | |
618 | gen_set_label(l2); | |
619 | tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT); | |
620 | gen_set_label(l3); | |
621 | } | |
622 | ||
636aa200 | 623 | static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 624 | { |
ea363694 AJ |
625 | TCGv t0 = tcg_const_local_tl(arg1); |
626 | gen_op_cmp(arg0, t0, s, crf); | |
627 | tcg_temp_free(t0); | |
e1571908 AJ |
628 | } |
629 | ||
630 | #if defined(TARGET_PPC64) | |
636aa200 | 631 | static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 632 | { |
ea363694 | 633 | TCGv t0, t1; |
a7812ae4 PB |
634 | t0 = tcg_temp_local_new(); |
635 | t1 = tcg_temp_local_new(); | |
e1571908 | 636 | if (s) { |
ea363694 AJ |
637 | tcg_gen_ext32s_tl(t0, arg0); |
638 | tcg_gen_ext32s_tl(t1, arg1); | |
e1571908 | 639 | } else { |
ea363694 AJ |
640 | tcg_gen_ext32u_tl(t0, arg0); |
641 | tcg_gen_ext32u_tl(t1, arg1); | |
e1571908 | 642 | } |
ea363694 AJ |
643 | gen_op_cmp(t0, t1, s, crf); |
644 | tcg_temp_free(t1); | |
645 | tcg_temp_free(t0); | |
e1571908 AJ |
646 | } |
647 | ||
636aa200 | 648 | static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 649 | { |
ea363694 AJ |
650 | TCGv t0 = tcg_const_local_tl(arg1); |
651 | gen_op_cmp32(arg0, t0, s, crf); | |
652 | tcg_temp_free(t0); | |
e1571908 AJ |
653 | } |
654 | #endif | |
655 | ||
636aa200 | 656 | static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg) |
e1571908 AJ |
657 | { |
658 | #if defined(TARGET_PPC64) | |
659 | if (!(ctx->sf_mode)) | |
660 | gen_op_cmpi32(reg, 0, 1, 0); | |
661 | else | |
662 | #endif | |
663 | gen_op_cmpi(reg, 0, 1, 0); | |
664 | } | |
665 | ||
666 | /* cmp */ | |
99e300ef | 667 | static void gen_cmp(DisasContext *ctx) |
e1571908 AJ |
668 | { |
669 | #if defined(TARGET_PPC64) | |
670 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
671 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
672 | 1, crfD(ctx->opcode)); | |
673 | else | |
674 | #endif | |
675 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
676 | 1, crfD(ctx->opcode)); | |
677 | } | |
678 | ||
679 | /* cmpi */ | |
99e300ef | 680 | static void gen_cmpi(DisasContext *ctx) |
e1571908 AJ |
681 | { |
682 | #if defined(TARGET_PPC64) | |
683 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
684 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
685 | 1, crfD(ctx->opcode)); | |
686 | else | |
687 | #endif | |
688 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
689 | 1, crfD(ctx->opcode)); | |
690 | } | |
691 | ||
692 | /* cmpl */ | |
99e300ef | 693 | static void gen_cmpl(DisasContext *ctx) |
e1571908 AJ |
694 | { |
695 | #if defined(TARGET_PPC64) | |
696 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
697 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
698 | 0, crfD(ctx->opcode)); | |
699 | else | |
700 | #endif | |
701 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
702 | 0, crfD(ctx->opcode)); | |
703 | } | |
704 | ||
705 | /* cmpli */ | |
99e300ef | 706 | static void gen_cmpli(DisasContext *ctx) |
e1571908 AJ |
707 | { |
708 | #if defined(TARGET_PPC64) | |
709 | if (!(ctx->sf_mode && (ctx->opcode & 0x00200000))) | |
710 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
711 | 0, crfD(ctx->opcode)); | |
712 | else | |
713 | #endif | |
714 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
715 | 0, crfD(ctx->opcode)); | |
716 | } | |
717 | ||
718 | /* isel (PowerPC 2.03 specification) */ | |
99e300ef | 719 | static void gen_isel(DisasContext *ctx) |
e1571908 AJ |
720 | { |
721 | int l1, l2; | |
722 | uint32_t bi = rC(ctx->opcode); | |
723 | uint32_t mask; | |
a7812ae4 | 724 | TCGv_i32 t0; |
e1571908 AJ |
725 | |
726 | l1 = gen_new_label(); | |
727 | l2 = gen_new_label(); | |
728 | ||
729 | mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 730 | t0 = tcg_temp_new_i32(); |
fea0c503 AJ |
731 | tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask); |
732 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
e1571908 AJ |
733 | if (rA(ctx->opcode) == 0) |
734 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
735 | else | |
736 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
737 | tcg_gen_br(l2); | |
738 | gen_set_label(l1); | |
739 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
740 | gen_set_label(l2); | |
a7812ae4 | 741 | tcg_temp_free_i32(t0); |
e1571908 AJ |
742 | } |
743 | ||
79aceca5 | 744 | /*** Integer arithmetic ***/ |
79aceca5 | 745 | |
636aa200 BS |
746 | static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, |
747 | TCGv arg1, TCGv arg2, int sub) | |
74637406 AJ |
748 | { |
749 | int l1; | |
750 | TCGv t0; | |
79aceca5 | 751 | |
74637406 AJ |
752 | l1 = gen_new_label(); |
753 | /* Start with XER OV disabled, the most likely case */ | |
754 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
a7812ae4 | 755 | t0 = tcg_temp_local_new(); |
74637406 AJ |
756 | tcg_gen_xor_tl(t0, arg0, arg1); |
757 | #if defined(TARGET_PPC64) | |
758 | if (!ctx->sf_mode) | |
759 | tcg_gen_ext32s_tl(t0, t0); | |
760 | #endif | |
761 | if (sub) | |
762 | tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1); | |
763 | else | |
764 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
765 | tcg_gen_xor_tl(t0, arg1, arg2); | |
766 | #if defined(TARGET_PPC64) | |
767 | if (!ctx->sf_mode) | |
768 | tcg_gen_ext32s_tl(t0, t0); | |
769 | #endif | |
770 | if (sub) | |
771 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
772 | else | |
773 | tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1); | |
774 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
775 | gen_set_label(l1); | |
776 | tcg_temp_free(t0); | |
79aceca5 FB |
777 | } |
778 | ||
636aa200 BS |
779 | static inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1, |
780 | TCGv arg2, int sub) | |
74637406 AJ |
781 | { |
782 | int l1 = gen_new_label(); | |
d9bce9d9 JM |
783 | |
784 | #if defined(TARGET_PPC64) | |
74637406 AJ |
785 | if (!(ctx->sf_mode)) { |
786 | TCGv t0, t1; | |
a7812ae4 PB |
787 | t0 = tcg_temp_new(); |
788 | t1 = tcg_temp_new(); | |
d9bce9d9 | 789 | |
74637406 AJ |
790 | tcg_gen_ext32u_tl(t0, arg1); |
791 | tcg_gen_ext32u_tl(t1, arg2); | |
792 | if (sub) { | |
793 | tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1); | |
bdc4e053 | 794 | } else { |
74637406 AJ |
795 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); |
796 | } | |
a9730017 AJ |
797 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
798 | gen_set_label(l1); | |
799 | tcg_temp_free(t0); | |
800 | tcg_temp_free(t1); | |
74637406 AJ |
801 | } else |
802 | #endif | |
a9730017 AJ |
803 | { |
804 | if (sub) { | |
805 | tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1); | |
806 | } else { | |
807 | tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1); | |
808 | } | |
809 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); | |
810 | gen_set_label(l1); | |
74637406 | 811 | } |
d9bce9d9 JM |
812 | } |
813 | ||
74637406 | 814 | /* Common add function */ |
636aa200 BS |
815 | static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
816 | TCGv arg2, int add_ca, int compute_ca, | |
817 | int compute_ov) | |
74637406 AJ |
818 | { |
819 | TCGv t0, t1; | |
d9bce9d9 | 820 | |
74637406 | 821 | if ((!compute_ca && !compute_ov) || |
a7812ae4 | 822 | (!TCGV_EQUAL(ret,arg1) && !TCGV_EQUAL(ret, arg2))) { |
74637406 AJ |
823 | t0 = ret; |
824 | } else { | |
a7812ae4 | 825 | t0 = tcg_temp_local_new(); |
74637406 | 826 | } |
79aceca5 | 827 | |
74637406 | 828 | if (add_ca) { |
a7812ae4 | 829 | t1 = tcg_temp_local_new(); |
74637406 AJ |
830 | tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA)); |
831 | tcg_gen_shri_tl(t1, t1, XER_CA); | |
d2e9fd8f | 832 | } else { |
833 | TCGV_UNUSED(t1); | |
74637406 | 834 | } |
79aceca5 | 835 | |
74637406 AJ |
836 | if (compute_ca && compute_ov) { |
837 | /* Start with XER CA and OV disabled, the most likely case */ | |
838 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV))); | |
839 | } else if (compute_ca) { | |
840 | /* Start with XER CA disabled, the most likely case */ | |
841 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
842 | } else if (compute_ov) { | |
843 | /* Start with XER OV disabled, the most likely case */ | |
844 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
845 | } | |
79aceca5 | 846 | |
74637406 AJ |
847 | tcg_gen_add_tl(t0, arg1, arg2); |
848 | ||
849 | if (compute_ca) { | |
850 | gen_op_arith_compute_ca(ctx, t0, arg1, 0); | |
851 | } | |
852 | if (add_ca) { | |
853 | tcg_gen_add_tl(t0, t0, t1); | |
854 | gen_op_arith_compute_ca(ctx, t0, t1, 0); | |
855 | tcg_temp_free(t1); | |
856 | } | |
857 | if (compute_ov) { | |
858 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0); | |
859 | } | |
860 | ||
861 | if (unlikely(Rc(ctx->opcode) != 0)) | |
862 | gen_set_Rc0(ctx, t0); | |
863 | ||
a7812ae4 | 864 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
865 | tcg_gen_mov_tl(ret, t0); |
866 | tcg_temp_free(t0); | |
867 | } | |
39dd32ee | 868 | } |
74637406 AJ |
869 | /* Add functions with two operands */ |
870 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
99e300ef | 871 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
872 | { \ |
873 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
874 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
875 | add_ca, compute_ca, compute_ov); \ | |
876 | } | |
877 | /* Add functions with one operand and one immediate */ | |
878 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
879 | add_ca, compute_ca, compute_ov) \ | |
99e300ef | 880 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
881 | { \ |
882 | TCGv t0 = tcg_const_local_tl(const_val); \ | |
883 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
884 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
885 | add_ca, compute_ca, compute_ov); \ | |
886 | tcg_temp_free(t0); \ | |
887 | } | |
888 | ||
889 | /* add add. addo addo. */ | |
890 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
891 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
892 | /* addc addc. addco addco. */ | |
893 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
894 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
895 | /* adde adde. addeo addeo. */ | |
896 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
897 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
898 | /* addme addme. addmeo addmeo. */ | |
899 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
900 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
901 | /* addze addze. addzeo addzeo.*/ | |
902 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
903 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
904 | /* addi */ | |
99e300ef | 905 | static void gen_addi(DisasContext *ctx) |
d9bce9d9 | 906 | { |
74637406 AJ |
907 | target_long simm = SIMM(ctx->opcode); |
908 | ||
909 | if (rA(ctx->opcode) == 0) { | |
910 | /* li case */ | |
911 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm); | |
912 | } else { | |
913 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm); | |
914 | } | |
d9bce9d9 | 915 | } |
74637406 | 916 | /* addic addic.*/ |
636aa200 BS |
917 | static inline void gen_op_addic(DisasContext *ctx, TCGv ret, TCGv arg1, |
918 | int compute_Rc0) | |
d9bce9d9 | 919 | { |
74637406 AJ |
920 | target_long simm = SIMM(ctx->opcode); |
921 | ||
922 | /* Start with XER CA and OV disabled, the most likely case */ | |
923 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
924 | ||
925 | if (likely(simm != 0)) { | |
a7812ae4 | 926 | TCGv t0 = tcg_temp_local_new(); |
74637406 AJ |
927 | tcg_gen_addi_tl(t0, arg1, simm); |
928 | gen_op_arith_compute_ca(ctx, t0, arg1, 0); | |
929 | tcg_gen_mov_tl(ret, t0); | |
930 | tcg_temp_free(t0); | |
931 | } else { | |
932 | tcg_gen_mov_tl(ret, arg1); | |
933 | } | |
934 | if (compute_Rc0) { | |
935 | gen_set_Rc0(ctx, ret); | |
936 | } | |
d9bce9d9 | 937 | } |
99e300ef BS |
938 | |
939 | static void gen_addic(DisasContext *ctx) | |
d9bce9d9 | 940 | { |
74637406 | 941 | gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0); |
d9bce9d9 | 942 | } |
e8eaa2c0 BS |
943 | |
944 | static void gen_addic_(DisasContext *ctx) | |
d9bce9d9 | 945 | { |
74637406 | 946 | gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1); |
d9bce9d9 | 947 | } |
99e300ef | 948 | |
54623277 | 949 | /* addis */ |
99e300ef | 950 | static void gen_addis(DisasContext *ctx) |
d9bce9d9 | 951 | { |
74637406 AJ |
952 | target_long simm = SIMM(ctx->opcode); |
953 | ||
954 | if (rA(ctx->opcode) == 0) { | |
955 | /* lis case */ | |
956 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16); | |
957 | } else { | |
958 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16); | |
959 | } | |
d9bce9d9 | 960 | } |
74637406 | 961 | |
636aa200 BS |
962 | static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1, |
963 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 964 | { |
2ef1b120 AJ |
965 | int l1 = gen_new_label(); |
966 | int l2 = gen_new_label(); | |
a7812ae4 PB |
967 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
968 | TCGv_i32 t1 = tcg_temp_local_new_i32(); | |
74637406 | 969 | |
2ef1b120 AJ |
970 | tcg_gen_trunc_tl_i32(t0, arg1); |
971 | tcg_gen_trunc_tl_i32(t1, arg2); | |
972 | tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1); | |
74637406 | 973 | if (sign) { |
2ef1b120 AJ |
974 | int l3 = gen_new_label(); |
975 | tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3); | |
976 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1); | |
74637406 | 977 | gen_set_label(l3); |
2ef1b120 | 978 | tcg_gen_div_i32(t0, t0, t1); |
74637406 | 979 | } else { |
2ef1b120 | 980 | tcg_gen_divu_i32(t0, t0, t1); |
74637406 AJ |
981 | } |
982 | if (compute_ov) { | |
983 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
984 | } | |
985 | tcg_gen_br(l2); | |
986 | gen_set_label(l1); | |
987 | if (sign) { | |
2ef1b120 | 988 | tcg_gen_sari_i32(t0, t0, 31); |
74637406 AJ |
989 | } else { |
990 | tcg_gen_movi_i32(t0, 0); | |
991 | } | |
992 | if (compute_ov) { | |
993 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
994 | } | |
995 | gen_set_label(l2); | |
2ef1b120 | 996 | tcg_gen_extu_i32_tl(ret, t0); |
a7812ae4 PB |
997 | tcg_temp_free_i32(t0); |
998 | tcg_temp_free_i32(t1); | |
74637406 AJ |
999 | if (unlikely(Rc(ctx->opcode) != 0)) |
1000 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1001 | } |
74637406 AJ |
1002 | /* Div functions */ |
1003 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
99e300ef | 1004 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1005 | { \ |
1006 | gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1007 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1008 | sign, compute_ov); \ | |
1009 | } | |
1010 | /* divwu divwu. divwuo divwuo. */ | |
1011 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0); | |
1012 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1); | |
1013 | /* divw divw. divwo divwo. */ | |
1014 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0); | |
1015 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1); | |
d9bce9d9 | 1016 | #if defined(TARGET_PPC64) |
636aa200 BS |
1017 | static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1, |
1018 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 1019 | { |
2ef1b120 AJ |
1020 | int l1 = gen_new_label(); |
1021 | int l2 = gen_new_label(); | |
74637406 AJ |
1022 | |
1023 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1); | |
1024 | if (sign) { | |
2ef1b120 | 1025 | int l3 = gen_new_label(); |
74637406 AJ |
1026 | tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3); |
1027 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1); | |
1028 | gen_set_label(l3); | |
74637406 AJ |
1029 | tcg_gen_div_i64(ret, arg1, arg2); |
1030 | } else { | |
1031 | tcg_gen_divu_i64(ret, arg1, arg2); | |
1032 | } | |
1033 | if (compute_ov) { | |
1034 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1035 | } | |
1036 | tcg_gen_br(l2); | |
1037 | gen_set_label(l1); | |
1038 | if (sign) { | |
1039 | tcg_gen_sari_i64(ret, arg1, 63); | |
1040 | } else { | |
1041 | tcg_gen_movi_i64(ret, 0); | |
1042 | } | |
1043 | if (compute_ov) { | |
1044 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1045 | } | |
1046 | gen_set_label(l2); | |
1047 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1048 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1049 | } |
74637406 | 1050 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ |
99e300ef | 1051 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1052 | { \ |
2ef1b120 AJ |
1053 | gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1054 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1055 | sign, compute_ov); \ | |
74637406 AJ |
1056 | } |
1057 | /* divwu divwu. divwuo divwuo. */ | |
1058 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0); | |
1059 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1); | |
1060 | /* divw divw. divwo divwo. */ | |
1061 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0); | |
1062 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1); | |
d9bce9d9 | 1063 | #endif |
74637406 AJ |
1064 | |
1065 | /* mulhw mulhw. */ | |
99e300ef | 1066 | static void gen_mulhw(DisasContext *ctx) |
d9bce9d9 | 1067 | { |
a7812ae4 | 1068 | TCGv_i64 t0, t1; |
74637406 | 1069 | |
a7812ae4 PB |
1070 | t0 = tcg_temp_new_i64(); |
1071 | t1 = tcg_temp_new_i64(); | |
74637406 AJ |
1072 | #if defined(TARGET_PPC64) |
1073 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
1074 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
1075 | tcg_gen_mul_i64(t0, t0, t1); | |
1076 | tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
1077 | #else | |
1078 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1079 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1080 | tcg_gen_mul_i64(t0, t0, t1); | |
1081 | tcg_gen_shri_i64(t0, t0, 32); | |
1082 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1083 | #endif | |
a7812ae4 PB |
1084 | tcg_temp_free_i64(t0); |
1085 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1086 | if (unlikely(Rc(ctx->opcode) != 0)) |
1087 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1088 | } |
99e300ef | 1089 | |
54623277 | 1090 | /* mulhwu mulhwu. */ |
99e300ef | 1091 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1092 | { |
a7812ae4 | 1093 | TCGv_i64 t0, t1; |
74637406 | 1094 | |
a7812ae4 PB |
1095 | t0 = tcg_temp_new_i64(); |
1096 | t1 = tcg_temp_new_i64(); | |
d9bce9d9 | 1097 | #if defined(TARGET_PPC64) |
74637406 AJ |
1098 | tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]); |
1099 | tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1100 | tcg_gen_mul_i64(t0, t0, t1); | |
1101 | tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
1102 | #else | |
1103 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1104 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1105 | tcg_gen_mul_i64(t0, t0, t1); | |
1106 | tcg_gen_shri_i64(t0, t0, 32); | |
1107 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1108 | #endif | |
a7812ae4 PB |
1109 | tcg_temp_free_i64(t0); |
1110 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1111 | if (unlikely(Rc(ctx->opcode) != 0)) |
1112 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1113 | } |
99e300ef | 1114 | |
54623277 | 1115 | /* mullw mullw. */ |
99e300ef | 1116 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1117 | { |
74637406 AJ |
1118 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1119 | cpu_gpr[rB(ctx->opcode)]); | |
1e4c090f | 1120 | tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]); |
74637406 AJ |
1121 | if (unlikely(Rc(ctx->opcode) != 0)) |
1122 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1123 | } |
99e300ef | 1124 | |
54623277 | 1125 | /* mullwo mullwo. */ |
99e300ef | 1126 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1127 | { |
74637406 | 1128 | int l1; |
a7812ae4 | 1129 | TCGv_i64 t0, t1; |
74637406 | 1130 | |
a7812ae4 PB |
1131 | t0 = tcg_temp_new_i64(); |
1132 | t1 = tcg_temp_new_i64(); | |
74637406 AJ |
1133 | l1 = gen_new_label(); |
1134 | /* Start with XER OV disabled, the most likely case */ | |
1135 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1136 | #if defined(TARGET_PPC64) | |
1137 | tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1138 | tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
1139 | #else | |
1140 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
1141 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
d9bce9d9 | 1142 | #endif |
74637406 AJ |
1143 | tcg_gen_mul_i64(t0, t0, t1); |
1144 | #if defined(TARGET_PPC64) | |
1145 | tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0); | |
1146 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1); | |
1147 | #else | |
1148 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1149 | tcg_gen_ext32s_i64(t1, t0); | |
1150 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
1151 | #endif | |
1152 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1153 | gen_set_label(l1); | |
a7812ae4 PB |
1154 | tcg_temp_free_i64(t0); |
1155 | tcg_temp_free_i64(t1); | |
74637406 AJ |
1156 | if (unlikely(Rc(ctx->opcode) != 0)) |
1157 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1158 | } |
99e300ef | 1159 | |
54623277 | 1160 | /* mulli */ |
99e300ef | 1161 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1162 | { |
74637406 AJ |
1163 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1164 | SIMM(ctx->opcode)); | |
d9bce9d9 JM |
1165 | } |
1166 | #if defined(TARGET_PPC64) | |
74637406 | 1167 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ |
99e300ef | 1168 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1169 | { \ |
a7812ae4 | 1170 | gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \ |
74637406 AJ |
1171 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
1172 | if (unlikely(Rc(ctx->opcode) != 0)) \ | |
1173 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \ | |
d9bce9d9 | 1174 | } |
74637406 AJ |
1175 | /* mulhd mulhd. */ |
1176 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00); | |
1177 | /* mulhdu mulhdu. */ | |
1178 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02); | |
99e300ef | 1179 | |
54623277 | 1180 | /* mulld mulld. */ |
99e300ef | 1181 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1182 | { |
74637406 AJ |
1183 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1184 | cpu_gpr[rB(ctx->opcode)]); | |
1185 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1186 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1187 | } |
74637406 AJ |
1188 | /* mulldo mulldo. */ |
1189 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17); | |
d9bce9d9 | 1190 | #endif |
74637406 AJ |
1191 | |
1192 | /* neg neg. nego nego. */ | |
636aa200 BS |
1193 | static inline void gen_op_arith_neg(DisasContext *ctx, TCGv ret, TCGv arg1, |
1194 | int ov_check) | |
d9bce9d9 | 1195 | { |
ec6469a3 AJ |
1196 | int l1 = gen_new_label(); |
1197 | int l2 = gen_new_label(); | |
a7812ae4 | 1198 | TCGv t0 = tcg_temp_local_new(); |
d9bce9d9 | 1199 | #if defined(TARGET_PPC64) |
74637406 | 1200 | if (ctx->sf_mode) { |
741a7444 | 1201 | tcg_gen_mov_tl(t0, arg1); |
ec6469a3 AJ |
1202 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1); |
1203 | } else | |
1204 | #endif | |
1205 | { | |
1206 | tcg_gen_ext32s_tl(t0, arg1); | |
74637406 AJ |
1207 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1); |
1208 | } | |
74637406 AJ |
1209 | tcg_gen_neg_tl(ret, arg1); |
1210 | if (ov_check) { | |
1211 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1212 | } | |
1213 | tcg_gen_br(l2); | |
1214 | gen_set_label(l1); | |
ec6469a3 | 1215 | tcg_gen_mov_tl(ret, t0); |
74637406 AJ |
1216 | if (ov_check) { |
1217 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
1218 | } | |
1219 | gen_set_label(l2); | |
ec6469a3 | 1220 | tcg_temp_free(t0); |
74637406 AJ |
1221 | if (unlikely(Rc(ctx->opcode) != 0)) |
1222 | gen_set_Rc0(ctx, ret); | |
1223 | } | |
99e300ef BS |
1224 | |
1225 | static void gen_neg(DisasContext *ctx) | |
d9bce9d9 | 1226 | { |
ec6469a3 | 1227 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0); |
d9bce9d9 | 1228 | } |
99e300ef BS |
1229 | |
1230 | static void gen_nego(DisasContext *ctx) | |
79aceca5 | 1231 | { |
ec6469a3 | 1232 | gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1); |
79aceca5 | 1233 | } |
74637406 AJ |
1234 | |
1235 | /* Common subf function */ | |
636aa200 BS |
1236 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
1237 | TCGv arg2, int add_ca, int compute_ca, | |
1238 | int compute_ov) | |
79aceca5 | 1239 | { |
74637406 | 1240 | TCGv t0, t1; |
76a66253 | 1241 | |
74637406 | 1242 | if ((!compute_ca && !compute_ov) || |
a7812ae4 | 1243 | (!TCGV_EQUAL(ret, arg1) && !TCGV_EQUAL(ret, arg2))) { |
74637406 | 1244 | t0 = ret; |
e864cabd | 1245 | } else { |
a7812ae4 | 1246 | t0 = tcg_temp_local_new(); |
d9bce9d9 | 1247 | } |
76a66253 | 1248 | |
74637406 | 1249 | if (add_ca) { |
a7812ae4 | 1250 | t1 = tcg_temp_local_new(); |
74637406 AJ |
1251 | tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA)); |
1252 | tcg_gen_shri_tl(t1, t1, XER_CA); | |
d2e9fd8f | 1253 | } else { |
1254 | TCGV_UNUSED(t1); | |
d9bce9d9 | 1255 | } |
79aceca5 | 1256 | |
74637406 AJ |
1257 | if (compute_ca && compute_ov) { |
1258 | /* Start with XER CA and OV disabled, the most likely case */ | |
1259 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV))); | |
1260 | } else if (compute_ca) { | |
1261 | /* Start with XER CA disabled, the most likely case */ | |
1262 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
1263 | } else if (compute_ov) { | |
1264 | /* Start with XER OV disabled, the most likely case */ | |
1265 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
1266 | } | |
1267 | ||
1268 | if (add_ca) { | |
1269 | tcg_gen_not_tl(t0, arg1); | |
1270 | tcg_gen_add_tl(t0, t0, arg2); | |
1271 | gen_op_arith_compute_ca(ctx, t0, arg2, 0); | |
1272 | tcg_gen_add_tl(t0, t0, t1); | |
1273 | gen_op_arith_compute_ca(ctx, t0, t1, 0); | |
1274 | tcg_temp_free(t1); | |
79aceca5 | 1275 | } else { |
74637406 AJ |
1276 | tcg_gen_sub_tl(t0, arg2, arg1); |
1277 | if (compute_ca) { | |
1278 | gen_op_arith_compute_ca(ctx, t0, arg2, 1); | |
1279 | } | |
1280 | } | |
1281 | if (compute_ov) { | |
1282 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1283 | } | |
1284 | ||
1285 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1286 | gen_set_Rc0(ctx, t0); | |
1287 | ||
a7812ae4 | 1288 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
1289 | tcg_gen_mov_tl(ret, t0); |
1290 | tcg_temp_free(t0); | |
79aceca5 | 1291 | } |
79aceca5 | 1292 | } |
74637406 AJ |
1293 | /* Sub functions with Two operands functions */ |
1294 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1295 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1296 | { \ |
1297 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1298 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1299 | add_ca, compute_ca, compute_ov); \ | |
1300 | } | |
1301 | /* Sub functions with one operand and one immediate */ | |
1302 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1303 | add_ca, compute_ca, compute_ov) \ | |
99e300ef | 1304 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1305 | { \ |
1306 | TCGv t0 = tcg_const_local_tl(const_val); \ | |
1307 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1308 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
1309 | add_ca, compute_ca, compute_ov); \ | |
1310 | tcg_temp_free(t0); \ | |
1311 | } | |
1312 | /* subf subf. subfo subfo. */ | |
1313 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1314 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1315 | /* subfc subfc. subfco subfco. */ | |
1316 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1317 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1318 | /* subfe subfe. subfeo subfo. */ | |
1319 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1320 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1321 | /* subfme subfme. subfmeo subfmeo. */ | |
1322 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1323 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1324 | /* subfze subfze. subfzeo subfzeo.*/ | |
1325 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1326 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1327 | |
54623277 | 1328 | /* subfic */ |
99e300ef | 1329 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1330 | { |
74637406 AJ |
1331 | /* Start with XER CA and OV disabled, the most likely case */ |
1332 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
a7812ae4 | 1333 | TCGv t0 = tcg_temp_local_new(); |
74637406 AJ |
1334 | TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode)); |
1335 | tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]); | |
1336 | gen_op_arith_compute_ca(ctx, t0, t1, 1); | |
1337 | tcg_temp_free(t1); | |
1338 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1339 | tcg_temp_free(t0); | |
79aceca5 FB |
1340 | } |
1341 | ||
79aceca5 | 1342 | /*** Integer logical ***/ |
26d67362 | 1343 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1344 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1345 | { \ |
26d67362 AJ |
1346 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1347 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1348 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1349 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1350 | } |
79aceca5 | 1351 | |
26d67362 | 1352 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1353 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1354 | { \ |
26d67362 | 1355 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1356 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1357 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1358 | } |
1359 | ||
1360 | /* and & and. */ | |
26d67362 | 1361 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1362 | /* andc & andc. */ |
26d67362 | 1363 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1364 | |
54623277 | 1365 | /* andi. */ |
e8eaa2c0 | 1366 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1367 | { |
26d67362 AJ |
1368 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1369 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1370 | } |
e8eaa2c0 | 1371 | |
54623277 | 1372 | /* andis. */ |
e8eaa2c0 | 1373 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1374 | { |
26d67362 AJ |
1375 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1376 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1377 | } |
99e300ef | 1378 | |
54623277 | 1379 | /* cntlzw */ |
99e300ef | 1380 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1381 | { |
a7812ae4 | 1382 | gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 | 1383 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1384 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1385 | } |
79aceca5 | 1386 | /* eqv & eqv. */ |
26d67362 | 1387 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1388 | /* extsb & extsb. */ |
26d67362 | 1389 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1390 | /* extsh & extsh. */ |
26d67362 | 1391 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1392 | /* nand & nand. */ |
26d67362 | 1393 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1394 | /* nor & nor. */ |
26d67362 | 1395 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1396 | |
54623277 | 1397 | /* or & or. */ |
99e300ef | 1398 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1399 | { |
76a66253 JM |
1400 | int rs, ra, rb; |
1401 | ||
1402 | rs = rS(ctx->opcode); | |
1403 | ra = rA(ctx->opcode); | |
1404 | rb = rB(ctx->opcode); | |
1405 | /* Optimisation for mr. ri case */ | |
1406 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1407 | if (rs != rb) |
1408 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1409 | else | |
1410 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1411 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1412 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1413 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1414 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 JM |
1415 | #if defined(TARGET_PPC64) |
1416 | } else { | |
26d67362 AJ |
1417 | int prio = 0; |
1418 | ||
c80f84e3 JM |
1419 | switch (rs) { |
1420 | case 1: | |
1421 | /* Set process priority to low */ | |
26d67362 | 1422 | prio = 2; |
c80f84e3 JM |
1423 | break; |
1424 | case 6: | |
1425 | /* Set process priority to medium-low */ | |
26d67362 | 1426 | prio = 3; |
c80f84e3 JM |
1427 | break; |
1428 | case 2: | |
1429 | /* Set process priority to normal */ | |
26d67362 | 1430 | prio = 4; |
c80f84e3 | 1431 | break; |
be147d08 JM |
1432 | #if !defined(CONFIG_USER_ONLY) |
1433 | case 31: | |
76db3ba4 | 1434 | if (ctx->mem_idx > 0) { |
be147d08 | 1435 | /* Set process priority to very low */ |
26d67362 | 1436 | prio = 1; |
be147d08 JM |
1437 | } |
1438 | break; | |
1439 | case 5: | |
76db3ba4 | 1440 | if (ctx->mem_idx > 0) { |
be147d08 | 1441 | /* Set process priority to medium-hight */ |
26d67362 | 1442 | prio = 5; |
be147d08 JM |
1443 | } |
1444 | break; | |
1445 | case 3: | |
76db3ba4 | 1446 | if (ctx->mem_idx > 0) { |
be147d08 | 1447 | /* Set process priority to high */ |
26d67362 | 1448 | prio = 6; |
be147d08 JM |
1449 | } |
1450 | break; | |
be147d08 | 1451 | case 7: |
76db3ba4 | 1452 | if (ctx->mem_idx > 1) { |
be147d08 | 1453 | /* Set process priority to very high */ |
26d67362 | 1454 | prio = 7; |
be147d08 JM |
1455 | } |
1456 | break; | |
be147d08 | 1457 | #endif |
c80f84e3 JM |
1458 | default: |
1459 | /* nop */ | |
1460 | break; | |
1461 | } | |
26d67362 | 1462 | if (prio) { |
a7812ae4 | 1463 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1464 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1465 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1466 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1467 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1468 | tcg_temp_free(t0); |
26d67362 | 1469 | } |
c80f84e3 | 1470 | #endif |
9a64fbe4 | 1471 | } |
9a64fbe4 | 1472 | } |
79aceca5 | 1473 | /* orc & orc. */ |
26d67362 | 1474 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1475 | |
54623277 | 1476 | /* xor & xor. */ |
99e300ef | 1477 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1478 | { |
9a64fbe4 | 1479 | /* Optimisation for "set to zero" case */ |
26d67362 | 1480 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1481 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1482 | else |
1483 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1484 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1485 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1486 | } |
99e300ef | 1487 | |
54623277 | 1488 | /* ori */ |
99e300ef | 1489 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1490 | { |
76a66253 | 1491 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1492 | |
9a64fbe4 FB |
1493 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1494 | /* NOP */ | |
76a66253 | 1495 | /* XXX: should handle special NOPs for POWER series */ |
9a64fbe4 | 1496 | return; |
76a66253 | 1497 | } |
26d67362 | 1498 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1499 | } |
99e300ef | 1500 | |
54623277 | 1501 | /* oris */ |
99e300ef | 1502 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1503 | { |
76a66253 | 1504 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1505 | |
9a64fbe4 FB |
1506 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1507 | /* NOP */ | |
1508 | return; | |
76a66253 | 1509 | } |
26d67362 | 1510 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1511 | } |
99e300ef | 1512 | |
54623277 | 1513 | /* xori */ |
99e300ef | 1514 | static void gen_xori(DisasContext *ctx) |
79aceca5 | 1515 | { |
76a66253 | 1516 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1517 | |
1518 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1519 | /* NOP */ | |
1520 | return; | |
1521 | } | |
26d67362 | 1522 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1523 | } |
99e300ef | 1524 | |
54623277 | 1525 | /* xoris */ |
99e300ef | 1526 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1527 | { |
76a66253 | 1528 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1529 | |
1530 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1531 | /* NOP */ | |
1532 | return; | |
1533 | } | |
26d67362 | 1534 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1535 | } |
99e300ef | 1536 | |
54623277 | 1537 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1538 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1539 | { |
eaabeef2 DG |
1540 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1541 | } | |
1542 | ||
1543 | static void gen_popcntw(DisasContext *ctx) | |
1544 | { | |
1545 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1546 | } | |
1547 | ||
d9bce9d9 | 1548 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1549 | /* popcntd: PowerPC 2.06 specification */ |
1550 | static void gen_popcntd(DisasContext *ctx) | |
1551 | { | |
1552 | gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 1553 | } |
eaabeef2 | 1554 | #endif |
d9bce9d9 JM |
1555 | |
1556 | #if defined(TARGET_PPC64) | |
1557 | /* extsw & extsw. */ | |
26d67362 | 1558 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1559 | |
54623277 | 1560 | /* cntlzd */ |
99e300ef | 1561 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1562 | { |
a7812ae4 | 1563 | gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 AJ |
1564 | if (unlikely(Rc(ctx->opcode) != 0)) |
1565 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1566 | } | |
d9bce9d9 JM |
1567 | #endif |
1568 | ||
79aceca5 | 1569 | /*** Integer rotate ***/ |
99e300ef | 1570 | |
54623277 | 1571 | /* rlwimi & rlwimi. */ |
99e300ef | 1572 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1573 | { |
76a66253 | 1574 | uint32_t mb, me, sh; |
79aceca5 FB |
1575 | |
1576 | mb = MB(ctx->opcode); | |
1577 | me = ME(ctx->opcode); | |
76a66253 | 1578 | sh = SH(ctx->opcode); |
d03ef511 AJ |
1579 | if (likely(sh == 0 && mb == 0 && me == 31)) { |
1580 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1581 | } else { | |
d03ef511 | 1582 | target_ulong mask; |
a7812ae4 PB |
1583 | TCGv t1; |
1584 | TCGv t0 = tcg_temp_new(); | |
54843a58 | 1585 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1586 | TCGv_i32 t2 = tcg_temp_new_i32(); |
1587 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]); | |
1588 | tcg_gen_rotli_i32(t2, t2, sh); | |
1589 | tcg_gen_extu_i32_i64(t0, t2); | |
1590 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1591 | #else |
1592 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1593 | #endif | |
76a66253 | 1594 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1595 | mb += 32; |
1596 | me += 32; | |
76a66253 | 1597 | #endif |
d03ef511 | 1598 | mask = MASK(mb, me); |
a7812ae4 | 1599 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1600 | tcg_gen_andi_tl(t0, t0, mask); |
1601 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1602 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1603 | tcg_temp_free(t0); | |
1604 | tcg_temp_free(t1); | |
1605 | } | |
76a66253 | 1606 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1607 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1608 | } |
99e300ef | 1609 | |
54623277 | 1610 | /* rlwinm & rlwinm. */ |
99e300ef | 1611 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 FB |
1612 | { |
1613 | uint32_t mb, me, sh; | |
3b46e624 | 1614 | |
79aceca5 FB |
1615 | sh = SH(ctx->opcode); |
1616 | mb = MB(ctx->opcode); | |
1617 | me = ME(ctx->opcode); | |
d03ef511 AJ |
1618 | |
1619 | if (likely(mb == 0 && me == (31 - sh))) { | |
1620 | if (likely(sh == 0)) { | |
1621 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1622 | } else { | |
a7812ae4 | 1623 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1624 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1625 | tcg_gen_shli_tl(t0, t0, sh); | |
1626 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1627 | tcg_temp_free(t0); | |
79aceca5 | 1628 | } |
d03ef511 | 1629 | } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) { |
a7812ae4 | 1630 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1631 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1632 | tcg_gen_shri_tl(t0, t0, mb); | |
1633 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1634 | tcg_temp_free(t0); | |
1635 | } else { | |
a7812ae4 | 1636 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1637 | #if defined(TARGET_PPC64) |
a7812ae4 | 1638 | TCGv_i32 t1 = tcg_temp_new_i32(); |
54843a58 AJ |
1639 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1640 | tcg_gen_rotli_i32(t1, t1, sh); | |
1641 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 | 1642 | tcg_temp_free_i32(t1); |
54843a58 AJ |
1643 | #else |
1644 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1645 | #endif | |
76a66253 | 1646 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1647 | mb += 32; |
1648 | me += 32; | |
76a66253 | 1649 | #endif |
d03ef511 AJ |
1650 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1651 | tcg_temp_free(t0); | |
1652 | } | |
76a66253 | 1653 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1654 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1655 | } |
99e300ef | 1656 | |
54623277 | 1657 | /* rlwnm & rlwnm. */ |
99e300ef | 1658 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 FB |
1659 | { |
1660 | uint32_t mb, me; | |
54843a58 AJ |
1661 | TCGv t0; |
1662 | #if defined(TARGET_PPC64) | |
a7812ae4 | 1663 | TCGv_i32 t1, t2; |
54843a58 | 1664 | #endif |
79aceca5 FB |
1665 | |
1666 | mb = MB(ctx->opcode); | |
1667 | me = ME(ctx->opcode); | |
a7812ae4 | 1668 | t0 = tcg_temp_new(); |
d03ef511 | 1669 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f); |
54843a58 | 1670 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1671 | t1 = tcg_temp_new_i32(); |
1672 | t2 = tcg_temp_new_i32(); | |
54843a58 AJ |
1673 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1674 | tcg_gen_trunc_i64_i32(t2, t0); | |
1675 | tcg_gen_rotl_i32(t1, t1, t2); | |
1676 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 PB |
1677 | tcg_temp_free_i32(t1); |
1678 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1679 | #else |
1680 | tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1681 | #endif | |
76a66253 JM |
1682 | if (unlikely(mb != 0 || me != 31)) { |
1683 | #if defined(TARGET_PPC64) | |
1684 | mb += 32; | |
1685 | me += 32; | |
1686 | #endif | |
54843a58 | 1687 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
d03ef511 | 1688 | } else { |
54843a58 | 1689 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
79aceca5 | 1690 | } |
54843a58 | 1691 | tcg_temp_free(t0); |
76a66253 | 1692 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1693 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 FB |
1694 | } |
1695 | ||
d9bce9d9 JM |
1696 | #if defined(TARGET_PPC64) |
1697 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1698 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1699 | { \ |
1700 | gen_##name(ctx, 0); \ | |
1701 | } \ | |
e8eaa2c0 BS |
1702 | \ |
1703 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1704 | { \ |
1705 | gen_##name(ctx, 1); \ | |
1706 | } | |
1707 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1708 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1709 | { \ |
1710 | gen_##name(ctx, 0, 0); \ | |
1711 | } \ | |
e8eaa2c0 BS |
1712 | \ |
1713 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1714 | { \ |
1715 | gen_##name(ctx, 0, 1); \ | |
1716 | } \ | |
e8eaa2c0 BS |
1717 | \ |
1718 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1719 | { \ |
1720 | gen_##name(ctx, 1, 0); \ | |
1721 | } \ | |
e8eaa2c0 BS |
1722 | \ |
1723 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1724 | { \ |
1725 | gen_##name(ctx, 1, 1); \ | |
1726 | } | |
51789c41 | 1727 | |
636aa200 BS |
1728 | static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me, |
1729 | uint32_t sh) | |
51789c41 | 1730 | { |
d03ef511 AJ |
1731 | if (likely(sh != 0 && mb == 0 && me == (63 - sh))) { |
1732 | tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
1733 | } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) { | |
1734 | tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb); | |
1735 | } else { | |
a7812ae4 | 1736 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1737 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
d03ef511 | 1738 | if (likely(mb == 0 && me == 63)) { |
54843a58 | 1739 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
d03ef511 AJ |
1740 | } else { |
1741 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); | |
51789c41 | 1742 | } |
d03ef511 | 1743 | tcg_temp_free(t0); |
51789c41 | 1744 | } |
51789c41 | 1745 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1746 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
51789c41 | 1747 | } |
d9bce9d9 | 1748 | /* rldicl - rldicl. */ |
636aa200 | 1749 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1750 | { |
51789c41 | 1751 | uint32_t sh, mb; |
d9bce9d9 | 1752 | |
9d53c753 JM |
1753 | sh = SH(ctx->opcode) | (shn << 5); |
1754 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 1755 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 1756 | } |
51789c41 | 1757 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
d9bce9d9 | 1758 | /* rldicr - rldicr. */ |
636aa200 | 1759 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 1760 | { |
51789c41 | 1761 | uint32_t sh, me; |
d9bce9d9 | 1762 | |
9d53c753 JM |
1763 | sh = SH(ctx->opcode) | (shn << 5); |
1764 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 1765 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 1766 | } |
51789c41 | 1767 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
d9bce9d9 | 1768 | /* rldic - rldic. */ |
636aa200 | 1769 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1770 | { |
51789c41 | 1771 | uint32_t sh, mb; |
d9bce9d9 | 1772 | |
9d53c753 JM |
1773 | sh = SH(ctx->opcode) | (shn << 5); |
1774 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
1775 | gen_rldinm(ctx, mb, 63 - sh, sh); |
1776 | } | |
1777 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
1778 | ||
636aa200 | 1779 | static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me) |
51789c41 | 1780 | { |
54843a58 | 1781 | TCGv t0; |
d03ef511 AJ |
1782 | |
1783 | mb = MB(ctx->opcode); | |
1784 | me = ME(ctx->opcode); | |
a7812ae4 | 1785 | t0 = tcg_temp_new(); |
d03ef511 | 1786 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f); |
54843a58 | 1787 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); |
51789c41 | 1788 | if (unlikely(mb != 0 || me != 63)) { |
54843a58 AJ |
1789 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1790 | } else { | |
1791 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1792 | } | |
1793 | tcg_temp_free(t0); | |
51789c41 | 1794 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1795 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1796 | } |
51789c41 | 1797 | |
d9bce9d9 | 1798 | /* rldcl - rldcl. */ |
636aa200 | 1799 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 1800 | { |
51789c41 | 1801 | uint32_t mb; |
d9bce9d9 | 1802 | |
9d53c753 | 1803 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 1804 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 1805 | } |
36081602 | 1806 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
d9bce9d9 | 1807 | /* rldcr - rldcr. */ |
636aa200 | 1808 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 1809 | { |
51789c41 | 1810 | uint32_t me; |
d9bce9d9 | 1811 | |
9d53c753 | 1812 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 1813 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 1814 | } |
36081602 | 1815 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
d9bce9d9 | 1816 | /* rldimi - rldimi. */ |
636aa200 | 1817 | static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1818 | { |
271a916e | 1819 | uint32_t sh, mb, me; |
d9bce9d9 | 1820 | |
9d53c753 JM |
1821 | sh = SH(ctx->opcode) | (shn << 5); |
1822 | mb = MB(ctx->opcode) | (mbn << 5); | |
271a916e | 1823 | me = 63 - sh; |
d03ef511 AJ |
1824 | if (unlikely(sh == 0 && mb == 0)) { |
1825 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1826 | } else { | |
1827 | TCGv t0, t1; | |
1828 | target_ulong mask; | |
1829 | ||
a7812ae4 | 1830 | t0 = tcg_temp_new(); |
54843a58 | 1831 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
a7812ae4 | 1832 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1833 | mask = MASK(mb, me); |
1834 | tcg_gen_andi_tl(t0, t0, mask); | |
1835 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1836 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1837 | tcg_temp_free(t0); | |
1838 | tcg_temp_free(t1); | |
51789c41 | 1839 | } |
51789c41 | 1840 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1841 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1842 | } |
36081602 | 1843 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
1844 | #endif |
1845 | ||
79aceca5 | 1846 | /*** Integer shift ***/ |
99e300ef | 1847 | |
54623277 | 1848 | /* slw & slw. */ |
99e300ef | 1849 | static void gen_slw(DisasContext *ctx) |
26d67362 | 1850 | { |
7fd6bf7d | 1851 | TCGv t0, t1; |
26d67362 | 1852 | |
7fd6bf7d AJ |
1853 | t0 = tcg_temp_new(); |
1854 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1855 | #if defined(TARGET_PPC64) | |
1856 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1857 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1858 | #else | |
1859 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1860 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1861 | #endif | |
1862 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1863 | t1 = tcg_temp_new(); | |
1864 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
1865 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1866 | tcg_temp_free(t1); | |
fea0c503 | 1867 | tcg_temp_free(t0); |
7fd6bf7d | 1868 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
1869 | if (unlikely(Rc(ctx->opcode) != 0)) |
1870 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1871 | } | |
99e300ef | 1872 | |
54623277 | 1873 | /* sraw & sraw. */ |
99e300ef | 1874 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 1875 | { |
a7812ae4 PB |
1876 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], |
1877 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
26d67362 AJ |
1878 | if (unlikely(Rc(ctx->opcode) != 0)) |
1879 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1880 | } | |
99e300ef | 1881 | |
54623277 | 1882 | /* srawi & srawi. */ |
99e300ef | 1883 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 1884 | { |
26d67362 AJ |
1885 | int sh = SH(ctx->opcode); |
1886 | if (sh != 0) { | |
1887 | int l1, l2; | |
fea0c503 | 1888 | TCGv t0; |
26d67362 AJ |
1889 | l1 = gen_new_label(); |
1890 | l2 = gen_new_label(); | |
a7812ae4 | 1891 | t0 = tcg_temp_local_new(); |
fea0c503 AJ |
1892 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1893 | tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1); | |
1894 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); | |
1895 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1896 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1897 | tcg_gen_br(l2); |
1898 | gen_set_label(l1); | |
269f3e95 | 1899 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1900 | gen_set_label(l2); |
fea0c503 AJ |
1901 | tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1902 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh); | |
1903 | tcg_temp_free(t0); | |
26d67362 AJ |
1904 | } else { |
1905 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1906 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1907 | } |
76a66253 | 1908 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1909 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1910 | } |
99e300ef | 1911 | |
54623277 | 1912 | /* srw & srw. */ |
99e300ef | 1913 | static void gen_srw(DisasContext *ctx) |
26d67362 | 1914 | { |
fea0c503 | 1915 | TCGv t0, t1; |
d9bce9d9 | 1916 | |
7fd6bf7d AJ |
1917 | t0 = tcg_temp_new(); |
1918 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1919 | #if defined(TARGET_PPC64) | |
1920 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1921 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1922 | #else | |
1923 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1924 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1925 | #endif | |
1926 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1927 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 1928 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
1929 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
1930 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 1931 | tcg_temp_free(t1); |
fea0c503 | 1932 | tcg_temp_free(t0); |
26d67362 AJ |
1933 | if (unlikely(Rc(ctx->opcode) != 0)) |
1934 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1935 | } | |
54623277 | 1936 | |
d9bce9d9 JM |
1937 | #if defined(TARGET_PPC64) |
1938 | /* sld & sld. */ | |
99e300ef | 1939 | static void gen_sld(DisasContext *ctx) |
26d67362 | 1940 | { |
7fd6bf7d | 1941 | TCGv t0, t1; |
26d67362 | 1942 | |
7fd6bf7d AJ |
1943 | t0 = tcg_temp_new(); |
1944 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
1945 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
1946 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1947 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1948 | t1 = tcg_temp_new(); | |
1949 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
1950 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1951 | tcg_temp_free(t1); | |
fea0c503 | 1952 | tcg_temp_free(t0); |
26d67362 AJ |
1953 | if (unlikely(Rc(ctx->opcode) != 0)) |
1954 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1955 | } | |
99e300ef | 1956 | |
54623277 | 1957 | /* srad & srad. */ |
99e300ef | 1958 | static void gen_srad(DisasContext *ctx) |
26d67362 | 1959 | { |
a7812ae4 PB |
1960 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], |
1961 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
26d67362 AJ |
1962 | if (unlikely(Rc(ctx->opcode) != 0)) |
1963 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1964 | } | |
d9bce9d9 | 1965 | /* sradi & sradi. */ |
636aa200 | 1966 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 1967 | { |
26d67362 | 1968 | int sh = SH(ctx->opcode) + (n << 5); |
d9bce9d9 | 1969 | if (sh != 0) { |
26d67362 | 1970 | int l1, l2; |
fea0c503 | 1971 | TCGv t0; |
26d67362 AJ |
1972 | l1 = gen_new_label(); |
1973 | l2 = gen_new_label(); | |
a7812ae4 | 1974 | t0 = tcg_temp_local_new(); |
26d67362 | 1975 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); |
fea0c503 AJ |
1976 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1); |
1977 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
269f3e95 | 1978 | tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA); |
26d67362 AJ |
1979 | tcg_gen_br(l2); |
1980 | gen_set_label(l1); | |
269f3e95 | 1981 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
26d67362 | 1982 | gen_set_label(l2); |
a9730017 | 1983 | tcg_temp_free(t0); |
26d67362 AJ |
1984 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); |
1985 | } else { | |
1986 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
269f3e95 | 1987 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); |
d9bce9d9 | 1988 | } |
d9bce9d9 | 1989 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1990 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1991 | } |
e8eaa2c0 BS |
1992 | |
1993 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
1994 | { |
1995 | gen_sradi(ctx, 0); | |
1996 | } | |
e8eaa2c0 BS |
1997 | |
1998 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
1999 | { |
2000 | gen_sradi(ctx, 1); | |
2001 | } | |
99e300ef | 2002 | |
54623277 | 2003 | /* srd & srd. */ |
99e300ef | 2004 | static void gen_srd(DisasContext *ctx) |
26d67362 | 2005 | { |
7fd6bf7d | 2006 | TCGv t0, t1; |
26d67362 | 2007 | |
7fd6bf7d AJ |
2008 | t0 = tcg_temp_new(); |
2009 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2010 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2011 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2012 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2013 | t1 = tcg_temp_new(); | |
2014 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2015 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2016 | tcg_temp_free(t1); | |
fea0c503 | 2017 | tcg_temp_free(t0); |
26d67362 AJ |
2018 | if (unlikely(Rc(ctx->opcode) != 0)) |
2019 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2020 | } | |
d9bce9d9 | 2021 | #endif |
79aceca5 FB |
2022 | |
2023 | /*** Floating-Point arithmetic ***/ | |
7c58044c | 2024 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ |
99e300ef | 2025 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2026 | { \ |
76a66253 | 2027 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2028 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2029 | return; \ |
2030 | } \ | |
eb44b959 AJ |
2031 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2032 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2033 | gen_reset_fpstatus(); \ |
af12906f AJ |
2034 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \ |
2035 | cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ | |
4ecc3190 | 2036 | if (isfloat) { \ |
af12906f | 2037 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \ |
4ecc3190 | 2038 | } \ |
af12906f AJ |
2039 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \ |
2040 | Rc(ctx->opcode) != 0); \ | |
9a64fbe4 FB |
2041 | } |
2042 | ||
7c58044c JM |
2043 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ |
2044 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \ | |
2045 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type); | |
9a64fbe4 | 2046 | |
7c58044c | 2047 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2048 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2049 | { \ |
76a66253 | 2050 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2051 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2052 | return; \ |
2053 | } \ | |
eb44b959 AJ |
2054 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2055 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2056 | gen_reset_fpstatus(); \ |
af12906f AJ |
2057 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \ |
2058 | cpu_fpr[rB(ctx->opcode)]); \ | |
4ecc3190 | 2059 | if (isfloat) { \ |
af12906f | 2060 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \ |
4ecc3190 | 2061 | } \ |
af12906f AJ |
2062 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2063 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2064 | } |
7c58044c JM |
2065 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ |
2066 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2067 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2068 | |
7c58044c | 2069 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2070 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2071 | { \ |
76a66253 | 2072 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2073 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2074 | return; \ |
2075 | } \ | |
eb44b959 AJ |
2076 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2077 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2078 | gen_reset_fpstatus(); \ |
af12906f AJ |
2079 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \ |
2080 | cpu_fpr[rC(ctx->opcode)]); \ | |
4ecc3190 | 2081 | if (isfloat) { \ |
af12906f | 2082 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \ |
4ecc3190 | 2083 | } \ |
af12906f AJ |
2084 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2085 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2086 | } |
7c58044c JM |
2087 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ |
2088 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2089 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2090 | |
7c58044c | 2091 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ |
99e300ef | 2092 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2093 | { \ |
76a66253 | 2094 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2095 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2096 | return; \ |
2097 | } \ | |
eb44b959 AJ |
2098 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2099 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2100 | gen_reset_fpstatus(); \ |
af12906f AJ |
2101 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
2102 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ | |
2103 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2104 | } |
2105 | ||
7c58044c | 2106 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ |
99e300ef | 2107 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2108 | { \ |
76a66253 | 2109 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2110 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2111 | return; \ |
2112 | } \ | |
eb44b959 AJ |
2113 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2114 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2115 | gen_reset_fpstatus(); \ |
af12906f AJ |
2116 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
2117 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ | |
2118 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2119 | } |
2120 | ||
9a64fbe4 | 2121 | /* fadd - fadds */ |
7c58044c | 2122 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2123 | /* fdiv - fdivs */ |
7c58044c | 2124 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2125 | /* fmul - fmuls */ |
7c58044c | 2126 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT); |
79aceca5 | 2127 | |
d7e4b87e | 2128 | /* fre */ |
7c58044c | 2129 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2130 | |
a750fc0b | 2131 | /* fres */ |
7c58044c | 2132 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES); |
79aceca5 | 2133 | |
a750fc0b | 2134 | /* frsqrte */ |
7c58044c JM |
2135 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE); |
2136 | ||
2137 | /* frsqrtes */ | |
99e300ef | 2138 | static void gen_frsqrtes(DisasContext *ctx) |
7c58044c | 2139 | { |
af12906f | 2140 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2141 | gen_exception(ctx, POWERPC_EXCP_FPU); |
af12906f AJ |
2142 | return; |
2143 | } | |
eb44b959 AJ |
2144 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2145 | gen_update_nip(ctx, ctx->nip - 4); | |
af12906f AJ |
2146 | gen_reset_fpstatus(); |
2147 | gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); | |
2148 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); | |
2149 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); | |
7c58044c | 2150 | } |
79aceca5 | 2151 | |
a750fc0b | 2152 | /* fsel */ |
7c58044c | 2153 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL); |
4ecc3190 | 2154 | /* fsub - fsubs */ |
7c58044c | 2155 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT); |
79aceca5 | 2156 | /* Optional: */ |
99e300ef | 2157 | |
54623277 | 2158 | /* fsqrt */ |
99e300ef | 2159 | static void gen_fsqrt(DisasContext *ctx) |
c7d344af | 2160 | { |
76a66253 | 2161 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2162 | gen_exception(ctx, POWERPC_EXCP_FPU); |
c7d344af FB |
2163 | return; |
2164 | } | |
eb44b959 AJ |
2165 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2166 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2167 | gen_reset_fpstatus(); |
af12906f AJ |
2168 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2169 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); | |
c7d344af | 2170 | } |
79aceca5 | 2171 | |
99e300ef | 2172 | static void gen_fsqrts(DisasContext *ctx) |
79aceca5 | 2173 | { |
76a66253 | 2174 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2175 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2176 | return; |
2177 | } | |
eb44b959 AJ |
2178 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2179 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2180 | gen_reset_fpstatus(); |
af12906f AJ |
2181 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2182 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); | |
2183 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); | |
79aceca5 FB |
2184 | } |
2185 | ||
2186 | /*** Floating-Point multiply-and-add ***/ | |
4ecc3190 | 2187 | /* fmadd - fmadds */ |
7c58044c | 2188 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT); |
4ecc3190 | 2189 | /* fmsub - fmsubs */ |
7c58044c | 2190 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT); |
4ecc3190 | 2191 | /* fnmadd - fnmadds */ |
7c58044c | 2192 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT); |
4ecc3190 | 2193 | /* fnmsub - fnmsubs */ |
7c58044c | 2194 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT); |
79aceca5 FB |
2195 | |
2196 | /*** Floating-Point round & convert ***/ | |
2197 | /* fctiw */ | |
7c58044c | 2198 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2199 | /* fctiwz */ |
7c58044c | 2200 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT); |
79aceca5 | 2201 | /* frsp */ |
7c58044c | 2202 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT); |
426613db JM |
2203 | #if defined(TARGET_PPC64) |
2204 | /* fcfid */ | |
7c58044c | 2205 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B); |
426613db | 2206 | /* fctid */ |
7c58044c | 2207 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B); |
426613db | 2208 | /* fctidz */ |
7c58044c | 2209 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B); |
426613db | 2210 | #endif |
79aceca5 | 2211 | |
d7e4b87e | 2212 | /* frin */ |
7c58044c | 2213 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2214 | /* friz */ |
7c58044c | 2215 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2216 | /* frip */ |
7c58044c | 2217 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2218 | /* frim */ |
7c58044c | 2219 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2220 | |
79aceca5 | 2221 | /*** Floating-Point compare ***/ |
99e300ef | 2222 | |
54623277 | 2223 | /* fcmpo */ |
99e300ef | 2224 | static void gen_fcmpo(DisasContext *ctx) |
79aceca5 | 2225 | { |
330c483b | 2226 | TCGv_i32 crf; |
76a66253 | 2227 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2228 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2229 | return; |
2230 | } | |
eb44b959 AJ |
2231 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2232 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2233 | gen_reset_fpstatus(); |
9a819377 AJ |
2234 | crf = tcg_const_i32(crfD(ctx->opcode)); |
2235 | gen_helper_fcmpo(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2236 | tcg_temp_free_i32(crf); |
af12906f | 2237 | gen_helper_float_check_status(); |
79aceca5 FB |
2238 | } |
2239 | ||
2240 | /* fcmpu */ | |
99e300ef | 2241 | static void gen_fcmpu(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 AJ |
2251 | crf = tcg_const_i32(crfD(ctx->opcode)); |
2252 | gen_helper_fcmpu(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2253 | tcg_temp_free_i32(crf); |
af12906f | 2254 | gen_helper_float_check_status(); |
79aceca5 FB |
2255 | } |
2256 | ||
9a64fbe4 FB |
2257 | /*** Floating-point move ***/ |
2258 | /* fabs */ | |
7c58044c JM |
2259 | /* XXX: beware that fabs never checks for NaNs nor update FPSCR */ |
2260 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT); | |
9a64fbe4 FB |
2261 | |
2262 | /* fmr - fmr. */ | |
7c58044c | 2263 | /* XXX: beware that fmr never checks for NaNs nor update FPSCR */ |
99e300ef | 2264 | static void gen_fmr(DisasContext *ctx) |
9a64fbe4 | 2265 | { |
76a66253 | 2266 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2267 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2268 | return; |
2269 | } | |
af12906f AJ |
2270 | tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2271 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
9a64fbe4 FB |
2272 | } |
2273 | ||
2274 | /* fnabs */ | |
7c58044c JM |
2275 | /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */ |
2276 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT); | |
9a64fbe4 | 2277 | /* fneg */ |
7c58044c JM |
2278 | /* XXX: beware that fneg never checks for NaNs nor update FPSCR */ |
2279 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT); | |
9a64fbe4 | 2280 | |
79aceca5 | 2281 | /*** Floating-Point status & ctrl register ***/ |
99e300ef | 2282 | |
54623277 | 2283 | /* mcrfs */ |
99e300ef | 2284 | static void gen_mcrfs(DisasContext *ctx) |
79aceca5 | 2285 | { |
7c58044c JM |
2286 | int bfa; |
2287 | ||
76a66253 | 2288 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2289 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2290 | return; |
2291 | } | |
7c58044c | 2292 | bfa = 4 * (7 - crfS(ctx->opcode)); |
e1571908 AJ |
2293 | tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa); |
2294 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf); | |
af12906f | 2295 | tcg_gen_andi_i32(cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); |
79aceca5 FB |
2296 | } |
2297 | ||
2298 | /* mffs */ | |
99e300ef | 2299 | static void gen_mffs(DisasContext *ctx) |
79aceca5 | 2300 | { |
76a66253 | 2301 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2302 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2303 | return; |
2304 | } | |
7c58044c | 2305 | gen_reset_fpstatus(); |
af12906f AJ |
2306 | tcg_gen_extu_i32_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr); |
2307 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
79aceca5 FB |
2308 | } |
2309 | ||
2310 | /* mtfsb0 */ | |
99e300ef | 2311 | static void gen_mtfsb0(DisasContext *ctx) |
79aceca5 | 2312 | { |
fb0eaffc | 2313 | uint8_t crb; |
3b46e624 | 2314 | |
76a66253 | 2315 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2316 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2317 | return; |
2318 | } | |
6e35d524 | 2319 | crb = 31 - crbD(ctx->opcode); |
7c58044c | 2320 | gen_reset_fpstatus(); |
6e35d524 | 2321 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) { |
eb44b959 AJ |
2322 | TCGv_i32 t0; |
2323 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2324 | gen_update_nip(ctx, ctx->nip - 4); | |
2325 | t0 = tcg_const_i32(crb); | |
6e35d524 AJ |
2326 | gen_helper_fpscr_clrbit(t0); |
2327 | tcg_temp_free_i32(t0); | |
2328 | } | |
7c58044c | 2329 | if (unlikely(Rc(ctx->opcode) != 0)) { |
e1571908 | 2330 | tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX); |
7c58044c | 2331 | } |
79aceca5 FB |
2332 | } |
2333 | ||
2334 | /* mtfsb1 */ | |
99e300ef | 2335 | static void gen_mtfsb1(DisasContext *ctx) |
79aceca5 | 2336 | { |
fb0eaffc | 2337 | uint8_t crb; |
3b46e624 | 2338 | |
76a66253 | 2339 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2340 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2341 | return; |
2342 | } | |
6e35d524 | 2343 | crb = 31 - crbD(ctx->opcode); |
7c58044c JM |
2344 | gen_reset_fpstatus(); |
2345 | /* XXX: we pretend we can only do IEEE floating-point computations */ | |
af12906f | 2346 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) { |
eb44b959 AJ |
2347 | TCGv_i32 t0; |
2348 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2349 | gen_update_nip(ctx, ctx->nip - 4); | |
2350 | t0 = tcg_const_i32(crb); | |
af12906f | 2351 | gen_helper_fpscr_setbit(t0); |
0f2f39c2 | 2352 | tcg_temp_free_i32(t0); |
af12906f | 2353 | } |
7c58044c | 2354 | if (unlikely(Rc(ctx->opcode) != 0)) { |
e1571908 | 2355 | tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX); |
7c58044c JM |
2356 | } |
2357 | /* We can raise a differed exception */ | |
af12906f | 2358 | gen_helper_float_check_status(); |
79aceca5 FB |
2359 | } |
2360 | ||
2361 | /* mtfsf */ | |
99e300ef | 2362 | static void gen_mtfsf(DisasContext *ctx) |
79aceca5 | 2363 | { |
0f2f39c2 | 2364 | TCGv_i32 t0; |
4911012d | 2365 | int L = ctx->opcode & 0x02000000; |
af12906f | 2366 | |
76a66253 | 2367 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2368 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2369 | return; |
2370 | } | |
eb44b959 AJ |
2371 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2372 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2373 | gen_reset_fpstatus(); |
4911012d BS |
2374 | if (L) |
2375 | t0 = tcg_const_i32(0xff); | |
2376 | else | |
2377 | t0 = tcg_const_i32(FM(ctx->opcode)); | |
af12906f | 2378 | gen_helper_store_fpscr(cpu_fpr[rB(ctx->opcode)], t0); |
0f2f39c2 | 2379 | tcg_temp_free_i32(t0); |
7c58044c | 2380 | if (unlikely(Rc(ctx->opcode) != 0)) { |
e1571908 | 2381 | tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX); |
7c58044c JM |
2382 | } |
2383 | /* We can raise a differed exception */ | |
af12906f | 2384 | gen_helper_float_check_status(); |
79aceca5 FB |
2385 | } |
2386 | ||
2387 | /* mtfsfi */ | |
99e300ef | 2388 | static void gen_mtfsfi(DisasContext *ctx) |
79aceca5 | 2389 | { |
7c58044c | 2390 | int bf, sh; |
0f2f39c2 AJ |
2391 | TCGv_i64 t0; |
2392 | TCGv_i32 t1; | |
7c58044c | 2393 | |
76a66253 | 2394 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2395 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2396 | return; |
2397 | } | |
7c58044c JM |
2398 | bf = crbD(ctx->opcode) >> 2; |
2399 | sh = 7 - bf; | |
eb44b959 AJ |
2400 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2401 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2402 | gen_reset_fpstatus(); |
0f2f39c2 | 2403 | t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh)); |
af12906f AJ |
2404 | t1 = tcg_const_i32(1 << sh); |
2405 | gen_helper_store_fpscr(t0, t1); | |
0f2f39c2 AJ |
2406 | tcg_temp_free_i64(t0); |
2407 | tcg_temp_free_i32(t1); | |
7c58044c | 2408 | if (unlikely(Rc(ctx->opcode) != 0)) { |
e1571908 | 2409 | tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX); |
7c58044c JM |
2410 | } |
2411 | /* We can raise a differed exception */ | |
af12906f | 2412 | gen_helper_float_check_status(); |
79aceca5 FB |
2413 | } |
2414 | ||
76a66253 JM |
2415 | /*** Addressing modes ***/ |
2416 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2417 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2418 | target_long maskl) | |
76a66253 JM |
2419 | { |
2420 | target_long simm = SIMM(ctx->opcode); | |
2421 | ||
be147d08 | 2422 | simm &= ~maskl; |
76db3ba4 AJ |
2423 | if (rA(ctx->opcode) == 0) { |
2424 | #if defined(TARGET_PPC64) | |
2425 | if (!ctx->sf_mode) { | |
2426 | tcg_gen_movi_tl(EA, (uint32_t)simm); | |
2427 | } else | |
2428 | #endif | |
e2be8d8d | 2429 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2430 | } else if (likely(simm != 0)) { |
e2be8d8d | 2431 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
76db3ba4 AJ |
2432 | #if defined(TARGET_PPC64) |
2433 | if (!ctx->sf_mode) { | |
2434 | tcg_gen_ext32u_tl(EA, EA); | |
2435 | } | |
2436 | #endif | |
2437 | } else { | |
2438 | #if defined(TARGET_PPC64) | |
2439 | if (!ctx->sf_mode) { | |
2440 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2441 | } else | |
2442 | #endif | |
e2be8d8d | 2443 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 | 2444 | } |
76a66253 JM |
2445 | } |
2446 | ||
636aa200 | 2447 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2448 | { |
76db3ba4 AJ |
2449 | if (rA(ctx->opcode) == 0) { |
2450 | #if defined(TARGET_PPC64) | |
2451 | if (!ctx->sf_mode) { | |
2452 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2453 | } else | |
2454 | #endif | |
e2be8d8d | 2455 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 | 2456 | } else { |
e2be8d8d | 2457 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76db3ba4 AJ |
2458 | #if defined(TARGET_PPC64) |
2459 | if (!ctx->sf_mode) { | |
2460 | tcg_gen_ext32u_tl(EA, EA); | |
2461 | } | |
2462 | #endif | |
2463 | } | |
76a66253 JM |
2464 | } |
2465 | ||
636aa200 | 2466 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2467 | { |
76db3ba4 | 2468 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2469 | tcg_gen_movi_tl(EA, 0); |
76db3ba4 AJ |
2470 | } else { |
2471 | #if defined(TARGET_PPC64) | |
2472 | if (!ctx->sf_mode) { | |
2473 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2474 | } else | |
2475 | #endif | |
2476 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2477 | } | |
2478 | } | |
2479 | ||
636aa200 BS |
2480 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2481 | target_long val) | |
76db3ba4 AJ |
2482 | { |
2483 | tcg_gen_addi_tl(ret, arg1, val); | |
2484 | #if defined(TARGET_PPC64) | |
2485 | if (!ctx->sf_mode) { | |
2486 | tcg_gen_ext32u_tl(ret, ret); | |
2487 | } | |
2488 | #endif | |
76a66253 JM |
2489 | } |
2490 | ||
636aa200 | 2491 | static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask) |
cf360a32 AJ |
2492 | { |
2493 | int l1 = gen_new_label(); | |
2494 | TCGv t0 = tcg_temp_new(); | |
2495 | TCGv_i32 t1, t2; | |
2496 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2497 | gen_update_nip(ctx, ctx->nip - 4); | |
2498 | tcg_gen_andi_tl(t0, EA, mask); | |
2499 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
2500 | t1 = tcg_const_i32(POWERPC_EXCP_ALIGN); | |
2501 | t2 = tcg_const_i32(0); | |
2502 | gen_helper_raise_exception_err(t1, t2); | |
2503 | tcg_temp_free_i32(t1); | |
2504 | tcg_temp_free_i32(t2); | |
2505 | gen_set_label(l1); | |
2506 | tcg_temp_free(t0); | |
2507 | } | |
2508 | ||
7863667f | 2509 | /*** Integer load ***/ |
636aa200 | 2510 | static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2511 | { |
2512 | tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx); | |
2513 | } | |
2514 | ||
636aa200 | 2515 | static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2516 | { |
2517 | tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx); | |
2518 | } | |
2519 | ||
636aa200 | 2520 | static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2521 | { |
2522 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); | |
2523 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2524 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2525 | } |
b61f2753 AJ |
2526 | } |
2527 | ||
636aa200 | 2528 | static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2529 | { |
76db3ba4 | 2530 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2531 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
fa3966a3 | 2532 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2533 | tcg_gen_ext16s_tl(arg1, arg1); |
76db3ba4 AJ |
2534 | } else { |
2535 | tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx); | |
2536 | } | |
b61f2753 AJ |
2537 | } |
2538 | ||
636aa200 | 2539 | static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2540 | { |
76db3ba4 AJ |
2541 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2542 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2543 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2544 | } |
b61f2753 AJ |
2545 | } |
2546 | ||
76db3ba4 | 2547 | #if defined(TARGET_PPC64) |
636aa200 | 2548 | static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2549 | { |
a457e7ee | 2550 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2551 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
fa3966a3 AJ |
2552 | tcg_gen_bswap32_tl(arg1, arg1); |
2553 | tcg_gen_ext32s_tl(arg1, arg1); | |
b61f2753 | 2554 | } else |
76db3ba4 | 2555 | tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx); |
b61f2753 | 2556 | } |
76db3ba4 | 2557 | #endif |
b61f2753 | 2558 | |
636aa200 | 2559 | static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2560 | { |
76db3ba4 AJ |
2561 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); |
2562 | if (unlikely(ctx->le_mode)) { | |
66896cb8 | 2563 | tcg_gen_bswap64_i64(arg1, arg1); |
76db3ba4 | 2564 | } |
b61f2753 AJ |
2565 | } |
2566 | ||
636aa200 | 2567 | static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2568 | { |
76db3ba4 | 2569 | tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2570 | } |
2571 | ||
636aa200 | 2572 | static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2573 | { |
76db3ba4 | 2574 | if (unlikely(ctx->le_mode)) { |
76db3ba4 AJ |
2575 | TCGv t0 = tcg_temp_new(); |
2576 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2577 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2578 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2579 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2580 | } else { |
2581 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2582 | } | |
b61f2753 AJ |
2583 | } |
2584 | ||
636aa200 | 2585 | static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2586 | { |
76db3ba4 | 2587 | if (unlikely(ctx->le_mode)) { |
fa3966a3 AJ |
2588 | TCGv t0 = tcg_temp_new(); |
2589 | tcg_gen_ext32u_tl(t0, arg1); | |
2590 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2591 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2592 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2593 | } else { |
2594 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2595 | } | |
b61f2753 AJ |
2596 | } |
2597 | ||
636aa200 | 2598 | static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2599 | { |
76db3ba4 | 2600 | if (unlikely(ctx->le_mode)) { |
a7812ae4 | 2601 | TCGv_i64 t0 = tcg_temp_new_i64(); |
66896cb8 | 2602 | tcg_gen_bswap64_i64(t0, arg1); |
76db3ba4 | 2603 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); |
a7812ae4 | 2604 | tcg_temp_free_i64(t0); |
b61f2753 | 2605 | } else |
76db3ba4 | 2606 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2607 | } |
2608 | ||
0c8aacd4 | 2609 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2610 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2611 | { \ |
76db3ba4 AJ |
2612 | TCGv EA; \ |
2613 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2614 | EA = tcg_temp_new(); \ | |
2615 | gen_addr_imm_index(ctx, EA, 0); \ | |
2616 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2617 | tcg_temp_free(EA); \ |
79aceca5 FB |
2618 | } |
2619 | ||
0c8aacd4 | 2620 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2621 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2622 | { \ |
b61f2753 | 2623 | TCGv EA; \ |
76a66253 JM |
2624 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2625 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2626 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2627 | return; \ |
9a64fbe4 | 2628 | } \ |
76db3ba4 | 2629 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2630 | EA = tcg_temp_new(); \ |
9d53c753 | 2631 | if (type == PPC_64B) \ |
76db3ba4 | 2632 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2633 | else \ |
76db3ba4 AJ |
2634 | gen_addr_imm_index(ctx, EA, 0); \ |
2635 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2636 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2637 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2638 | } |
2639 | ||
0c8aacd4 | 2640 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2641 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2642 | { \ |
b61f2753 | 2643 | TCGv EA; \ |
76a66253 JM |
2644 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2645 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2646 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2647 | return; \ |
9a64fbe4 | 2648 | } \ |
76db3ba4 | 2649 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2650 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2651 | gen_addr_reg_index(ctx, EA); \ |
2652 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2653 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2654 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2655 | } |
2656 | ||
0c8aacd4 | 2657 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2658 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2659 | { \ |
76db3ba4 AJ |
2660 | TCGv EA; \ |
2661 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2662 | EA = tcg_temp_new(); \ | |
2663 | gen_addr_reg_index(ctx, EA); \ | |
2664 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2665 | tcg_temp_free(EA); \ |
79aceca5 FB |
2666 | } |
2667 | ||
0c8aacd4 AJ |
2668 | #define GEN_LDS(name, ldop, op, type) \ |
2669 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2670 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2671 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2672 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2673 | |
2674 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2675 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2676 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2677 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2678 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2679 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2680 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2681 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
d9bce9d9 | 2682 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2683 | /* lwaux */ |
0c8aacd4 | 2684 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2685 | /* lwax */ |
0c8aacd4 | 2686 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2687 | /* ldux */ |
0c8aacd4 | 2688 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2689 | /* ldx */ |
0c8aacd4 | 2690 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B); |
99e300ef BS |
2691 | |
2692 | static void gen_ld(DisasContext *ctx) | |
d9bce9d9 | 2693 | { |
b61f2753 | 2694 | TCGv EA; |
d9bce9d9 JM |
2695 | if (Rc(ctx->opcode)) { |
2696 | if (unlikely(rA(ctx->opcode) == 0 || | |
2697 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2698 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2699 | return; |
2700 | } | |
2701 | } | |
76db3ba4 | 2702 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2703 | EA = tcg_temp_new(); |
76db3ba4 | 2704 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2705 | if (ctx->opcode & 0x02) { |
2706 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2707 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2708 | } else { |
2709 | /* ld - ldu */ | |
76db3ba4 | 2710 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2711 | } |
d9bce9d9 | 2712 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2713 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2714 | tcg_temp_free(EA); | |
d9bce9d9 | 2715 | } |
99e300ef | 2716 | |
54623277 | 2717 | /* lq */ |
99e300ef | 2718 | static void gen_lq(DisasContext *ctx) |
be147d08 JM |
2719 | { |
2720 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2721 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2722 | #else |
2723 | int ra, rd; | |
b61f2753 | 2724 | TCGv EA; |
be147d08 JM |
2725 | |
2726 | /* Restore CPU state */ | |
76db3ba4 | 2727 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2728 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2729 | return; |
2730 | } | |
2731 | ra = rA(ctx->opcode); | |
2732 | rd = rD(ctx->opcode); | |
2733 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2734 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2735 | return; |
2736 | } | |
76db3ba4 | 2737 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2738 | /* Little-endian mode is not handled */ |
e06fcd75 | 2739 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2740 | return; |
2741 | } | |
76db3ba4 | 2742 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2743 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2744 | gen_addr_imm_index(ctx, EA, 0x0F); |
2745 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2746 | gen_addr_add(ctx, EA, EA, 8); | |
2747 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
b61f2753 | 2748 | tcg_temp_free(EA); |
be147d08 JM |
2749 | #endif |
2750 | } | |
d9bce9d9 | 2751 | #endif |
79aceca5 FB |
2752 | |
2753 | /*** Integer store ***/ | |
0c8aacd4 | 2754 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2755 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2756 | { \ |
76db3ba4 AJ |
2757 | TCGv EA; \ |
2758 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2759 | EA = tcg_temp_new(); \ | |
2760 | gen_addr_imm_index(ctx, EA, 0); \ | |
2761 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2762 | tcg_temp_free(EA); \ |
79aceca5 FB |
2763 | } |
2764 | ||
0c8aacd4 | 2765 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2766 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2767 | { \ |
b61f2753 | 2768 | TCGv EA; \ |
76a66253 | 2769 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2770 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2771 | return; \ |
9a64fbe4 | 2772 | } \ |
76db3ba4 | 2773 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2774 | EA = tcg_temp_new(); \ |
9d53c753 | 2775 | if (type == PPC_64B) \ |
76db3ba4 | 2776 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2777 | else \ |
76db3ba4 AJ |
2778 | gen_addr_imm_index(ctx, EA, 0); \ |
2779 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2780 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2781 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2782 | } |
2783 | ||
0c8aacd4 | 2784 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2785 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2786 | { \ |
b61f2753 | 2787 | TCGv EA; \ |
76a66253 | 2788 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2789 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2790 | return; \ |
9a64fbe4 | 2791 | } \ |
76db3ba4 | 2792 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2793 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2794 | gen_addr_reg_index(ctx, EA); \ |
2795 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2796 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2797 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2798 | } |
2799 | ||
0c8aacd4 | 2800 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
99e300ef | 2801 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2802 | { \ |
76db3ba4 AJ |
2803 | TCGv EA; \ |
2804 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2805 | EA = tcg_temp_new(); \ | |
2806 | gen_addr_reg_index(ctx, EA); \ | |
2807 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2808 | tcg_temp_free(EA); \ |
79aceca5 FB |
2809 | } |
2810 | ||
0c8aacd4 AJ |
2811 | #define GEN_STS(name, stop, op, type) \ |
2812 | GEN_ST(name, stop, op | 0x20, type); \ | |
2813 | GEN_STU(name, stop, op | 0x21, type); \ | |
2814 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2815 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2816 | |
2817 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2818 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2819 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2820 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2821 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2822 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
d9bce9d9 | 2823 | #if defined(TARGET_PPC64) |
0c8aacd4 AJ |
2824 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B); |
2825 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B); | |
99e300ef BS |
2826 | |
2827 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 2828 | { |
be147d08 | 2829 | int rs; |
b61f2753 | 2830 | TCGv EA; |
be147d08 JM |
2831 | |
2832 | rs = rS(ctx->opcode); | |
2833 | if ((ctx->opcode & 0x3) == 0x2) { | |
2834 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2835 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2836 | #else |
2837 | /* stq */ | |
76db3ba4 | 2838 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2839 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2840 | return; |
2841 | } | |
2842 | if (unlikely(rs & 1)) { | |
e06fcd75 | 2843 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2844 | return; |
2845 | } | |
76db3ba4 | 2846 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2847 | /* Little-endian mode is not handled */ |
e06fcd75 | 2848 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2849 | return; |
2850 | } | |
76db3ba4 | 2851 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2852 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2853 | gen_addr_imm_index(ctx, EA, 0x03); |
2854 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
2855 | gen_addr_add(ctx, EA, EA, 8); | |
2856 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
b61f2753 | 2857 | tcg_temp_free(EA); |
be147d08 JM |
2858 | #endif |
2859 | } else { | |
2860 | /* std / stdu */ | |
2861 | if (Rc(ctx->opcode)) { | |
2862 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 2863 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2864 | return; |
2865 | } | |
2866 | } | |
76db3ba4 | 2867 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2868 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2869 | gen_addr_imm_index(ctx, EA, 0x03); |
2870 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
be147d08 | 2871 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2872 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2873 | tcg_temp_free(EA); | |
d9bce9d9 | 2874 | } |
d9bce9d9 JM |
2875 | } |
2876 | #endif | |
79aceca5 FB |
2877 | /*** Integer load and store with byte reverse ***/ |
2878 | /* lhbrx */ | |
86178a57 | 2879 | static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2880 | { |
76db3ba4 AJ |
2881 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
2882 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2883 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2884 | } |
b61f2753 | 2885 | } |
0c8aacd4 | 2886 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 2887 | |
79aceca5 | 2888 | /* lwbrx */ |
86178a57 | 2889 | static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2890 | { |
76db3ba4 AJ |
2891 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2892 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 2893 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2894 | } |
b61f2753 | 2895 | } |
0c8aacd4 | 2896 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 2897 | |
79aceca5 | 2898 | /* sthbrx */ |
86178a57 | 2899 | static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2900 | { |
76db3ba4 | 2901 | if (likely(!ctx->le_mode)) { |
76db3ba4 AJ |
2902 | TCGv t0 = tcg_temp_new(); |
2903 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2904 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2905 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2906 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2907 | } else { |
2908 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2909 | } | |
b61f2753 | 2910 | } |
0c8aacd4 | 2911 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
b61f2753 | 2912 | |
79aceca5 | 2913 | /* stwbrx */ |
86178a57 | 2914 | static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2915 | { |
76db3ba4 | 2916 | if (likely(!ctx->le_mode)) { |
fa3966a3 AJ |
2917 | TCGv t0 = tcg_temp_new(); |
2918 | tcg_gen_ext32u_tl(t0, arg1); | |
2919 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2920 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2921 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2922 | } else { |
2923 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2924 | } | |
b61f2753 | 2925 | } |
0c8aacd4 | 2926 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 FB |
2927 | |
2928 | /*** Integer load and store multiple ***/ | |
99e300ef | 2929 | |
54623277 | 2930 | /* lmw */ |
99e300ef | 2931 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 2932 | { |
76db3ba4 AJ |
2933 | TCGv t0; |
2934 | TCGv_i32 t1; | |
2935 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 2936 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 2937 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
2938 | t0 = tcg_temp_new(); |
2939 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
2940 | gen_addr_imm_index(ctx, t0, 0); | |
ff4a62cd AJ |
2941 | gen_helper_lmw(t0, t1); |
2942 | tcg_temp_free(t0); | |
2943 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
2944 | } |
2945 | ||
2946 | /* stmw */ | |
99e300ef | 2947 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 2948 | { |
76db3ba4 AJ |
2949 | TCGv t0; |
2950 | TCGv_i32 t1; | |
2951 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 2952 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 2953 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
2954 | t0 = tcg_temp_new(); |
2955 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
2956 | gen_addr_imm_index(ctx, t0, 0); | |
ff4a62cd AJ |
2957 | gen_helper_stmw(t0, t1); |
2958 | tcg_temp_free(t0); | |
2959 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
2960 | } |
2961 | ||
2962 | /*** Integer load and store strings ***/ | |
54623277 | 2963 | |
79aceca5 | 2964 | /* lswi */ |
3fc6c082 | 2965 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
2966 | * rA is in the range of registers to be loaded. |
2967 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
2968 | * For now, I'll follow the spec... | |
2969 | */ | |
99e300ef | 2970 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 2971 | { |
dfbc799d AJ |
2972 | TCGv t0; |
2973 | TCGv_i32 t1, t2; | |
79aceca5 FB |
2974 | int nb = NB(ctx->opcode); |
2975 | int start = rD(ctx->opcode); | |
9a64fbe4 | 2976 | int ra = rA(ctx->opcode); |
79aceca5 FB |
2977 | int nr; |
2978 | ||
2979 | if (nb == 0) | |
2980 | nb = 32; | |
2981 | nr = nb / 4; | |
76a66253 JM |
2982 | if (unlikely(((start + nr) > 32 && |
2983 | start <= ra && (start + nr - 32) > ra) || | |
2984 | ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) { | |
e06fcd75 | 2985 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 2986 | return; |
297d8e62 | 2987 | } |
76db3ba4 | 2988 | gen_set_access_type(ctx, ACCESS_INT); |
8dd4983c | 2989 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 2990 | gen_update_nip(ctx, ctx->nip - 4); |
dfbc799d | 2991 | t0 = tcg_temp_new(); |
76db3ba4 | 2992 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
2993 | t1 = tcg_const_i32(nb); |
2994 | t2 = tcg_const_i32(start); | |
2995 | gen_helper_lsw(t0, t1, t2); | |
2996 | tcg_temp_free(t0); | |
2997 | tcg_temp_free_i32(t1); | |
2998 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
2999 | } |
3000 | ||
3001 | /* lswx */ | |
99e300ef | 3002 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 3003 | { |
76db3ba4 AJ |
3004 | TCGv t0; |
3005 | TCGv_i32 t1, t2, t3; | |
3006 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3007 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3008 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3009 | t0 = tcg_temp_new(); |
3010 | gen_addr_reg_index(ctx, t0); | |
3011 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3012 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
3013 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
dfbc799d AJ |
3014 | gen_helper_lswx(t0, t1, t2, t3); |
3015 | tcg_temp_free(t0); | |
3016 | tcg_temp_free_i32(t1); | |
3017 | tcg_temp_free_i32(t2); | |
3018 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
3019 | } |
3020 | ||
3021 | /* stswi */ | |
99e300ef | 3022 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 3023 | { |
76db3ba4 AJ |
3024 | TCGv t0; |
3025 | TCGv_i32 t1, t2; | |
4b3686fa | 3026 | int nb = NB(ctx->opcode); |
76db3ba4 | 3027 | gen_set_access_type(ctx, ACCESS_INT); |
76a66253 | 3028 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3029 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3030 | t0 = tcg_temp_new(); |
3031 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
3032 | if (nb == 0) |
3033 | nb = 32; | |
dfbc799d | 3034 | t1 = tcg_const_i32(nb); |
76db3ba4 | 3035 | t2 = tcg_const_i32(rS(ctx->opcode)); |
dfbc799d AJ |
3036 | gen_helper_stsw(t0, t1, t2); |
3037 | tcg_temp_free(t0); | |
3038 | tcg_temp_free_i32(t1); | |
3039 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3040 | } |
3041 | ||
3042 | /* stswx */ | |
99e300ef | 3043 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3044 | { |
76db3ba4 AJ |
3045 | TCGv t0; |
3046 | TCGv_i32 t1, t2; | |
3047 | gen_set_access_type(ctx, ACCESS_INT); | |
8dd4983c | 3048 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5fafdf24 | 3049 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3050 | t0 = tcg_temp_new(); |
3051 | gen_addr_reg_index(ctx, t0); | |
3052 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3053 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3054 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3055 | t2 = tcg_const_i32(rS(ctx->opcode)); |
dfbc799d AJ |
3056 | gen_helper_stsw(t0, t1, t2); |
3057 | tcg_temp_free(t0); | |
3058 | tcg_temp_free_i32(t1); | |
3059 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3060 | } |
3061 | ||
3062 | /*** Memory synchronisation ***/ | |
3063 | /* eieio */ | |
99e300ef | 3064 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3065 | { |
79aceca5 FB |
3066 | } |
3067 | ||
3068 | /* isync */ | |
99e300ef | 3069 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3070 | { |
e06fcd75 | 3071 | gen_stop_exception(ctx); |
79aceca5 FB |
3072 | } |
3073 | ||
111bfab3 | 3074 | /* lwarx */ |
99e300ef | 3075 | static void gen_lwarx(DisasContext *ctx) |
79aceca5 | 3076 | { |
76db3ba4 | 3077 | TCGv t0; |
18b21a2f | 3078 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3079 | gen_set_access_type(ctx, ACCESS_RES); |
3080 | t0 = tcg_temp_local_new(); | |
3081 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3082 | gen_check_align(ctx, t0, 0x03); |
18b21a2f | 3083 | gen_qemu_ld32u(ctx, gpr, t0); |
cf360a32 | 3084 | tcg_gen_mov_tl(cpu_reserve, t0); |
18b21a2f | 3085 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val)); |
cf360a32 | 3086 | tcg_temp_free(t0); |
79aceca5 FB |
3087 | } |
3088 | ||
4425265b NF |
3089 | #if defined(CONFIG_USER_ONLY) |
3090 | static void gen_conditional_store (DisasContext *ctx, TCGv EA, | |
3091 | int reg, int size) | |
3092 | { | |
3093 | TCGv t0 = tcg_temp_new(); | |
3094 | uint32_t save_exception = ctx->exception; | |
3095 | ||
3096 | tcg_gen_st_tl(EA, cpu_env, offsetof(CPUState, reserve_ea)); | |
3097 | tcg_gen_movi_tl(t0, (size << 5) | reg); | |
3098 | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, reserve_info)); | |
3099 | tcg_temp_free(t0); | |
3100 | gen_update_nip(ctx, ctx->nip-4); | |
3101 | ctx->exception = POWERPC_EXCP_BRANCH; | |
3102 | gen_exception(ctx, POWERPC_EXCP_STCX); | |
3103 | ctx->exception = save_exception; | |
3104 | } | |
3105 | #endif | |
3106 | ||
79aceca5 | 3107 | /* stwcx. */ |
e8eaa2c0 | 3108 | static void gen_stwcx_(DisasContext *ctx) |
79aceca5 | 3109 | { |
76db3ba4 AJ |
3110 | TCGv t0; |
3111 | gen_set_access_type(ctx, ACCESS_RES); | |
3112 | t0 = tcg_temp_local_new(); | |
3113 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3114 | gen_check_align(ctx, t0, 0x03); |
4425265b NF |
3115 | #if defined(CONFIG_USER_ONLY) |
3116 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 4); | |
3117 | #else | |
3118 | { | |
3119 | int l1; | |
3120 | ||
3121 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3122 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3123 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3124 | l1 = gen_new_label(); | |
3125 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3126 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3127 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3128 | gen_set_label(l1); | |
3129 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3130 | } | |
3131 | #endif | |
cf360a32 | 3132 | tcg_temp_free(t0); |
79aceca5 FB |
3133 | } |
3134 | ||
426613db | 3135 | #if defined(TARGET_PPC64) |
426613db | 3136 | /* ldarx */ |
99e300ef | 3137 | static void gen_ldarx(DisasContext *ctx) |
426613db | 3138 | { |
76db3ba4 | 3139 | TCGv t0; |
18b21a2f | 3140 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; |
76db3ba4 AJ |
3141 | gen_set_access_type(ctx, ACCESS_RES); |
3142 | t0 = tcg_temp_local_new(); | |
3143 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3144 | gen_check_align(ctx, t0, 0x07); |
18b21a2f | 3145 | gen_qemu_ld64(ctx, gpr, t0); |
cf360a32 | 3146 | tcg_gen_mov_tl(cpu_reserve, t0); |
18b21a2f | 3147 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val)); |
cf360a32 | 3148 | tcg_temp_free(t0); |
426613db JM |
3149 | } |
3150 | ||
3151 | /* stdcx. */ | |
e8eaa2c0 | 3152 | static void gen_stdcx_(DisasContext *ctx) |
426613db | 3153 | { |
76db3ba4 AJ |
3154 | TCGv t0; |
3155 | gen_set_access_type(ctx, ACCESS_RES); | |
3156 | t0 = tcg_temp_local_new(); | |
3157 | gen_addr_reg_index(ctx, t0); | |
cf360a32 | 3158 | gen_check_align(ctx, t0, 0x07); |
4425265b NF |
3159 | #if defined(CONFIG_USER_ONLY) |
3160 | gen_conditional_store(ctx, t0, rS(ctx->opcode), 8); | |
3161 | #else | |
3162 | { | |
3163 | int l1; | |
3164 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
3165 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
3166 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
3167 | l1 = gen_new_label(); | |
3168 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3169 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3170 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0); | |
3171 | gen_set_label(l1); | |
3172 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3173 | } | |
3174 | #endif | |
cf360a32 | 3175 | tcg_temp_free(t0); |
426613db JM |
3176 | } |
3177 | #endif /* defined(TARGET_PPC64) */ | |
3178 | ||
79aceca5 | 3179 | /* sync */ |
99e300ef | 3180 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3181 | { |
79aceca5 FB |
3182 | } |
3183 | ||
0db1b20e | 3184 | /* wait */ |
99e300ef | 3185 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3186 | { |
931ff272 AJ |
3187 | TCGv_i32 t0 = tcg_temp_new_i32(); |
3188 | tcg_gen_st_i32(t0, cpu_env, offsetof(CPUState, halted)); | |
3189 | tcg_temp_free_i32(t0); | |
0db1b20e | 3190 | /* Stop translation, as the CPU is supposed to sleep from now */ |
e06fcd75 | 3191 | gen_exception_err(ctx, EXCP_HLT, 1); |
0db1b20e JM |
3192 | } |
3193 | ||
79aceca5 | 3194 | /*** Floating-point load ***/ |
a0d7d5a7 | 3195 | #define GEN_LDF(name, ldop, opc, type) \ |
99e300ef | 3196 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3197 | { \ |
a0d7d5a7 | 3198 | TCGv EA; \ |
76a66253 | 3199 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3200 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3201 | return; \ |
3202 | } \ | |
76db3ba4 | 3203 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3204 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3205 | gen_addr_imm_index(ctx, EA, 0); \ |
3206 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3207 | tcg_temp_free(EA); \ |
79aceca5 FB |
3208 | } |
3209 | ||
a0d7d5a7 | 3210 | #define GEN_LDUF(name, ldop, opc, type) \ |
99e300ef | 3211 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3212 | { \ |
a0d7d5a7 | 3213 | TCGv EA; \ |
76a66253 | 3214 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3215 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3216 | return; \ |
3217 | } \ | |
76a66253 | 3218 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3219 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3220 | return; \ |
9a64fbe4 | 3221 | } \ |
76db3ba4 | 3222 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3223 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3224 | gen_addr_imm_index(ctx, EA, 0); \ |
3225 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3226 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3227 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3228 | } |
3229 | ||
a0d7d5a7 | 3230 | #define GEN_LDUXF(name, ldop, opc, type) \ |
99e300ef | 3231 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3232 | { \ |
a0d7d5a7 | 3233 | TCGv EA; \ |
76a66253 | 3234 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3235 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3236 | return; \ |
3237 | } \ | |
76a66253 | 3238 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3239 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3240 | return; \ |
9a64fbe4 | 3241 | } \ |
76db3ba4 | 3242 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3243 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3244 | gen_addr_reg_index(ctx, EA); \ |
3245 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3246 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3247 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3248 | } |
3249 | ||
a0d7d5a7 | 3250 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ |
99e300ef | 3251 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3252 | { \ |
a0d7d5a7 | 3253 | TCGv EA; \ |
76a66253 | 3254 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3255 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3256 | return; \ |
3257 | } \ | |
76db3ba4 | 3258 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3259 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3260 | gen_addr_reg_index(ctx, EA); \ |
3261 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3262 | tcg_temp_free(EA); \ |
79aceca5 FB |
3263 | } |
3264 | ||
a0d7d5a7 AJ |
3265 | #define GEN_LDFS(name, ldop, op, type) \ |
3266 | GEN_LDF(name, ldop, op | 0x20, type); \ | |
3267 | GEN_LDUF(name, ldop, op | 0x21, type); \ | |
3268 | GEN_LDUXF(name, ldop, op | 0x01, type); \ | |
3269 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
3270 | ||
636aa200 | 3271 | static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3272 | { |
3273 | TCGv t0 = tcg_temp_new(); | |
3274 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
76db3ba4 | 3275 | gen_qemu_ld32u(ctx, t0, arg2); |
a0d7d5a7 AJ |
3276 | tcg_gen_trunc_tl_i32(t1, t0); |
3277 | tcg_temp_free(t0); | |
3278 | gen_helper_float32_to_float64(arg1, t1); | |
3279 | tcg_temp_free_i32(t1); | |
3280 | } | |
79aceca5 | 3281 | |
a0d7d5a7 AJ |
3282 | /* lfd lfdu lfdux lfdx */ |
3283 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT); | |
3284 | /* lfs lfsu lfsux lfsx */ | |
3285 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT); | |
79aceca5 FB |
3286 | |
3287 | /*** Floating-point store ***/ | |
a0d7d5a7 | 3288 | #define GEN_STF(name, stop, opc, type) \ |
99e300ef | 3289 | static void glue(gen_, name)(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 | } \ | |
76db3ba4 | 3296 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3297 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3298 | gen_addr_imm_index(ctx, EA, 0); \ |
3299 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3300 | tcg_temp_free(EA); \ |
79aceca5 FB |
3301 | } |
3302 | ||
a0d7d5a7 | 3303 | #define GEN_STUF(name, stop, opc, type) \ |
99e300ef | 3304 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3305 | { \ |
a0d7d5a7 | 3306 | TCGv EA; \ |
76a66253 | 3307 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3308 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3309 | return; \ |
3310 | } \ | |
76a66253 | 3311 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3312 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3313 | return; \ |
9a64fbe4 | 3314 | } \ |
76db3ba4 | 3315 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3316 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3317 | gen_addr_imm_index(ctx, EA, 0); \ |
3318 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3319 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3320 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3321 | } |
3322 | ||
a0d7d5a7 | 3323 | #define GEN_STUXF(name, stop, opc, type) \ |
99e300ef | 3324 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3325 | { \ |
a0d7d5a7 | 3326 | TCGv EA; \ |
76a66253 | 3327 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3328 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3329 | return; \ |
3330 | } \ | |
76a66253 | 3331 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3332 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3333 | return; \ |
9a64fbe4 | 3334 | } \ |
76db3ba4 | 3335 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3336 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3337 | gen_addr_reg_index(ctx, EA); \ |
3338 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3339 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3340 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3341 | } |
3342 | ||
a0d7d5a7 | 3343 | #define GEN_STXF(name, stop, opc2, opc3, type) \ |
99e300ef | 3344 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3345 | { \ |
a0d7d5a7 | 3346 | TCGv EA; \ |
76a66253 | 3347 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3348 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3349 | return; \ |
3350 | } \ | |
76db3ba4 | 3351 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3352 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3353 | gen_addr_reg_index(ctx, EA); \ |
3354 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3355 | tcg_temp_free(EA); \ |
79aceca5 FB |
3356 | } |
3357 | ||
a0d7d5a7 AJ |
3358 | #define GEN_STFS(name, stop, op, type) \ |
3359 | GEN_STF(name, stop, op | 0x20, type); \ | |
3360 | GEN_STUF(name, stop, op | 0x21, type); \ | |
3361 | GEN_STUXF(name, stop, op | 0x01, type); \ | |
3362 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
3363 | ||
636aa200 | 3364 | static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3365 | { |
3366 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
3367 | TCGv t1 = tcg_temp_new(); | |
3368 | gen_helper_float64_to_float32(t0, arg1); | |
3369 | tcg_gen_extu_i32_tl(t1, t0); | |
3370 | tcg_temp_free_i32(t0); | |
76db3ba4 | 3371 | gen_qemu_st32(ctx, t1, arg2); |
a0d7d5a7 AJ |
3372 | tcg_temp_free(t1); |
3373 | } | |
79aceca5 FB |
3374 | |
3375 | /* stfd stfdu stfdux stfdx */ | |
a0d7d5a7 | 3376 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT); |
79aceca5 | 3377 | /* stfs stfsu stfsux stfsx */ |
a0d7d5a7 | 3378 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT); |
79aceca5 FB |
3379 | |
3380 | /* Optional: */ | |
636aa200 | 3381 | static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3382 | { |
3383 | TCGv t0 = tcg_temp_new(); | |
3384 | tcg_gen_trunc_i64_tl(t0, arg1), | |
76db3ba4 | 3385 | gen_qemu_st32(ctx, t0, arg2); |
a0d7d5a7 AJ |
3386 | tcg_temp_free(t0); |
3387 | } | |
79aceca5 | 3388 | /* stfiwx */ |
a0d7d5a7 | 3389 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
79aceca5 | 3390 | |
697ab892 DG |
3391 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3392 | { | |
3393 | #if defined(TARGET_PPC64) | |
3394 | if (ctx->has_cfar) | |
3395 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3396 | #endif | |
3397 | } | |
3398 | ||
79aceca5 | 3399 | /*** Branch ***/ |
636aa200 | 3400 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 FB |
3401 | { |
3402 | TranslationBlock *tb; | |
3403 | tb = ctx->tb; | |
a2ffb812 AJ |
3404 | #if defined(TARGET_PPC64) |
3405 | if (!ctx->sf_mode) | |
3406 | dest = (uint32_t) dest; | |
3407 | #endif | |
57fec1fe | 3408 | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && |
8cbcb4fa | 3409 | likely(!ctx->singlestep_enabled)) { |
57fec1fe | 3410 | tcg_gen_goto_tb(n); |
a2ffb812 | 3411 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
4b4a72e5 | 3412 | tcg_gen_exit_tb((tcg_target_long)tb + n); |
c1942362 | 3413 | } else { |
a2ffb812 | 3414 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cbcb4fa AJ |
3415 | if (unlikely(ctx->singlestep_enabled)) { |
3416 | if ((ctx->singlestep_enabled & | |
bdc4e053 | 3417 | (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) && |
8cbcb4fa AJ |
3418 | ctx->exception == POWERPC_EXCP_BRANCH) { |
3419 | target_ulong tmp = ctx->nip; | |
3420 | ctx->nip = dest; | |
e06fcd75 | 3421 | gen_exception(ctx, POWERPC_EXCP_TRACE); |
8cbcb4fa AJ |
3422 | ctx->nip = tmp; |
3423 | } | |
3424 | if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) { | |
e06fcd75 | 3425 | gen_debug_exception(ctx); |
8cbcb4fa AJ |
3426 | } |
3427 | } | |
57fec1fe | 3428 | tcg_gen_exit_tb(0); |
c1942362 | 3429 | } |
c53be334 FB |
3430 | } |
3431 | ||
636aa200 | 3432 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f JM |
3433 | { |
3434 | #if defined(TARGET_PPC64) | |
a2ffb812 AJ |
3435 | if (ctx->sf_mode == 0) |
3436 | tcg_gen_movi_tl(cpu_lr, (uint32_t)nip); | |
e1833e1f JM |
3437 | else |
3438 | #endif | |
a2ffb812 | 3439 | tcg_gen_movi_tl(cpu_lr, nip); |
e1833e1f JM |
3440 | } |
3441 | ||
79aceca5 | 3442 | /* b ba bl bla */ |
99e300ef | 3443 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3444 | { |
76a66253 | 3445 | target_ulong li, target; |
38a64f9d | 3446 | |
8cbcb4fa | 3447 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3448 | /* sign extend LI */ |
76a66253 | 3449 | #if defined(TARGET_PPC64) |
d9bce9d9 JM |
3450 | if (ctx->sf_mode) |
3451 | li = ((int64_t)LI(ctx->opcode) << 38) >> 38; | |
3452 | else | |
76a66253 | 3453 | #endif |
d9bce9d9 | 3454 | li = ((int32_t)LI(ctx->opcode) << 6) >> 6; |
76a66253 | 3455 | if (likely(AA(ctx->opcode) == 0)) |
046d6672 | 3456 | target = ctx->nip + li - 4; |
79aceca5 | 3457 | else |
9a64fbe4 | 3458 | target = li; |
e1833e1f JM |
3459 | if (LK(ctx->opcode)) |
3460 | gen_setlr(ctx, ctx->nip); | |
697ab892 | 3461 | gen_update_cfar(ctx, ctx->nip); |
c1942362 | 3462 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3463 | } |
3464 | ||
e98a6e40 FB |
3465 | #define BCOND_IM 0 |
3466 | #define BCOND_LR 1 | |
3467 | #define BCOND_CTR 2 | |
3468 | ||
636aa200 | 3469 | static inline void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3470 | { |
d9bce9d9 | 3471 | uint32_t bo = BO(ctx->opcode); |
05f92404 | 3472 | int l1; |
a2ffb812 | 3473 | TCGv target; |
e98a6e40 | 3474 | |
8cbcb4fa | 3475 | ctx->exception = POWERPC_EXCP_BRANCH; |
a2ffb812 | 3476 | if (type == BCOND_LR || type == BCOND_CTR) { |
a7812ae4 | 3477 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3478 | if (type == BCOND_CTR) |
3479 | tcg_gen_mov_tl(target, cpu_ctr); | |
3480 | else | |
3481 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3482 | } else { |
3483 | TCGV_UNUSED(target); | |
e98a6e40 | 3484 | } |
e1833e1f JM |
3485 | if (LK(ctx->opcode)) |
3486 | gen_setlr(ctx, ctx->nip); | |
a2ffb812 AJ |
3487 | l1 = gen_new_label(); |
3488 | if ((bo & 0x4) == 0) { | |
3489 | /* Decrement and test CTR */ | |
a7812ae4 | 3490 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3491 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3492 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3493 | return; |
3494 | } | |
3495 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
d9bce9d9 | 3496 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3497 | if (!ctx->sf_mode) |
3498 | tcg_gen_ext32u_tl(temp, cpu_ctr); | |
3499 | else | |
d9bce9d9 | 3500 | #endif |
a2ffb812 AJ |
3501 | tcg_gen_mov_tl(temp, cpu_ctr); |
3502 | if (bo & 0x2) { | |
3503 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3504 | } else { | |
3505 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3506 | } |
a7812ae4 | 3507 | tcg_temp_free(temp); |
a2ffb812 AJ |
3508 | } |
3509 | if ((bo & 0x10) == 0) { | |
3510 | /* Test CR */ | |
3511 | uint32_t bi = BI(ctx->opcode); | |
3512 | uint32_t mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 3513 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3514 | |
d9bce9d9 | 3515 | if (bo & 0x8) { |
a2ffb812 AJ |
3516 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3517 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3518 | } else { |
a2ffb812 AJ |
3519 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3520 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3521 | } |
a7812ae4 | 3522 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3523 | } |
697ab892 | 3524 | gen_update_cfar(ctx, ctx->nip); |
e98a6e40 | 3525 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3526 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3527 | if (likely(AA(ctx->opcode) == 0)) { | |
3528 | gen_goto_tb(ctx, 0, ctx->nip + li - 4); | |
3529 | } else { | |
3530 | gen_goto_tb(ctx, 0, li); | |
3531 | } | |
c53be334 | 3532 | gen_set_label(l1); |
c1942362 | 3533 | gen_goto_tb(ctx, 1, ctx->nip); |
e98a6e40 | 3534 | } else { |
d9bce9d9 | 3535 | #if defined(TARGET_PPC64) |
a2ffb812 AJ |
3536 | if (!(ctx->sf_mode)) |
3537 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); | |
3538 | else | |
3539 | #endif | |
3540 | tcg_gen_andi_tl(cpu_nip, target, ~3); | |
3541 | tcg_gen_exit_tb(0); | |
3542 | gen_set_label(l1); | |
3543 | #if defined(TARGET_PPC64) | |
3544 | if (!(ctx->sf_mode)) | |
3545 | tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip); | |
d9bce9d9 JM |
3546 | else |
3547 | #endif | |
a2ffb812 | 3548 | tcg_gen_movi_tl(cpu_nip, ctx->nip); |
57fec1fe | 3549 | tcg_gen_exit_tb(0); |
08e46e54 | 3550 | } |
e98a6e40 FB |
3551 | } |
3552 | ||
99e300ef | 3553 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3554 | { |
e98a6e40 FB |
3555 | gen_bcond(ctx, BCOND_IM); |
3556 | } | |
3557 | ||
99e300ef | 3558 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3559 | { |
e98a6e40 FB |
3560 | gen_bcond(ctx, BCOND_CTR); |
3561 | } | |
3562 | ||
99e300ef | 3563 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3564 | { |
e98a6e40 FB |
3565 | gen_bcond(ctx, BCOND_LR); |
3566 | } | |
79aceca5 FB |
3567 | |
3568 | /*** Condition register logical ***/ | |
e1571908 | 3569 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3570 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3571 | { \ |
fc0d441e JM |
3572 | uint8_t bitmask; \ |
3573 | int sh; \ | |
a7812ae4 | 3574 | TCGv_i32 t0, t1; \ |
fc0d441e | 3575 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3576 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3577 | if (sh > 0) \ |
fea0c503 | 3578 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3579 | else if (sh < 0) \ |
fea0c503 | 3580 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3581 | else \ |
fea0c503 | 3582 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3583 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3584 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3585 | if (sh > 0) \ | |
fea0c503 | 3586 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3587 | else if (sh < 0) \ |
fea0c503 | 3588 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3589 | else \ |
fea0c503 AJ |
3590 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3591 | tcg_op(t0, t0, t1); \ | |
fc0d441e | 3592 | bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \ |
fea0c503 AJ |
3593 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3594 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3595 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3596 | tcg_temp_free_i32(t0); \ |
3597 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3598 | } |
3599 | ||
3600 | /* crand */ | |
e1571908 | 3601 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3602 | /* crandc */ |
e1571908 | 3603 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3604 | /* creqv */ |
e1571908 | 3605 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3606 | /* crnand */ |
e1571908 | 3607 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3608 | /* crnor */ |
e1571908 | 3609 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3610 | /* cror */ |
e1571908 | 3611 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3612 | /* crorc */ |
e1571908 | 3613 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3614 | /* crxor */ |
e1571908 | 3615 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3616 | |
54623277 | 3617 | /* mcrf */ |
99e300ef | 3618 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3619 | { |
47e4661c | 3620 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3621 | } |
3622 | ||
3623 | /*** System linkage ***/ | |
99e300ef | 3624 | |
54623277 | 3625 | /* rfi (mem_idx only) */ |
99e300ef | 3626 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 3627 | { |
9a64fbe4 | 3628 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3629 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 FB |
3630 | #else |
3631 | /* Restore CPU state */ | |
76db3ba4 | 3632 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3633 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 3634 | return; |
9a64fbe4 | 3635 | } |
697ab892 | 3636 | gen_update_cfar(ctx, ctx->nip); |
d72a19f7 | 3637 | gen_helper_rfi(); |
e06fcd75 | 3638 | gen_sync_exception(ctx); |
9a64fbe4 | 3639 | #endif |
79aceca5 FB |
3640 | } |
3641 | ||
426613db | 3642 | #if defined(TARGET_PPC64) |
99e300ef | 3643 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
3644 | { |
3645 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3646 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3647 | #else |
3648 | /* Restore CPU state */ | |
76db3ba4 | 3649 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3650 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3651 | return; |
3652 | } | |
697ab892 | 3653 | gen_update_cfar(ctx, ctx->nip); |
d72a19f7 | 3654 | gen_helper_rfid(); |
e06fcd75 | 3655 | gen_sync_exception(ctx); |
426613db JM |
3656 | #endif |
3657 | } | |
426613db | 3658 | |
99e300ef | 3659 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
3660 | { |
3661 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3662 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3663 | #else |
3664 | /* Restore CPU state */ | |
76db3ba4 | 3665 | if (unlikely(ctx->mem_idx <= 1)) { |
e06fcd75 | 3666 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3667 | return; |
3668 | } | |
d72a19f7 | 3669 | gen_helper_hrfid(); |
e06fcd75 | 3670 | gen_sync_exception(ctx); |
be147d08 JM |
3671 | #endif |
3672 | } | |
3673 | #endif | |
3674 | ||
79aceca5 | 3675 | /* sc */ |
417bf010 JM |
3676 | #if defined(CONFIG_USER_ONLY) |
3677 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
3678 | #else | |
3679 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
3680 | #endif | |
99e300ef | 3681 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 3682 | { |
e1833e1f JM |
3683 | uint32_t lev; |
3684 | ||
3685 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 3686 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
3687 | } |
3688 | ||
3689 | /*** Trap ***/ | |
99e300ef | 3690 | |
54623277 | 3691 | /* tw */ |
99e300ef | 3692 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 3693 | { |
cab3bee2 | 3694 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3695 | /* Update the nip since this might generate a trap exception */ |
3696 | gen_update_nip(ctx, ctx->nip); | |
cab3bee2 AJ |
3697 | gen_helper_tw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); |
3698 | tcg_temp_free_i32(t0); | |
79aceca5 FB |
3699 | } |
3700 | ||
3701 | /* twi */ | |
99e300ef | 3702 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 3703 | { |
cab3bee2 AJ |
3704 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3705 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3706 | /* Update the nip since this might generate a trap exception */ |
3707 | gen_update_nip(ctx, ctx->nip); | |
cab3bee2 AJ |
3708 | gen_helper_tw(cpu_gpr[rA(ctx->opcode)], t0, t1); |
3709 | tcg_temp_free(t0); | |
3710 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3711 | } |
3712 | ||
d9bce9d9 JM |
3713 | #if defined(TARGET_PPC64) |
3714 | /* td */ | |
99e300ef | 3715 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 3716 | { |
cab3bee2 | 3717 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3718 | /* Update the nip since this might generate a trap exception */ |
3719 | gen_update_nip(ctx, ctx->nip); | |
cab3bee2 AJ |
3720 | gen_helper_td(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); |
3721 | tcg_temp_free_i32(t0); | |
d9bce9d9 JM |
3722 | } |
3723 | ||
3724 | /* tdi */ | |
99e300ef | 3725 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 3726 | { |
cab3bee2 AJ |
3727 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3728 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3729 | /* Update the nip since this might generate a trap exception */ |
3730 | gen_update_nip(ctx, ctx->nip); | |
cab3bee2 AJ |
3731 | gen_helper_td(cpu_gpr[rA(ctx->opcode)], t0, t1); |
3732 | tcg_temp_free(t0); | |
3733 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
3734 | } |
3735 | #endif | |
3736 | ||
79aceca5 | 3737 | /*** Processor control ***/ |
99e300ef | 3738 | |
54623277 | 3739 | /* mcrxr */ |
99e300ef | 3740 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 3741 | { |
3d7b417e AJ |
3742 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer); |
3743 | tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA); | |
269f3e95 | 3744 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA)); |
79aceca5 FB |
3745 | } |
3746 | ||
0cfe11ea | 3747 | /* mfcr mfocrf */ |
99e300ef | 3748 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 3749 | { |
76a66253 | 3750 | uint32_t crm, crn; |
3b46e624 | 3751 | |
76a66253 JM |
3752 | if (likely(ctx->opcode & 0x00100000)) { |
3753 | crm = CRM(ctx->opcode); | |
8dd640e4 | 3754 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 3755 | crn = ctz32 (crm); |
e1571908 | 3756 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
3757 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
3758 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 3759 | } |
d9bce9d9 | 3760 | } else { |
651721b2 AJ |
3761 | TCGv_i32 t0 = tcg_temp_new_i32(); |
3762 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
3763 | tcg_gen_shli_i32(t0, t0, 4); | |
3764 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
3765 | tcg_gen_shli_i32(t0, t0, 4); | |
3766 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
3767 | tcg_gen_shli_i32(t0, t0, 4); | |
3768 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
3769 | tcg_gen_shli_i32(t0, t0, 4); | |
3770 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
3771 | tcg_gen_shli_i32(t0, t0, 4); | |
3772 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
3773 | tcg_gen_shli_i32(t0, t0, 4); | |
3774 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
3775 | tcg_gen_shli_i32(t0, t0, 4); | |
3776 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
3777 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
3778 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 3779 | } |
79aceca5 FB |
3780 | } |
3781 | ||
3782 | /* mfmsr */ | |
99e300ef | 3783 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 3784 | { |
9a64fbe4 | 3785 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3786 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3787 | #else |
76db3ba4 | 3788 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3789 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3790 | return; |
9a64fbe4 | 3791 | } |
6527f6ea | 3792 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
9a64fbe4 | 3793 | #endif |
79aceca5 FB |
3794 | } |
3795 | ||
7b13448f | 3796 | static void spr_noaccess(void *opaque, int gprn, int sprn) |
3fc6c082 | 3797 | { |
7b13448f | 3798 | #if 0 |
3fc6c082 FB |
3799 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
3800 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 3801 | #endif |
3fc6c082 FB |
3802 | } |
3803 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 3804 | |
79aceca5 | 3805 | /* mfspr */ |
636aa200 | 3806 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 3807 | { |
45d827d2 | 3808 | void (*read_cb)(void *opaque, int gprn, int sprn); |
79aceca5 FB |
3809 | uint32_t sprn = SPR(ctx->opcode); |
3810 | ||
3fc6c082 | 3811 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 3812 | if (ctx->mem_idx == 2) |
be147d08 | 3813 | read_cb = ctx->spr_cb[sprn].hea_read; |
76db3ba4 | 3814 | else if (ctx->mem_idx) |
3fc6c082 FB |
3815 | read_cb = ctx->spr_cb[sprn].oea_read; |
3816 | else | |
9a64fbe4 | 3817 | #endif |
3fc6c082 | 3818 | read_cb = ctx->spr_cb[sprn].uea_read; |
76a66253 JM |
3819 | if (likely(read_cb != NULL)) { |
3820 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 3821 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
3822 | } else { |
3823 | /* Privilege exception */ | |
9fceefa7 JM |
3824 | /* This is a hack to avoid warnings when running Linux: |
3825 | * this OS breaks the PowerPC virtualisation model, | |
3826 | * allowing userland application to read the PVR | |
3827 | */ | |
3828 | if (sprn != SPR_PVR) { | |
93fcfe39 | 3829 | qemu_log("Trying to read privileged spr %d %03x at " |
90e189ec BS |
3830 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3831 | printf("Trying to read privileged spr %d %03x at " | |
3832 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); | |
f24e5695 | 3833 | } |
e06fcd75 | 3834 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 3835 | } |
3fc6c082 FB |
3836 | } else { |
3837 | /* Not defined */ | |
93fcfe39 | 3838 | qemu_log("Trying to read invalid spr %d %03x at " |
90e189ec BS |
3839 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3840 | printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 3841 | sprn, sprn, ctx->nip); |
e06fcd75 | 3842 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 3843 | } |
79aceca5 FB |
3844 | } |
3845 | ||
99e300ef | 3846 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 3847 | { |
3fc6c082 | 3848 | gen_op_mfspr(ctx); |
76a66253 | 3849 | } |
3fc6c082 FB |
3850 | |
3851 | /* mftb */ | |
99e300ef | 3852 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
3853 | { |
3854 | gen_op_mfspr(ctx); | |
79aceca5 FB |
3855 | } |
3856 | ||
0cfe11ea | 3857 | /* mtcrf mtocrf*/ |
99e300ef | 3858 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 3859 | { |
76a66253 | 3860 | uint32_t crm, crn; |
3b46e624 | 3861 | |
76a66253 | 3862 | crm = CRM(ctx->opcode); |
8dd640e4 | 3863 | if (likely((ctx->opcode & 0x00100000))) { |
3864 | if (crm && ((crm & (crm - 1)) == 0)) { | |
3865 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 3866 | crn = ctz32 (crm); |
8dd640e4 | 3867 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
3868 | tcg_gen_shri_i32(temp, temp, crn * 4); |
3869 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 3870 | tcg_temp_free_i32(temp); |
3871 | } | |
76a66253 | 3872 | } else { |
651721b2 AJ |
3873 | TCGv_i32 temp = tcg_temp_new_i32(); |
3874 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
3875 | for (crn = 0 ; crn < 8 ; crn++) { | |
3876 | if (crm & (1 << crn)) { | |
3877 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
3878 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
3879 | } | |
3880 | } | |
a7812ae4 | 3881 | tcg_temp_free_i32(temp); |
76a66253 | 3882 | } |
79aceca5 FB |
3883 | } |
3884 | ||
3885 | /* mtmsr */ | |
426613db | 3886 | #if defined(TARGET_PPC64) |
99e300ef | 3887 | static void gen_mtmsrd(DisasContext *ctx) |
426613db JM |
3888 | { |
3889 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3890 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db | 3891 | #else |
76db3ba4 | 3892 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3893 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db JM |
3894 | return; |
3895 | } | |
be147d08 JM |
3896 | if (ctx->opcode & 0x00010000) { |
3897 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3898 | TCGv t0 = tcg_temp_new(); |
3899 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3900 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3901 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3902 | tcg_temp_free(t0); | |
be147d08 | 3903 | } else { |
056b05f8 JM |
3904 | /* XXX: we need to update nip before the store |
3905 | * if we enter power saving mode, we will exit the loop | |
3906 | * directly from ppc_store_msr | |
3907 | */ | |
be147d08 | 3908 | gen_update_nip(ctx, ctx->nip); |
6527f6ea | 3909 | gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
3910 | /* Must stop the translation as machine state (may have) changed */ |
3911 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 3912 | gen_stop_exception(ctx); |
be147d08 | 3913 | } |
426613db JM |
3914 | #endif |
3915 | } | |
3916 | #endif | |
3917 | ||
99e300ef | 3918 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 3919 | { |
9a64fbe4 | 3920 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3921 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 3922 | #else |
76db3ba4 | 3923 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3924 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 3925 | return; |
9a64fbe4 | 3926 | } |
be147d08 JM |
3927 | if (ctx->opcode & 0x00010000) { |
3928 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
3929 | TCGv t0 = tcg_temp_new(); |
3930 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
3931 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
3932 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
3933 | tcg_temp_free(t0); | |
be147d08 | 3934 | } else { |
8018dc63 AG |
3935 | TCGv msr = tcg_temp_new(); |
3936 | ||
056b05f8 JM |
3937 | /* XXX: we need to update nip before the store |
3938 | * if we enter power saving mode, we will exit the loop | |
3939 | * directly from ppc_store_msr | |
3940 | */ | |
be147d08 | 3941 | gen_update_nip(ctx, ctx->nip); |
d9bce9d9 | 3942 | #if defined(TARGET_PPC64) |
8018dc63 AG |
3943 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
3944 | #else | |
3945 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 3946 | #endif |
8018dc63 | 3947 | gen_helper_store_msr(msr); |
be147d08 | 3948 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 3949 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 3950 | gen_stop_exception(ctx); |
be147d08 | 3951 | } |
9a64fbe4 | 3952 | #endif |
79aceca5 FB |
3953 | } |
3954 | ||
3955 | /* mtspr */ | |
99e300ef | 3956 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 3957 | { |
45d827d2 | 3958 | void (*write_cb)(void *opaque, int sprn, int gprn); |
79aceca5 FB |
3959 | uint32_t sprn = SPR(ctx->opcode); |
3960 | ||
3fc6c082 | 3961 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 3962 | if (ctx->mem_idx == 2) |
be147d08 | 3963 | write_cb = ctx->spr_cb[sprn].hea_write; |
76db3ba4 | 3964 | else if (ctx->mem_idx) |
3fc6c082 FB |
3965 | write_cb = ctx->spr_cb[sprn].oea_write; |
3966 | else | |
9a64fbe4 | 3967 | #endif |
3fc6c082 | 3968 | write_cb = ctx->spr_cb[sprn].uea_write; |
76a66253 JM |
3969 | if (likely(write_cb != NULL)) { |
3970 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 3971 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
3972 | } else { |
3973 | /* Privilege exception */ | |
93fcfe39 | 3974 | qemu_log("Trying to write privileged spr %d %03x at " |
90e189ec BS |
3975 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3976 | printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx | |
3977 | "\n", sprn, sprn, ctx->nip); | |
e06fcd75 | 3978 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 3979 | } |
3fc6c082 FB |
3980 | } else { |
3981 | /* Not defined */ | |
93fcfe39 | 3982 | qemu_log("Trying to write invalid spr %d %03x at " |
90e189ec BS |
3983 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip); |
3984 | printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n", | |
077fc206 | 3985 | sprn, sprn, ctx->nip); |
e06fcd75 | 3986 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 3987 | } |
79aceca5 FB |
3988 | } |
3989 | ||
3990 | /*** Cache management ***/ | |
99e300ef | 3991 | |
54623277 | 3992 | /* dcbf */ |
99e300ef | 3993 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 3994 | { |
dac454af | 3995 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
3996 | TCGv t0; |
3997 | gen_set_access_type(ctx, ACCESS_CACHE); | |
3998 | t0 = tcg_temp_new(); | |
3999 | gen_addr_reg_index(ctx, t0); | |
4000 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4001 | tcg_temp_free(t0); |
79aceca5 FB |
4002 | } |
4003 | ||
4004 | /* dcbi (Supervisor only) */ | |
99e300ef | 4005 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4006 | { |
a541f297 | 4007 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4008 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a541f297 | 4009 | #else |
b61f2753 | 4010 | TCGv EA, val; |
76db3ba4 | 4011 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4012 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4013 | return; |
9a64fbe4 | 4014 | } |
a7812ae4 | 4015 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4016 | gen_set_access_type(ctx, ACCESS_CACHE); |
4017 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4018 | val = tcg_temp_new(); |
76a66253 | 4019 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4020 | gen_qemu_ld8u(ctx, val, EA); |
4021 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4022 | tcg_temp_free(val); |
4023 | tcg_temp_free(EA); | |
a541f297 | 4024 | #endif |
79aceca5 FB |
4025 | } |
4026 | ||
4027 | /* dcdst */ | |
99e300ef | 4028 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4029 | { |
76a66253 | 4030 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4031 | TCGv t0; |
4032 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4033 | t0 = tcg_temp_new(); | |
4034 | gen_addr_reg_index(ctx, t0); | |
4035 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4036 | tcg_temp_free(t0); |
79aceca5 FB |
4037 | } |
4038 | ||
4039 | /* dcbt */ | |
99e300ef | 4040 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4041 | { |
0db1b20e | 4042 | /* interpreted as no-op */ |
76a66253 JM |
4043 | /* XXX: specification say this is treated as a load by the MMU |
4044 | * but does not generate any exception | |
4045 | */ | |
79aceca5 FB |
4046 | } |
4047 | ||
4048 | /* dcbtst */ | |
99e300ef | 4049 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4050 | { |
0db1b20e | 4051 | /* interpreted as no-op */ |
76a66253 JM |
4052 | /* XXX: specification say this is treated as a load by the MMU |
4053 | * but does not generate any exception | |
4054 | */ | |
79aceca5 FB |
4055 | } |
4056 | ||
4057 | /* dcbz */ | |
99e300ef | 4058 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4059 | { |
76db3ba4 AJ |
4060 | TCGv t0; |
4061 | gen_set_access_type(ctx, ACCESS_CACHE); | |
799a8c8d AJ |
4062 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4063 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4064 | t0 = tcg_temp_new(); |
4065 | gen_addr_reg_index(ctx, t0); | |
799a8c8d AJ |
4066 | gen_helper_dcbz(t0); |
4067 | tcg_temp_free(t0); | |
d63001d1 JM |
4068 | } |
4069 | ||
e8eaa2c0 | 4070 | static void gen_dcbz_970(DisasContext *ctx) |
d63001d1 | 4071 | { |
76db3ba4 AJ |
4072 | TCGv t0; |
4073 | gen_set_access_type(ctx, ACCESS_CACHE); | |
799a8c8d AJ |
4074 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4075 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4076 | t0 = tcg_temp_new(); |
4077 | gen_addr_reg_index(ctx, t0); | |
d63001d1 | 4078 | if (ctx->opcode & 0x00200000) |
799a8c8d | 4079 | gen_helper_dcbz(t0); |
d63001d1 | 4080 | else |
799a8c8d AJ |
4081 | gen_helper_dcbz_970(t0); |
4082 | tcg_temp_free(t0); | |
79aceca5 FB |
4083 | } |
4084 | ||
ae1c1a3d | 4085 | /* dst / dstt */ |
99e300ef | 4086 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4087 | { |
4088 | if (rA(ctx->opcode) == 0) { | |
4089 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4090 | } else { | |
4091 | /* interpreted as no-op */ | |
4092 | } | |
4093 | } | |
4094 | ||
4095 | /* dstst /dststt */ | |
99e300ef | 4096 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4097 | { |
4098 | if (rA(ctx->opcode) == 0) { | |
4099 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4100 | } else { | |
4101 | /* interpreted as no-op */ | |
4102 | } | |
4103 | ||
4104 | } | |
4105 | ||
4106 | /* dss / dssall */ | |
99e300ef | 4107 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4108 | { |
4109 | /* interpreted as no-op */ | |
4110 | } | |
4111 | ||
79aceca5 | 4112 | /* icbi */ |
99e300ef | 4113 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4114 | { |
76db3ba4 AJ |
4115 | TCGv t0; |
4116 | gen_set_access_type(ctx, ACCESS_CACHE); | |
30032c94 JM |
4117 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4118 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4119 | t0 = tcg_temp_new(); |
4120 | gen_addr_reg_index(ctx, t0); | |
37d269df AJ |
4121 | gen_helper_icbi(t0); |
4122 | tcg_temp_free(t0); | |
79aceca5 FB |
4123 | } |
4124 | ||
4125 | /* Optional: */ | |
4126 | /* dcba */ | |
99e300ef | 4127 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4128 | { |
0db1b20e JM |
4129 | /* interpreted as no-op */ |
4130 | /* XXX: specification say this is treated as a store by the MMU | |
4131 | * but does not generate any exception | |
4132 | */ | |
79aceca5 FB |
4133 | } |
4134 | ||
4135 | /*** Segment register manipulation ***/ | |
4136 | /* Supervisor only: */ | |
99e300ef | 4137 | |
54623277 | 4138 | /* mfsr */ |
99e300ef | 4139 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4140 | { |
9a64fbe4 | 4141 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4142 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4143 | #else |
74d37793 | 4144 | TCGv t0; |
76db3ba4 | 4145 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4146 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4147 | return; |
9a64fbe4 | 4148 | } |
74d37793 AJ |
4149 | t0 = tcg_const_tl(SR(ctx->opcode)); |
4150 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0); | |
4151 | tcg_temp_free(t0); | |
9a64fbe4 | 4152 | #endif |
79aceca5 FB |
4153 | } |
4154 | ||
4155 | /* mfsrin */ | |
99e300ef | 4156 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4157 | { |
9a64fbe4 | 4158 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4159 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4160 | #else |
74d37793 | 4161 | TCGv t0; |
76db3ba4 | 4162 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4163 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4164 | return; |
9a64fbe4 | 4165 | } |
74d37793 AJ |
4166 | t0 = tcg_temp_new(); |
4167 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4168 | tcg_gen_andi_tl(t0, t0, 0xF); | |
4169 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0); | |
4170 | tcg_temp_free(t0); | |
9a64fbe4 | 4171 | #endif |
79aceca5 FB |
4172 | } |
4173 | ||
4174 | /* mtsr */ | |
99e300ef | 4175 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4176 | { |
9a64fbe4 | 4177 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4178 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4179 | #else |
74d37793 | 4180 | TCGv t0; |
76db3ba4 | 4181 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4182 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4183 | return; |
9a64fbe4 | 4184 | } |
74d37793 AJ |
4185 | t0 = tcg_const_tl(SR(ctx->opcode)); |
4186 | gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]); | |
4187 | tcg_temp_free(t0); | |
9a64fbe4 | 4188 | #endif |
79aceca5 FB |
4189 | } |
4190 | ||
4191 | /* mtsrin */ | |
99e300ef | 4192 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4193 | { |
9a64fbe4 | 4194 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4195 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4196 | #else |
74d37793 | 4197 | TCGv t0; |
76db3ba4 | 4198 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4199 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4200 | return; |
9a64fbe4 | 4201 | } |
74d37793 AJ |
4202 | t0 = tcg_temp_new(); |
4203 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4204 | tcg_gen_andi_tl(t0, t0, 0xF); | |
4205 | gen_helper_store_sr(t0, cpu_gpr[rD(ctx->opcode)]); | |
4206 | tcg_temp_free(t0); | |
9a64fbe4 | 4207 | #endif |
79aceca5 FB |
4208 | } |
4209 | ||
12de9a39 JM |
4210 | #if defined(TARGET_PPC64) |
4211 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4212 | |
54623277 | 4213 | /* mfsr */ |
e8eaa2c0 | 4214 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4215 | { |
4216 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4217 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4218 | #else |
74d37793 | 4219 | TCGv t0; |
76db3ba4 | 4220 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4221 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4222 | return; |
4223 | } | |
74d37793 | 4224 | t0 = tcg_const_tl(SR(ctx->opcode)); |
f6b868fc | 4225 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0); |
74d37793 | 4226 | tcg_temp_free(t0); |
12de9a39 JM |
4227 | #endif |
4228 | } | |
4229 | ||
4230 | /* mfsrin */ | |
e8eaa2c0 | 4231 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4232 | { |
4233 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4234 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4235 | #else |
74d37793 | 4236 | TCGv t0; |
76db3ba4 | 4237 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4238 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4239 | return; |
4240 | } | |
74d37793 AJ |
4241 | t0 = tcg_temp_new(); |
4242 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4243 | tcg_gen_andi_tl(t0, t0, 0xF); | |
f6b868fc | 4244 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0); |
74d37793 | 4245 | tcg_temp_free(t0); |
12de9a39 JM |
4246 | #endif |
4247 | } | |
4248 | ||
4249 | /* mtsr */ | |
e8eaa2c0 | 4250 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4251 | { |
4252 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4253 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4254 | #else |
74d37793 | 4255 | TCGv t0; |
76db3ba4 | 4256 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4257 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4258 | return; |
4259 | } | |
74d37793 | 4260 | t0 = tcg_const_tl(SR(ctx->opcode)); |
f6b868fc | 4261 | gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4262 | tcg_temp_free(t0); |
12de9a39 JM |
4263 | #endif |
4264 | } | |
4265 | ||
4266 | /* mtsrin */ | |
e8eaa2c0 | 4267 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4268 | { |
4269 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4270 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4271 | #else |
74d37793 | 4272 | TCGv t0; |
76db3ba4 | 4273 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4274 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4275 | return; |
4276 | } | |
74d37793 AJ |
4277 | t0 = tcg_temp_new(); |
4278 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4279 | tcg_gen_andi_tl(t0, t0, 0xF); | |
f6b868fc | 4280 | gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4281 | tcg_temp_free(t0); |
12de9a39 JM |
4282 | #endif |
4283 | } | |
f6b868fc BS |
4284 | |
4285 | /* slbmte */ | |
e8eaa2c0 | 4286 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
4287 | { |
4288 | #if defined(CONFIG_USER_ONLY) | |
4289 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4290 | #else | |
4291 | if (unlikely(!ctx->mem_idx)) { | |
4292 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4293 | return; | |
4294 | } | |
4295 | gen_helper_store_slb(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
4296 | #endif | |
4297 | } | |
4298 | ||
efdef95f DG |
4299 | static void gen_slbmfee(DisasContext *ctx) |
4300 | { | |
4301 | #if defined(CONFIG_USER_ONLY) | |
4302 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4303 | #else | |
4304 | if (unlikely(!ctx->mem_idx)) { | |
4305 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4306 | return; | |
4307 | } | |
4308 | gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], | |
4309 | cpu_gpr[rB(ctx->opcode)]); | |
4310 | #endif | |
4311 | } | |
4312 | ||
4313 | static void gen_slbmfev(DisasContext *ctx) | |
4314 | { | |
4315 | #if defined(CONFIG_USER_ONLY) | |
4316 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4317 | #else | |
4318 | if (unlikely(!ctx->mem_idx)) { | |
4319 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4320 | return; | |
4321 | } | |
4322 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], | |
4323 | cpu_gpr[rB(ctx->opcode)]); | |
4324 | #endif | |
4325 | } | |
12de9a39 JM |
4326 | #endif /* defined(TARGET_PPC64) */ |
4327 | ||
79aceca5 | 4328 | /*** Lookaside buffer management ***/ |
76db3ba4 | 4329 | /* Optional & mem_idx only: */ |
99e300ef | 4330 | |
54623277 | 4331 | /* tlbia */ |
99e300ef | 4332 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4333 | { |
9a64fbe4 | 4334 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4335 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4336 | #else |
76db3ba4 | 4337 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4338 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4339 | return; |
9a64fbe4 | 4340 | } |
74d37793 | 4341 | gen_helper_tlbia(); |
9a64fbe4 | 4342 | #endif |
79aceca5 FB |
4343 | } |
4344 | ||
bf14b1ce | 4345 | /* tlbiel */ |
99e300ef | 4346 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4347 | { |
4348 | #if defined(CONFIG_USER_ONLY) | |
4349 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4350 | #else | |
4351 | if (unlikely(!ctx->mem_idx)) { | |
4352 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4353 | return; | |
4354 | } | |
4355 | gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]); | |
4356 | #endif | |
4357 | } | |
4358 | ||
79aceca5 | 4359 | /* tlbie */ |
99e300ef | 4360 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4361 | { |
9a64fbe4 | 4362 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4363 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4364 | #else |
76db3ba4 | 4365 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4366 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4367 | return; |
9a64fbe4 | 4368 | } |
d9bce9d9 | 4369 | #if defined(TARGET_PPC64) |
74d37793 AJ |
4370 | if (!ctx->sf_mode) { |
4371 | TCGv t0 = tcg_temp_new(); | |
4372 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
4373 | gen_helper_tlbie(t0); | |
4374 | tcg_temp_free(t0); | |
4375 | } else | |
d9bce9d9 | 4376 | #endif |
74d37793 | 4377 | gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]); |
9a64fbe4 | 4378 | #endif |
79aceca5 FB |
4379 | } |
4380 | ||
4381 | /* tlbsync */ | |
99e300ef | 4382 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4383 | { |
9a64fbe4 | 4384 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4385 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4386 | #else |
76db3ba4 | 4387 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4388 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4389 | return; |
9a64fbe4 FB |
4390 | } |
4391 | /* This has no effect: it should ensure that all previous | |
4392 | * tlbie have completed | |
4393 | */ | |
e06fcd75 | 4394 | gen_stop_exception(ctx); |
9a64fbe4 | 4395 | #endif |
79aceca5 FB |
4396 | } |
4397 | ||
426613db JM |
4398 | #if defined(TARGET_PPC64) |
4399 | /* slbia */ | |
99e300ef | 4400 | static void gen_slbia(DisasContext *ctx) |
426613db JM |
4401 | { |
4402 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4403 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4404 | #else |
76db3ba4 | 4405 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4406 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4407 | return; |
4408 | } | |
74d37793 | 4409 | gen_helper_slbia(); |
426613db JM |
4410 | #endif |
4411 | } | |
4412 | ||
4413 | /* slbie */ | |
99e300ef | 4414 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4415 | { |
4416 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4417 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4418 | #else |
76db3ba4 | 4419 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4420 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4421 | return; |
4422 | } | |
74d37793 | 4423 | gen_helper_slbie(cpu_gpr[rB(ctx->opcode)]); |
426613db JM |
4424 | #endif |
4425 | } | |
4426 | #endif | |
4427 | ||
79aceca5 FB |
4428 | /*** External control ***/ |
4429 | /* Optional: */ | |
99e300ef | 4430 | |
54623277 | 4431 | /* eciwx */ |
99e300ef | 4432 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4433 | { |
76db3ba4 | 4434 | TCGv t0; |
fa407c03 | 4435 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4436 | gen_set_access_type(ctx, ACCESS_EXT); |
4437 | t0 = tcg_temp_new(); | |
4438 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4439 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4440 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4441 | tcg_temp_free(t0); |
76a66253 JM |
4442 | } |
4443 | ||
4444 | /* ecowx */ | |
99e300ef | 4445 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4446 | { |
76db3ba4 | 4447 | TCGv t0; |
fa407c03 | 4448 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4449 | gen_set_access_type(ctx, ACCESS_EXT); |
4450 | t0 = tcg_temp_new(); | |
4451 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4452 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4453 | gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4454 | tcg_temp_free(t0); |
76a66253 JM |
4455 | } |
4456 | ||
4457 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4458 | |
54623277 | 4459 | /* abs - abs. */ |
99e300ef | 4460 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4461 | { |
22e0e173 AJ |
4462 | int l1 = gen_new_label(); |
4463 | int l2 = gen_new_label(); | |
4464 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4465 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4466 | tcg_gen_br(l2); | |
4467 | gen_set_label(l1); | |
4468 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4469 | gen_set_label(l2); | |
76a66253 | 4470 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4471 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4472 | } |
4473 | ||
4474 | /* abso - abso. */ | |
99e300ef | 4475 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4476 | { |
22e0e173 AJ |
4477 | int l1 = gen_new_label(); |
4478 | int l2 = gen_new_label(); | |
4479 | int l3 = gen_new_label(); | |
4480 | /* Start with XER OV disabled, the most likely case */ | |
4481 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4482 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); | |
4483 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
4484 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4485 | tcg_gen_br(l2); | |
4486 | gen_set_label(l1); | |
4487 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4488 | tcg_gen_br(l3); | |
4489 | gen_set_label(l2); | |
4490 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4491 | gen_set_label(l3); | |
76a66253 | 4492 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4493 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4494 | } |
4495 | ||
4496 | /* clcs */ | |
99e300ef | 4497 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 4498 | { |
22e0e173 AJ |
4499 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
4500 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], t0); | |
4501 | tcg_temp_free_i32(t0); | |
c7697e1f | 4502 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
4503 | } |
4504 | ||
4505 | /* div - div. */ | |
99e300ef | 4506 | static void gen_div(DisasContext *ctx) |
76a66253 | 4507 | { |
22e0e173 | 4508 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76a66253 | 4509 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4510 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4511 | } |
4512 | ||
4513 | /* divo - divo. */ | |
99e300ef | 4514 | static void gen_divo(DisasContext *ctx) |
76a66253 | 4515 | { |
22e0e173 | 4516 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76a66253 | 4517 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4518 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4519 | } |
4520 | ||
4521 | /* divs - divs. */ | |
99e300ef | 4522 | static void gen_divs(DisasContext *ctx) |
76a66253 | 4523 | { |
22e0e173 | 4524 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76a66253 | 4525 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4526 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4527 | } |
4528 | ||
4529 | /* divso - divso. */ | |
99e300ef | 4530 | static void gen_divso(DisasContext *ctx) |
76a66253 | 4531 | { |
22e0e173 | 4532 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
76a66253 | 4533 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4534 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4535 | } |
4536 | ||
4537 | /* doz - doz. */ | |
99e300ef | 4538 | static void gen_doz(DisasContext *ctx) |
76a66253 | 4539 | { |
22e0e173 AJ |
4540 | int l1 = gen_new_label(); |
4541 | int l2 = gen_new_label(); | |
4542 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4543 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4544 | tcg_gen_br(l2); | |
4545 | gen_set_label(l1); | |
4546 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4547 | gen_set_label(l2); | |
76a66253 | 4548 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4549 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4550 | } |
4551 | ||
4552 | /* dozo - dozo. */ | |
99e300ef | 4553 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 4554 | { |
22e0e173 AJ |
4555 | int l1 = gen_new_label(); |
4556 | int l2 = gen_new_label(); | |
4557 | TCGv t0 = tcg_temp_new(); | |
4558 | TCGv t1 = tcg_temp_new(); | |
4559 | TCGv t2 = tcg_temp_new(); | |
4560 | /* Start with XER OV disabled, the most likely case */ | |
4561 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4562 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4563 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4564 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4565 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
4566 | tcg_gen_andc_tl(t1, t1, t2); | |
4567 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4568 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
4569 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4570 | tcg_gen_br(l2); | |
4571 | gen_set_label(l1); | |
4572 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4573 | gen_set_label(l2); | |
4574 | tcg_temp_free(t0); | |
4575 | tcg_temp_free(t1); | |
4576 | tcg_temp_free(t2); | |
76a66253 | 4577 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4578 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4579 | } |
4580 | ||
4581 | /* dozi */ | |
99e300ef | 4582 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 4583 | { |
22e0e173 AJ |
4584 | target_long simm = SIMM(ctx->opcode); |
4585 | int l1 = gen_new_label(); | |
4586 | int l2 = gen_new_label(); | |
4587 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); | |
4588 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
4589 | tcg_gen_br(l2); | |
4590 | gen_set_label(l1); | |
4591 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4592 | gen_set_label(l2); | |
4593 | if (unlikely(Rc(ctx->opcode) != 0)) | |
4594 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
4595 | } |
4596 | ||
76a66253 | 4597 | /* lscbx - lscbx. */ |
99e300ef | 4598 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 4599 | { |
bdb4b689 AJ |
4600 | TCGv t0 = tcg_temp_new(); |
4601 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
4602 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
4603 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 4604 | |
76db3ba4 | 4605 | gen_addr_reg_index(ctx, t0); |
76a66253 | 4606 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 4607 | gen_update_nip(ctx, ctx->nip - 4); |
bdb4b689 AJ |
4608 | gen_helper_lscbx(t0, t0, t1, t2, t3); |
4609 | tcg_temp_free_i32(t1); | |
4610 | tcg_temp_free_i32(t2); | |
4611 | tcg_temp_free_i32(t3); | |
3d7b417e | 4612 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 4613 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 4614 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
4615 | gen_set_Rc0(ctx, t0); |
4616 | tcg_temp_free(t0); | |
76a66253 JM |
4617 | } |
4618 | ||
4619 | /* maskg - maskg. */ | |
99e300ef | 4620 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 4621 | { |
22e0e173 AJ |
4622 | int l1 = gen_new_label(); |
4623 | TCGv t0 = tcg_temp_new(); | |
4624 | TCGv t1 = tcg_temp_new(); | |
4625 | TCGv t2 = tcg_temp_new(); | |
4626 | TCGv t3 = tcg_temp_new(); | |
4627 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
4628 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4629 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
4630 | tcg_gen_addi_tl(t2, t0, 1); | |
4631 | tcg_gen_shr_tl(t2, t3, t2); | |
4632 | tcg_gen_shr_tl(t3, t3, t1); | |
4633 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
4634 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
4635 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4636 | gen_set_label(l1); | |
4637 | tcg_temp_free(t0); | |
4638 | tcg_temp_free(t1); | |
4639 | tcg_temp_free(t2); | |
4640 | tcg_temp_free(t3); | |
76a66253 | 4641 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4642 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4643 | } |
4644 | ||
4645 | /* maskir - maskir. */ | |
99e300ef | 4646 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 4647 | { |
22e0e173 AJ |
4648 | TCGv t0 = tcg_temp_new(); |
4649 | TCGv t1 = tcg_temp_new(); | |
4650 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4651 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4652 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4653 | tcg_temp_free(t0); | |
4654 | tcg_temp_free(t1); | |
76a66253 | 4655 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4656 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4657 | } |
4658 | ||
4659 | /* mul - mul. */ | |
99e300ef | 4660 | static void gen_mul(DisasContext *ctx) |
76a66253 | 4661 | { |
22e0e173 AJ |
4662 | TCGv_i64 t0 = tcg_temp_new_i64(); |
4663 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4664 | TCGv t2 = tcg_temp_new(); | |
4665 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4666 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4667 | tcg_gen_mul_i64(t0, t0, t1); | |
4668 | tcg_gen_trunc_i64_tl(t2, t0); | |
4669 | gen_store_spr(SPR_MQ, t2); | |
4670 | tcg_gen_shri_i64(t1, t0, 32); | |
4671 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4672 | tcg_temp_free_i64(t0); | |
4673 | tcg_temp_free_i64(t1); | |
4674 | tcg_temp_free(t2); | |
76a66253 | 4675 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4676 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4677 | } |
4678 | ||
4679 | /* mulo - mulo. */ | |
99e300ef | 4680 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 4681 | { |
22e0e173 AJ |
4682 | int l1 = gen_new_label(); |
4683 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
4684 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4685 | TCGv t2 = tcg_temp_new(); | |
4686 | /* Start with XER OV disabled, the most likely case */ | |
4687 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
4688 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4689 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4690 | tcg_gen_mul_i64(t0, t0, t1); | |
4691 | tcg_gen_trunc_i64_tl(t2, t0); | |
4692 | gen_store_spr(SPR_MQ, t2); | |
4693 | tcg_gen_shri_i64(t1, t0, 32); | |
4694 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4695 | tcg_gen_ext32s_i64(t1, t0); | |
4696 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
4697 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
4698 | gen_set_label(l1); | |
4699 | tcg_temp_free_i64(t0); | |
4700 | tcg_temp_free_i64(t1); | |
4701 | tcg_temp_free(t2); | |
76a66253 | 4702 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4703 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4704 | } |
4705 | ||
4706 | /* nabs - nabs. */ | |
99e300ef | 4707 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 4708 | { |
22e0e173 AJ |
4709 | int l1 = gen_new_label(); |
4710 | int l2 = gen_new_label(); | |
4711 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4712 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4713 | tcg_gen_br(l2); | |
4714 | gen_set_label(l1); | |
4715 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4716 | gen_set_label(l2); | |
76a66253 | 4717 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4718 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4719 | } |
4720 | ||
4721 | /* nabso - nabso. */ | |
99e300ef | 4722 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 4723 | { |
22e0e173 AJ |
4724 | int l1 = gen_new_label(); |
4725 | int l2 = gen_new_label(); | |
4726 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4727 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4728 | tcg_gen_br(l2); | |
4729 | gen_set_label(l1); | |
4730 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4731 | gen_set_label(l2); | |
4732 | /* nabs never overflows */ | |
4733 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
76a66253 | 4734 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4735 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4736 | } |
4737 | ||
4738 | /* rlmi - rlmi. */ | |
99e300ef | 4739 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 4740 | { |
7487953d AJ |
4741 | uint32_t mb = MB(ctx->opcode); |
4742 | uint32_t me = ME(ctx->opcode); | |
4743 | TCGv t0 = tcg_temp_new(); | |
4744 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4745 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4746 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
4747 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
4748 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
4749 | tcg_temp_free(t0); | |
76a66253 | 4750 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4751 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4752 | } |
4753 | ||
4754 | /* rrib - rrib. */ | |
99e300ef | 4755 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 4756 | { |
7487953d AJ |
4757 | TCGv t0 = tcg_temp_new(); |
4758 | TCGv t1 = tcg_temp_new(); | |
4759 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4760 | tcg_gen_movi_tl(t1, 0x80000000); | |
4761 | tcg_gen_shr_tl(t1, t1, t0); | |
4762 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4763 | tcg_gen_and_tl(t0, t0, t1); | |
4764 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
4765 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4766 | tcg_temp_free(t0); | |
4767 | tcg_temp_free(t1); | |
76a66253 | 4768 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4769 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4770 | } |
4771 | ||
4772 | /* sle - sle. */ | |
99e300ef | 4773 | static void gen_sle(DisasContext *ctx) |
76a66253 | 4774 | { |
7487953d AJ |
4775 | TCGv t0 = tcg_temp_new(); |
4776 | TCGv t1 = tcg_temp_new(); | |
4777 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4778 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4779 | tcg_gen_subfi_tl(t1, 32, t1); | |
4780 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4781 | tcg_gen_or_tl(t1, t0, t1); | |
4782 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4783 | gen_store_spr(SPR_MQ, t1); | |
4784 | tcg_temp_free(t0); | |
4785 | tcg_temp_free(t1); | |
76a66253 | 4786 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4787 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4788 | } |
4789 | ||
4790 | /* sleq - sleq. */ | |
99e300ef | 4791 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 4792 | { |
7487953d AJ |
4793 | TCGv t0 = tcg_temp_new(); |
4794 | TCGv t1 = tcg_temp_new(); | |
4795 | TCGv t2 = tcg_temp_new(); | |
4796 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4797 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
4798 | tcg_gen_shl_tl(t2, t2, t0); | |
4799 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4800 | gen_load_spr(t1, SPR_MQ); | |
4801 | gen_store_spr(SPR_MQ, t0); | |
4802 | tcg_gen_and_tl(t0, t0, t2); | |
4803 | tcg_gen_andc_tl(t1, t1, t2); | |
4804 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4805 | tcg_temp_free(t0); | |
4806 | tcg_temp_free(t1); | |
4807 | tcg_temp_free(t2); | |
76a66253 | 4808 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4809 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4810 | } |
4811 | ||
4812 | /* sliq - sliq. */ | |
99e300ef | 4813 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 4814 | { |
7487953d AJ |
4815 | int sh = SH(ctx->opcode); |
4816 | TCGv t0 = tcg_temp_new(); | |
4817 | TCGv t1 = tcg_temp_new(); | |
4818 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4819 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4820 | tcg_gen_or_tl(t1, t0, t1); | |
4821 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4822 | gen_store_spr(SPR_MQ, t1); | |
4823 | tcg_temp_free(t0); | |
4824 | tcg_temp_free(t1); | |
76a66253 | 4825 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4826 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4827 | } |
4828 | ||
4829 | /* slliq - slliq. */ | |
99e300ef | 4830 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 4831 | { |
7487953d AJ |
4832 | int sh = SH(ctx->opcode); |
4833 | TCGv t0 = tcg_temp_new(); | |
4834 | TCGv t1 = tcg_temp_new(); | |
4835 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4836 | gen_load_spr(t1, SPR_MQ); | |
4837 | gen_store_spr(SPR_MQ, t0); | |
4838 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
4839 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
4840 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4841 | tcg_temp_free(t0); | |
4842 | tcg_temp_free(t1); | |
76a66253 | 4843 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4844 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4845 | } |
4846 | ||
4847 | /* sllq - sllq. */ | |
99e300ef | 4848 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 4849 | { |
7487953d AJ |
4850 | int l1 = gen_new_label(); |
4851 | int l2 = gen_new_label(); | |
4852 | TCGv t0 = tcg_temp_local_new(); | |
4853 | TCGv t1 = tcg_temp_local_new(); | |
4854 | TCGv t2 = tcg_temp_local_new(); | |
4855 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4856 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
4857 | tcg_gen_shl_tl(t1, t1, t2); | |
4858 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4859 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
4860 | gen_load_spr(t0, SPR_MQ); | |
4861 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4862 | tcg_gen_br(l2); | |
4863 | gen_set_label(l1); | |
4864 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4865 | gen_load_spr(t2, SPR_MQ); | |
4866 | tcg_gen_andc_tl(t1, t2, t1); | |
4867 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4868 | gen_set_label(l2); | |
4869 | tcg_temp_free(t0); | |
4870 | tcg_temp_free(t1); | |
4871 | tcg_temp_free(t2); | |
76a66253 | 4872 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4873 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4874 | } |
4875 | ||
4876 | /* slq - slq. */ | |
99e300ef | 4877 | static void gen_slq(DisasContext *ctx) |
76a66253 | 4878 | { |
7487953d AJ |
4879 | int l1 = gen_new_label(); |
4880 | TCGv t0 = tcg_temp_new(); | |
4881 | TCGv t1 = tcg_temp_new(); | |
4882 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4883 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4884 | tcg_gen_subfi_tl(t1, 32, t1); | |
4885 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4886 | tcg_gen_or_tl(t1, t0, t1); | |
4887 | gen_store_spr(SPR_MQ, t1); | |
4888 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4889 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4890 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4891 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
4892 | gen_set_label(l1); | |
4893 | tcg_temp_free(t0); | |
4894 | tcg_temp_free(t1); | |
76a66253 | 4895 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4896 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4897 | } |
4898 | ||
d9bce9d9 | 4899 | /* sraiq - sraiq. */ |
99e300ef | 4900 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 4901 | { |
7487953d AJ |
4902 | int sh = SH(ctx->opcode); |
4903 | int l1 = gen_new_label(); | |
4904 | TCGv t0 = tcg_temp_new(); | |
4905 | TCGv t1 = tcg_temp_new(); | |
4906 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
4907 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
4908 | tcg_gen_or_tl(t0, t0, t1); | |
4909 | gen_store_spr(SPR_MQ, t0); | |
4910 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
4911 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
4912 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
4913 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
4914 | gen_set_label(l1); | |
4915 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
4916 | tcg_temp_free(t0); | |
4917 | tcg_temp_free(t1); | |
76a66253 | 4918 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4919 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4920 | } |
4921 | ||
4922 | /* sraq - sraq. */ | |
99e300ef | 4923 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 4924 | { |
7487953d AJ |
4925 | int l1 = gen_new_label(); |
4926 | int l2 = gen_new_label(); | |
4927 | TCGv t0 = tcg_temp_new(); | |
4928 | TCGv t1 = tcg_temp_local_new(); | |
4929 | TCGv t2 = tcg_temp_local_new(); | |
4930 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4931 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
4932 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
4933 | tcg_gen_subfi_tl(t2, 32, t2); | |
4934 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
4935 | tcg_gen_or_tl(t0, t0, t2); | |
4936 | gen_store_spr(SPR_MQ, t0); | |
4937 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
4938 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
4939 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
4940 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
4941 | gen_set_label(l1); | |
4942 | tcg_temp_free(t0); | |
4943 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
4944 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA)); | |
4945 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
4946 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
4947 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA)); | |
4948 | gen_set_label(l2); | |
4949 | tcg_temp_free(t1); | |
4950 | tcg_temp_free(t2); | |
76a66253 | 4951 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4952 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4953 | } |
4954 | ||
4955 | /* sre - sre. */ | |
99e300ef | 4956 | static void gen_sre(DisasContext *ctx) |
76a66253 | 4957 | { |
7487953d AJ |
4958 | TCGv t0 = tcg_temp_new(); |
4959 | TCGv t1 = tcg_temp_new(); | |
4960 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4961 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4962 | tcg_gen_subfi_tl(t1, 32, t1); | |
4963 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
4964 | tcg_gen_or_tl(t1, t0, t1); | |
4965 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
4966 | gen_store_spr(SPR_MQ, t1); | |
4967 | tcg_temp_free(t0); | |
4968 | tcg_temp_free(t1); | |
76a66253 | 4969 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 4970 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4971 | } |
4972 | ||
4973 | /* srea - srea. */ | |
99e300ef | 4974 | static void gen_srea(DisasContext *ctx) |
76a66253 | 4975 | { |
7487953d AJ |
4976 | TCGv t0 = tcg_temp_new(); |
4977 | TCGv t1 = tcg_temp_new(); | |
4978 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4979 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
4980 | gen_store_spr(SPR_MQ, t0); | |
4981 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
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 | /* sreq */ | |
99e300ef | 4989 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 4990 | { |
7487953d AJ |
4991 | TCGv t0 = tcg_temp_new(); |
4992 | TCGv t1 = tcg_temp_new(); | |
4993 | TCGv t2 = tcg_temp_new(); | |
4994 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4995 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
4996 | tcg_gen_shr_tl(t1, t1, t0); | |
4997 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
4998 | gen_load_spr(t2, SPR_MQ); | |
4999 | gen_store_spr(SPR_MQ, t0); | |
5000 | tcg_gen_and_tl(t0, t0, t1); | |
5001 | tcg_gen_andc_tl(t2, t2, t1); | |
5002 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5003 | tcg_temp_free(t0); | |
5004 | tcg_temp_free(t1); | |
5005 | tcg_temp_free(t2); | |
76a66253 | 5006 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5007 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5008 | } |
5009 | ||
5010 | /* sriq */ | |
99e300ef | 5011 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5012 | { |
7487953d AJ |
5013 | int sh = SH(ctx->opcode); |
5014 | TCGv t0 = tcg_temp_new(); | |
5015 | TCGv t1 = tcg_temp_new(); | |
5016 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5017 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5018 | tcg_gen_or_tl(t1, t0, t1); | |
5019 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5020 | gen_store_spr(SPR_MQ, t1); | |
5021 | tcg_temp_free(t0); | |
5022 | tcg_temp_free(t1); | |
76a66253 | 5023 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5024 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5025 | } |
5026 | ||
5027 | /* srliq */ | |
99e300ef | 5028 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5029 | { |
7487953d AJ |
5030 | int sh = SH(ctx->opcode); |
5031 | TCGv t0 = tcg_temp_new(); | |
5032 | TCGv t1 = tcg_temp_new(); | |
5033 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5034 | gen_load_spr(t1, SPR_MQ); | |
5035 | gen_store_spr(SPR_MQ, t0); | |
5036 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5037 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5038 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5039 | tcg_temp_free(t0); | |
5040 | tcg_temp_free(t1); | |
76a66253 | 5041 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5042 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5043 | } |
5044 | ||
5045 | /* srlq */ | |
99e300ef | 5046 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5047 | { |
7487953d AJ |
5048 | int l1 = gen_new_label(); |
5049 | int l2 = gen_new_label(); | |
5050 | TCGv t0 = tcg_temp_local_new(); | |
5051 | TCGv t1 = tcg_temp_local_new(); | |
5052 | TCGv t2 = tcg_temp_local_new(); | |
5053 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5054 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5055 | tcg_gen_shr_tl(t2, t1, t2); | |
5056 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5057 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5058 | gen_load_spr(t0, SPR_MQ); | |
5059 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5060 | tcg_gen_br(l2); | |
5061 | gen_set_label(l1); | |
5062 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5063 | tcg_gen_and_tl(t0, t0, t2); | |
5064 | gen_load_spr(t1, SPR_MQ); | |
5065 | tcg_gen_andc_tl(t1, t1, t2); | |
5066 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5067 | gen_set_label(l2); | |
5068 | tcg_temp_free(t0); | |
5069 | tcg_temp_free(t1); | |
5070 | tcg_temp_free(t2); | |
76a66253 | 5071 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5072 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5073 | } |
5074 | ||
5075 | /* srq */ | |
99e300ef | 5076 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5077 | { |
7487953d AJ |
5078 | int l1 = gen_new_label(); |
5079 | TCGv t0 = tcg_temp_new(); | |
5080 | TCGv t1 = tcg_temp_new(); | |
5081 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5082 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5083 | tcg_gen_subfi_tl(t1, 32, t1); | |
5084 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5085 | tcg_gen_or_tl(t1, t0, t1); | |
5086 | gen_store_spr(SPR_MQ, t1); | |
5087 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5088 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5089 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5090 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5091 | gen_set_label(l1); | |
5092 | tcg_temp_free(t0); | |
5093 | tcg_temp_free(t1); | |
76a66253 | 5094 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5095 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5096 | } |
5097 | ||
5098 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5099 | |
54623277 | 5100 | /* dsa */ |
99e300ef | 5101 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5102 | { |
5103 | /* XXX: TODO */ | |
e06fcd75 | 5104 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5105 | } |
5106 | ||
5107 | /* esa */ | |
99e300ef | 5108 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5109 | { |
5110 | /* XXX: TODO */ | |
e06fcd75 | 5111 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5112 | } |
5113 | ||
5114 | /* mfrom */ | |
99e300ef | 5115 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5116 | { |
5117 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5118 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5119 | #else |
76db3ba4 | 5120 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5121 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5122 | return; |
5123 | } | |
cf02a65c | 5124 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5125 | #endif |
5126 | } | |
5127 | ||
5128 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5129 | |
54623277 | 5130 | /* tlbld */ |
e8eaa2c0 | 5131 | static void gen_tlbld_6xx(DisasContext *ctx) |
76a66253 JM |
5132 | { |
5133 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5134 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5135 | #else |
76db3ba4 | 5136 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5137 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5138 | return; |
5139 | } | |
74d37793 | 5140 | gen_helper_6xx_tlbd(cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5141 | #endif |
5142 | } | |
5143 | ||
5144 | /* tlbli */ | |
e8eaa2c0 | 5145 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5146 | { |
5147 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5148 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5149 | #else |
76db3ba4 | 5150 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5151 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5152 | return; |
5153 | } | |
74d37793 | 5154 | gen_helper_6xx_tlbi(cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5155 | #endif |
5156 | } | |
5157 | ||
7dbe11ac | 5158 | /* 74xx TLB management */ |
e8eaa2c0 | 5159 | |
54623277 | 5160 | /* tlbld */ |
e8eaa2c0 | 5161 | static void gen_tlbld_74xx(DisasContext *ctx) |
7dbe11ac JM |
5162 | { |
5163 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5164 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5165 | #else |
76db3ba4 | 5166 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5167 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5168 | return; |
5169 | } | |
74d37793 | 5170 | gen_helper_74xx_tlbd(cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5171 | #endif |
5172 | } | |
5173 | ||
5174 | /* tlbli */ | |
e8eaa2c0 | 5175 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5176 | { |
5177 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5178 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5179 | #else |
76db3ba4 | 5180 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5181 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5182 | return; |
5183 | } | |
74d37793 | 5184 | gen_helper_74xx_tlbi(cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5185 | #endif |
5186 | } | |
5187 | ||
76a66253 | 5188 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5189 | |
54623277 | 5190 | /* clf */ |
99e300ef | 5191 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5192 | { |
5193 | /* Cache line flush: implemented as no-op */ | |
5194 | } | |
5195 | ||
5196 | /* cli */ | |
99e300ef | 5197 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5198 | { |
7f75ffd3 | 5199 | /* Cache line invalidate: privileged and treated as no-op */ |
76a66253 | 5200 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5201 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5202 | #else |
76db3ba4 | 5203 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5204 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5205 | return; |
5206 | } | |
5207 | #endif | |
5208 | } | |
5209 | ||
5210 | /* dclst */ | |
99e300ef | 5211 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5212 | { |
5213 | /* Data cache line store: treated as no-op */ | |
5214 | } | |
5215 | ||
99e300ef | 5216 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5217 | { |
5218 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5219 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5220 | #else |
74d37793 AJ |
5221 | int ra = rA(ctx->opcode); |
5222 | int rd = rD(ctx->opcode); | |
5223 | TCGv t0; | |
76db3ba4 | 5224 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5225 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5226 | return; |
5227 | } | |
74d37793 | 5228 | t0 = tcg_temp_new(); |
76db3ba4 | 5229 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5230 | tcg_gen_shri_tl(t0, t0, 28); |
5231 | tcg_gen_andi_tl(t0, t0, 0xF); | |
5232 | gen_helper_load_sr(cpu_gpr[rd], t0); | |
5233 | tcg_temp_free(t0); | |
76a66253 | 5234 | if (ra != 0 && ra != rd) |
74d37793 | 5235 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
76a66253 JM |
5236 | #endif |
5237 | } | |
5238 | ||
99e300ef | 5239 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5240 | { |
5241 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5242 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5243 | #else |
22e0e173 | 5244 | TCGv t0; |
76db3ba4 | 5245 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5246 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5247 | return; |
5248 | } | |
22e0e173 | 5249 | t0 = tcg_temp_new(); |
76db3ba4 | 5250 | gen_addr_reg_index(ctx, t0); |
22e0e173 AJ |
5251 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], t0); |
5252 | tcg_temp_free(t0); | |
76a66253 JM |
5253 | #endif |
5254 | } | |
5255 | ||
99e300ef | 5256 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5257 | { |
5258 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5259 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5260 | #else |
76db3ba4 | 5261 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5262 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5263 | return; |
5264 | } | |
d72a19f7 | 5265 | gen_helper_rfsvc(); |
e06fcd75 | 5266 | gen_sync_exception(ctx); |
76a66253 JM |
5267 | #endif |
5268 | } | |
5269 | ||
5270 | /* svc is not implemented for now */ | |
5271 | ||
5272 | /* POWER2 specific instructions */ | |
5273 | /* Quad manipulation (load/store two floats at a time) */ | |
76a66253 JM |
5274 | |
5275 | /* lfq */ | |
99e300ef | 5276 | static void gen_lfq(DisasContext *ctx) |
76a66253 | 5277 | { |
01a4afeb | 5278 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5279 | TCGv t0; |
5280 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5281 | t0 = tcg_temp_new(); | |
5282 | gen_addr_imm_index(ctx, t0, 0); | |
5283 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5284 | gen_addr_add(ctx, t0, t0, 8); | |
5285 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5286 | tcg_temp_free(t0); |
76a66253 JM |
5287 | } |
5288 | ||
5289 | /* lfqu */ | |
99e300ef | 5290 | static void gen_lfqu(DisasContext *ctx) |
76a66253 JM |
5291 | { |
5292 | int ra = rA(ctx->opcode); | |
01a4afeb | 5293 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5294 | TCGv t0, t1; |
5295 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5296 | t0 = tcg_temp_new(); | |
5297 | t1 = tcg_temp_new(); | |
5298 | gen_addr_imm_index(ctx, t0, 0); | |
5299 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5300 | gen_addr_add(ctx, t1, t0, 8); | |
5301 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
76a66253 | 5302 | if (ra != 0) |
01a4afeb AJ |
5303 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5304 | tcg_temp_free(t0); | |
5305 | tcg_temp_free(t1); | |
76a66253 JM |
5306 | } |
5307 | ||
5308 | /* lfqux */ | |
99e300ef | 5309 | static void gen_lfqux(DisasContext *ctx) |
76a66253 JM |
5310 | { |
5311 | int ra = rA(ctx->opcode); | |
01a4afeb | 5312 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5313 | gen_set_access_type(ctx, ACCESS_FLOAT); |
5314 | TCGv t0, t1; | |
5315 | t0 = tcg_temp_new(); | |
5316 | gen_addr_reg_index(ctx, t0); | |
5317 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5318 | t1 = tcg_temp_new(); | |
5319 | gen_addr_add(ctx, t1, t0, 8); | |
5320 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5321 | tcg_temp_free(t1); | |
76a66253 | 5322 | if (ra != 0) |
01a4afeb AJ |
5323 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5324 | tcg_temp_free(t0); | |
76a66253 JM |
5325 | } |
5326 | ||
5327 | /* lfqx */ | |
99e300ef | 5328 | static void gen_lfqx(DisasContext *ctx) |
76a66253 | 5329 | { |
01a4afeb | 5330 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5331 | TCGv t0; |
5332 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5333 | t0 = tcg_temp_new(); | |
5334 | gen_addr_reg_index(ctx, t0); | |
5335 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5336 | gen_addr_add(ctx, t0, t0, 8); | |
5337 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5338 | tcg_temp_free(t0); |
76a66253 JM |
5339 | } |
5340 | ||
5341 | /* stfq */ | |
99e300ef | 5342 | static void gen_stfq(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_st64(ctx, cpu_fpr[rd], t0); | |
5350 | gen_addr_add(ctx, t0, t0, 8); | |
5351 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5352 | tcg_temp_free(t0); |
76a66253 JM |
5353 | } |
5354 | ||
5355 | /* stfqu */ | |
99e300ef | 5356 | static void gen_stfqu(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 | gen_addr_imm_index(ctx, t0, 0); | |
5364 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5365 | t1 = tcg_temp_new(); | |
5366 | gen_addr_add(ctx, t1, t0, 8); | |
5367 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5368 | tcg_temp_free(t1); | |
76a66253 | 5369 | if (ra != 0) |
01a4afeb AJ |
5370 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5371 | tcg_temp_free(t0); | |
76a66253 JM |
5372 | } |
5373 | ||
5374 | /* stfqux */ | |
99e300ef | 5375 | static void gen_stfqux(DisasContext *ctx) |
76a66253 JM |
5376 | { |
5377 | int ra = rA(ctx->opcode); | |
01a4afeb | 5378 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5379 | TCGv t0, t1; |
5380 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5381 | t0 = tcg_temp_new(); | |
5382 | gen_addr_reg_index(ctx, t0); | |
5383 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5384 | t1 = tcg_temp_new(); | |
5385 | gen_addr_add(ctx, t1, t0, 8); | |
5386 | gen_qemu_st64(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 | /* stfqx */ | |
99e300ef | 5394 | static void gen_stfqx(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_st64(ctx, cpu_fpr[rd], t0); | |
5402 | gen_addr_add(ctx, t0, t0, 8); | |
5403 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5404 | tcg_temp_free(t0); |
76a66253 JM |
5405 | } |
5406 | ||
5407 | /* BookE specific instructions */ | |
99e300ef | 5408 | |
54623277 | 5409 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5410 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5411 | { |
5412 | /* XXX: TODO */ | |
e06fcd75 | 5413 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5414 | } |
5415 | ||
2662a059 | 5416 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5417 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5418 | { |
5419 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5420 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5421 | #else |
74d37793 | 5422 | TCGv t0; |
76db3ba4 | 5423 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5424 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5425 | return; |
5426 | } | |
ec72e276 | 5427 | t0 = tcg_temp_new(); |
76db3ba4 | 5428 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5429 | gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]); |
5430 | tcg_temp_free(t0); | |
76a66253 JM |
5431 | #endif |
5432 | } | |
5433 | ||
5434 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5435 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5436 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5437 | { |
182608d4 AJ |
5438 | TCGv t0, t1; |
5439 | ||
a7812ae4 PB |
5440 | t0 = tcg_temp_local_new(); |
5441 | t1 = tcg_temp_local_new(); | |
182608d4 | 5442 | |
76a66253 JM |
5443 | switch (opc3 & 0x0D) { |
5444 | case 0x05: | |
5445 | /* macchw - macchw. - macchwo - macchwo. */ | |
5446 | /* macchws - macchws. - macchwso - macchwso. */ | |
5447 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5448 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5449 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5450 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5451 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5452 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5453 | break; |
5454 | case 0x04: | |
5455 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5456 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5457 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5458 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5459 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5460 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5461 | break; |
5462 | case 0x01: | |
5463 | /* machhw - machhw. - machhwo - machhwo. */ | |
5464 | /* machhws - machhws. - machhwso - machhwso. */ | |
5465 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5466 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5467 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5468 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5469 | tcg_gen_ext16s_tl(t0, t0); | |
5470 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5471 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5472 | break; |
5473 | case 0x00: | |
5474 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5475 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5476 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5477 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5478 | tcg_gen_ext16u_tl(t0, t0); | |
5479 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5480 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5481 | break; |
5482 | case 0x0D: | |
5483 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5484 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5485 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5486 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5487 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5488 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5489 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5490 | break; |
5491 | case 0x0C: | |
5492 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5493 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5494 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5495 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5496 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5497 | break; |
5498 | } | |
76a66253 | 5499 | if (opc2 & 0x04) { |
182608d4 AJ |
5500 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5501 | tcg_gen_mul_tl(t1, t0, t1); | |
5502 | if (opc2 & 0x02) { | |
5503 | /* nmultiply-and-accumulate (0x0E) */ | |
5504 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5505 | } else { | |
5506 | /* multiply-and-accumulate (0x0C) */ | |
5507 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5508 | } | |
5509 | ||
5510 | if (opc3 & 0x12) { | |
5511 | /* Check overflow and/or saturate */ | |
5512 | int l1 = gen_new_label(); | |
5513 | ||
5514 | if (opc3 & 0x10) { | |
5515 | /* Start with XER OV disabled, the most likely case */ | |
5516 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV)); | |
5517 | } | |
5518 | if (opc3 & 0x01) { | |
5519 | /* Signed */ | |
5520 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5521 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5522 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5523 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5524 | if (opc3 & 0x02) { |
182608d4 AJ |
5525 | /* Saturate */ |
5526 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5527 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5528 | } | |
5529 | } else { | |
5530 | /* Unsigned */ | |
5531 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5532 | if (opc3 & 0x02) { |
182608d4 AJ |
5533 | /* Saturate */ |
5534 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5535 | } | |
5536 | } | |
5537 | if (opc3 & 0x10) { | |
5538 | /* Check overflow */ | |
5539 | tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO)); | |
5540 | } | |
5541 | gen_set_label(l1); | |
5542 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5543 | } | |
5544 | } else { | |
5545 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5546 | } |
182608d4 AJ |
5547 | tcg_temp_free(t0); |
5548 | tcg_temp_free(t1); | |
76a66253 JM |
5549 | if (unlikely(Rc) != 0) { |
5550 | /* Update Rc0 */ | |
182608d4 | 5551 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5552 | } |
5553 | } | |
5554 | ||
a750fc0b | 5555 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5556 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5557 | { \ |
5558 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5559 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5560 | } | |
5561 | ||
5562 | /* macchw - macchw. */ | |
a750fc0b | 5563 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5564 | /* macchwo - macchwo. */ |
a750fc0b | 5565 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5566 | /* macchws - macchws. */ |
a750fc0b | 5567 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5568 | /* macchwso - macchwso. */ |
a750fc0b | 5569 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5570 | /* macchwsu - macchwsu. */ |
a750fc0b | 5571 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5572 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5573 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5574 | /* macchwu - macchwu. */ |
a750fc0b | 5575 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5576 | /* macchwuo - macchwuo. */ |
a750fc0b | 5577 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 5578 | /* machhw - machhw. */ |
a750fc0b | 5579 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 5580 | /* machhwo - machhwo. */ |
a750fc0b | 5581 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 5582 | /* machhws - machhws. */ |
a750fc0b | 5583 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 5584 | /* machhwso - machhwso. */ |
a750fc0b | 5585 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 5586 | /* machhwsu - machhwsu. */ |
a750fc0b | 5587 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 5588 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 5589 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 5590 | /* machhwu - machhwu. */ |
a750fc0b | 5591 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 5592 | /* machhwuo - machhwuo. */ |
a750fc0b | 5593 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 5594 | /* maclhw - maclhw. */ |
a750fc0b | 5595 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 5596 | /* maclhwo - maclhwo. */ |
a750fc0b | 5597 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 5598 | /* maclhws - maclhws. */ |
a750fc0b | 5599 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 5600 | /* maclhwso - maclhwso. */ |
a750fc0b | 5601 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 5602 | /* maclhwu - maclhwu. */ |
a750fc0b | 5603 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 5604 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 5605 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 5606 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 5607 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 5608 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 5609 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 5610 | /* nmacchw - nmacchw. */ |
a750fc0b | 5611 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 5612 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 5613 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 5614 | /* nmacchws - nmacchws. */ |
a750fc0b | 5615 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 5616 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 5617 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 5618 | /* nmachhw - nmachhw. */ |
a750fc0b | 5619 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 5620 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 5621 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 5622 | /* nmachhws - nmachhws. */ |
a750fc0b | 5623 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 5624 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 5625 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 5626 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 5627 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 5628 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 5629 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 5630 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 5631 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 5632 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 5633 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
5634 | |
5635 | /* mulchw - mulchw. */ | |
a750fc0b | 5636 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 5637 | /* mulchwu - mulchwu. */ |
a750fc0b | 5638 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 5639 | /* mulhhw - mulhhw. */ |
a750fc0b | 5640 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 5641 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 5642 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 5643 | /* mullhw - mullhw. */ |
a750fc0b | 5644 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 5645 | /* mullhwu - mullhwu. */ |
a750fc0b | 5646 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
5647 | |
5648 | /* mfdcr */ | |
99e300ef | 5649 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
5650 | { |
5651 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5652 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5653 | #else |
06dca6a7 | 5654 | TCGv dcrn; |
76db3ba4 | 5655 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5656 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5657 | return; |
5658 | } | |
06dca6a7 AJ |
5659 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5660 | gen_update_nip(ctx, ctx->nip - 4); | |
5661 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
5662 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], dcrn); | |
5663 | tcg_temp_free(dcrn); | |
76a66253 JM |
5664 | #endif |
5665 | } | |
5666 | ||
5667 | /* mtdcr */ | |
99e300ef | 5668 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
5669 | { |
5670 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5671 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5672 | #else |
06dca6a7 | 5673 | TCGv dcrn; |
76db3ba4 | 5674 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5675 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5676 | return; |
5677 | } | |
06dca6a7 AJ |
5678 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5679 | gen_update_nip(ctx, ctx->nip - 4); | |
5680 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
5681 | gen_helper_store_dcr(dcrn, cpu_gpr[rS(ctx->opcode)]); | |
5682 | tcg_temp_free(dcrn); | |
a42bd6cc JM |
5683 | #endif |
5684 | } | |
5685 | ||
5686 | /* mfdcrx */ | |
2662a059 | 5687 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5688 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
5689 | { |
5690 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5691 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5692 | #else |
76db3ba4 | 5693 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5694 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5695 | return; |
5696 | } | |
06dca6a7 AJ |
5697 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5698 | gen_update_nip(ctx, ctx->nip - 4); | |
5699 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 5700 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
a42bd6cc JM |
5701 | #endif |
5702 | } | |
5703 | ||
5704 | /* mtdcrx */ | |
2662a059 | 5705 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5706 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
5707 | { |
5708 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5709 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5710 | #else |
76db3ba4 | 5711 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5712 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5713 | return; |
5714 | } | |
06dca6a7 AJ |
5715 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5716 | gen_update_nip(ctx, ctx->nip - 4); | |
5717 | gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 5718 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
76a66253 JM |
5719 | #endif |
5720 | } | |
5721 | ||
a750fc0b | 5722 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 5723 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 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 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
5728 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5729 | } | |
5730 | ||
5731 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 5732 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 5733 | { |
06dca6a7 AJ |
5734 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5735 | gen_update_nip(ctx, ctx->nip - 4); | |
5736 | gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b JM |
5737 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
5738 | } | |
5739 | ||
76a66253 | 5740 | /* dccci */ |
99e300ef | 5741 | static void gen_dccci(DisasContext *ctx) |
76a66253 JM |
5742 | { |
5743 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5744 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5745 | #else |
76db3ba4 | 5746 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5747 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5748 | return; |
5749 | } | |
5750 | /* interpreted as no-op */ | |
5751 | #endif | |
5752 | } | |
5753 | ||
5754 | /* dcread */ | |
99e300ef | 5755 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
5756 | { |
5757 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5758 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5759 | #else |
b61f2753 | 5760 | TCGv EA, val; |
76db3ba4 | 5761 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5762 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5763 | return; |
5764 | } | |
76db3ba4 | 5765 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 5766 | EA = tcg_temp_new(); |
76db3ba4 | 5767 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 5768 | val = tcg_temp_new(); |
76db3ba4 | 5769 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
5770 | tcg_temp_free(val); |
5771 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
5772 | tcg_temp_free(EA); | |
76a66253 JM |
5773 | #endif |
5774 | } | |
5775 | ||
5776 | /* icbt */ | |
e8eaa2c0 | 5777 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
5778 | { |
5779 | /* interpreted as no-op */ | |
5780 | /* XXX: specification say this is treated as a load by the MMU | |
5781 | * but does not generate any exception | |
5782 | */ | |
5783 | } | |
5784 | ||
5785 | /* iccci */ | |
99e300ef | 5786 | static void gen_iccci(DisasContext *ctx) |
76a66253 JM |
5787 | { |
5788 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5789 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5790 | #else |
76db3ba4 | 5791 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5792 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5793 | return; |
5794 | } | |
5795 | /* interpreted as no-op */ | |
5796 | #endif | |
5797 | } | |
5798 | ||
5799 | /* icread */ | |
99e300ef | 5800 | static void gen_icread(DisasContext *ctx) |
76a66253 JM |
5801 | { |
5802 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5803 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5804 | #else |
76db3ba4 | 5805 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5806 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5807 | return; |
5808 | } | |
5809 | /* interpreted as no-op */ | |
5810 | #endif | |
5811 | } | |
5812 | ||
76db3ba4 | 5813 | /* rfci (mem_idx only) */ |
e8eaa2c0 | 5814 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
5815 | { |
5816 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5817 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5818 | #else |
76db3ba4 | 5819 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5820 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5821 | return; |
5822 | } | |
5823 | /* Restore CPU state */ | |
d72a19f7 | 5824 | gen_helper_40x_rfci(); |
e06fcd75 | 5825 | gen_sync_exception(ctx); |
a42bd6cc JM |
5826 | #endif |
5827 | } | |
5828 | ||
99e300ef | 5829 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
5830 | { |
5831 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5832 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5833 | #else |
76db3ba4 | 5834 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5835 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5836 | return; |
5837 | } | |
5838 | /* Restore CPU state */ | |
d72a19f7 | 5839 | gen_helper_rfci(); |
e06fcd75 | 5840 | gen_sync_exception(ctx); |
a42bd6cc JM |
5841 | #endif |
5842 | } | |
5843 | ||
5844 | /* BookE specific */ | |
99e300ef | 5845 | |
54623277 | 5846 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5847 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
5848 | { |
5849 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5850 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5851 | #else |
76db3ba4 | 5852 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5853 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5854 | return; |
5855 | } | |
5856 | /* Restore CPU state */ | |
d72a19f7 | 5857 | gen_helper_rfdi(); |
e06fcd75 | 5858 | gen_sync_exception(ctx); |
76a66253 JM |
5859 | #endif |
5860 | } | |
5861 | ||
2662a059 | 5862 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5863 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
5864 | { |
5865 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5866 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 5867 | #else |
76db3ba4 | 5868 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5869 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
5870 | return; |
5871 | } | |
5872 | /* Restore CPU state */ | |
d72a19f7 | 5873 | gen_helper_rfmci(); |
e06fcd75 | 5874 | gen_sync_exception(ctx); |
a42bd6cc JM |
5875 | #endif |
5876 | } | |
5eb7995e | 5877 | |
d9bce9d9 | 5878 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 5879 | |
54623277 | 5880 | /* tlbre */ |
e8eaa2c0 | 5881 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
5882 | { |
5883 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5884 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5885 | #else |
76db3ba4 | 5886 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5887 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5888 | return; |
5889 | } | |
5890 | switch (rB(ctx->opcode)) { | |
5891 | case 0: | |
74d37793 | 5892 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5893 | break; |
5894 | case 1: | |
74d37793 | 5895 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5896 | break; |
5897 | default: | |
e06fcd75 | 5898 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 5899 | break; |
9a64fbe4 | 5900 | } |
76a66253 JM |
5901 | #endif |
5902 | } | |
5903 | ||
d9bce9d9 | 5904 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 5905 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
5906 | { |
5907 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5908 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5909 | #else |
74d37793 | 5910 | TCGv t0; |
76db3ba4 | 5911 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5912 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5913 | return; |
5914 | } | |
74d37793 | 5915 | t0 = tcg_temp_new(); |
76db3ba4 | 5916 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5917 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], t0); |
5918 | tcg_temp_free(t0); | |
5919 | if (Rc(ctx->opcode)) { | |
5920 | int l1 = gen_new_label(); | |
5921 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
5922 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
5923 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
5924 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
5925 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
5926 | gen_set_label(l1); | |
5927 | } | |
76a66253 | 5928 | #endif |
79aceca5 FB |
5929 | } |
5930 | ||
76a66253 | 5931 | /* tlbwe */ |
e8eaa2c0 | 5932 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 5933 | { |
76a66253 | 5934 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5935 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5936 | #else |
76db3ba4 | 5937 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5938 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5939 | return; |
5940 | } | |
5941 | switch (rB(ctx->opcode)) { | |
5942 | case 0: | |
74d37793 | 5943 | gen_helper_4xx_tlbwe_hi(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
76a66253 JM |
5944 | break; |
5945 | case 1: | |
74d37793 | 5946 | gen_helper_4xx_tlbwe_lo(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
76a66253 JM |
5947 | break; |
5948 | default: | |
e06fcd75 | 5949 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 5950 | break; |
9a64fbe4 | 5951 | } |
76a66253 JM |
5952 | #endif |
5953 | } | |
5954 | ||
a4bb6c3e | 5955 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 5956 | |
54623277 | 5957 | /* tlbre */ |
e8eaa2c0 | 5958 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
5959 | { |
5960 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5961 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 5962 | #else |
76db3ba4 | 5963 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5964 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
5965 | return; |
5966 | } | |
5967 | switch (rB(ctx->opcode)) { | |
5968 | case 0: | |
5eb7995e | 5969 | case 1: |
5eb7995e | 5970 | case 2: |
74d37793 AJ |
5971 | { |
5972 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
5823947f | 5973 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], t0, cpu_gpr[rA(ctx->opcode)]); |
74d37793 AJ |
5974 | tcg_temp_free_i32(t0); |
5975 | } | |
5eb7995e JM |
5976 | break; |
5977 | default: | |
e06fcd75 | 5978 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
5979 | break; |
5980 | } | |
5981 | #endif | |
5982 | } | |
5983 | ||
5984 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 5985 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
5986 | { |
5987 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5988 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 5989 | #else |
74d37793 | 5990 | TCGv t0; |
76db3ba4 | 5991 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5992 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
5993 | return; |
5994 | } | |
74d37793 | 5995 | t0 = tcg_temp_new(); |
76db3ba4 | 5996 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5997 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], t0); |
5998 | tcg_temp_free(t0); | |
5999 | if (Rc(ctx->opcode)) { | |
6000 | int l1 = gen_new_label(); | |
6001 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer); | |
6002 | tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO); | |
6003 | tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1); | |
6004 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); | |
6005 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6006 | gen_set_label(l1); | |
6007 | } | |
5eb7995e JM |
6008 | #endif |
6009 | } | |
6010 | ||
6011 | /* tlbwe */ | |
e8eaa2c0 | 6012 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6013 | { |
6014 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6015 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6016 | #else |
76db3ba4 | 6017 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6018 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6019 | return; |
6020 | } | |
6021 | switch (rB(ctx->opcode)) { | |
6022 | case 0: | |
5eb7995e | 6023 | case 1: |
5eb7995e | 6024 | case 2: |
74d37793 AJ |
6025 | { |
6026 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
6027 | gen_helper_440_tlbwe(t0, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
6028 | tcg_temp_free_i32(t0); | |
6029 | } | |
5eb7995e JM |
6030 | break; |
6031 | default: | |
e06fcd75 | 6032 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6033 | break; |
6034 | } | |
6035 | #endif | |
6036 | } | |
6037 | ||
01662f3e AG |
6038 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6039 | ||
6040 | /* tlbre */ | |
6041 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6042 | { | |
6043 | #if defined(CONFIG_USER_ONLY) | |
6044 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6045 | #else | |
6046 | if (unlikely(!ctx->mem_idx)) { | |
6047 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6048 | return; | |
6049 | } | |
6050 | ||
6051 | gen_helper_booke206_tlbre(); | |
6052 | #endif | |
6053 | } | |
6054 | ||
6055 | /* tlbsx - tlbsx. */ | |
6056 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6057 | { | |
6058 | #if defined(CONFIG_USER_ONLY) | |
6059 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6060 | #else | |
6061 | TCGv t0; | |
6062 | if (unlikely(!ctx->mem_idx)) { | |
6063 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6064 | return; | |
6065 | } | |
6066 | ||
6067 | if (rA(ctx->opcode)) { | |
6068 | t0 = tcg_temp_new(); | |
6069 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6070 | } else { | |
6071 | t0 = tcg_const_tl(0); | |
6072 | } | |
6073 | ||
6074 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
6075 | gen_helper_booke206_tlbsx(t0); | |
6076 | #endif | |
6077 | } | |
6078 | ||
6079 | /* tlbwe */ | |
6080 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6081 | { | |
6082 | #if defined(CONFIG_USER_ONLY) | |
6083 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6084 | #else | |
6085 | if (unlikely(!ctx->mem_idx)) { | |
6086 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6087 | return; | |
6088 | } | |
6089 | gen_helper_booke206_tlbwe(); | |
6090 | #endif | |
6091 | } | |
6092 | ||
6093 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6094 | { | |
6095 | #if defined(CONFIG_USER_ONLY) | |
6096 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6097 | #else | |
6098 | TCGv t0; | |
6099 | if (unlikely(!ctx->mem_idx)) { | |
6100 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6101 | return; | |
6102 | } | |
6103 | ||
6104 | t0 = tcg_temp_new(); | |
6105 | gen_addr_reg_index(ctx, t0); | |
6106 | ||
6107 | gen_helper_booke206_tlbivax(t0); | |
6108 | #endif | |
6109 | } | |
6110 | ||
6111 | ||
76a66253 | 6112 | /* wrtee */ |
99e300ef | 6113 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6114 | { |
6115 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6116 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6117 | #else |
6527f6ea | 6118 | TCGv t0; |
76db3ba4 | 6119 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6120 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6121 | return; |
6122 | } | |
6527f6ea AJ |
6123 | t0 = tcg_temp_new(); |
6124 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6125 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6126 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6127 | tcg_temp_free(t0); | |
dee96f6c JM |
6128 | /* Stop translation to have a chance to raise an exception |
6129 | * if we just set msr_ee to 1 | |
6130 | */ | |
e06fcd75 | 6131 | gen_stop_exception(ctx); |
76a66253 JM |
6132 | #endif |
6133 | } | |
6134 | ||
6135 | /* wrteei */ | |
99e300ef | 6136 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6137 | { |
6138 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6139 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6140 | #else |
76db3ba4 | 6141 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6142 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6143 | return; |
6144 | } | |
fbe73008 | 6145 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6146 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6147 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6148 | gen_stop_exception(ctx); |
6527f6ea | 6149 | } else { |
1b6e5f99 | 6150 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6151 | } |
76a66253 JM |
6152 | #endif |
6153 | } | |
6154 | ||
08e46e54 | 6155 | /* PowerPC 440 specific instructions */ |
99e300ef | 6156 | |
54623277 | 6157 | /* dlmzb */ |
99e300ef | 6158 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6159 | { |
ef0d51af AJ |
6160 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
6161 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], | |
6162 | cpu_gpr[rB(ctx->opcode)], t0); | |
6163 | tcg_temp_free_i32(t0); | |
76a66253 JM |
6164 | } |
6165 | ||
6166 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6167 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6168 | { |
6169 | /* interpreted as no-op */ | |
6170 | } | |
6171 | ||
6172 | /* msync replaces sync on 440 */ | |
99e300ef | 6173 | static void gen_msync(DisasContext *ctx) |
76a66253 JM |
6174 | { |
6175 | /* interpreted as no-op */ | |
6176 | } | |
6177 | ||
6178 | /* icbt */ | |
e8eaa2c0 | 6179 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6180 | { |
6181 | /* interpreted as no-op */ | |
6182 | /* XXX: specification say this is treated as a load by the MMU | |
6183 | * but does not generate any exception | |
6184 | */ | |
79aceca5 FB |
6185 | } |
6186 | ||
a9d9eb8f JM |
6187 | /*** Altivec vector extension ***/ |
6188 | /* Altivec registers moves */ | |
a9d9eb8f | 6189 | |
636aa200 | 6190 | static inline TCGv_ptr gen_avr_ptr(int reg) |
564e571a | 6191 | { |
e4704b3b | 6192 | TCGv_ptr r = tcg_temp_new_ptr(); |
564e571a AJ |
6193 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg])); |
6194 | return r; | |
6195 | } | |
6196 | ||
a9d9eb8f | 6197 | #define GEN_VR_LDX(name, opc2, opc3) \ |
99e300ef | 6198 | static void glue(gen_, name)(DisasContext *ctx) \ |
a9d9eb8f | 6199 | { \ |
fe1e5c53 | 6200 | TCGv EA; \ |
a9d9eb8f | 6201 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6202 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6203 | return; \ |
6204 | } \ | |
76db3ba4 | 6205 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6206 | EA = tcg_temp_new(); \ |
76db3ba4 | 6207 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6208 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6209 | if (ctx->le_mode) { \ |
6210 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6211 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6212 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6213 | } else { \ |
76db3ba4 | 6214 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6215 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6216 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6217 | } \ |
6218 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6219 | } |
6220 | ||
6221 | #define GEN_VR_STX(name, opc2, opc3) \ | |
99e300ef | 6222 | static void gen_st##name(DisasContext *ctx) \ |
a9d9eb8f | 6223 | { \ |
fe1e5c53 | 6224 | TCGv EA; \ |
a9d9eb8f | 6225 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6226 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6227 | return; \ |
6228 | } \ | |
76db3ba4 | 6229 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6230 | EA = tcg_temp_new(); \ |
76db3ba4 | 6231 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6232 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6233 | if (ctx->le_mode) { \ |
6234 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6235 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6236 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6237 | } else { \ |
76db3ba4 | 6238 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6239 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6240 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6241 | } \ |
6242 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6243 | } |
6244 | ||
cbfb6ae9 | 6245 | #define GEN_VR_LVE(name, opc2, opc3) \ |
99e300ef | 6246 | static void gen_lve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6247 | { \ |
6248 | TCGv EA; \ | |
6249 | TCGv_ptr rs; \ | |
6250 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6251 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6252 | return; \ | |
6253 | } \ | |
6254 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6255 | EA = tcg_temp_new(); \ | |
6256 | gen_addr_reg_index(ctx, EA); \ | |
6257 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
6258 | gen_helper_lve##name (rs, EA); \ | |
6259 | tcg_temp_free(EA); \ | |
6260 | tcg_temp_free_ptr(rs); \ | |
6261 | } | |
6262 | ||
6263 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
99e300ef | 6264 | static void gen_stve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6265 | { \ |
6266 | TCGv EA; \ | |
6267 | TCGv_ptr rs; \ | |
6268 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6269 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6270 | return; \ | |
6271 | } \ | |
6272 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6273 | EA = tcg_temp_new(); \ | |
6274 | gen_addr_reg_index(ctx, EA); \ | |
6275 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
6276 | gen_helper_stve##name (rs, EA); \ | |
6277 | tcg_temp_free(EA); \ | |
6278 | tcg_temp_free_ptr(rs); \ | |
6279 | } | |
6280 | ||
fe1e5c53 | 6281 | GEN_VR_LDX(lvx, 0x07, 0x03); |
a9d9eb8f | 6282 | /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */ |
fe1e5c53 | 6283 | GEN_VR_LDX(lvxl, 0x07, 0x0B); |
a9d9eb8f | 6284 | |
cbfb6ae9 AJ |
6285 | GEN_VR_LVE(bx, 0x07, 0x00); |
6286 | GEN_VR_LVE(hx, 0x07, 0x01); | |
6287 | GEN_VR_LVE(wx, 0x07, 0x02); | |
6288 | ||
fe1e5c53 | 6289 | GEN_VR_STX(svx, 0x07, 0x07); |
a9d9eb8f | 6290 | /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */ |
fe1e5c53 | 6291 | GEN_VR_STX(svxl, 0x07, 0x0F); |
a9d9eb8f | 6292 | |
cbfb6ae9 AJ |
6293 | GEN_VR_STVE(bx, 0x07, 0x04); |
6294 | GEN_VR_STVE(hx, 0x07, 0x05); | |
6295 | GEN_VR_STVE(wx, 0x07, 0x06); | |
6296 | ||
99e300ef | 6297 | static void gen_lvsl(DisasContext *ctx) |
bf8d8ded AJ |
6298 | { |
6299 | TCGv_ptr rd; | |
6300 | TCGv EA; | |
6301 | if (unlikely(!ctx->altivec_enabled)) { | |
6302 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6303 | return; | |
6304 | } | |
6305 | EA = tcg_temp_new(); | |
6306 | gen_addr_reg_index(ctx, EA); | |
6307 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6308 | gen_helper_lvsl(rd, EA); | |
6309 | tcg_temp_free(EA); | |
6310 | tcg_temp_free_ptr(rd); | |
6311 | } | |
6312 | ||
99e300ef | 6313 | static void gen_lvsr(DisasContext *ctx) |
bf8d8ded AJ |
6314 | { |
6315 | TCGv_ptr rd; | |
6316 | TCGv EA; | |
6317 | if (unlikely(!ctx->altivec_enabled)) { | |
6318 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6319 | return; | |
6320 | } | |
6321 | EA = tcg_temp_new(); | |
6322 | gen_addr_reg_index(ctx, EA); | |
6323 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6324 | gen_helper_lvsr(rd, EA); | |
6325 | tcg_temp_free(EA); | |
6326 | tcg_temp_free_ptr(rd); | |
6327 | } | |
6328 | ||
99e300ef | 6329 | static void gen_mfvscr(DisasContext *ctx) |
785f451b AJ |
6330 | { |
6331 | TCGv_i32 t; | |
6332 | if (unlikely(!ctx->altivec_enabled)) { | |
6333 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6334 | return; | |
6335 | } | |
6336 | tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0); | |
6337 | t = tcg_temp_new_i32(); | |
6338 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, vscr)); | |
6339 | tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t); | |
fce5ecb7 | 6340 | tcg_temp_free_i32(t); |
785f451b AJ |
6341 | } |
6342 | ||
99e300ef | 6343 | static void gen_mtvscr(DisasContext *ctx) |
785f451b | 6344 | { |
6e87b7c7 | 6345 | TCGv_ptr p; |
785f451b AJ |
6346 | if (unlikely(!ctx->altivec_enabled)) { |
6347 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6348 | return; | |
6349 | } | |
6e87b7c7 AJ |
6350 | p = gen_avr_ptr(rD(ctx->opcode)); |
6351 | gen_helper_mtvscr(p); | |
6352 | tcg_temp_free_ptr(p); | |
785f451b AJ |
6353 | } |
6354 | ||
7a9b96cf AJ |
6355 | /* Logical operations */ |
6356 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
99e300ef | 6357 | static void glue(gen_, name)(DisasContext *ctx) \ |
7a9b96cf AJ |
6358 | { \ |
6359 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6360 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6361 | return; \ | |
6362 | } \ | |
6363 | tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \ | |
6364 | tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \ | |
6365 | } | |
6366 | ||
6367 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16); | |
6368 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17); | |
6369 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18); | |
6370 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19); | |
6371 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20); | |
6372 | ||
8e27dd6f | 6373 | #define GEN_VXFORM(name, opc2, opc3) \ |
99e300ef | 6374 | static void glue(gen_, name)(DisasContext *ctx) \ |
8e27dd6f AJ |
6375 | { \ |
6376 | TCGv_ptr ra, rb, rd; \ | |
6377 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6378 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6379 | return; \ | |
6380 | } \ | |
6381 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6382 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6383 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6384 | gen_helper_##name (rd, ra, rb); \ | |
6385 | tcg_temp_free_ptr(ra); \ | |
6386 | tcg_temp_free_ptr(rb); \ | |
6387 | tcg_temp_free_ptr(rd); \ | |
6388 | } | |
6389 | ||
7872c51c AJ |
6390 | GEN_VXFORM(vaddubm, 0, 0); |
6391 | GEN_VXFORM(vadduhm, 0, 1); | |
6392 | GEN_VXFORM(vadduwm, 0, 2); | |
6393 | GEN_VXFORM(vsububm, 0, 16); | |
6394 | GEN_VXFORM(vsubuhm, 0, 17); | |
6395 | GEN_VXFORM(vsubuwm, 0, 18); | |
e4039339 AJ |
6396 | GEN_VXFORM(vmaxub, 1, 0); |
6397 | GEN_VXFORM(vmaxuh, 1, 1); | |
6398 | GEN_VXFORM(vmaxuw, 1, 2); | |
6399 | GEN_VXFORM(vmaxsb, 1, 4); | |
6400 | GEN_VXFORM(vmaxsh, 1, 5); | |
6401 | GEN_VXFORM(vmaxsw, 1, 6); | |
6402 | GEN_VXFORM(vminub, 1, 8); | |
6403 | GEN_VXFORM(vminuh, 1, 9); | |
6404 | GEN_VXFORM(vminuw, 1, 10); | |
6405 | GEN_VXFORM(vminsb, 1, 12); | |
6406 | GEN_VXFORM(vminsh, 1, 13); | |
6407 | GEN_VXFORM(vminsw, 1, 14); | |
fab3cbe9 AJ |
6408 | GEN_VXFORM(vavgub, 1, 16); |
6409 | GEN_VXFORM(vavguh, 1, 17); | |
6410 | GEN_VXFORM(vavguw, 1, 18); | |
6411 | GEN_VXFORM(vavgsb, 1, 20); | |
6412 | GEN_VXFORM(vavgsh, 1, 21); | |
6413 | GEN_VXFORM(vavgsw, 1, 22); | |
3b430048 AJ |
6414 | GEN_VXFORM(vmrghb, 6, 0); |
6415 | GEN_VXFORM(vmrghh, 6, 1); | |
6416 | GEN_VXFORM(vmrghw, 6, 2); | |
6417 | GEN_VXFORM(vmrglb, 6, 4); | |
6418 | GEN_VXFORM(vmrglh, 6, 5); | |
6419 | GEN_VXFORM(vmrglw, 6, 6); | |
2c277908 AJ |
6420 | GEN_VXFORM(vmuloub, 4, 0); |
6421 | GEN_VXFORM(vmulouh, 4, 1); | |
6422 | GEN_VXFORM(vmulosb, 4, 4); | |
6423 | GEN_VXFORM(vmulosh, 4, 5); | |
6424 | GEN_VXFORM(vmuleub, 4, 8); | |
6425 | GEN_VXFORM(vmuleuh, 4, 9); | |
6426 | GEN_VXFORM(vmulesb, 4, 12); | |
6427 | GEN_VXFORM(vmulesh, 4, 13); | |
d79f0809 AJ |
6428 | GEN_VXFORM(vslb, 2, 4); |
6429 | GEN_VXFORM(vslh, 2, 5); | |
6430 | GEN_VXFORM(vslw, 2, 6); | |
07ef34c3 AJ |
6431 | GEN_VXFORM(vsrb, 2, 8); |
6432 | GEN_VXFORM(vsrh, 2, 9); | |
6433 | GEN_VXFORM(vsrw, 2, 10); | |
6434 | GEN_VXFORM(vsrab, 2, 12); | |
6435 | GEN_VXFORM(vsrah, 2, 13); | |
6436 | GEN_VXFORM(vsraw, 2, 14); | |
7b239bec AJ |
6437 | GEN_VXFORM(vslo, 6, 16); |
6438 | GEN_VXFORM(vsro, 6, 17); | |
e343da72 AJ |
6439 | GEN_VXFORM(vaddcuw, 0, 6); |
6440 | GEN_VXFORM(vsubcuw, 0, 22); | |
5ab09f33 AJ |
6441 | GEN_VXFORM(vaddubs, 0, 8); |
6442 | GEN_VXFORM(vadduhs, 0, 9); | |
6443 | GEN_VXFORM(vadduws, 0, 10); | |
6444 | GEN_VXFORM(vaddsbs, 0, 12); | |
6445 | GEN_VXFORM(vaddshs, 0, 13); | |
6446 | GEN_VXFORM(vaddsws, 0, 14); | |
6447 | GEN_VXFORM(vsububs, 0, 24); | |
6448 | GEN_VXFORM(vsubuhs, 0, 25); | |
6449 | GEN_VXFORM(vsubuws, 0, 26); | |
6450 | GEN_VXFORM(vsubsbs, 0, 28); | |
6451 | GEN_VXFORM(vsubshs, 0, 29); | |
6452 | GEN_VXFORM(vsubsws, 0, 30); | |
5e1d0985 AJ |
6453 | GEN_VXFORM(vrlb, 2, 0); |
6454 | GEN_VXFORM(vrlh, 2, 1); | |
6455 | GEN_VXFORM(vrlw, 2, 2); | |
d9430add AJ |
6456 | GEN_VXFORM(vsl, 2, 7); |
6457 | GEN_VXFORM(vsr, 2, 11); | |
5335a145 AJ |
6458 | GEN_VXFORM(vpkuhum, 7, 0); |
6459 | GEN_VXFORM(vpkuwum, 7, 1); | |
6460 | GEN_VXFORM(vpkuhus, 7, 2); | |
6461 | GEN_VXFORM(vpkuwus, 7, 3); | |
6462 | GEN_VXFORM(vpkshus, 7, 4); | |
6463 | GEN_VXFORM(vpkswus, 7, 5); | |
6464 | GEN_VXFORM(vpkshss, 7, 6); | |
6465 | GEN_VXFORM(vpkswss, 7, 7); | |
1dd9ffb9 | 6466 | GEN_VXFORM(vpkpx, 7, 12); |
8142cddd AJ |
6467 | GEN_VXFORM(vsum4ubs, 4, 24); |
6468 | GEN_VXFORM(vsum4sbs, 4, 28); | |
6469 | GEN_VXFORM(vsum4shs, 4, 25); | |
6470 | GEN_VXFORM(vsum2sws, 4, 26); | |
6471 | GEN_VXFORM(vsumsws, 4, 30); | |
56fdd213 AJ |
6472 | GEN_VXFORM(vaddfp, 5, 0); |
6473 | GEN_VXFORM(vsubfp, 5, 1); | |
1536ff64 AJ |
6474 | GEN_VXFORM(vmaxfp, 5, 16); |
6475 | GEN_VXFORM(vminfp, 5, 17); | |
fab3cbe9 | 6476 | |
0cbcd906 | 6477 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ |
e8eaa2c0 | 6478 | static void glue(gen_, name)(DisasContext *ctx) \ |
0cbcd906 AJ |
6479 | { \ |
6480 | TCGv_ptr ra, rb, rd; \ | |
6481 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6482 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6483 | return; \ | |
6484 | } \ | |
6485 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6486 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6487 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6488 | gen_helper_##opname (rd, ra, rb); \ | |
6489 | tcg_temp_free_ptr(ra); \ | |
6490 | tcg_temp_free_ptr(rb); \ | |
6491 | tcg_temp_free_ptr(rd); \ | |
6492 | } | |
6493 | ||
6494 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
6495 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
6496 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
6497 | ||
1add6e23 AJ |
6498 | GEN_VXRFORM(vcmpequb, 3, 0) |
6499 | GEN_VXRFORM(vcmpequh, 3, 1) | |
6500 | GEN_VXRFORM(vcmpequw, 3, 2) | |
6501 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
6502 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
6503 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
6504 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
6505 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
6506 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
819ca121 AJ |
6507 | GEN_VXRFORM(vcmpeqfp, 3, 3) |
6508 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
6509 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
6510 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
1add6e23 | 6511 | |
c026766b | 6512 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6513 | static void glue(gen_, name)(DisasContext *ctx) \ |
c026766b AJ |
6514 | { \ |
6515 | TCGv_ptr rd; \ | |
6516 | TCGv_i32 simm; \ | |
6517 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6518 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6519 | return; \ | |
6520 | } \ | |
6521 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6522 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6523 | gen_helper_##name (rd, simm); \ | |
6524 | tcg_temp_free_i32(simm); \ | |
6525 | tcg_temp_free_ptr(rd); \ | |
6526 | } | |
6527 | ||
6528 | GEN_VXFORM_SIMM(vspltisb, 6, 12); | |
6529 | GEN_VXFORM_SIMM(vspltish, 6, 13); | |
6530 | GEN_VXFORM_SIMM(vspltisw, 6, 14); | |
6531 | ||
de5f2484 | 6532 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ |
99e300ef | 6533 | static void glue(gen_, name)(DisasContext *ctx) \ |
de5f2484 AJ |
6534 | { \ |
6535 | TCGv_ptr rb, rd; \ | |
6536 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6537 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6538 | return; \ | |
6539 | } \ | |
6540 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6541 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6542 | gen_helper_##name (rd, rb); \ | |
6543 | tcg_temp_free_ptr(rb); \ | |
6544 | tcg_temp_free_ptr(rd); \ | |
6545 | } | |
6546 | ||
6cf1c6e5 AJ |
6547 | GEN_VXFORM_NOA(vupkhsb, 7, 8); |
6548 | GEN_VXFORM_NOA(vupkhsh, 7, 9); | |
6549 | GEN_VXFORM_NOA(vupklsb, 7, 10); | |
6550 | GEN_VXFORM_NOA(vupklsh, 7, 11); | |
79f85c3a AJ |
6551 | GEN_VXFORM_NOA(vupkhpx, 7, 13); |
6552 | GEN_VXFORM_NOA(vupklpx, 7, 15); | |
bdfbac35 | 6553 | GEN_VXFORM_NOA(vrefp, 5, 4); |
071fc3b1 | 6554 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5); |
0bffbc6c | 6555 | GEN_VXFORM_NOA(vexptefp, 5, 6); |
b580763f | 6556 | GEN_VXFORM_NOA(vlogefp, 5, 7); |
f6b19645 AJ |
6557 | GEN_VXFORM_NOA(vrfim, 5, 8); |
6558 | GEN_VXFORM_NOA(vrfin, 5, 9); | |
6559 | GEN_VXFORM_NOA(vrfip, 5, 10); | |
6560 | GEN_VXFORM_NOA(vrfiz, 5, 11); | |
79f85c3a | 6561 | |
21d21583 | 6562 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6563 | static void glue(gen_, name)(DisasContext *ctx) \ |
21d21583 AJ |
6564 | { \ |
6565 | TCGv_ptr rd; \ | |
6566 | TCGv_i32 simm; \ | |
6567 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6568 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6569 | return; \ | |
6570 | } \ | |
6571 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6572 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6573 | gen_helper_##name (rd, simm); \ | |
6574 | tcg_temp_free_i32(simm); \ | |
6575 | tcg_temp_free_ptr(rd); \ | |
6576 | } | |
6577 | ||
27a4edb3 | 6578 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ |
99e300ef | 6579 | static void glue(gen_, name)(DisasContext *ctx) \ |
27a4edb3 AJ |
6580 | { \ |
6581 | TCGv_ptr rb, rd; \ | |
6582 | TCGv_i32 uimm; \ | |
6583 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6584 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6585 | return; \ | |
6586 | } \ | |
6587 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6588 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6589 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6590 | gen_helper_##name (rd, rb, uimm); \ | |
6591 | tcg_temp_free_i32(uimm); \ | |
6592 | tcg_temp_free_ptr(rb); \ | |
6593 | tcg_temp_free_ptr(rd); \ | |
6594 | } | |
6595 | ||
e4e6bee7 AJ |
6596 | GEN_VXFORM_UIMM(vspltb, 6, 8); |
6597 | GEN_VXFORM_UIMM(vsplth, 6, 9); | |
6598 | GEN_VXFORM_UIMM(vspltw, 6, 10); | |
e140632e AJ |
6599 | GEN_VXFORM_UIMM(vcfux, 5, 12); |
6600 | GEN_VXFORM_UIMM(vcfsx, 5, 13); | |
875b31db AJ |
6601 | GEN_VXFORM_UIMM(vctuxs, 5, 14); |
6602 | GEN_VXFORM_UIMM(vctsxs, 5, 15); | |
e4e6bee7 | 6603 | |
99e300ef | 6604 | static void gen_vsldoi(DisasContext *ctx) |
cd633b10 AJ |
6605 | { |
6606 | TCGv_ptr ra, rb, rd; | |
fce5ecb7 | 6607 | TCGv_i32 sh; |
cd633b10 AJ |
6608 | if (unlikely(!ctx->altivec_enabled)) { |
6609 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6610 | return; | |
6611 | } | |
6612 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6613 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6614 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6615 | sh = tcg_const_i32(VSH(ctx->opcode)); | |
6616 | gen_helper_vsldoi (rd, ra, rb, sh); | |
6617 | tcg_temp_free_ptr(ra); | |
6618 | tcg_temp_free_ptr(rb); | |
6619 | tcg_temp_free_ptr(rd); | |
fce5ecb7 | 6620 | tcg_temp_free_i32(sh); |
cd633b10 AJ |
6621 | } |
6622 | ||
707cec33 | 6623 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ |
99e300ef | 6624 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
707cec33 AJ |
6625 | { \ |
6626 | TCGv_ptr ra, rb, rc, rd; \ | |
6627 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6628 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6629 | return; \ | |
6630 | } \ | |
6631 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6632 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6633 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
6634 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6635 | if (Rc(ctx->opcode)) { \ | |
6636 | gen_helper_##name1 (rd, ra, rb, rc); \ | |
6637 | } else { \ | |
6638 | gen_helper_##name0 (rd, ra, rb, rc); \ | |
6639 | } \ | |
6640 | tcg_temp_free_ptr(ra); \ | |
6641 | tcg_temp_free_ptr(rb); \ | |
6642 | tcg_temp_free_ptr(rc); \ | |
6643 | tcg_temp_free_ptr(rd); \ | |
6644 | } | |
6645 | ||
b161ae27 AJ |
6646 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16) |
6647 | ||
99e300ef | 6648 | static void gen_vmladduhm(DisasContext *ctx) |
bcd2ee23 AJ |
6649 | { |
6650 | TCGv_ptr ra, rb, rc, rd; | |
6651 | if (unlikely(!ctx->altivec_enabled)) { | |
6652 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6653 | return; | |
6654 | } | |
6655 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
6656 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
6657 | rc = gen_avr_ptr(rC(ctx->opcode)); | |
6658 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6659 | gen_helper_vmladduhm(rd, ra, rb, rc); | |
6660 | tcg_temp_free_ptr(ra); | |
6661 | tcg_temp_free_ptr(rb); | |
6662 | tcg_temp_free_ptr(rc); | |
6663 | tcg_temp_free_ptr(rd); | |
6664 | } | |
6665 | ||
b04ae981 | 6666 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18) |
4d9903b6 | 6667 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19) |
eae07261 | 6668 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20) |
d1258698 | 6669 | GEN_VAFORM_PAIRED(vsel, vperm, 21) |
35cf7c7e | 6670 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23) |
b04ae981 | 6671 | |
0487d6a8 | 6672 | /*** SPE extension ***/ |
0487d6a8 | 6673 | /* Register moves */ |
3cd7d1dd | 6674 | |
a0e13900 FC |
6675 | |
6676 | static inline void gen_evmra(DisasContext *ctx) | |
6677 | { | |
6678 | ||
6679 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 6680 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
6681 | return; |
6682 | } | |
6683 | ||
6684 | #if defined(TARGET_PPC64) | |
6685 | /* rD := rA */ | |
6686 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6687 | ||
6688 | /* spe_acc := rA */ | |
6689 | tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)], | |
6690 | cpu_env, | |
6691 | offsetof(CPUState, spe_acc)); | |
6692 | #else | |
6693 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
6694 | ||
6695 | /* tmp := rA_lo + rA_hi << 32 */ | |
6696 | tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6697 | ||
6698 | /* spe_acc := tmp */ | |
6699 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc)); | |
6700 | tcg_temp_free_i64(tmp); | |
6701 | ||
6702 | /* rD := rA */ | |
6703 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
6704 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
6705 | #endif | |
6706 | } | |
6707 | ||
636aa200 BS |
6708 | static inline void gen_load_gpr64(TCGv_i64 t, int reg) |
6709 | { | |
f78fb44e AJ |
6710 | #if defined(TARGET_PPC64) |
6711 | tcg_gen_mov_i64(t, cpu_gpr[reg]); | |
6712 | #else | |
36aa55dc | 6713 | tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]); |
3cd7d1dd | 6714 | #endif |
f78fb44e | 6715 | } |
3cd7d1dd | 6716 | |
636aa200 BS |
6717 | static inline void gen_store_gpr64(int reg, TCGv_i64 t) |
6718 | { | |
f78fb44e AJ |
6719 | #if defined(TARGET_PPC64) |
6720 | tcg_gen_mov_i64(cpu_gpr[reg], t); | |
6721 | #else | |
a7812ae4 | 6722 | TCGv_i64 tmp = tcg_temp_new_i64(); |
f78fb44e | 6723 | tcg_gen_trunc_i64_i32(cpu_gpr[reg], t); |
f78fb44e AJ |
6724 | tcg_gen_shri_i64(tmp, t, 32); |
6725 | tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp); | |
a7812ae4 | 6726 | tcg_temp_free_i64(tmp); |
3cd7d1dd | 6727 | #endif |
f78fb44e | 6728 | } |
3cd7d1dd | 6729 | |
70560da7 | 6730 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
99e300ef | 6731 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
0487d6a8 JM |
6732 | { \ |
6733 | if (Rc(ctx->opcode)) \ | |
6734 | gen_##name1(ctx); \ | |
6735 | else \ | |
6736 | gen_##name0(ctx); \ | |
6737 | } | |
6738 | ||
6739 | /* Handler for undefined SPE opcodes */ | |
636aa200 | 6740 | static inline void gen_speundef(DisasContext *ctx) |
0487d6a8 | 6741 | { |
e06fcd75 | 6742 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
0487d6a8 JM |
6743 | } |
6744 | ||
57951c27 AJ |
6745 | /* SPE logic */ |
6746 | #if defined(TARGET_PPC64) | |
6747 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6748 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6749 | { \ |
6750 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6751 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6752 | return; \ |
6753 | } \ | |
57951c27 AJ |
6754 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6755 | cpu_gpr[rB(ctx->opcode)]); \ | |
6756 | } | |
6757 | #else | |
6758 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 6759 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
6760 | { \ |
6761 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6762 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
6763 | return; \ |
6764 | } \ | |
6765 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ | |
6766 | cpu_gpr[rB(ctx->opcode)]); \ | |
6767 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6768 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 6769 | } |
57951c27 AJ |
6770 | #endif |
6771 | ||
6772 | GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl); | |
6773 | GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl); | |
6774 | GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl); | |
6775 | GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl); | |
6776 | GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl); | |
6777 | GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl); | |
6778 | GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl); | |
6779 | GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl); | |
0487d6a8 | 6780 | |
57951c27 AJ |
6781 | /* SPE logic immediate */ |
6782 | #if defined(TARGET_PPC64) | |
6783 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6784 | static inline void gen_##name(DisasContext *ctx) \ |
3d3a6a0a AJ |
6785 | { \ |
6786 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6787 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
3d3a6a0a AJ |
6788 | return; \ |
6789 | } \ | |
a7812ae4 PB |
6790 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
6791 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
6792 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
6793 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
6794 | tcg_opi(t0, t0, rB(ctx->opcode)); \ | |
6795 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
6796 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 6797 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
6798 | tcg_opi(t1, t1, rB(ctx->opcode)); \ |
6799 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
6800 | tcg_temp_free_i32(t0); \ |
6801 | tcg_temp_free_i32(t1); \ | |
3d3a6a0a | 6802 | } |
57951c27 AJ |
6803 | #else |
6804 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 6805 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6806 | { \ |
6807 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6808 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6809 | return; \ |
6810 | } \ | |
57951c27 AJ |
6811 | tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6812 | rB(ctx->opcode)); \ | |
6813 | tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6814 | rB(ctx->opcode)); \ | |
0487d6a8 | 6815 | } |
57951c27 AJ |
6816 | #endif |
6817 | GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32); | |
6818 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32); | |
6819 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32); | |
6820 | GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32); | |
0487d6a8 | 6821 | |
57951c27 AJ |
6822 | /* SPE arithmetic */ |
6823 | #if defined(TARGET_PPC64) | |
6824 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ | |
636aa200 | 6825 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6826 | { \ |
6827 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6828 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6829 | return; \ |
6830 | } \ | |
a7812ae4 PB |
6831 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
6832 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
6833 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
6834 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
6835 | tcg_op(t0, t0); \ | |
6836 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
6837 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 6838 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
6839 | tcg_op(t1, t1); \ |
6840 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
6841 | tcg_temp_free_i32(t0); \ |
6842 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 6843 | } |
57951c27 | 6844 | #else |
a7812ae4 | 6845 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ |
636aa200 | 6846 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
6847 | { \ |
6848 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6849 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
6850 | return; \ |
6851 | } \ | |
6852 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \ | |
6853 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \ | |
6854 | } | |
6855 | #endif | |
0487d6a8 | 6856 | |
636aa200 | 6857 | static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1) |
57951c27 AJ |
6858 | { |
6859 | int l1 = gen_new_label(); | |
6860 | int l2 = gen_new_label(); | |
0487d6a8 | 6861 | |
57951c27 AJ |
6862 | tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1); |
6863 | tcg_gen_neg_i32(ret, arg1); | |
6864 | tcg_gen_br(l2); | |
6865 | gen_set_label(l1); | |
a7812ae4 | 6866 | tcg_gen_mov_i32(ret, arg1); |
57951c27 AJ |
6867 | gen_set_label(l2); |
6868 | } | |
6869 | GEN_SPEOP_ARITH1(evabs, gen_op_evabs); | |
6870 | GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32); | |
6871 | GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32); | |
6872 | GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32); | |
636aa200 | 6873 | static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1) |
0487d6a8 | 6874 | { |
57951c27 AJ |
6875 | tcg_gen_addi_i32(ret, arg1, 0x8000); |
6876 | tcg_gen_ext16u_i32(ret, ret); | |
6877 | } | |
6878 | GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw); | |
a7812ae4 PB |
6879 | GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32); |
6880 | GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32); | |
0487d6a8 | 6881 | |
57951c27 AJ |
6882 | #if defined(TARGET_PPC64) |
6883 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 6884 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6885 | { \ |
6886 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6887 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6888 | return; \ |
6889 | } \ | |
a7812ae4 PB |
6890 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
6891 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
6892 | TCGv_i32 t2 = tcg_temp_local_new_i32(); \ | |
501e23c4 | 6893 | TCGv_i64 t3 = tcg_temp_local_new_i64(); \ |
57951c27 AJ |
6894 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
6895 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \ | |
6896 | tcg_op(t0, t0, t2); \ | |
6897 | tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \ | |
6898 | tcg_gen_trunc_i64_i32(t1, t3); \ | |
6899 | tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \ | |
6900 | tcg_gen_trunc_i64_i32(t2, t3); \ | |
a7812ae4 | 6901 | tcg_temp_free_i64(t3); \ |
57951c27 | 6902 | tcg_op(t1, t1, t2); \ |
a7812ae4 | 6903 | tcg_temp_free_i32(t2); \ |
57951c27 | 6904 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ |
a7812ae4 PB |
6905 | tcg_temp_free_i32(t0); \ |
6906 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 6907 | } |
57951c27 AJ |
6908 | #else |
6909 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 6910 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
6911 | { \ |
6912 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 6913 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
6914 | return; \ |
6915 | } \ | |
57951c27 AJ |
6916 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
6917 | cpu_gpr[rB(ctx->opcode)]); \ | |
6918 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
6919 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 6920 | } |
57951c27 | 6921 | #endif |
0487d6a8 | 6922 | |
636aa200 | 6923 | static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 6924 | { |
a7812ae4 | 6925 | TCGv_i32 t0; |
57951c27 | 6926 | int l1, l2; |
0487d6a8 | 6927 | |
57951c27 AJ |
6928 | l1 = gen_new_label(); |
6929 | l2 = gen_new_label(); | |
a7812ae4 | 6930 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
6931 | /* No error here: 6 bits are used */ |
6932 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
6933 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
6934 | tcg_gen_shr_i32(ret, arg1, t0); | |
6935 | tcg_gen_br(l2); | |
6936 | gen_set_label(l1); | |
6937 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 6938 | gen_set_label(l2); |
a7812ae4 | 6939 | tcg_temp_free_i32(t0); |
57951c27 AJ |
6940 | } |
6941 | GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu); | |
636aa200 | 6942 | static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 6943 | { |
a7812ae4 | 6944 | TCGv_i32 t0; |
57951c27 AJ |
6945 | int l1, l2; |
6946 | ||
6947 | l1 = gen_new_label(); | |
6948 | l2 = gen_new_label(); | |
a7812ae4 | 6949 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
6950 | /* No error here: 6 bits are used */ |
6951 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
6952 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
6953 | tcg_gen_sar_i32(ret, arg1, t0); | |
6954 | tcg_gen_br(l2); | |
6955 | gen_set_label(l1); | |
6956 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 6957 | gen_set_label(l2); |
a7812ae4 | 6958 | tcg_temp_free_i32(t0); |
57951c27 AJ |
6959 | } |
6960 | GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws); | |
636aa200 | 6961 | static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 6962 | { |
a7812ae4 | 6963 | TCGv_i32 t0; |
57951c27 AJ |
6964 | int l1, l2; |
6965 | ||
6966 | l1 = gen_new_label(); | |
6967 | l2 = gen_new_label(); | |
a7812ae4 | 6968 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
6969 | /* No error here: 6 bits are used */ |
6970 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
6971 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
6972 | tcg_gen_shl_i32(ret, arg1, t0); | |
6973 | tcg_gen_br(l2); | |
6974 | gen_set_label(l1); | |
6975 | tcg_gen_movi_i32(ret, 0); | |
e29ef9fa | 6976 | gen_set_label(l2); |
a7812ae4 | 6977 | tcg_temp_free_i32(t0); |
57951c27 AJ |
6978 | } |
6979 | GEN_SPEOP_ARITH2(evslw, gen_op_evslw); | |
636aa200 | 6980 | static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 6981 | { |
a7812ae4 | 6982 | TCGv_i32 t0 = tcg_temp_new_i32(); |
57951c27 AJ |
6983 | tcg_gen_andi_i32(t0, arg2, 0x1F); |
6984 | tcg_gen_rotl_i32(ret, arg1, t0); | |
a7812ae4 | 6985 | tcg_temp_free_i32(t0); |
57951c27 AJ |
6986 | } |
6987 | GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw); | |
636aa200 | 6988 | static inline void gen_evmergehi(DisasContext *ctx) |
57951c27 AJ |
6989 | { |
6990 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 6991 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
6992 | return; |
6993 | } | |
6994 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
6995 | TCGv t0 = tcg_temp_new(); |
6996 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
6997 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
6998 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); | |
6999 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7000 | tcg_temp_free(t0); | |
7001 | tcg_temp_free(t1); | |
7002 | #else | |
7003 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7004 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7005 | #endif | |
7006 | } | |
7007 | GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32); | |
636aa200 | 7008 | static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
0487d6a8 | 7009 | { |
57951c27 AJ |
7010 | tcg_gen_sub_i32(ret, arg2, arg1); |
7011 | } | |
7012 | GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf); | |
0487d6a8 | 7013 | |
57951c27 AJ |
7014 | /* SPE arithmetic immediate */ |
7015 | #if defined(TARGET_PPC64) | |
7016 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 7017 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7018 | { \ |
7019 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7020 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
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[rB(ctx->opcode)]); \ |
7027 | tcg_op(t0, t0, rA(ctx->opcode)); \ | |
7028 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7029 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
e06fcd75 | 7030 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7031 | tcg_op(t1, t1, rA(ctx->opcode)); \ |
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); \ | |
57951c27 AJ |
7035 | } |
7036 | #else | |
7037 | #define GEN_SPEOP_ARITH_IMM2(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[rB(ctx->opcode)], \ | |
7045 | rA(ctx->opcode)); \ | |
7046 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \ | |
7047 | rA(ctx->opcode)); \ | |
7048 | } | |
7049 | #endif | |
7050 | GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32); | |
7051 | GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32); | |
7052 | ||
7053 | /* SPE comparison */ | |
7054 | #if defined(TARGET_PPC64) | |
7055 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7056 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7057 | { \ |
7058 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7059 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7060 | return; \ |
7061 | } \ | |
7062 | int l1 = gen_new_label(); \ | |
7063 | int l2 = gen_new_label(); \ | |
7064 | int l3 = gen_new_label(); \ | |
7065 | int l4 = gen_new_label(); \ | |
a7812ae4 PB |
7066 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7067 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7068 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7069 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7070 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
7071 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \ | |
a7812ae4 | 7072 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \ |
57951c27 AJ |
7073 | tcg_gen_br(l2); \ |
7074 | gen_set_label(l1); \ | |
7075 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7076 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7077 | gen_set_label(l2); \ | |
7078 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7079 | tcg_gen_trunc_i64_i32(t0, t2); \ | |
7080 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
7081 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7082 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7083 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \ |
7084 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7085 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7086 | tcg_gen_br(l4); \ | |
7087 | gen_set_label(l3); \ | |
7088 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7089 | CRF_CH | CRF_CH_OR_CL); \ | |
7090 | gen_set_label(l4); \ | |
a7812ae4 PB |
7091 | tcg_temp_free_i32(t0); \ |
7092 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
7093 | } |
7094 | #else | |
7095 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 7096 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7097 | { \ |
7098 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7099 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7100 | return; \ |
7101 | } \ | |
7102 | int l1 = gen_new_label(); \ | |
7103 | int l2 = gen_new_label(); \ | |
7104 | int l3 = gen_new_label(); \ | |
7105 | int l4 = gen_new_label(); \ | |
7106 | \ | |
7107 | tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \ | |
7108 | cpu_gpr[rB(ctx->opcode)], l1); \ | |
7109 | tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \ | |
7110 | tcg_gen_br(l2); \ | |
7111 | gen_set_label(l1); \ | |
7112 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
7113 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
7114 | gen_set_label(l2); \ | |
7115 | tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \ | |
7116 | cpu_gprh[rB(ctx->opcode)], l3); \ | |
7117 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7118 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
7119 | tcg_gen_br(l4); \ | |
7120 | gen_set_label(l3); \ | |
7121 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
7122 | CRF_CH | CRF_CH_OR_CL); \ | |
7123 | gen_set_label(l4); \ | |
7124 | } | |
7125 | #endif | |
7126 | GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU); | |
7127 | GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT); | |
7128 | GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU); | |
7129 | GEN_SPEOP_COMP(evcmplts, TCG_COND_LT); | |
7130 | GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ); | |
7131 | ||
7132 | /* SPE misc */ | |
636aa200 | 7133 | static inline void gen_brinc(DisasContext *ctx) |
57951c27 AJ |
7134 | { |
7135 | /* Note: brinc is usable even if SPE is disabled */ | |
a7812ae4 PB |
7136 | gen_helper_brinc(cpu_gpr[rD(ctx->opcode)], |
7137 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
0487d6a8 | 7138 | } |
636aa200 | 7139 | static inline void gen_evmergelo(DisasContext *ctx) |
57951c27 AJ |
7140 | { |
7141 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7142 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7143 | return; |
7144 | } | |
7145 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7146 | TCGv t0 = tcg_temp_new(); |
7147 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7148 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7149 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); |
7150 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7151 | tcg_temp_free(t0); | |
7152 | tcg_temp_free(t1); | |
7153 | #else | |
57951c27 | 7154 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
33890b3e | 7155 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7156 | #endif |
7157 | } | |
636aa200 | 7158 | static inline void gen_evmergehilo(DisasContext *ctx) |
57951c27 AJ |
7159 | { |
7160 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7161 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7162 | return; |
7163 | } | |
7164 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7165 | TCGv t0 = tcg_temp_new(); |
7166 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 7167 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7168 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); |
7169 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7170 | tcg_temp_free(t0); | |
7171 | tcg_temp_free(t1); | |
7172 | #else | |
7173 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7174 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7175 | #endif | |
7176 | } | |
636aa200 | 7177 | static inline void gen_evmergelohi(DisasContext *ctx) |
57951c27 AJ |
7178 | { |
7179 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7180 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
7181 | return; |
7182 | } | |
7183 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
7184 | TCGv t0 = tcg_temp_new(); |
7185 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
7186 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
7187 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); | |
7188 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
7189 | tcg_temp_free(t0); | |
7190 | tcg_temp_free(t1); | |
7191 | #else | |
33890b3e NF |
7192 | if (rD(ctx->opcode) == rA(ctx->opcode)) { |
7193 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
7194 | tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); | |
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)], tmp); | |
7197 | tcg_temp_free_i32(tmp); | |
7198 | } else { | |
7199 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7200 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7201 | } | |
57951c27 AJ |
7202 | #endif |
7203 | } | |
636aa200 | 7204 | static inline void gen_evsplati(DisasContext *ctx) |
57951c27 | 7205 | { |
ae01847f | 7206 | uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27; |
0487d6a8 | 7207 | |
57951c27 | 7208 | #if defined(TARGET_PPC64) |
38d14952 | 7209 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7210 | #else |
7211 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7212 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7213 | #endif | |
7214 | } | |
636aa200 | 7215 | static inline void gen_evsplatfi(DisasContext *ctx) |
0487d6a8 | 7216 | { |
ae01847f | 7217 | uint64_t imm = rA(ctx->opcode) << 27; |
0487d6a8 | 7218 | |
57951c27 | 7219 | #if defined(TARGET_PPC64) |
38d14952 | 7220 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
7221 | #else |
7222 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
7223 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
7224 | #endif | |
0487d6a8 JM |
7225 | } |
7226 | ||
636aa200 | 7227 | static inline void gen_evsel(DisasContext *ctx) |
57951c27 AJ |
7228 | { |
7229 | int l1 = gen_new_label(); | |
7230 | int l2 = gen_new_label(); | |
7231 | int l3 = gen_new_label(); | |
7232 | int l4 = gen_new_label(); | |
a7812ae4 | 7233 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
57951c27 | 7234 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
7235 | TCGv t1 = tcg_temp_local_new(); |
7236 | TCGv t2 = tcg_temp_local_new(); | |
57951c27 AJ |
7237 | #endif |
7238 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | |
7239 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
7240 | #if defined(TARGET_PPC64) | |
7241 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7242 | #else | |
7243 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7244 | #endif | |
7245 | tcg_gen_br(l2); | |
7246 | gen_set_label(l1); | |
7247 | #if defined(TARGET_PPC64) | |
7248 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
7249 | #else | |
7250 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
7251 | #endif | |
7252 | gen_set_label(l2); | |
7253 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2); | |
7254 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3); | |
7255 | #if defined(TARGET_PPC64) | |
17d9b3af | 7256 | tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]); |
57951c27 AJ |
7257 | #else |
7258 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7259 | #endif | |
7260 | tcg_gen_br(l4); | |
7261 | gen_set_label(l3); | |
7262 | #if defined(TARGET_PPC64) | |
17d9b3af | 7263 | tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
7264 | #else |
7265 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
7266 | #endif | |
7267 | gen_set_label(l4); | |
a7812ae4 | 7268 | tcg_temp_free_i32(t0); |
57951c27 AJ |
7269 | #if defined(TARGET_PPC64) |
7270 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2); | |
7271 | tcg_temp_free(t1); | |
7272 | tcg_temp_free(t2); | |
7273 | #endif | |
7274 | } | |
e8eaa2c0 BS |
7275 | |
7276 | static void gen_evsel0(DisasContext *ctx) | |
57951c27 AJ |
7277 | { |
7278 | gen_evsel(ctx); | |
7279 | } | |
e8eaa2c0 BS |
7280 | |
7281 | static void gen_evsel1(DisasContext *ctx) | |
57951c27 AJ |
7282 | { |
7283 | gen_evsel(ctx); | |
7284 | } | |
e8eaa2c0 BS |
7285 | |
7286 | static void gen_evsel2(DisasContext *ctx) | |
57951c27 AJ |
7287 | { |
7288 | gen_evsel(ctx); | |
7289 | } | |
e8eaa2c0 BS |
7290 | |
7291 | static void gen_evsel3(DisasContext *ctx) | |
57951c27 AJ |
7292 | { |
7293 | gen_evsel(ctx); | |
7294 | } | |
0487d6a8 | 7295 | |
a0e13900 FC |
7296 | /* Multiply */ |
7297 | ||
7298 | static inline void gen_evmwumi(DisasContext *ctx) | |
7299 | { | |
7300 | TCGv_i64 t0, t1; | |
7301 | ||
7302 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7303 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7304 | return; |
7305 | } | |
7306 | ||
7307 | t0 = tcg_temp_new_i64(); | |
7308 | t1 = tcg_temp_new_i64(); | |
7309 | ||
7310 | /* t0 := rA; t1 := rB */ | |
7311 | #if defined(TARGET_PPC64) | |
7312 | tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7313 | tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7314 | #else | |
7315 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7316 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7317 | #endif | |
7318 | ||
7319 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7320 | ||
7321 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7322 | ||
7323 | tcg_temp_free_i64(t0); | |
7324 | tcg_temp_free_i64(t1); | |
7325 | } | |
7326 | ||
7327 | static inline void gen_evmwumia(DisasContext *ctx) | |
7328 | { | |
7329 | TCGv_i64 tmp; | |
7330 | ||
7331 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7332 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7333 | return; |
7334 | } | |
7335 | ||
7336 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7337 | ||
7338 | tmp = tcg_temp_new_i64(); | |
7339 | ||
7340 | /* acc := rD */ | |
7341 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7342 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc)); | |
7343 | tcg_temp_free_i64(tmp); | |
7344 | } | |
7345 | ||
7346 | static inline void gen_evmwumiaa(DisasContext *ctx) | |
7347 | { | |
7348 | TCGv_i64 acc; | |
7349 | TCGv_i64 tmp; | |
7350 | ||
7351 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7352 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7353 | return; |
7354 | } | |
7355 | ||
7356 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
7357 | ||
7358 | acc = tcg_temp_new_i64(); | |
7359 | tmp = tcg_temp_new_i64(); | |
7360 | ||
7361 | /* tmp := rD */ | |
7362 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7363 | ||
7364 | /* Load acc */ | |
7365 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); | |
7366 | ||
7367 | /* acc := tmp + acc */ | |
7368 | tcg_gen_add_i64(acc, acc, tmp); | |
7369 | ||
7370 | /* Store acc */ | |
7371 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); | |
7372 | ||
7373 | /* rD := acc */ | |
7374 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7375 | ||
7376 | tcg_temp_free_i64(acc); | |
7377 | tcg_temp_free_i64(tmp); | |
7378 | } | |
7379 | ||
7380 | static inline void gen_evmwsmi(DisasContext *ctx) | |
7381 | { | |
7382 | TCGv_i64 t0, t1; | |
7383 | ||
7384 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7385 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7386 | return; |
7387 | } | |
7388 | ||
7389 | t0 = tcg_temp_new_i64(); | |
7390 | t1 = tcg_temp_new_i64(); | |
7391 | ||
7392 | /* t0 := rA; t1 := rB */ | |
7393 | #if defined(TARGET_PPC64) | |
7394 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
7395 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
7396 | #else | |
7397 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
7398 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
7399 | #endif | |
7400 | ||
7401 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
7402 | ||
7403 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
7404 | ||
7405 | tcg_temp_free_i64(t0); | |
7406 | tcg_temp_free_i64(t1); | |
7407 | } | |
7408 | ||
7409 | static inline void gen_evmwsmia(DisasContext *ctx) | |
7410 | { | |
7411 | TCGv_i64 tmp; | |
7412 | ||
7413 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7414 | ||
7415 | tmp = tcg_temp_new_i64(); | |
7416 | ||
7417 | /* acc := rD */ | |
7418 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7419 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc)); | |
7420 | ||
7421 | tcg_temp_free_i64(tmp); | |
7422 | } | |
7423 | ||
7424 | static inline void gen_evmwsmiaa(DisasContext *ctx) | |
7425 | { | |
7426 | TCGv_i64 acc = tcg_temp_new_i64(); | |
7427 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
7428 | ||
7429 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
7430 | ||
7431 | acc = tcg_temp_new_i64(); | |
7432 | tmp = tcg_temp_new_i64(); | |
7433 | ||
7434 | /* tmp := rD */ | |
7435 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
7436 | ||
7437 | /* Load acc */ | |
7438 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); | |
7439 | ||
7440 | /* acc := tmp + acc */ | |
7441 | tcg_gen_add_i64(acc, acc, tmp); | |
7442 | ||
7443 | /* Store acc */ | |
7444 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc)); | |
7445 | ||
7446 | /* rD := acc */ | |
7447 | gen_store_gpr64(rD(ctx->opcode), acc); | |
7448 | ||
7449 | tcg_temp_free_i64(acc); | |
7450 | tcg_temp_free_i64(tmp); | |
7451 | } | |
7452 | ||
70560da7 FC |
7453 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// |
7454 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7455 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7456 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7457 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7458 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7459 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
7460 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); // | |
7461 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE); | |
7462 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7463 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7464 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7465 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7466 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7467 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7468 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
7469 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
7470 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7471 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7472 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE); | |
7473 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
7474 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7475 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); // | |
7476 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE); | |
7477 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7478 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
7479 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7480 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
7481 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); //// | |
0487d6a8 | 7482 | |
6a6ae23f | 7483 | /* SPE load and stores */ |
636aa200 | 7484 | static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh) |
6a6ae23f AJ |
7485 | { |
7486 | target_ulong uimm = rB(ctx->opcode); | |
7487 | ||
76db3ba4 | 7488 | if (rA(ctx->opcode) == 0) { |
6a6ae23f | 7489 | tcg_gen_movi_tl(EA, uimm << sh); |
76db3ba4 | 7490 | } else { |
6a6ae23f | 7491 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh); |
76db3ba4 AJ |
7492 | #if defined(TARGET_PPC64) |
7493 | if (!ctx->sf_mode) { | |
7494 | tcg_gen_ext32u_tl(EA, EA); | |
7495 | } | |
7496 | #endif | |
7497 | } | |
0487d6a8 | 7498 | } |
6a6ae23f | 7499 | |
636aa200 | 7500 | static inline void gen_op_evldd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7501 | { |
7502 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7503 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
6a6ae23f AJ |
7504 | #else |
7505 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
76db3ba4 | 7506 | gen_qemu_ld64(ctx, t0, addr); |
6a6ae23f AJ |
7507 | tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0); |
7508 | tcg_gen_shri_i64(t0, t0, 32); | |
7509 | tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0); | |
7510 | tcg_temp_free_i64(t0); | |
7511 | #endif | |
0487d6a8 | 7512 | } |
6a6ae23f | 7513 | |
636aa200 | 7514 | static inline void gen_op_evldw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7515 | { |
0487d6a8 | 7516 | #if defined(TARGET_PPC64) |
6a6ae23f | 7517 | TCGv t0 = tcg_temp_new(); |
76db3ba4 | 7518 | gen_qemu_ld32u(ctx, t0, addr); |
6a6ae23f | 7519 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
76db3ba4 AJ |
7520 | gen_addr_add(ctx, addr, addr, 4); |
7521 | gen_qemu_ld32u(ctx, t0, addr); | |
6a6ae23f AJ |
7522 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7523 | tcg_temp_free(t0); | |
7524 | #else | |
76db3ba4 AJ |
7525 | gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7526 | gen_addr_add(ctx, addr, addr, 4); | |
7527 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f | 7528 | #endif |
0487d6a8 | 7529 | } |
6a6ae23f | 7530 | |
636aa200 | 7531 | static inline void gen_op_evldh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7532 | { |
7533 | TCGv t0 = tcg_temp_new(); | |
7534 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7535 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7536 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7537 | gen_addr_add(ctx, addr, addr, 2); |
7538 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7539 | tcg_gen_shli_tl(t0, t0, 32); |
7540 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7541 | gen_addr_add(ctx, addr, addr, 2); |
7542 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7543 | tcg_gen_shli_tl(t0, t0, 16); |
7544 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7545 | gen_addr_add(ctx, addr, addr, 2); |
7546 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7547 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7548 | #else |
76db3ba4 | 7549 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7550 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7551 | gen_addr_add(ctx, addr, addr, 2); |
7552 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7553 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7554 | gen_addr_add(ctx, addr, addr, 2); |
7555 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7556 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7557 | gen_addr_add(ctx, addr, addr, 2); |
7558 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 7559 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 7560 | #endif |
6a6ae23f | 7561 | tcg_temp_free(t0); |
0487d6a8 JM |
7562 | } |
7563 | ||
636aa200 | 7564 | static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7565 | { |
7566 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7567 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7568 | #if defined(TARGET_PPC64) |
7569 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); | |
7570 | tcg_gen_shli_tl(t0, t0, 16); | |
7571 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7572 | #else | |
7573 | tcg_gen_shli_tl(t0, t0, 16); | |
7574 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7575 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7576 | #endif | |
7577 | tcg_temp_free(t0); | |
0487d6a8 JM |
7578 | } |
7579 | ||
636aa200 | 7580 | static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7581 | { |
7582 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7583 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7584 | #if defined(TARGET_PPC64) |
7585 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
7586 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7587 | #else | |
7588 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7589 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7590 | #endif | |
7591 | tcg_temp_free(t0); | |
0487d6a8 JM |
7592 | } |
7593 | ||
636aa200 | 7594 | static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7595 | { |
7596 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7597 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f AJ |
7598 | #if defined(TARGET_PPC64) |
7599 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
7600 | tcg_gen_ext32u_tl(t0, t0); | |
7601 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7602 | #else | |
7603 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7604 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7605 | #endif | |
7606 | tcg_temp_free(t0); | |
7607 | } | |
7608 | ||
636aa200 | 7609 | static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7610 | { |
7611 | TCGv t0 = tcg_temp_new(); | |
7612 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7613 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7614 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
7615 | gen_addr_add(ctx, addr, addr, 2); |
7616 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7617 | tcg_gen_shli_tl(t0, t0, 16); |
7618 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7619 | #else | |
76db3ba4 | 7620 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 7621 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
7622 | gen_addr_add(ctx, addr, addr, 2); |
7623 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7624 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7625 | #endif | |
7626 | tcg_temp_free(t0); | |
7627 | } | |
7628 | ||
636aa200 | 7629 | static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7630 | { |
7631 | #if defined(TARGET_PPC64) | |
7632 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 AJ |
7633 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
7634 | gen_addr_add(ctx, addr, addr, 2); | |
7635 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7636 | tcg_gen_shli_tl(t0, t0, 32); |
7637 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7638 | tcg_temp_free(t0); | |
7639 | #else | |
76db3ba4 AJ |
7640 | gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7641 | gen_addr_add(ctx, addr, addr, 2); | |
7642 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7643 | #endif |
7644 | } | |
7645 | ||
636aa200 | 7646 | static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7647 | { |
7648 | #if defined(TARGET_PPC64) | |
7649 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7650 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f | 7651 | tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
7652 | gen_addr_add(ctx, addr, addr, 2); |
7653 | gen_qemu_ld16s(ctx, t0, addr); | |
6a6ae23f AJ |
7654 | tcg_gen_shli_tl(t0, t0, 32); |
7655 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7656 | tcg_temp_free(t0); | |
7657 | #else | |
76db3ba4 AJ |
7658 | gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
7659 | gen_addr_add(ctx, addr, addr, 2); | |
7660 | gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
7661 | #endif |
7662 | } | |
7663 | ||
636aa200 | 7664 | static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7665 | { |
7666 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 7667 | gen_qemu_ld32u(ctx, t0, addr); |
0487d6a8 | 7668 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7669 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
7670 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7671 | #else | |
7672 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
7673 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
7674 | #endif | |
7675 | tcg_temp_free(t0); | |
7676 | } | |
7677 | ||
636aa200 | 7678 | static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7679 | { |
7680 | TCGv t0 = tcg_temp_new(); | |
7681 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7682 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7683 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
7684 | tcg_gen_shli_tl(t0, t0, 32); | |
7685 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7686 | gen_addr_add(ctx, addr, addr, 2); |
7687 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7688 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
7689 | tcg_gen_shli_tl(t0, t0, 16); | |
7690 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
7691 | #else | |
76db3ba4 | 7692 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
7693 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
7694 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
7695 | gen_addr_add(ctx, addr, addr, 2); |
7696 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
7697 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
7698 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
0487d6a8 | 7699 | #endif |
6a6ae23f AJ |
7700 | tcg_temp_free(t0); |
7701 | } | |
7702 | ||
636aa200 | 7703 | static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7704 | { |
7705 | #if defined(TARGET_PPC64) | |
76db3ba4 | 7706 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
0487d6a8 | 7707 | #else |
6a6ae23f AJ |
7708 | TCGv_i64 t0 = tcg_temp_new_i64(); |
7709 | tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]); | |
76db3ba4 | 7710 | gen_qemu_st64(ctx, t0, addr); |
6a6ae23f AJ |
7711 | tcg_temp_free_i64(t0); |
7712 | #endif | |
7713 | } | |
7714 | ||
636aa200 | 7715 | static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7716 | { |
0487d6a8 | 7717 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
7718 | TCGv t0 = tcg_temp_new(); |
7719 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7720 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7721 | tcg_temp_free(t0); |
7722 | #else | |
76db3ba4 | 7723 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7724 | #endif |
76db3ba4 AJ |
7725 | gen_addr_add(ctx, addr, addr, 4); |
7726 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7727 | } |
7728 | ||
636aa200 | 7729 | static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7730 | { |
7731 | TCGv t0 = tcg_temp_new(); | |
7732 | #if defined(TARGET_PPC64) | |
7733 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7734 | #else | |
7735 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7736 | #endif | |
76db3ba4 AJ |
7737 | gen_qemu_st16(ctx, t0, addr); |
7738 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f AJ |
7739 | #if defined(TARGET_PPC64) |
7740 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7741 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7742 | #else |
76db3ba4 | 7743 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7744 | #endif |
76db3ba4 | 7745 | gen_addr_add(ctx, addr, addr, 2); |
6a6ae23f | 7746 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7747 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 7748 | tcg_temp_free(t0); |
76db3ba4 AJ |
7749 | gen_addr_add(ctx, addr, addr, 2); |
7750 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7751 | } |
7752 | ||
636aa200 | 7753 | static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7754 | { |
7755 | TCGv t0 = tcg_temp_new(); | |
7756 | #if defined(TARGET_PPC64) | |
7757 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
7758 | #else | |
7759 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
7760 | #endif | |
76db3ba4 AJ |
7761 | gen_qemu_st16(ctx, t0, addr); |
7762 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f | 7763 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 7764 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
7765 | tcg_temp_free(t0); |
7766 | } | |
7767 | ||
636aa200 | 7768 | static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7769 | { |
7770 | #if defined(TARGET_PPC64) | |
7771 | TCGv t0 = tcg_temp_new(); | |
7772 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7773 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
7774 | tcg_temp_free(t0); |
7775 | #else | |
76db3ba4 | 7776 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 7777 | #endif |
76db3ba4 AJ |
7778 | gen_addr_add(ctx, addr, addr, 2); |
7779 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
7780 | } |
7781 | ||
636aa200 | 7782 | static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
7783 | { |
7784 | #if defined(TARGET_PPC64) | |
7785 | TCGv t0 = tcg_temp_new(); | |
7786 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 7787 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
7788 | tcg_temp_free(t0); |
7789 | #else | |
76db3ba4 | 7790 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7791 | #endif |
7792 | } | |
7793 | ||
636aa200 | 7794 | static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr) |
6a6ae23f | 7795 | { |
76db3ba4 | 7796 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
7797 | } |
7798 | ||
7799 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
99e300ef | 7800 | static void glue(gen_, name)(DisasContext *ctx) \ |
6a6ae23f AJ |
7801 | { \ |
7802 | TCGv t0; \ | |
7803 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7804 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
6a6ae23f AJ |
7805 | return; \ |
7806 | } \ | |
76db3ba4 | 7807 | gen_set_access_type(ctx, ACCESS_INT); \ |
6a6ae23f AJ |
7808 | t0 = tcg_temp_new(); \ |
7809 | if (Rc(ctx->opcode)) { \ | |
76db3ba4 | 7810 | gen_addr_spe_imm_index(ctx, t0, sh); \ |
6a6ae23f | 7811 | } else { \ |
76db3ba4 | 7812 | gen_addr_reg_index(ctx, t0); \ |
6a6ae23f AJ |
7813 | } \ |
7814 | gen_op_##name(ctx, t0); \ | |
7815 | tcg_temp_free(t0); \ | |
7816 | } | |
7817 | ||
7818 | GEN_SPEOP_LDST(evldd, 0x00, 3); | |
7819 | GEN_SPEOP_LDST(evldw, 0x01, 3); | |
7820 | GEN_SPEOP_LDST(evldh, 0x02, 3); | |
7821 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1); | |
7822 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1); | |
7823 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1); | |
7824 | GEN_SPEOP_LDST(evlwhe, 0x08, 2); | |
7825 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2); | |
7826 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2); | |
7827 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2); | |
7828 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2); | |
7829 | ||
7830 | GEN_SPEOP_LDST(evstdd, 0x10, 3); | |
7831 | GEN_SPEOP_LDST(evstdw, 0x11, 3); | |
7832 | GEN_SPEOP_LDST(evstdh, 0x12, 3); | |
7833 | GEN_SPEOP_LDST(evstwhe, 0x18, 2); | |
7834 | GEN_SPEOP_LDST(evstwho, 0x1A, 2); | |
7835 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2); | |
7836 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2); | |
0487d6a8 JM |
7837 | |
7838 | /* Multiply and add - TODO */ | |
7839 | #if 0 | |
70560da7 FC |
7840 | GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);// |
7841 | GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7842 | GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
7843 | GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7844 | GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
7845 | GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7846 | GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7847 | GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7848 | GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
7849 | GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7850 | GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
7851 | GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7852 | ||
7853 | GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7854 | GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7855 | GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7856 | GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7857 | GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7858 | GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7859 | GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7860 | GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
7861 | GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
7862 | GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7863 | GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7864 | GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7865 | ||
7866 | GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
7867 | GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
7868 | GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
7869 | GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
7870 | GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE); | |
7871 | ||
7872 | GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7873 | GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7874 | GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7875 | GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7876 | GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7877 | GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7878 | GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7879 | GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7880 | GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7881 | GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7882 | GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
7883 | GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7884 | ||
7885 | GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
7886 | GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
7887 | GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7888 | GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7889 | ||
7890 | GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7891 | GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7892 | GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7893 | GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7894 | GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7895 | GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7896 | GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7897 | GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7898 | GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7899 | GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7900 | GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
7901 | GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7902 | ||
7903 | GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
7904 | GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
7905 | GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
7906 | GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
7907 | GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
0487d6a8 JM |
7908 | #endif |
7909 | ||
7910 | /*** SPE floating-point extension ***/ | |
1c97856d AJ |
7911 | #if defined(TARGET_PPC64) |
7912 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 7913 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 | 7914 | { \ |
1c97856d AJ |
7915 | TCGv_i32 t0; \ |
7916 | TCGv t1; \ | |
7917 | t0 = tcg_temp_new_i32(); \ | |
7918 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
7919 | gen_helper_##name(t0, t0); \ | |
7920 | t1 = tcg_temp_new(); \ | |
7921 | tcg_gen_extu_i32_tl(t1, t0); \ | |
7922 | tcg_temp_free_i32(t0); \ | |
7923 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
7924 | 0xFFFFFFFF00000000ULL); \ | |
7925 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
7926 | tcg_temp_free(t1); \ | |
0487d6a8 | 7927 | } |
1c97856d | 7928 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 7929 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
7930 | { \ |
7931 | TCGv_i32 t0; \ | |
7932 | TCGv t1; \ | |
7933 | t0 = tcg_temp_new_i32(); \ | |
7934 | gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
7935 | t1 = tcg_temp_new(); \ | |
7936 | tcg_gen_extu_i32_tl(t1, t0); \ | |
7937 | tcg_temp_free_i32(t0); \ | |
7938 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
7939 | 0xFFFFFFFF00000000ULL); \ | |
7940 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
7941 | tcg_temp_free(t1); \ | |
7942 | } | |
7943 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 7944 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
7945 | { \ |
7946 | TCGv_i32 t0 = tcg_temp_new_i32(); \ | |
7947 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
7948 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \ | |
7949 | tcg_temp_free_i32(t0); \ | |
7950 | } | |
7951 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 7952 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
7953 | { \ |
7954 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
7955 | } | |
7956 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 7957 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 7958 | { \ |
1c97856d AJ |
7959 | TCGv_i32 t0, t1; \ |
7960 | TCGv_i64 t2; \ | |
57951c27 | 7961 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 7962 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7963 | return; \ |
7964 | } \ | |
1c97856d AJ |
7965 | t0 = tcg_temp_new_i32(); \ |
7966 | t1 = tcg_temp_new_i32(); \ | |
7967 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
7968 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
7969 | gen_helper_##name(t0, t0, t1); \ | |
7970 | tcg_temp_free_i32(t1); \ | |
7971 | t2 = tcg_temp_new(); \ | |
7972 | tcg_gen_extu_i32_tl(t2, t0); \ | |
7973 | tcg_temp_free_i32(t0); \ | |
7974 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
7975 | 0xFFFFFFFF00000000ULL); \ | |
7976 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \ | |
7977 | tcg_temp_free(t2); \ | |
57951c27 | 7978 | } |
1c97856d | 7979 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ |
636aa200 | 7980 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7981 | { \ |
7982 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7983 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7984 | return; \ |
7985 | } \ | |
1c97856d AJ |
7986 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7987 | cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 7988 | } |
1c97856d | 7989 | #define GEN_SPEFPUOP_COMP_32(name) \ |
636aa200 | 7990 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 7991 | { \ |
1c97856d | 7992 | TCGv_i32 t0, t1; \ |
57951c27 | 7993 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 7994 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7995 | return; \ |
7996 | } \ | |
1c97856d AJ |
7997 | t0 = tcg_temp_new_i32(); \ |
7998 | t1 = tcg_temp_new_i32(); \ | |
7999 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
8000 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8001 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \ | |
8002 | tcg_temp_free_i32(t0); \ | |
8003 | tcg_temp_free_i32(t1); \ | |
8004 | } | |
8005 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8006 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8007 | { \ |
8008 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8009 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8010 | return; \ |
8011 | } \ | |
8012 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \ | |
8013 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
8014 | } | |
8015 | #else | |
8016 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 8017 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8018 | { \ |
8019 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 8020 | } |
1c97856d | 8021 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 8022 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8023 | { \ |
8024 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8025 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8026 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \ | |
8027 | tcg_temp_free_i64(t0); \ | |
8028 | } | |
8029 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 8030 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8031 | { \ |
8032 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8033 | gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8034 | gen_store_gpr64(rD(ctx->opcode), t0); \ | |
8035 | tcg_temp_free_i64(t0); \ | |
8036 | } | |
8037 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 8038 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8039 | { \ |
8040 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8041 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8042 | gen_helper_##name(t0, t0); \ | |
8043 | gen_store_gpr64(rD(ctx->opcode), t0); \ | |
8044 | tcg_temp_free_i64(t0); \ | |
8045 | } | |
8046 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 8047 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8048 | { \ |
8049 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8050 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8051 | return; \ |
8052 | } \ | |
8053 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \ | |
8054 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
8055 | } | |
8056 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ | |
636aa200 | 8057 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8058 | { \ |
8059 | TCGv_i64 t0, t1; \ | |
8060 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8061 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8062 | return; \ |
8063 | } \ | |
8064 | t0 = tcg_temp_new_i64(); \ | |
8065 | t1 = tcg_temp_new_i64(); \ | |
8066 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8067 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8068 | gen_helper_##name(t0, t0, t1); \ | |
8069 | gen_store_gpr64(rD(ctx->opcode), t0); \ | |
8070 | tcg_temp_free_i64(t0); \ | |
8071 | tcg_temp_free_i64(t1); \ | |
8072 | } | |
8073 | #define GEN_SPEFPUOP_COMP_32(name) \ | |
636aa200 | 8074 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8075 | { \ |
8076 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8077 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8078 | return; \ |
8079 | } \ | |
8080 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \ | |
8081 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
8082 | } | |
8083 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 8084 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
8085 | { \ |
8086 | TCGv_i64 t0, t1; \ | |
8087 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8088 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
8089 | return; \ |
8090 | } \ | |
8091 | t0 = tcg_temp_new_i64(); \ | |
8092 | t1 = tcg_temp_new_i64(); \ | |
8093 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
8094 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8095 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \ | |
8096 | tcg_temp_free_i64(t0); \ | |
8097 | tcg_temp_free_i64(t1); \ | |
8098 | } | |
8099 | #endif | |
57951c27 | 8100 | |
0487d6a8 JM |
8101 | /* Single precision floating-point vectors operations */ |
8102 | /* Arithmetic */ | |
1c97856d AJ |
8103 | GEN_SPEFPUOP_ARITH2_64_64(evfsadd); |
8104 | GEN_SPEFPUOP_ARITH2_64_64(evfssub); | |
8105 | GEN_SPEFPUOP_ARITH2_64_64(evfsmul); | |
8106 | GEN_SPEFPUOP_ARITH2_64_64(evfsdiv); | |
636aa200 | 8107 | static inline void gen_evfsabs(DisasContext *ctx) |
1c97856d AJ |
8108 | { |
8109 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8110 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8111 | return; |
8112 | } | |
8113 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8114 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL); |
1c97856d | 8115 | #else |
6d5c34fa MP |
8116 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000); |
8117 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8118 | #endif |
8119 | } | |
636aa200 | 8120 | static inline void gen_evfsnabs(DisasContext *ctx) |
1c97856d AJ |
8121 | { |
8122 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8123 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8124 | return; |
8125 | } | |
8126 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8127 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8128 | #else |
6d5c34fa MP |
8129 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8130 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8131 | #endif |
8132 | } | |
636aa200 | 8133 | static inline void gen_evfsneg(DisasContext *ctx) |
1c97856d AJ |
8134 | { |
8135 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8136 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8137 | return; |
8138 | } | |
8139 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8140 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 8141 | #else |
6d5c34fa MP |
8142 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
8143 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8144 | #endif |
8145 | } | |
8146 | ||
0487d6a8 | 8147 | /* Conversion */ |
1c97856d AJ |
8148 | GEN_SPEFPUOP_CONV_64_64(evfscfui); |
8149 | GEN_SPEFPUOP_CONV_64_64(evfscfsi); | |
8150 | GEN_SPEFPUOP_CONV_64_64(evfscfuf); | |
8151 | GEN_SPEFPUOP_CONV_64_64(evfscfsf); | |
8152 | GEN_SPEFPUOP_CONV_64_64(evfsctui); | |
8153 | GEN_SPEFPUOP_CONV_64_64(evfsctsi); | |
8154 | GEN_SPEFPUOP_CONV_64_64(evfsctuf); | |
8155 | GEN_SPEFPUOP_CONV_64_64(evfsctsf); | |
8156 | GEN_SPEFPUOP_CONV_64_64(evfsctuiz); | |
8157 | GEN_SPEFPUOP_CONV_64_64(evfsctsiz); | |
8158 | ||
0487d6a8 | 8159 | /* Comparison */ |
1c97856d AJ |
8160 | GEN_SPEFPUOP_COMP_64(evfscmpgt); |
8161 | GEN_SPEFPUOP_COMP_64(evfscmplt); | |
8162 | GEN_SPEFPUOP_COMP_64(evfscmpeq); | |
8163 | GEN_SPEFPUOP_COMP_64(evfststgt); | |
8164 | GEN_SPEFPUOP_COMP_64(evfststlt); | |
8165 | GEN_SPEFPUOP_COMP_64(evfststeq); | |
0487d6a8 JM |
8166 | |
8167 | /* Opcodes definitions */ | |
70560da7 FC |
8168 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8169 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8170 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8171 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8172 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8173 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8174 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8175 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8176 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8177 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8178 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8179 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8180 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8181 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8182 | |
8183 | /* Single precision floating-point operations */ | |
8184 | /* Arithmetic */ | |
1c97856d AJ |
8185 | GEN_SPEFPUOP_ARITH2_32_32(efsadd); |
8186 | GEN_SPEFPUOP_ARITH2_32_32(efssub); | |
8187 | GEN_SPEFPUOP_ARITH2_32_32(efsmul); | |
8188 | GEN_SPEFPUOP_ARITH2_32_32(efsdiv); | |
636aa200 | 8189 | static inline void gen_efsabs(DisasContext *ctx) |
1c97856d AJ |
8190 | { |
8191 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8192 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8193 | return; |
8194 | } | |
6d5c34fa | 8195 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL); |
1c97856d | 8196 | } |
636aa200 | 8197 | static inline void gen_efsnabs(DisasContext *ctx) |
1c97856d AJ |
8198 | { |
8199 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8200 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8201 | return; |
8202 | } | |
6d5c34fa | 8203 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d | 8204 | } |
636aa200 | 8205 | static inline void gen_efsneg(DisasContext *ctx) |
1c97856d AJ |
8206 | { |
8207 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8208 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8209 | return; |
8210 | } | |
6d5c34fa | 8211 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d AJ |
8212 | } |
8213 | ||
0487d6a8 | 8214 | /* Conversion */ |
1c97856d AJ |
8215 | GEN_SPEFPUOP_CONV_32_32(efscfui); |
8216 | GEN_SPEFPUOP_CONV_32_32(efscfsi); | |
8217 | GEN_SPEFPUOP_CONV_32_32(efscfuf); | |
8218 | GEN_SPEFPUOP_CONV_32_32(efscfsf); | |
8219 | GEN_SPEFPUOP_CONV_32_32(efsctui); | |
8220 | GEN_SPEFPUOP_CONV_32_32(efsctsi); | |
8221 | GEN_SPEFPUOP_CONV_32_32(efsctuf); | |
8222 | GEN_SPEFPUOP_CONV_32_32(efsctsf); | |
8223 | GEN_SPEFPUOP_CONV_32_32(efsctuiz); | |
8224 | GEN_SPEFPUOP_CONV_32_32(efsctsiz); | |
8225 | GEN_SPEFPUOP_CONV_32_64(efscfd); | |
8226 | ||
0487d6a8 | 8227 | /* Comparison */ |
1c97856d AJ |
8228 | GEN_SPEFPUOP_COMP_32(efscmpgt); |
8229 | GEN_SPEFPUOP_COMP_32(efscmplt); | |
8230 | GEN_SPEFPUOP_COMP_32(efscmpeq); | |
8231 | GEN_SPEFPUOP_COMP_32(efststgt); | |
8232 | GEN_SPEFPUOP_COMP_32(efststlt); | |
8233 | GEN_SPEFPUOP_COMP_32(efststeq); | |
0487d6a8 JM |
8234 | |
8235 | /* Opcodes definitions */ | |
70560da7 FC |
8236 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
8237 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
8238 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8239 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
8240 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8241 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); // | |
8242 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8243 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8244 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8245 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
8246 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8247 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
8248 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
8249 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
8250 | |
8251 | /* Double precision floating-point operations */ | |
8252 | /* Arithmetic */ | |
1c97856d AJ |
8253 | GEN_SPEFPUOP_ARITH2_64_64(efdadd); |
8254 | GEN_SPEFPUOP_ARITH2_64_64(efdsub); | |
8255 | GEN_SPEFPUOP_ARITH2_64_64(efdmul); | |
8256 | GEN_SPEFPUOP_ARITH2_64_64(efddiv); | |
636aa200 | 8257 | static inline void gen_efdabs(DisasContext *ctx) |
1c97856d AJ |
8258 | { |
8259 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8260 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8261 | return; |
8262 | } | |
8263 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8264 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL); |
1c97856d | 8265 | #else |
6d5c34fa MP |
8266 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8267 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
8268 | #endif |
8269 | } | |
636aa200 | 8270 | static inline void gen_efdnabs(DisasContext *ctx) |
1c97856d AJ |
8271 | { |
8272 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8273 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8274 | return; |
8275 | } | |
8276 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8277 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8278 | #else |
6d5c34fa MP |
8279 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8280 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8281 | #endif |
8282 | } | |
636aa200 | 8283 | static inline void gen_efdneg(DisasContext *ctx) |
1c97856d AJ |
8284 | { |
8285 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8286 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
8287 | return; |
8288 | } | |
8289 | #if defined(TARGET_PPC64) | |
6d5c34fa | 8290 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 8291 | #else |
6d5c34fa MP |
8292 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
8293 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
8294 | #endif |
8295 | } | |
8296 | ||
0487d6a8 | 8297 | /* Conversion */ |
1c97856d AJ |
8298 | GEN_SPEFPUOP_CONV_64_32(efdcfui); |
8299 | GEN_SPEFPUOP_CONV_64_32(efdcfsi); | |
8300 | GEN_SPEFPUOP_CONV_64_32(efdcfuf); | |
8301 | GEN_SPEFPUOP_CONV_64_32(efdcfsf); | |
8302 | GEN_SPEFPUOP_CONV_32_64(efdctui); | |
8303 | GEN_SPEFPUOP_CONV_32_64(efdctsi); | |
8304 | GEN_SPEFPUOP_CONV_32_64(efdctuf); | |
8305 | GEN_SPEFPUOP_CONV_32_64(efdctsf); | |
8306 | GEN_SPEFPUOP_CONV_32_64(efdctuiz); | |
8307 | GEN_SPEFPUOP_CONV_32_64(efdctsiz); | |
8308 | GEN_SPEFPUOP_CONV_64_32(efdcfs); | |
8309 | GEN_SPEFPUOP_CONV_64_64(efdcfuid); | |
8310 | GEN_SPEFPUOP_CONV_64_64(efdcfsid); | |
8311 | GEN_SPEFPUOP_CONV_64_64(efdctuidz); | |
8312 | GEN_SPEFPUOP_CONV_64_64(efdctsidz); | |
0487d6a8 | 8313 | |
0487d6a8 | 8314 | /* Comparison */ |
1c97856d AJ |
8315 | GEN_SPEFPUOP_COMP_64(efdcmpgt); |
8316 | GEN_SPEFPUOP_COMP_64(efdcmplt); | |
8317 | GEN_SPEFPUOP_COMP_64(efdcmpeq); | |
8318 | GEN_SPEFPUOP_COMP_64(efdtstgt); | |
8319 | GEN_SPEFPUOP_COMP_64(efdtstlt); | |
8320 | GEN_SPEFPUOP_COMP_64(efdtsteq); | |
0487d6a8 JM |
8321 | |
8322 | /* Opcodes definitions */ | |
70560da7 FC |
8323 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // |
8324 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8325 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); // | |
8326 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8327 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // | |
8328 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8329 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8330 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); // | |
8331 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8332 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8333 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8334 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
8335 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8336 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
8337 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
8338 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
0487d6a8 | 8339 | |
c227f099 | 8340 | static opcode_t opcodes[] = { |
5c55ff99 BS |
8341 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
8342 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
8343 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8344 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER), | |
8345 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
8346 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), | |
8347 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8348 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8349 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8350 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8351 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), | |
8352 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
8353 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
8354 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
8355 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8356 | #if defined(TARGET_PPC64) | |
8357 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
8358 | #endif | |
8359 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
8360 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
8361 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8362 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8363 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8364 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
8365 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), | |
8366 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
8367 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8368 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8369 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8370 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8371 | GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), | |
eaabeef2 | 8372 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 8373 | #if defined(TARGET_PPC64) |
eaabeef2 | 8374 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 BS |
8375 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
8376 | #endif | |
8377 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8378 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8379 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8380 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
8381 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
8382 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
8383 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
8384 | #if defined(TARGET_PPC64) | |
8385 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
8386 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
8387 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
8388 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
8389 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
8390 | #endif | |
8391 | GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES), | |
8392 | GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8393 | GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
8394 | GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT), | |
8395 | GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT), | |
8396 | GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT), | |
8397 | GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT), | |
8398 | GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT), | |
8399 | GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT), | |
8400 | GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT), | |
8401 | GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT), | |
8402 | GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT), | |
8403 | #if defined(TARGET_PPC64) | |
8404 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8405 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
8406 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8407 | #endif | |
8408 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8409 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
8410 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
8411 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
8412 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
8413 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
8414 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO), | |
8415 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), | |
f844c817 | 8416 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
5c55ff99 BS |
8417 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
8418 | #if defined(TARGET_PPC64) | |
f844c817 | 8419 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
5c55ff99 BS |
8420 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
8421 | #endif | |
8422 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
8423 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
8424 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8425 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8426 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
8427 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
8428 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), | |
8429 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
8430 | #if defined(TARGET_PPC64) | |
8431 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
8432 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), | |
8433 | #endif | |
8434 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
8435 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
8436 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
8437 | #if defined(TARGET_PPC64) | |
8438 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
8439 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
8440 | #endif | |
8441 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
8442 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
8443 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
8444 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
8445 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
8446 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
8447 | #if defined(TARGET_PPC64) | |
8448 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
8449 | #endif | |
8450 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC), | |
8451 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC), | |
8452 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), | |
8453 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), | |
8454 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
8455 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE), | |
8456 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE), | |
8457 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ), | |
8458 | GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT), | |
8459 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), | |
8460 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC), | |
8461 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), | |
8462 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
8463 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), | |
8464 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
8465 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
8466 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
8467 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
8468 | #if defined(TARGET_PPC64) | |
8469 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
8470 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
8471 | PPC_SEGMENT_64B), | |
8472 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
8473 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
8474 | PPC_SEGMENT_64B), | |
efdef95f DG |
8475 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
8476 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
8477 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
5c55ff99 BS |
8478 | #endif |
8479 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
8480 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE), | |
8481 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE), | |
8482 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), | |
8483 | #if defined(TARGET_PPC64) | |
8484 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI), | |
8485 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), | |
8486 | #endif | |
8487 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
8488 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
8489 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
8490 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
8491 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
8492 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
8493 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
8494 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
8495 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
8496 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
8497 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
8498 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8499 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
8500 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
8501 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
8502 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
8503 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
8504 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
8505 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
8506 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
8507 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
8508 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
8509 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
8510 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
8511 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
8512 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
8513 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
8514 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
8515 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
8516 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
8517 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
8518 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
8519 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
8520 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
8521 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
8522 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
8523 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
8524 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
8525 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
8526 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
8527 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
8528 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
8529 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
8530 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
8531 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
8532 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
8533 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
8534 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
8535 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
8536 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8537 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8538 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
8539 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
8540 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8541 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
8542 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
8543 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
8544 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
8545 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
8546 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
8547 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
8548 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
8549 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
8550 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
8551 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
8552 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
8553 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
8554 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
8555 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
8556 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
8557 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 8558 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
8559 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
8560 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
8561 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
8562 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
8563 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
8564 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
8565 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
8566 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
8567 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
8568 | PPC_NONE, PPC2_BOOKE206), | |
8569 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
8570 | PPC_NONE, PPC2_BOOKE206), | |
8571 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
8572 | PPC_NONE, PPC2_BOOKE206), | |
8573 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
8574 | PPC_NONE, PPC2_BOOKE206), | |
5c55ff99 | 8575 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 8576 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 8577 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
8578 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
8579 | PPC_BOOKE, PPC2_BOOKE206), | |
8580 | GEN_HANDLER_E(msync, 0x1F, 0x16, 0x12, 0x03FFF801, | |
8581 | PPC_BOOKE, PPC2_BOOKE206), | |
8582 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, | |
8583 | PPC_BOOKE, PPC2_BOOKE206), | |
5c55ff99 BS |
8584 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
8585 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
8586 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
8587 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
8588 | GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC), | |
8589 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), | |
8590 | GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE), | |
8591 | GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE), | |
8592 | GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE), | |
8593 | GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE), | |
8594 | ||
8595 | #undef GEN_INT_ARITH_ADD | |
8596 | #undef GEN_INT_ARITH_ADD_CONST | |
8597 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8598 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
8599 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
8600 | add_ca, compute_ca, compute_ov) \ | |
8601 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
8602 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
8603 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
8604 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
8605 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
8606 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
8607 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
8608 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
8609 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
8610 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
8611 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
8612 | ||
8613 | #undef GEN_INT_ARITH_DIVW | |
8614 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
8615 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
8616 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
8617 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
8618 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
8619 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
8620 | ||
8621 | #if defined(TARGET_PPC64) | |
8622 | #undef GEN_INT_ARITH_DIVD | |
8623 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
8624 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8625 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
8626 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
8627 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
8628 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
8629 | ||
8630 | #undef GEN_INT_ARITH_MUL_HELPER | |
8631 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
8632 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
8633 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
8634 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
8635 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
8636 | #endif | |
8637 | ||
8638 | #undef GEN_INT_ARITH_SUBF | |
8639 | #undef GEN_INT_ARITH_SUBF_CONST | |
8640 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
8641 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
8642 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
8643 | add_ca, compute_ca, compute_ov) \ | |
8644 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
8645 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
8646 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
8647 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
8648 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
8649 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
8650 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
8651 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
8652 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
8653 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
8654 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
8655 | ||
8656 | #undef GEN_LOGICAL1 | |
8657 | #undef GEN_LOGICAL2 | |
8658 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
8659 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
8660 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
8661 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
8662 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
8663 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
8664 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
8665 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
8666 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
8667 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
8668 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
8669 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
8670 | #if defined(TARGET_PPC64) | |
8671 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
8672 | #endif | |
8673 | ||
8674 | #if defined(TARGET_PPC64) | |
8675 | #undef GEN_PPC64_R2 | |
8676 | #undef GEN_PPC64_R4 | |
8677 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
8678 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8679 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8680 | PPC_64B) | |
8681 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
8682 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
8683 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
8684 | PPC_64B), \ | |
8685 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
8686 | PPC_64B), \ | |
8687 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
8688 | PPC_64B) | |
8689 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
8690 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
8691 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
8692 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
8693 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
8694 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
8695 | #endif | |
8696 | ||
8697 | #undef _GEN_FLOAT_ACB | |
8698 | #undef GEN_FLOAT_ACB | |
8699 | #undef _GEN_FLOAT_AB | |
8700 | #undef GEN_FLOAT_AB | |
8701 | #undef _GEN_FLOAT_AC | |
8702 | #undef GEN_FLOAT_AC | |
8703 | #undef GEN_FLOAT_B | |
8704 | #undef GEN_FLOAT_BS | |
8705 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ | |
8706 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) | |
8707 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ | |
8708 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \ | |
8709 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type) | |
8710 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8711 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8712 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ | |
8713 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8714 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8715 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
8716 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
8717 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ | |
8718 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
8719 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
8720 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ | |
8721 | GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) | |
8722 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ | |
8723 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) | |
8724 | ||
8725 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT), | |
8726 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT), | |
8727 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT), | |
8728 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT), | |
8729 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES), | |
8730 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE), | |
8731 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL), | |
8732 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT), | |
8733 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT), | |
8734 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT), | |
8735 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT), | |
8736 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT), | |
8737 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT), | |
8738 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT), | |
8739 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT), | |
8740 | #if defined(TARGET_PPC64) | |
8741 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B), | |
8742 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B), | |
8743 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B), | |
8744 | #endif | |
8745 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT), | |
8746 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT), | |
8747 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT), | |
8748 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), | |
8749 | GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT), | |
8750 | GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT), | |
8751 | GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT), | |
8752 | ||
8753 | #undef GEN_LD | |
8754 | #undef GEN_LDU | |
8755 | #undef GEN_LDUX | |
8756 | #undef GEN_LDX | |
8757 | #undef GEN_LDS | |
8758 | #define GEN_LD(name, ldop, opc, type) \ | |
8759 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8760 | #define GEN_LDU(name, ldop, opc, type) \ | |
8761 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8762 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
8763 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
8764 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ | |
8765 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
8766 | #define GEN_LDS(name, ldop, op, type) \ | |
8767 | GEN_LD(name, ldop, op | 0x20, type) \ | |
8768 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
8769 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
8770 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
8771 | ||
8772 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
8773 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
8774 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
8775 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
8776 | #if defined(TARGET_PPC64) | |
8777 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
8778 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
8779 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B) | |
8780 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B) | |
8781 | #endif | |
8782 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
8783 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
8784 | ||
8785 | #undef GEN_ST | |
8786 | #undef GEN_STU | |
8787 | #undef GEN_STUX | |
8788 | #undef GEN_STX | |
8789 | #undef GEN_STS | |
8790 | #define GEN_ST(name, stop, opc, type) \ | |
8791 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8792 | #define GEN_STU(name, stop, opc, type) \ | |
8793 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8794 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
8795 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
8796 | #define GEN_STX(name, stop, opc2, opc3, type) \ | |
8797 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
8798 | #define GEN_STS(name, stop, op, type) \ | |
8799 | GEN_ST(name, stop, op | 0x20, type) \ | |
8800 | GEN_STU(name, stop, op | 0x21, type) \ | |
8801 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
8802 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
8803 | ||
8804 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
8805 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
8806 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
8807 | #if defined(TARGET_PPC64) | |
8808 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B) | |
8809 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B) | |
8810 | #endif | |
8811 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
8812 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
8813 | ||
8814 | #undef GEN_LDF | |
8815 | #undef GEN_LDUF | |
8816 | #undef GEN_LDUXF | |
8817 | #undef GEN_LDXF | |
8818 | #undef GEN_LDFS | |
8819 | #define GEN_LDF(name, ldop, opc, type) \ | |
8820 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8821 | #define GEN_LDUF(name, ldop, opc, type) \ | |
8822 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8823 | #define GEN_LDUXF(name, ldop, opc, type) \ | |
8824 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
8825 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ | |
8826 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
8827 | #define GEN_LDFS(name, ldop, op, type) \ | |
8828 | GEN_LDF(name, ldop, op | 0x20, type) \ | |
8829 | GEN_LDUF(name, ldop, op | 0x21, type) \ | |
8830 | GEN_LDUXF(name, ldop, op | 0x01, type) \ | |
8831 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
8832 | ||
8833 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT) | |
8834 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT) | |
8835 | ||
8836 | #undef GEN_STF | |
8837 | #undef GEN_STUF | |
8838 | #undef GEN_STUXF | |
8839 | #undef GEN_STXF | |
8840 | #undef GEN_STFS | |
8841 | #define GEN_STF(name, stop, opc, type) \ | |
8842 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
8843 | #define GEN_STUF(name, stop, opc, type) \ | |
8844 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
8845 | #define GEN_STUXF(name, stop, opc, type) \ | |
8846 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
8847 | #define GEN_STXF(name, stop, opc2, opc3, type) \ | |
8848 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
8849 | #define GEN_STFS(name, stop, op, type) \ | |
8850 | GEN_STF(name, stop, op | 0x20, type) \ | |
8851 | GEN_STUF(name, stop, op | 0x21, type) \ | |
8852 | GEN_STUXF(name, stop, op | 0x01, type) \ | |
8853 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
8854 | ||
8855 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT) | |
8856 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT) | |
8857 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX) | |
8858 | ||
8859 | #undef GEN_CRLOGIC | |
8860 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
8861 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
8862 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
8863 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
8864 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
8865 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
8866 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
8867 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
8868 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
8869 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
8870 | ||
8871 | #undef GEN_MAC_HANDLER | |
8872 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
8873 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
8874 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
8875 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
8876 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
8877 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
8878 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
8879 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
8880 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
8881 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
8882 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
8883 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
8884 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
8885 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
8886 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
8887 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
8888 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
8889 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
8890 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
8891 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
8892 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
8893 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
8894 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
8895 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
8896 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
8897 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
8898 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
8899 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
8900 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
8901 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
8902 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
8903 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
8904 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
8905 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
8906 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
8907 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
8908 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
8909 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
8910 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
8911 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
8912 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
8913 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
8914 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
8915 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
8916 | ||
8917 | #undef GEN_VR_LDX | |
8918 | #undef GEN_VR_STX | |
8919 | #undef GEN_VR_LVE | |
8920 | #undef GEN_VR_STVE | |
8921 | #define GEN_VR_LDX(name, opc2, opc3) \ | |
8922 | GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
8923 | #define GEN_VR_STX(name, opc2, opc3) \ | |
8924 | GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
8925 | #define GEN_VR_LVE(name, opc2, opc3) \ | |
8926 | GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
8927 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
8928 | GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
8929 | GEN_VR_LDX(lvx, 0x07, 0x03), | |
8930 | GEN_VR_LDX(lvxl, 0x07, 0x0B), | |
8931 | GEN_VR_LVE(bx, 0x07, 0x00), | |
8932 | GEN_VR_LVE(hx, 0x07, 0x01), | |
8933 | GEN_VR_LVE(wx, 0x07, 0x02), | |
8934 | GEN_VR_STX(svx, 0x07, 0x07), | |
8935 | GEN_VR_STX(svxl, 0x07, 0x0F), | |
8936 | GEN_VR_STVE(bx, 0x07, 0x04), | |
8937 | GEN_VR_STVE(hx, 0x07, 0x05), | |
8938 | GEN_VR_STVE(wx, 0x07, 0x06), | |
8939 | ||
8940 | #undef GEN_VX_LOGICAL | |
8941 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
8942 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
8943 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16), | |
8944 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17), | |
8945 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18), | |
8946 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19), | |
8947 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20), | |
8948 | ||
8949 | #undef GEN_VXFORM | |
8950 | #define GEN_VXFORM(name, opc2, opc3) \ | |
8951 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
8952 | GEN_VXFORM(vaddubm, 0, 0), | |
8953 | GEN_VXFORM(vadduhm, 0, 1), | |
8954 | GEN_VXFORM(vadduwm, 0, 2), | |
8955 | GEN_VXFORM(vsububm, 0, 16), | |
8956 | GEN_VXFORM(vsubuhm, 0, 17), | |
8957 | GEN_VXFORM(vsubuwm, 0, 18), | |
8958 | GEN_VXFORM(vmaxub, 1, 0), | |
8959 | GEN_VXFORM(vmaxuh, 1, 1), | |
8960 | GEN_VXFORM(vmaxuw, 1, 2), | |
8961 | GEN_VXFORM(vmaxsb, 1, 4), | |
8962 | GEN_VXFORM(vmaxsh, 1, 5), | |
8963 | GEN_VXFORM(vmaxsw, 1, 6), | |
8964 | GEN_VXFORM(vminub, 1, 8), | |
8965 | GEN_VXFORM(vminuh, 1, 9), | |
8966 | GEN_VXFORM(vminuw, 1, 10), | |
8967 | GEN_VXFORM(vminsb, 1, 12), | |
8968 | GEN_VXFORM(vminsh, 1, 13), | |
8969 | GEN_VXFORM(vminsw, 1, 14), | |
8970 | GEN_VXFORM(vavgub, 1, 16), | |
8971 | GEN_VXFORM(vavguh, 1, 17), | |
8972 | GEN_VXFORM(vavguw, 1, 18), | |
8973 | GEN_VXFORM(vavgsb, 1, 20), | |
8974 | GEN_VXFORM(vavgsh, 1, 21), | |
8975 | GEN_VXFORM(vavgsw, 1, 22), | |
8976 | GEN_VXFORM(vmrghb, 6, 0), | |
8977 | GEN_VXFORM(vmrghh, 6, 1), | |
8978 | GEN_VXFORM(vmrghw, 6, 2), | |
8979 | GEN_VXFORM(vmrglb, 6, 4), | |
8980 | GEN_VXFORM(vmrglh, 6, 5), | |
8981 | GEN_VXFORM(vmrglw, 6, 6), | |
8982 | GEN_VXFORM(vmuloub, 4, 0), | |
8983 | GEN_VXFORM(vmulouh, 4, 1), | |
8984 | GEN_VXFORM(vmulosb, 4, 4), | |
8985 | GEN_VXFORM(vmulosh, 4, 5), | |
8986 | GEN_VXFORM(vmuleub, 4, 8), | |
8987 | GEN_VXFORM(vmuleuh, 4, 9), | |
8988 | GEN_VXFORM(vmulesb, 4, 12), | |
8989 | GEN_VXFORM(vmulesh, 4, 13), | |
8990 | GEN_VXFORM(vslb, 2, 4), | |
8991 | GEN_VXFORM(vslh, 2, 5), | |
8992 | GEN_VXFORM(vslw, 2, 6), | |
8993 | GEN_VXFORM(vsrb, 2, 8), | |
8994 | GEN_VXFORM(vsrh, 2, 9), | |
8995 | GEN_VXFORM(vsrw, 2, 10), | |
8996 | GEN_VXFORM(vsrab, 2, 12), | |
8997 | GEN_VXFORM(vsrah, 2, 13), | |
8998 | GEN_VXFORM(vsraw, 2, 14), | |
8999 | GEN_VXFORM(vslo, 6, 16), | |
9000 | GEN_VXFORM(vsro, 6, 17), | |
9001 | GEN_VXFORM(vaddcuw, 0, 6), | |
9002 | GEN_VXFORM(vsubcuw, 0, 22), | |
9003 | GEN_VXFORM(vaddubs, 0, 8), | |
9004 | GEN_VXFORM(vadduhs, 0, 9), | |
9005 | GEN_VXFORM(vadduws, 0, 10), | |
9006 | GEN_VXFORM(vaddsbs, 0, 12), | |
9007 | GEN_VXFORM(vaddshs, 0, 13), | |
9008 | GEN_VXFORM(vaddsws, 0, 14), | |
9009 | GEN_VXFORM(vsububs, 0, 24), | |
9010 | GEN_VXFORM(vsubuhs, 0, 25), | |
9011 | GEN_VXFORM(vsubuws, 0, 26), | |
9012 | GEN_VXFORM(vsubsbs, 0, 28), | |
9013 | GEN_VXFORM(vsubshs, 0, 29), | |
9014 | GEN_VXFORM(vsubsws, 0, 30), | |
9015 | GEN_VXFORM(vrlb, 2, 0), | |
9016 | GEN_VXFORM(vrlh, 2, 1), | |
9017 | GEN_VXFORM(vrlw, 2, 2), | |
9018 | GEN_VXFORM(vsl, 2, 7), | |
9019 | GEN_VXFORM(vsr, 2, 11), | |
9020 | GEN_VXFORM(vpkuhum, 7, 0), | |
9021 | GEN_VXFORM(vpkuwum, 7, 1), | |
9022 | GEN_VXFORM(vpkuhus, 7, 2), | |
9023 | GEN_VXFORM(vpkuwus, 7, 3), | |
9024 | GEN_VXFORM(vpkshus, 7, 4), | |
9025 | GEN_VXFORM(vpkswus, 7, 5), | |
9026 | GEN_VXFORM(vpkshss, 7, 6), | |
9027 | GEN_VXFORM(vpkswss, 7, 7), | |
9028 | GEN_VXFORM(vpkpx, 7, 12), | |
9029 | GEN_VXFORM(vsum4ubs, 4, 24), | |
9030 | GEN_VXFORM(vsum4sbs, 4, 28), | |
9031 | GEN_VXFORM(vsum4shs, 4, 25), | |
9032 | GEN_VXFORM(vsum2sws, 4, 26), | |
9033 | GEN_VXFORM(vsumsws, 4, 30), | |
9034 | GEN_VXFORM(vaddfp, 5, 0), | |
9035 | GEN_VXFORM(vsubfp, 5, 1), | |
9036 | GEN_VXFORM(vmaxfp, 5, 16), | |
9037 | GEN_VXFORM(vminfp, 5, 17), | |
9038 | ||
9039 | #undef GEN_VXRFORM1 | |
9040 | #undef GEN_VXRFORM | |
9041 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ | |
9042 | GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC), | |
9043 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
9044 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
9045 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
9046 | GEN_VXRFORM(vcmpequb, 3, 0) | |
9047 | GEN_VXRFORM(vcmpequh, 3, 1) | |
9048 | GEN_VXRFORM(vcmpequw, 3, 2) | |
9049 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
9050 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
9051 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
9052 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
9053 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
9054 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
9055 | GEN_VXRFORM(vcmpeqfp, 3, 3) | |
9056 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
9057 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
9058 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
9059 | ||
9060 | #undef GEN_VXFORM_SIMM | |
9061 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ | |
9062 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9063 | GEN_VXFORM_SIMM(vspltisb, 6, 12), | |
9064 | GEN_VXFORM_SIMM(vspltish, 6, 13), | |
9065 | GEN_VXFORM_SIMM(vspltisw, 6, 14), | |
9066 | ||
9067 | #undef GEN_VXFORM_NOA | |
9068 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ | |
9069 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) | |
9070 | GEN_VXFORM_NOA(vupkhsb, 7, 8), | |
9071 | GEN_VXFORM_NOA(vupkhsh, 7, 9), | |
9072 | GEN_VXFORM_NOA(vupklsb, 7, 10), | |
9073 | GEN_VXFORM_NOA(vupklsh, 7, 11), | |
9074 | GEN_VXFORM_NOA(vupkhpx, 7, 13), | |
9075 | GEN_VXFORM_NOA(vupklpx, 7, 15), | |
9076 | GEN_VXFORM_NOA(vrefp, 5, 4), | |
9077 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5), | |
0bffbc6c | 9078 | GEN_VXFORM_NOA(vexptefp, 5, 6), |
5c55ff99 BS |
9079 | GEN_VXFORM_NOA(vlogefp, 5, 7), |
9080 | GEN_VXFORM_NOA(vrfim, 5, 8), | |
9081 | GEN_VXFORM_NOA(vrfin, 5, 9), | |
9082 | GEN_VXFORM_NOA(vrfip, 5, 10), | |
9083 | GEN_VXFORM_NOA(vrfiz, 5, 11), | |
9084 | ||
9085 | #undef GEN_VXFORM_UIMM | |
9086 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ | |
9087 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
9088 | GEN_VXFORM_UIMM(vspltb, 6, 8), | |
9089 | GEN_VXFORM_UIMM(vsplth, 6, 9), | |
9090 | GEN_VXFORM_UIMM(vspltw, 6, 10), | |
9091 | GEN_VXFORM_UIMM(vcfux, 5, 12), | |
9092 | GEN_VXFORM_UIMM(vcfsx, 5, 13), | |
9093 | GEN_VXFORM_UIMM(vctuxs, 5, 14), | |
9094 | GEN_VXFORM_UIMM(vctsxs, 5, 15), | |
9095 | ||
9096 | #undef GEN_VAFORM_PAIRED | |
9097 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ | |
9098 | GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) | |
9099 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16), | |
9100 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18), | |
9101 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19), | |
9102 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20), | |
9103 | GEN_VAFORM_PAIRED(vsel, vperm, 21), | |
9104 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23), | |
9105 | ||
9106 | #undef GEN_SPE | |
70560da7 FC |
9107 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
9108 | GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE) | |
9109 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9110 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9111 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9112 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9113 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9114 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9115 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
9116 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE), | |
9117 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE), | |
9118 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9119 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9120 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9121 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9122 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9123 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
9124 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE), | |
9125 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
9126 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9127 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9128 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9129 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9130 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
9131 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9132 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
9133 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9134 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
9135 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9136 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
9137 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE), | |
9138 | ||
9139 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9140 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9141 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9142 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9143 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9144 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9145 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9146 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9147 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9148 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9149 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9150 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9151 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9152 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9153 | ||
9154 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9155 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
9156 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9157 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
9158 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9159 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE), | |
9160 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9161 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9162 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9163 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
9164 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9165 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9166 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
9167 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
9168 | ||
9169 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9170 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9171 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE), | |
9172 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9173 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
9174 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9175 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9176 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE), | |
9177 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9178 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9179 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9180 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
9181 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9182 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
9183 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
9184 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
5c55ff99 BS |
9185 | |
9186 | #undef GEN_SPEOP_LDST | |
9187 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
9188 | GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) | |
9189 | GEN_SPEOP_LDST(evldd, 0x00, 3), | |
9190 | GEN_SPEOP_LDST(evldw, 0x01, 3), | |
9191 | GEN_SPEOP_LDST(evldh, 0x02, 3), | |
9192 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1), | |
9193 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1), | |
9194 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1), | |
9195 | GEN_SPEOP_LDST(evlwhe, 0x08, 2), | |
9196 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2), | |
9197 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2), | |
9198 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2), | |
9199 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2), | |
9200 | ||
9201 | GEN_SPEOP_LDST(evstdd, 0x10, 3), | |
9202 | GEN_SPEOP_LDST(evstdw, 0x11, 3), | |
9203 | GEN_SPEOP_LDST(evstdh, 0x12, 3), | |
9204 | GEN_SPEOP_LDST(evstwhe, 0x18, 2), | |
9205 | GEN_SPEOP_LDST(evstwho, 0x1A, 2), | |
9206 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2), | |
9207 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2), | |
9208 | }; | |
9209 | ||
3fc6c082 | 9210 | #include "translate_init.c" |
0411a972 | 9211 | #include "helper_regs.h" |
79aceca5 | 9212 | |
9a64fbe4 | 9213 | /*****************************************************************************/ |
3fc6c082 | 9214 | /* Misc PowerPC helpers */ |
9a78eead | 9215 | void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf, |
36081602 | 9216 | int flags) |
79aceca5 | 9217 | { |
3fc6c082 FB |
9218 | #define RGPL 4 |
9219 | #define RFPL 4 | |
3fc6c082 | 9220 | |
79aceca5 FB |
9221 | int i; |
9222 | ||
90e189ec | 9223 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
9a78eead SW |
9224 | TARGET_FMT_lx " XER " TARGET_FMT_lx "\n", |
9225 | env->nip, env->lr, env->ctr, env->xer); | |
90e189ec BS |
9226 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
9227 | TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0], | |
9228 | env->hflags, env->mmu_idx); | |
d9bce9d9 | 9229 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 9230 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 9231 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 9232 | " DECR %08" PRIu32 |
76a66253 JM |
9233 | #endif |
9234 | "\n", | |
077fc206 | 9235 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
9236 | #if !defined(CONFIG_USER_ONLY) |
9237 | , cpu_ppc_load_decr(env) | |
9238 | #endif | |
9239 | ); | |
077fc206 | 9240 | #endif |
76a66253 | 9241 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
9242 | if ((i & (RGPL - 1)) == 0) |
9243 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 9244 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 9245 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 9246 | cpu_fprintf(f, "\n"); |
76a66253 | 9247 | } |
3fc6c082 | 9248 | cpu_fprintf(f, "CR "); |
76a66253 | 9249 | for (i = 0; i < 8; i++) |
7fe48483 FB |
9250 | cpu_fprintf(f, "%01x", env->crf[i]); |
9251 | cpu_fprintf(f, " ["); | |
76a66253 JM |
9252 | for (i = 0; i < 8; i++) { |
9253 | char a = '-'; | |
9254 | if (env->crf[i] & 0x08) | |
9255 | a = 'L'; | |
9256 | else if (env->crf[i] & 0x04) | |
9257 | a = 'G'; | |
9258 | else if (env->crf[i] & 0x02) | |
9259 | a = 'E'; | |
7fe48483 | 9260 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 9261 | } |
90e189ec BS |
9262 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
9263 | env->reserve_addr); | |
3fc6c082 FB |
9264 | for (i = 0; i < 32; i++) { |
9265 | if ((i & (RFPL - 1)) == 0) | |
9266 | cpu_fprintf(f, "FPR%02d", i); | |
26a76461 | 9267 | cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); |
3fc6c082 | 9268 | if ((i & (RFPL - 1)) == (RFPL - 1)) |
7fe48483 | 9269 | cpu_fprintf(f, "\n"); |
79aceca5 | 9270 | } |
7889270a | 9271 | cpu_fprintf(f, "FPSCR %08x\n", env->fpscr); |
f2e63a42 | 9272 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
9273 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
9274 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
9275 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
9276 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
9277 | ||
9278 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
9279 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
9280 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
9281 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
9282 | ||
9283 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
9284 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
9285 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
9286 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
9287 | ||
9288 | if (env->excp_model == POWERPC_EXCP_BOOKE) { | |
9289 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
9290 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
9291 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
9292 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
9293 | ||
9294 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
9295 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
9296 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
9297 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
9298 | ||
9299 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
9300 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
9301 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
9302 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
9303 | ||
9304 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
9305 | " EPR " TARGET_FMT_lx "\n", | |
9306 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
9307 | env->spr[SPR_BOOKE_EPR]); | |
9308 | ||
9309 | /* FSL-specific */ | |
9310 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
9311 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
9312 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
9313 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
9314 | ||
9315 | /* | |
9316 | * IVORs are left out as they are large and do not change often -- | |
9317 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
9318 | */ | |
9319 | } | |
9320 | ||
697ab892 DG |
9321 | #if defined(TARGET_PPC64) |
9322 | if (env->flags & POWERPC_FLAG_CFAR) { | |
9323 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
9324 | } | |
9325 | #endif | |
9326 | ||
90dc8812 SW |
9327 | switch (env->mmu_model) { |
9328 | case POWERPC_MMU_32B: | |
9329 | case POWERPC_MMU_601: | |
9330 | case POWERPC_MMU_SOFT_6xx: | |
9331 | case POWERPC_MMU_SOFT_74xx: | |
9332 | #if defined(TARGET_PPC64) | |
9333 | case POWERPC_MMU_620: | |
9334 | case POWERPC_MMU_64B: | |
9335 | #endif | |
9336 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]); | |
9337 | break; | |
01662f3e | 9338 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
9339 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
9340 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
9341 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
9342 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
9343 | ||
9344 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
9345 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
9346 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
9347 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
9348 | ||
9349 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
9350 | " TLB1CFG " TARGET_FMT_lx "\n", | |
9351 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
9352 | env->spr[SPR_BOOKE_TLB1CFG]); | |
9353 | break; | |
9354 | default: | |
9355 | break; | |
9356 | } | |
f2e63a42 | 9357 | #endif |
79aceca5 | 9358 | |
3fc6c082 FB |
9359 | #undef RGPL |
9360 | #undef RFPL | |
79aceca5 FB |
9361 | } |
9362 | ||
9a78eead | 9363 | void cpu_dump_statistics (CPUState *env, FILE*f, fprintf_function cpu_fprintf, |
76a66253 JM |
9364 | int flags) |
9365 | { | |
9366 | #if defined(DO_PPC_STATISTICS) | |
c227f099 | 9367 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
9368 | int op1, op2, op3; |
9369 | ||
9370 | t1 = env->opcodes; | |
9371 | for (op1 = 0; op1 < 64; op1++) { | |
9372 | handler = t1[op1]; | |
9373 | if (is_indirect_opcode(handler)) { | |
9374 | t2 = ind_table(handler); | |
9375 | for (op2 = 0; op2 < 32; op2++) { | |
9376 | handler = t2[op2]; | |
9377 | if (is_indirect_opcode(handler)) { | |
9378 | t3 = ind_table(handler); | |
9379 | for (op3 = 0; op3 < 32; op3++) { | |
9380 | handler = t3[op3]; | |
9381 | if (handler->count == 0) | |
9382 | continue; | |
9383 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9384 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9385 | op1, op2, op3, op1, (op3 << 5) | op2, |
9386 | handler->oname, | |
9387 | handler->count, handler->count); | |
9388 | } | |
9389 | } else { | |
9390 | if (handler->count == 0) | |
9391 | continue; | |
9392 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 9393 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
9394 | op1, op2, op1, op2, handler->oname, |
9395 | handler->count, handler->count); | |
9396 | } | |
9397 | } | |
9398 | } else { | |
9399 | if (handler->count == 0) | |
9400 | continue; | |
0bfcd599 BS |
9401 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
9402 | " %" PRId64 "\n", | |
76a66253 JM |
9403 | op1, op1, handler->oname, |
9404 | handler->count, handler->count); | |
9405 | } | |
9406 | } | |
9407 | #endif | |
9408 | } | |
9409 | ||
9a64fbe4 | 9410 | /*****************************************************************************/ |
636aa200 BS |
9411 | static inline void gen_intermediate_code_internal(CPUState *env, |
9412 | TranslationBlock *tb, | |
9413 | int search_pc) | |
79aceca5 | 9414 | { |
9fddaa0c | 9415 | DisasContext ctx, *ctxp = &ctx; |
c227f099 | 9416 | opc_handler_t **table, *handler; |
0fa85d43 | 9417 | target_ulong pc_start; |
79aceca5 | 9418 | uint16_t *gen_opc_end; |
a1d1bb31 | 9419 | CPUBreakpoint *bp; |
79aceca5 | 9420 | int j, lj = -1; |
2e70f6ef PB |
9421 | int num_insns; |
9422 | int max_insns; | |
79aceca5 FB |
9423 | |
9424 | pc_start = tb->pc; | |
79aceca5 | 9425 | gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
046d6672 | 9426 | ctx.nip = pc_start; |
79aceca5 | 9427 | ctx.tb = tb; |
e1833e1f | 9428 | ctx.exception = POWERPC_EXCP_NONE; |
3fc6c082 | 9429 | ctx.spr_cb = env->spr_cb; |
76db3ba4 AJ |
9430 | ctx.mem_idx = env->mmu_idx; |
9431 | ctx.access_type = -1; | |
9432 | ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0; | |
d9bce9d9 JM |
9433 | #if defined(TARGET_PPC64) |
9434 | ctx.sf_mode = msr_sf; | |
697ab892 | 9435 | ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); |
9a64fbe4 | 9436 | #endif |
3cc62370 | 9437 | ctx.fpu_enabled = msr_fp; |
a9d9eb8f | 9438 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
d26bfc9a JM |
9439 | ctx.spe_enabled = msr_spe; |
9440 | else | |
9441 | ctx.spe_enabled = 0; | |
a9d9eb8f JM |
9442 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
9443 | ctx.altivec_enabled = msr_vr; | |
9444 | else | |
9445 | ctx.altivec_enabled = 0; | |
d26bfc9a | 9446 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
8cbcb4fa | 9447 | ctx.singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 9448 | else |
8cbcb4fa | 9449 | ctx.singlestep_enabled = 0; |
d26bfc9a | 9450 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
8cbcb4fa AJ |
9451 | ctx.singlestep_enabled |= CPU_BRANCH_STEP; |
9452 | if (unlikely(env->singlestep_enabled)) | |
9453 | ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP; | |
3fc6c082 | 9454 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
9455 | /* Single step trace mode */ |
9456 | msr_se = 1; | |
9457 | #endif | |
2e70f6ef PB |
9458 | num_insns = 0; |
9459 | max_insns = tb->cflags & CF_COUNT_MASK; | |
9460 | if (max_insns == 0) | |
9461 | max_insns = CF_COUNT_MASK; | |
9462 | ||
9463 | gen_icount_start(); | |
9a64fbe4 | 9464 | /* Set env in case of segfault during code fetch */ |
e1833e1f | 9465 | while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) { |
72cf2d4f BS |
9466 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { |
9467 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
a1d1bb31 | 9468 | if (bp->pc == ctx.nip) { |
e06fcd75 | 9469 | gen_debug_exception(ctxp); |
ea4e754f FB |
9470 | break; |
9471 | } | |
9472 | } | |
9473 | } | |
76a66253 | 9474 | if (unlikely(search_pc)) { |
79aceca5 FB |
9475 | j = gen_opc_ptr - gen_opc_buf; |
9476 | if (lj < j) { | |
9477 | lj++; | |
9478 | while (lj < j) | |
9479 | gen_opc_instr_start[lj++] = 0; | |
79aceca5 | 9480 | } |
af4b6c54 AJ |
9481 | gen_opc_pc[lj] = ctx.nip; |
9482 | gen_opc_instr_start[lj] = 1; | |
9483 | gen_opc_icount[lj] = num_insns; | |
79aceca5 | 9484 | } |
d12d51d5 | 9485 | LOG_DISAS("----------------\n"); |
90e189ec | 9486 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", |
d12d51d5 | 9487 | ctx.nip, ctx.mem_idx, (int)msr_ir); |
2e70f6ef PB |
9488 | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
9489 | gen_io_start(); | |
76db3ba4 | 9490 | if (unlikely(ctx.le_mode)) { |
056401ea JM |
9491 | ctx.opcode = bswap32(ldl_code(ctx.nip)); |
9492 | } else { | |
9493 | ctx.opcode = ldl_code(ctx.nip); | |
111bfab3 | 9494 | } |
d12d51d5 | 9495 | LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n", |
9a64fbe4 | 9496 | ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
056401ea | 9497 | opc3(ctx.opcode), little_endian ? "little" : "big"); |
731c54f8 AJ |
9498 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) |
9499 | tcg_gen_debug_insn_start(ctx.nip); | |
046d6672 | 9500 | ctx.nip += 4; |
3fc6c082 | 9501 | table = env->opcodes; |
2e70f6ef | 9502 | num_insns++; |
79aceca5 FB |
9503 | handler = table[opc1(ctx.opcode)]; |
9504 | if (is_indirect_opcode(handler)) { | |
9505 | table = ind_table(handler); | |
9506 | handler = table[opc2(ctx.opcode)]; | |
9507 | if (is_indirect_opcode(handler)) { | |
9508 | table = ind_table(handler); | |
9509 | handler = table[opc3(ctx.opcode)]; | |
9510 | } | |
9511 | } | |
9512 | /* Is opcode *REALLY* valid ? */ | |
76a66253 | 9513 | if (unlikely(handler->handler == &gen_invalid)) { |
93fcfe39 AL |
9514 | if (qemu_log_enabled()) { |
9515 | qemu_log("invalid/unsupported opcode: " | |
90e189ec BS |
9516 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n", |
9517 | opc1(ctx.opcode), opc2(ctx.opcode), | |
9518 | opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir); | |
4b3686fa | 9519 | } |
76a66253 | 9520 | } else { |
70560da7 FC |
9521 | uint32_t inval; |
9522 | ||
9523 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) { | |
9524 | inval = handler->inval2; | |
9525 | } else { | |
9526 | inval = handler->inval1; | |
9527 | } | |
9528 | ||
9529 | if (unlikely((ctx.opcode & inval) != 0)) { | |
93fcfe39 AL |
9530 | if (qemu_log_enabled()) { |
9531 | qemu_log("invalid bits: %08x for opcode: " | |
90e189ec | 9532 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n", |
70560da7 | 9533 | ctx.opcode & inval, opc1(ctx.opcode), |
90e189ec BS |
9534 | opc2(ctx.opcode), opc3(ctx.opcode), |
9535 | ctx.opcode, ctx.nip - 4); | |
76a66253 | 9536 | } |
e06fcd75 | 9537 | gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL); |
4b3686fa | 9538 | break; |
79aceca5 | 9539 | } |
79aceca5 | 9540 | } |
4b3686fa | 9541 | (*(handler->handler))(&ctx); |
76a66253 JM |
9542 | #if defined(DO_PPC_STATISTICS) |
9543 | handler->count++; | |
9544 | #endif | |
9a64fbe4 | 9545 | /* Check trace mode exceptions */ |
8cbcb4fa AJ |
9546 | if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP && |
9547 | (ctx.nip <= 0x100 || ctx.nip > 0xF00) && | |
9548 | ctx.exception != POWERPC_SYSCALL && | |
9549 | ctx.exception != POWERPC_EXCP_TRAP && | |
9550 | ctx.exception != POWERPC_EXCP_BRANCH)) { | |
e06fcd75 | 9551 | gen_exception(ctxp, POWERPC_EXCP_TRACE); |
d26bfc9a | 9552 | } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
2e70f6ef | 9553 | (env->singlestep_enabled) || |
1b530a6d | 9554 | singlestep || |
2e70f6ef | 9555 | num_insns >= max_insns)) { |
d26bfc9a JM |
9556 | /* if we reach a page boundary or are single stepping, stop |
9557 | * generation | |
9558 | */ | |
8dd4983c | 9559 | break; |
76a66253 | 9560 | } |
3fc6c082 | 9561 | } |
2e70f6ef PB |
9562 | if (tb->cflags & CF_LAST_IO) |
9563 | gen_io_end(); | |
e1833e1f | 9564 | if (ctx.exception == POWERPC_EXCP_NONE) { |
c1942362 | 9565 | gen_goto_tb(&ctx, 0, ctx.nip); |
e1833e1f | 9566 | } else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
8cbcb4fa | 9567 | if (unlikely(env->singlestep_enabled)) { |
e06fcd75 | 9568 | gen_debug_exception(ctxp); |
8cbcb4fa | 9569 | } |
76a66253 | 9570 | /* Generate the return instruction */ |
57fec1fe | 9571 | tcg_gen_exit_tb(0); |
9a64fbe4 | 9572 | } |
2e70f6ef | 9573 | gen_icount_end(tb, num_insns); |
79aceca5 | 9574 | *gen_opc_ptr = INDEX_op_end; |
76a66253 | 9575 | if (unlikely(search_pc)) { |
9a64fbe4 FB |
9576 | j = gen_opc_ptr - gen_opc_buf; |
9577 | lj++; | |
9578 | while (lj <= j) | |
9579 | gen_opc_instr_start[lj++] = 0; | |
9a64fbe4 | 9580 | } else { |
046d6672 | 9581 | tb->size = ctx.nip - pc_start; |
2e70f6ef | 9582 | tb->icount = num_insns; |
9a64fbe4 | 9583 | } |
d9bce9d9 | 9584 | #if defined(DEBUG_DISAS) |
8fec2b8c | 9585 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
76a66253 | 9586 | int flags; |
237c0af0 | 9587 | flags = env->bfd_mach; |
76db3ba4 | 9588 | flags |= ctx.le_mode << 16; |
93fcfe39 AL |
9589 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); |
9590 | log_target_disas(pc_start, ctx.nip - pc_start, flags); | |
9591 | qemu_log("\n"); | |
9fddaa0c | 9592 | } |
79aceca5 | 9593 | #endif |
79aceca5 FB |
9594 | } |
9595 | ||
2cfc5f17 | 9596 | void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb) |
79aceca5 | 9597 | { |
2cfc5f17 | 9598 | gen_intermediate_code_internal(env, tb, 0); |
79aceca5 FB |
9599 | } |
9600 | ||
2cfc5f17 | 9601 | void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb) |
79aceca5 | 9602 | { |
2cfc5f17 | 9603 | gen_intermediate_code_internal(env, tb, 1); |
79aceca5 | 9604 | } |
d2856f1a | 9605 | |
e87b7cb0 | 9606 | void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos) |
d2856f1a | 9607 | { |
d2856f1a | 9608 | env->nip = gen_opc_pc[pc_pos]; |
d2856f1a | 9609 | } |