]>
Commit | Line | Data |
---|---|---|
10ec5117 AG |
1 | /* |
2 | * S/390 translation | |
3 | * | |
4 | * Copyright (c) 2009 Ulrich Hecht | |
e023e832 | 5 | * Copyright (c) 2010 Alexander Graf |
10ec5117 AG |
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 | |
70539e18 | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
10ec5117 | 19 | */ |
e023e832 | 20 | |
e023e832 AG |
21 | /* #define DEBUG_INLINE_BRANCHES */ |
22 | #define S390X_DEBUG_DISAS | |
23 | /* #define S390X_DEBUG_DISAS_VERBOSE */ | |
24 | ||
25 | #ifdef S390X_DEBUG_DISAS_VERBOSE | |
26 | # define LOG_DISAS(...) qemu_log(__VA_ARGS__) | |
27 | #else | |
28 | # define LOG_DISAS(...) do { } while (0) | |
29 | #endif | |
10ec5117 AG |
30 | |
31 | #include "cpu.h" | |
76cad711 | 32 | #include "disas/disas.h" |
10ec5117 | 33 | #include "tcg-op.h" |
1de7afc9 | 34 | #include "qemu/log.h" |
58a9e35b | 35 | #include "qemu/host-utils.h" |
10ec5117 | 36 | |
e023e832 AG |
37 | /* global register indexes */ |
38 | static TCGv_ptr cpu_env; | |
39 | ||
022c62cb | 40 | #include "exec/gen-icount.h" |
3208afbe | 41 | #include "helper.h" |
e023e832 | 42 | #define GEN_HELPER 1 |
3208afbe | 43 | #include "helper.h" |
e023e832 | 44 | |
ad044d09 RH |
45 | |
46 | /* Information that (most) every instruction needs to manipulate. */ | |
e023e832 | 47 | typedef struct DisasContext DisasContext; |
ad044d09 RH |
48 | typedef struct DisasInsn DisasInsn; |
49 | typedef struct DisasFields DisasFields; | |
50 | ||
e023e832 | 51 | struct DisasContext { |
e023e832 | 52 | struct TranslationBlock *tb; |
ad044d09 RH |
53 | const DisasInsn *insn; |
54 | DisasFields *fields; | |
55 | uint64_t pc, next_pc; | |
56 | enum cc_op cc_op; | |
57 | bool singlestep_enabled; | |
58 | int is_jmp; | |
e023e832 AG |
59 | }; |
60 | ||
3fde06f5 RH |
61 | /* Information carried about a condition to be evaluated. */ |
62 | typedef struct { | |
63 | TCGCond cond:8; | |
64 | bool is_64; | |
65 | bool g1; | |
66 | bool g2; | |
67 | union { | |
68 | struct { TCGv_i64 a, b; } s64; | |
69 | struct { TCGv_i32 a, b; } s32; | |
70 | } u; | |
71 | } DisasCompare; | |
72 | ||
e023e832 AG |
73 | #define DISAS_EXCP 4 |
74 | ||
75 | static void gen_op_calc_cc(DisasContext *s); | |
76 | ||
77 | #ifdef DEBUG_INLINE_BRANCHES | |
78 | static uint64_t inline_branch_hit[CC_OP_MAX]; | |
79 | static uint64_t inline_branch_miss[CC_OP_MAX]; | |
80 | #endif | |
81 | ||
82 | static inline void debug_insn(uint64_t insn) | |
83 | { | |
84 | LOG_DISAS("insn: 0x%" PRIx64 "\n", insn); | |
85 | } | |
86 | ||
87 | static inline uint64_t pc_to_link_info(DisasContext *s, uint64_t pc) | |
88 | { | |
89 | if (!(s->tb->flags & FLAG_MASK_64)) { | |
90 | if (s->tb->flags & FLAG_MASK_32) { | |
91 | return pc | 0x80000000; | |
92 | } | |
93 | } | |
94 | return pc; | |
95 | } | |
96 | ||
a4e3ad19 | 97 | void cpu_dump_state(CPUS390XState *env, FILE *f, fprintf_function cpu_fprintf, |
10ec5117 AG |
98 | int flags) |
99 | { | |
100 | int i; | |
e023e832 | 101 | |
d885bdd4 RH |
102 | if (env->cc_op > 3) { |
103 | cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %15s\n", | |
104 | env->psw.mask, env->psw.addr, cc_name(env->cc_op)); | |
105 | } else { | |
106 | cpu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %02x\n", | |
107 | env->psw.mask, env->psw.addr, env->cc_op); | |
108 | } | |
109 | ||
10ec5117 | 110 | for (i = 0; i < 16; i++) { |
e023e832 | 111 | cpu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]); |
10ec5117 AG |
112 | if ((i % 4) == 3) { |
113 | cpu_fprintf(f, "\n"); | |
114 | } else { | |
115 | cpu_fprintf(f, " "); | |
116 | } | |
117 | } | |
e023e832 | 118 | |
10ec5117 | 119 | for (i = 0; i < 16; i++) { |
431253c2 | 120 | cpu_fprintf(f, "F%02d=%016" PRIx64, i, env->fregs[i].ll); |
10ec5117 AG |
121 | if ((i % 4) == 3) { |
122 | cpu_fprintf(f, "\n"); | |
123 | } else { | |
124 | cpu_fprintf(f, " "); | |
125 | } | |
126 | } | |
e023e832 | 127 | |
e023e832 AG |
128 | #ifndef CONFIG_USER_ONLY |
129 | for (i = 0; i < 16; i++) { | |
130 | cpu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]); | |
131 | if ((i % 4) == 3) { | |
132 | cpu_fprintf(f, "\n"); | |
133 | } else { | |
134 | cpu_fprintf(f, " "); | |
135 | } | |
136 | } | |
137 | #endif | |
138 | ||
e023e832 AG |
139 | #ifdef DEBUG_INLINE_BRANCHES |
140 | for (i = 0; i < CC_OP_MAX; i++) { | |
141 | cpu_fprintf(f, " %15s = %10ld\t%10ld\n", cc_name(i), | |
142 | inline_branch_miss[i], inline_branch_hit[i]); | |
143 | } | |
144 | #endif | |
d885bdd4 RH |
145 | |
146 | cpu_fprintf(f, "\n"); | |
10ec5117 AG |
147 | } |
148 | ||
e023e832 AG |
149 | static TCGv_i64 psw_addr; |
150 | static TCGv_i64 psw_mask; | |
151 | ||
152 | static TCGv_i32 cc_op; | |
153 | static TCGv_i64 cc_src; | |
154 | static TCGv_i64 cc_dst; | |
155 | static TCGv_i64 cc_vr; | |
156 | ||
431253c2 | 157 | static char cpu_reg_names[32][4]; |
e023e832 | 158 | static TCGv_i64 regs[16]; |
431253c2 | 159 | static TCGv_i64 fregs[16]; |
e023e832 AG |
160 | |
161 | static uint8_t gen_opc_cc_op[OPC_BUF_SIZE]; | |
162 | ||
d5a43964 AG |
163 | void s390x_translate_init(void) |
164 | { | |
e023e832 | 165 | int i; |
e023e832 AG |
166 | |
167 | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); | |
431253c2 RH |
168 | psw_addr = tcg_global_mem_new_i64(TCG_AREG0, |
169 | offsetof(CPUS390XState, psw.addr), | |
e023e832 | 170 | "psw_addr"); |
431253c2 RH |
171 | psw_mask = tcg_global_mem_new_i64(TCG_AREG0, |
172 | offsetof(CPUS390XState, psw.mask), | |
e023e832 AG |
173 | "psw_mask"); |
174 | ||
a4e3ad19 | 175 | cc_op = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUS390XState, cc_op), |
e023e832 | 176 | "cc_op"); |
a4e3ad19 | 177 | cc_src = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_src), |
e023e832 | 178 | "cc_src"); |
a4e3ad19 | 179 | cc_dst = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_dst), |
e023e832 | 180 | "cc_dst"); |
a4e3ad19 | 181 | cc_vr = tcg_global_mem_new_i64(TCG_AREG0, offsetof(CPUS390XState, cc_vr), |
e023e832 AG |
182 | "cc_vr"); |
183 | ||
e023e832 | 184 | for (i = 0; i < 16; i++) { |
431253c2 | 185 | snprintf(cpu_reg_names[i], sizeof(cpu_reg_names[0]), "r%d", i); |
e023e832 | 186 | regs[i] = tcg_global_mem_new(TCG_AREG0, |
431253c2 RH |
187 | offsetof(CPUS390XState, regs[i]), |
188 | cpu_reg_names[i]); | |
189 | } | |
190 | ||
191 | for (i = 0; i < 16; i++) { | |
192 | snprintf(cpu_reg_names[i + 16], sizeof(cpu_reg_names[0]), "f%d", i); | |
193 | fregs[i] = tcg_global_mem_new(TCG_AREG0, | |
194 | offsetof(CPUS390XState, fregs[i].d), | |
195 | cpu_reg_names[i + 16]); | |
e023e832 | 196 | } |
7e68da2a RH |
197 | |
198 | /* register helpers */ | |
199 | #define GEN_HELPER 2 | |
200 | #include "helper.h" | |
d5a43964 AG |
201 | } |
202 | ||
e023e832 | 203 | static inline TCGv_i64 load_reg(int reg) |
10ec5117 | 204 | { |
e023e832 AG |
205 | TCGv_i64 r = tcg_temp_new_i64(); |
206 | tcg_gen_mov_i64(r, regs[reg]); | |
207 | return r; | |
10ec5117 AG |
208 | } |
209 | ||
e023e832 | 210 | static inline TCGv_i64 load_freg(int reg) |
10ec5117 | 211 | { |
e023e832 | 212 | TCGv_i64 r = tcg_temp_new_i64(); |
431253c2 | 213 | tcg_gen_mov_i64(r, fregs[reg]); |
e023e832 | 214 | return r; |
10ec5117 AG |
215 | } |
216 | ||
e023e832 | 217 | static inline TCGv_i32 load_freg32(int reg) |
10ec5117 | 218 | { |
e023e832 | 219 | TCGv_i32 r = tcg_temp_new_i32(); |
431253c2 RH |
220 | #if HOST_LONG_BITS == 32 |
221 | tcg_gen_mov_i32(r, TCGV_HIGH(fregs[reg])); | |
222 | #else | |
223 | tcg_gen_shri_i64(MAKE_TCGV_I64(GET_TCGV_I32(r)), fregs[reg], 32); | |
224 | #endif | |
e023e832 AG |
225 | return r; |
226 | } | |
227 | ||
d764a8d1 RH |
228 | static inline TCGv_i64 load_freg32_i64(int reg) |
229 | { | |
230 | TCGv_i64 r = tcg_temp_new_i64(); | |
231 | tcg_gen_shri_i64(r, fregs[reg], 32); | |
232 | return r; | |
233 | } | |
234 | ||
e023e832 AG |
235 | static inline TCGv_i32 load_reg32(int reg) |
236 | { | |
237 | TCGv_i32 r = tcg_temp_new_i32(); | |
238 | tcg_gen_trunc_i64_i32(r, regs[reg]); | |
239 | return r; | |
240 | } | |
241 | ||
242 | static inline TCGv_i64 load_reg32_i64(int reg) | |
243 | { | |
244 | TCGv_i64 r = tcg_temp_new_i64(); | |
245 | tcg_gen_ext32s_i64(r, regs[reg]); | |
246 | return r; | |
247 | } | |
248 | ||
249 | static inline void store_reg(int reg, TCGv_i64 v) | |
250 | { | |
251 | tcg_gen_mov_i64(regs[reg], v); | |
252 | } | |
253 | ||
254 | static inline void store_freg(int reg, TCGv_i64 v) | |
255 | { | |
431253c2 | 256 | tcg_gen_mov_i64(fregs[reg], v); |
e023e832 AG |
257 | } |
258 | ||
259 | static inline void store_reg32(int reg, TCGv_i32 v) | |
260 | { | |
431253c2 | 261 | /* 32 bit register writes keep the upper half */ |
e023e832 AG |
262 | #if HOST_LONG_BITS == 32 |
263 | tcg_gen_mov_i32(TCGV_LOW(regs[reg]), v); | |
264 | #else | |
431253c2 RH |
265 | tcg_gen_deposit_i64(regs[reg], regs[reg], |
266 | MAKE_TCGV_I64(GET_TCGV_I32(v)), 0, 32); | |
e023e832 AG |
267 | #endif |
268 | } | |
269 | ||
270 | static inline void store_reg32_i64(int reg, TCGv_i64 v) | |
271 | { | |
272 | /* 32 bit register writes keep the upper half */ | |
e023e832 | 273 | tcg_gen_deposit_i64(regs[reg], regs[reg], v, 0, 32); |
e023e832 AG |
274 | } |
275 | ||
77f8d6c3 RH |
276 | static inline void store_reg32h_i64(int reg, TCGv_i64 v) |
277 | { | |
278 | tcg_gen_deposit_i64(regs[reg], regs[reg], v, 32, 32); | |
279 | } | |
280 | ||
e023e832 AG |
281 | static inline void store_freg32(int reg, TCGv_i32 v) |
282 | { | |
431253c2 RH |
283 | /* 32 bit register writes keep the lower half */ |
284 | #if HOST_LONG_BITS == 32 | |
285 | tcg_gen_mov_i32(TCGV_HIGH(fregs[reg]), v); | |
286 | #else | |
287 | tcg_gen_deposit_i64(fregs[reg], fregs[reg], | |
288 | MAKE_TCGV_I64(GET_TCGV_I32(v)), 32, 32); | |
289 | #endif | |
e023e832 AG |
290 | } |
291 | ||
d764a8d1 RH |
292 | static inline void store_freg32_i64(int reg, TCGv_i64 v) |
293 | { | |
294 | tcg_gen_deposit_i64(fregs[reg], fregs[reg], v, 32, 32); | |
295 | } | |
296 | ||
1ac5889f RH |
297 | static inline void return_low128(TCGv_i64 dest) |
298 | { | |
299 | tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUS390XState, retxl)); | |
300 | } | |
301 | ||
e023e832 AG |
302 | static inline void update_psw_addr(DisasContext *s) |
303 | { | |
304 | /* psw.addr */ | |
305 | tcg_gen_movi_i64(psw_addr, s->pc); | |
306 | } | |
307 | ||
308 | static inline void potential_page_fault(DisasContext *s) | |
309 | { | |
310 | #ifndef CONFIG_USER_ONLY | |
311 | update_psw_addr(s); | |
312 | gen_op_calc_cc(s); | |
313 | #endif | |
314 | } | |
315 | ||
46ee3d84 | 316 | static inline uint64_t ld_code2(CPUS390XState *env, uint64_t pc) |
e023e832 | 317 | { |
46ee3d84 | 318 | return (uint64_t)cpu_lduw_code(env, pc); |
e023e832 AG |
319 | } |
320 | ||
46ee3d84 | 321 | static inline uint64_t ld_code4(CPUS390XState *env, uint64_t pc) |
e023e832 | 322 | { |
ad044d09 | 323 | return (uint64_t)(uint32_t)cpu_ldl_code(env, pc); |
e023e832 AG |
324 | } |
325 | ||
46ee3d84 | 326 | static inline uint64_t ld_code6(CPUS390XState *env, uint64_t pc) |
e023e832 | 327 | { |
ad044d09 | 328 | return (ld_code2(env, pc) << 32) | ld_code4(env, pc + 2); |
e023e832 AG |
329 | } |
330 | ||
331 | static inline int get_mem_index(DisasContext *s) | |
332 | { | |
333 | switch (s->tb->flags & FLAG_MASK_ASC) { | |
334 | case PSW_ASC_PRIMARY >> 32: | |
335 | return 0; | |
336 | case PSW_ASC_SECONDARY >> 32: | |
337 | return 1; | |
338 | case PSW_ASC_HOME >> 32: | |
339 | return 2; | |
340 | default: | |
341 | tcg_abort(); | |
342 | break; | |
343 | } | |
344 | } | |
345 | ||
d5a103cd | 346 | static void gen_exception(int excp) |
e023e832 | 347 | { |
d5a103cd | 348 | TCGv_i32 tmp = tcg_const_i32(excp); |
089f5c06 | 349 | gen_helper_exception(cpu_env, tmp); |
e023e832 | 350 | tcg_temp_free_i32(tmp); |
e023e832 AG |
351 | } |
352 | ||
d5a103cd | 353 | static void gen_program_exception(DisasContext *s, int code) |
e023e832 AG |
354 | { |
355 | TCGv_i32 tmp; | |
356 | ||
d5a103cd | 357 | /* Remember what pgm exeption this was. */ |
e023e832 | 358 | tmp = tcg_const_i32(code); |
a4e3ad19 | 359 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_code)); |
e023e832 AG |
360 | tcg_temp_free_i32(tmp); |
361 | ||
d5a103cd RH |
362 | tmp = tcg_const_i32(s->next_pc - s->pc); |
363 | tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_ilen)); | |
e023e832 AG |
364 | tcg_temp_free_i32(tmp); |
365 | ||
d5a103cd RH |
366 | /* Advance past instruction. */ |
367 | s->pc = s->next_pc; | |
e023e832 AG |
368 | update_psw_addr(s); |
369 | ||
d5a103cd | 370 | /* Save off cc. */ |
e023e832 AG |
371 | gen_op_calc_cc(s); |
372 | ||
d5a103cd RH |
373 | /* Trigger exception. */ |
374 | gen_exception(EXCP_PGM); | |
e023e832 | 375 | |
d5a103cd | 376 | /* End TB here. */ |
e023e832 AG |
377 | s->is_jmp = DISAS_EXCP; |
378 | } | |
379 | ||
d5a103cd | 380 | static inline void gen_illegal_opcode(DisasContext *s) |
e023e832 | 381 | { |
d5a103cd | 382 | gen_program_exception(s, PGM_SPECIFICATION); |
e023e832 AG |
383 | } |
384 | ||
d5a103cd | 385 | static inline void check_privileged(DisasContext *s) |
e023e832 AG |
386 | { |
387 | if (s->tb->flags & (PSW_MASK_PSTATE >> 32)) { | |
d5a103cd | 388 | gen_program_exception(s, PGM_PRIVILEGED); |
e023e832 AG |
389 | } |
390 | } | |
391 | ||
e023e832 AG |
392 | static TCGv_i64 get_address(DisasContext *s, int x2, int b2, int d2) |
393 | { | |
394 | TCGv_i64 tmp; | |
395 | ||
396 | /* 31-bitify the immediate part; register contents are dealt with below */ | |
397 | if (!(s->tb->flags & FLAG_MASK_64)) { | |
398 | d2 &= 0x7fffffffUL; | |
399 | } | |
400 | ||
401 | if (x2) { | |
402 | if (d2) { | |
403 | tmp = tcg_const_i64(d2); | |
404 | tcg_gen_add_i64(tmp, tmp, regs[x2]); | |
405 | } else { | |
406 | tmp = load_reg(x2); | |
407 | } | |
408 | if (b2) { | |
409 | tcg_gen_add_i64(tmp, tmp, regs[b2]); | |
410 | } | |
411 | } else if (b2) { | |
412 | if (d2) { | |
413 | tmp = tcg_const_i64(d2); | |
414 | tcg_gen_add_i64(tmp, tmp, regs[b2]); | |
415 | } else { | |
416 | tmp = load_reg(b2); | |
417 | } | |
418 | } else { | |
419 | tmp = tcg_const_i64(d2); | |
420 | } | |
421 | ||
422 | /* 31-bit mode mask if there are values loaded from registers */ | |
423 | if (!(s->tb->flags & FLAG_MASK_64) && (x2 || b2)) { | |
424 | tcg_gen_andi_i64(tmp, tmp, 0x7fffffffUL); | |
425 | } | |
426 | ||
427 | return tmp; | |
428 | } | |
429 | ||
aa31bf60 | 430 | static inline void gen_op_movi_cc(DisasContext *s, uint32_t val) |
e023e832 AG |
431 | { |
432 | s->cc_op = CC_OP_CONST0 + val; | |
433 | } | |
434 | ||
435 | static void gen_op_update1_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 dst) | |
436 | { | |
437 | tcg_gen_discard_i64(cc_src); | |
438 | tcg_gen_mov_i64(cc_dst, dst); | |
439 | tcg_gen_discard_i64(cc_vr); | |
440 | s->cc_op = op; | |
441 | } | |
442 | ||
443 | static void gen_op_update1_cc_i32(DisasContext *s, enum cc_op op, TCGv_i32 dst) | |
444 | { | |
445 | tcg_gen_discard_i64(cc_src); | |
446 | tcg_gen_extu_i32_i64(cc_dst, dst); | |
447 | tcg_gen_discard_i64(cc_vr); | |
448 | s->cc_op = op; | |
449 | } | |
450 | ||
451 | static void gen_op_update2_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src, | |
452 | TCGv_i64 dst) | |
453 | { | |
454 | tcg_gen_mov_i64(cc_src, src); | |
455 | tcg_gen_mov_i64(cc_dst, dst); | |
456 | tcg_gen_discard_i64(cc_vr); | |
457 | s->cc_op = op; | |
458 | } | |
459 | ||
460 | static void gen_op_update2_cc_i32(DisasContext *s, enum cc_op op, TCGv_i32 src, | |
461 | TCGv_i32 dst) | |
462 | { | |
463 | tcg_gen_extu_i32_i64(cc_src, src); | |
464 | tcg_gen_extu_i32_i64(cc_dst, dst); | |
465 | tcg_gen_discard_i64(cc_vr); | |
466 | s->cc_op = op; | |
467 | } | |
468 | ||
469 | static void gen_op_update3_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src, | |
470 | TCGv_i64 dst, TCGv_i64 vr) | |
471 | { | |
472 | tcg_gen_mov_i64(cc_src, src); | |
473 | tcg_gen_mov_i64(cc_dst, dst); | |
474 | tcg_gen_mov_i64(cc_vr, vr); | |
475 | s->cc_op = op; | |
476 | } | |
477 | ||
e023e832 AG |
478 | static inline void set_cc_nz_u32(DisasContext *s, TCGv_i32 val) |
479 | { | |
480 | gen_op_update1_cc_i32(s, CC_OP_NZ, val); | |
481 | } | |
482 | ||
483 | static inline void set_cc_nz_u64(DisasContext *s, TCGv_i64 val) | |
484 | { | |
485 | gen_op_update1_cc_i64(s, CC_OP_NZ, val); | |
486 | } | |
487 | ||
68c8bd93 RH |
488 | static inline void gen_set_cc_nz_f32(DisasContext *s, TCGv_i64 val) |
489 | { | |
490 | gen_op_update1_cc_i64(s, CC_OP_NZ_F32, val); | |
491 | } | |
492 | ||
493 | static inline void gen_set_cc_nz_f64(DisasContext *s, TCGv_i64 val) | |
494 | { | |
495 | gen_op_update1_cc_i64(s, CC_OP_NZ_F64, val); | |
496 | } | |
497 | ||
498 | static inline void gen_set_cc_nz_f128(DisasContext *s, TCGv_i64 vh, TCGv_i64 vl) | |
499 | { | |
500 | gen_op_update2_cc_i64(s, CC_OP_NZ_F128, vh, vl); | |
501 | } | |
502 | ||
e023e832 AG |
503 | static inline void cmp_32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2, |
504 | enum cc_op cond) | |
505 | { | |
506 | gen_op_update2_cc_i32(s, cond, v1, v2); | |
507 | } | |
508 | ||
509 | static inline void cmp_64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2, | |
510 | enum cc_op cond) | |
511 | { | |
512 | gen_op_update2_cc_i64(s, cond, v1, v2); | |
513 | } | |
514 | ||
515 | static inline void cmp_s32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2) | |
516 | { | |
517 | cmp_32(s, v1, v2, CC_OP_LTGT_32); | |
518 | } | |
519 | ||
520 | static inline void cmp_u32(DisasContext *s, TCGv_i32 v1, TCGv_i32 v2) | |
521 | { | |
522 | cmp_32(s, v1, v2, CC_OP_LTUGTU_32); | |
523 | } | |
524 | ||
525 | static inline void cmp_s32c(DisasContext *s, TCGv_i32 v1, int32_t v2) | |
526 | { | |
527 | /* XXX optimize for the constant? put it in s? */ | |
528 | TCGv_i32 tmp = tcg_const_i32(v2); | |
529 | cmp_32(s, v1, tmp, CC_OP_LTGT_32); | |
530 | tcg_temp_free_i32(tmp); | |
531 | } | |
532 | ||
533 | static inline void cmp_u32c(DisasContext *s, TCGv_i32 v1, uint32_t v2) | |
534 | { | |
535 | TCGv_i32 tmp = tcg_const_i32(v2); | |
536 | cmp_32(s, v1, tmp, CC_OP_LTUGTU_32); | |
537 | tcg_temp_free_i32(tmp); | |
538 | } | |
539 | ||
540 | static inline void cmp_s64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2) | |
541 | { | |
542 | cmp_64(s, v1, v2, CC_OP_LTGT_64); | |
543 | } | |
544 | ||
545 | static inline void cmp_u64(DisasContext *s, TCGv_i64 v1, TCGv_i64 v2) | |
546 | { | |
547 | cmp_64(s, v1, v2, CC_OP_LTUGTU_64); | |
548 | } | |
549 | ||
550 | static inline void cmp_s64c(DisasContext *s, TCGv_i64 v1, int64_t v2) | |
551 | { | |
552 | TCGv_i64 tmp = tcg_const_i64(v2); | |
553 | cmp_s64(s, v1, tmp); | |
554 | tcg_temp_free_i64(tmp); | |
555 | } | |
556 | ||
557 | static inline void cmp_u64c(DisasContext *s, TCGv_i64 v1, uint64_t v2) | |
558 | { | |
559 | TCGv_i64 tmp = tcg_const_i64(v2); | |
560 | cmp_u64(s, v1, tmp); | |
561 | tcg_temp_free_i64(tmp); | |
562 | } | |
563 | ||
564 | static inline void set_cc_s32(DisasContext *s, TCGv_i32 val) | |
565 | { | |
566 | gen_op_update1_cc_i32(s, CC_OP_LTGT0_32, val); | |
567 | } | |
568 | ||
569 | static inline void set_cc_s64(DisasContext *s, TCGv_i64 val) | |
570 | { | |
571 | gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, val); | |
572 | } | |
573 | ||
e023e832 AG |
574 | /* CC value is in env->cc_op */ |
575 | static inline void set_cc_static(DisasContext *s) | |
576 | { | |
577 | tcg_gen_discard_i64(cc_src); | |
578 | tcg_gen_discard_i64(cc_dst); | |
579 | tcg_gen_discard_i64(cc_vr); | |
580 | s->cc_op = CC_OP_STATIC; | |
581 | } | |
582 | ||
583 | static inline void gen_op_set_cc_op(DisasContext *s) | |
584 | { | |
585 | if (s->cc_op != CC_OP_DYNAMIC && s->cc_op != CC_OP_STATIC) { | |
586 | tcg_gen_movi_i32(cc_op, s->cc_op); | |
587 | } | |
588 | } | |
589 | ||
590 | static inline void gen_update_cc_op(DisasContext *s) | |
591 | { | |
592 | gen_op_set_cc_op(s); | |
593 | } | |
594 | ||
595 | /* calculates cc into cc_op */ | |
596 | static void gen_op_calc_cc(DisasContext *s) | |
597 | { | |
598 | TCGv_i32 local_cc_op = tcg_const_i32(s->cc_op); | |
599 | TCGv_i64 dummy = tcg_const_i64(0); | |
600 | ||
601 | switch (s->cc_op) { | |
602 | case CC_OP_CONST0: | |
603 | case CC_OP_CONST1: | |
604 | case CC_OP_CONST2: | |
605 | case CC_OP_CONST3: | |
606 | /* s->cc_op is the cc value */ | |
607 | tcg_gen_movi_i32(cc_op, s->cc_op - CC_OP_CONST0); | |
608 | break; | |
609 | case CC_OP_STATIC: | |
610 | /* env->cc_op already is the cc value */ | |
611 | break; | |
612 | case CC_OP_NZ: | |
613 | case CC_OP_ABS_64: | |
614 | case CC_OP_NABS_64: | |
615 | case CC_OP_ABS_32: | |
616 | case CC_OP_NABS_32: | |
617 | case CC_OP_LTGT0_32: | |
618 | case CC_OP_LTGT0_64: | |
619 | case CC_OP_COMP_32: | |
620 | case CC_OP_COMP_64: | |
621 | case CC_OP_NZ_F32: | |
622 | case CC_OP_NZ_F64: | |
102bf2c6 | 623 | case CC_OP_FLOGR: |
e023e832 | 624 | /* 1 argument */ |
932385a3 | 625 | gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, dummy, cc_dst, dummy); |
e023e832 AG |
626 | break; |
627 | case CC_OP_ICM: | |
628 | case CC_OP_LTGT_32: | |
629 | case CC_OP_LTGT_64: | |
630 | case CC_OP_LTUGTU_32: | |
631 | case CC_OP_LTUGTU_64: | |
632 | case CC_OP_TM_32: | |
633 | case CC_OP_TM_64: | |
cbe24bfa RH |
634 | case CC_OP_SLA_32: |
635 | case CC_OP_SLA_64: | |
587626f8 | 636 | case CC_OP_NZ_F128: |
e023e832 | 637 | /* 2 arguments */ |
932385a3 | 638 | gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, dummy); |
e023e832 AG |
639 | break; |
640 | case CC_OP_ADD_64: | |
641 | case CC_OP_ADDU_64: | |
4e4bb438 | 642 | case CC_OP_ADDC_64: |
e023e832 AG |
643 | case CC_OP_SUB_64: |
644 | case CC_OP_SUBU_64: | |
4e4bb438 | 645 | case CC_OP_SUBB_64: |
e023e832 AG |
646 | case CC_OP_ADD_32: |
647 | case CC_OP_ADDU_32: | |
4e4bb438 | 648 | case CC_OP_ADDC_32: |
e023e832 AG |
649 | case CC_OP_SUB_32: |
650 | case CC_OP_SUBU_32: | |
4e4bb438 | 651 | case CC_OP_SUBB_32: |
e023e832 | 652 | /* 3 arguments */ |
932385a3 | 653 | gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, cc_vr); |
e023e832 AG |
654 | break; |
655 | case CC_OP_DYNAMIC: | |
656 | /* unknown operation - assume 3 arguments and cc_op in env */ | |
932385a3 | 657 | gen_helper_calc_cc(cc_op, cpu_env, cc_op, cc_src, cc_dst, cc_vr); |
e023e832 AG |
658 | break; |
659 | default: | |
660 | tcg_abort(); | |
661 | } | |
662 | ||
663 | tcg_temp_free_i32(local_cc_op); | |
063eb0f3 | 664 | tcg_temp_free_i64(dummy); |
e023e832 AG |
665 | |
666 | /* We now have cc in cc_op as constant */ | |
667 | set_cc_static(s); | |
668 | } | |
669 | ||
670 | static inline void decode_rr(DisasContext *s, uint64_t insn, int *r1, int *r2) | |
671 | { | |
672 | debug_insn(insn); | |
673 | ||
674 | *r1 = (insn >> 4) & 0xf; | |
675 | *r2 = insn & 0xf; | |
676 | } | |
677 | ||
678 | static inline TCGv_i64 decode_rx(DisasContext *s, uint64_t insn, int *r1, | |
679 | int *x2, int *b2, int *d2) | |
680 | { | |
681 | debug_insn(insn); | |
682 | ||
683 | *r1 = (insn >> 20) & 0xf; | |
684 | *x2 = (insn >> 16) & 0xf; | |
685 | *b2 = (insn >> 12) & 0xf; | |
686 | *d2 = insn & 0xfff; | |
687 | ||
688 | return get_address(s, *x2, *b2, *d2); | |
689 | } | |
690 | ||
691 | static inline void decode_rs(DisasContext *s, uint64_t insn, int *r1, int *r3, | |
692 | int *b2, int *d2) | |
693 | { | |
694 | debug_insn(insn); | |
695 | ||
696 | *r1 = (insn >> 20) & 0xf; | |
697 | /* aka m3 */ | |
698 | *r3 = (insn >> 16) & 0xf; | |
699 | *b2 = (insn >> 12) & 0xf; | |
700 | *d2 = insn & 0xfff; | |
701 | } | |
702 | ||
703 | static inline TCGv_i64 decode_si(DisasContext *s, uint64_t insn, int *i2, | |
704 | int *b1, int *d1) | |
705 | { | |
706 | debug_insn(insn); | |
707 | ||
708 | *i2 = (insn >> 16) & 0xff; | |
709 | *b1 = (insn >> 12) & 0xf; | |
710 | *d1 = insn & 0xfff; | |
711 | ||
712 | return get_address(s, 0, *b1, *d1); | |
713 | } | |
714 | ||
8ac33cdb | 715 | static int use_goto_tb(DisasContext *s, uint64_t dest) |
e023e832 | 716 | { |
8ac33cdb RH |
717 | /* NOTE: we handle the case where the TB spans two pages here */ |
718 | return (((dest & TARGET_PAGE_MASK) == (s->tb->pc & TARGET_PAGE_MASK) | |
719 | || (dest & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) | |
720 | && !s->singlestep_enabled | |
721 | && !(s->tb->cflags & CF_LAST_IO)); | |
722 | } | |
e023e832 | 723 | |
8ac33cdb RH |
724 | static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc) |
725 | { | |
e023e832 AG |
726 | gen_update_cc_op(s); |
727 | ||
8ac33cdb | 728 | if (use_goto_tb(s, pc)) { |
e023e832 AG |
729 | tcg_gen_goto_tb(tb_num); |
730 | tcg_gen_movi_i64(psw_addr, pc); | |
8ac33cdb | 731 | tcg_gen_exit_tb((tcg_target_long)s->tb + tb_num); |
e023e832 AG |
732 | } else { |
733 | /* jump to another page: currently not optimized */ | |
734 | tcg_gen_movi_i64(psw_addr, pc); | |
735 | tcg_gen_exit_tb(0); | |
736 | } | |
737 | } | |
738 | ||
739 | static inline void account_noninline_branch(DisasContext *s, int cc_op) | |
740 | { | |
741 | #ifdef DEBUG_INLINE_BRANCHES | |
742 | inline_branch_miss[cc_op]++; | |
743 | #endif | |
744 | } | |
745 | ||
3fde06f5 | 746 | static inline void account_inline_branch(DisasContext *s, int cc_op) |
e023e832 AG |
747 | { |
748 | #ifdef DEBUG_INLINE_BRANCHES | |
3fde06f5 | 749 | inline_branch_hit[cc_op]++; |
e023e832 AG |
750 | #endif |
751 | } | |
752 | ||
3fde06f5 RH |
753 | /* Table of mask values to comparison codes, given a comparison as input. |
754 | For a true comparison CC=3 will never be set, but we treat this | |
755 | conservatively for possible use when CC=3 indicates overflow. */ | |
756 | static const TCGCond ltgt_cond[16] = { | |
757 | TCG_COND_NEVER, TCG_COND_NEVER, /* | | | x */ | |
758 | TCG_COND_GT, TCG_COND_NEVER, /* | | GT | x */ | |
759 | TCG_COND_LT, TCG_COND_NEVER, /* | LT | | x */ | |
760 | TCG_COND_NE, TCG_COND_NEVER, /* | LT | GT | x */ | |
761 | TCG_COND_EQ, TCG_COND_NEVER, /* EQ | | | x */ | |
762 | TCG_COND_GE, TCG_COND_NEVER, /* EQ | | GT | x */ | |
763 | TCG_COND_LE, TCG_COND_NEVER, /* EQ | LT | | x */ | |
764 | TCG_COND_ALWAYS, TCG_COND_ALWAYS, /* EQ | LT | GT | x */ | |
765 | }; | |
766 | ||
767 | /* Table of mask values to comparison codes, given a logic op as input. | |
768 | For such, only CC=0 and CC=1 should be possible. */ | |
769 | static const TCGCond nz_cond[16] = { | |
770 | /* | | x | x */ | |
771 | TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER, TCG_COND_NEVER, | |
772 | /* | NE | x | x */ | |
773 | TCG_COND_NE, TCG_COND_NE, TCG_COND_NE, TCG_COND_NE, | |
774 | /* EQ | | x | x */ | |
775 | TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ, TCG_COND_EQ, | |
776 | /* EQ | NE | x | x */ | |
777 | TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS, TCG_COND_ALWAYS, | |
778 | }; | |
779 | ||
780 | /* Interpret MASK in terms of S->CC_OP, and fill in C with all the | |
781 | details required to generate a TCG comparison. */ | |
782 | static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask) | |
e023e832 | 783 | { |
3fde06f5 RH |
784 | TCGCond cond; |
785 | enum cc_op old_cc_op = s->cc_op; | |
e023e832 | 786 | |
3fde06f5 RH |
787 | if (mask == 15 || mask == 0) { |
788 | c->cond = (mask ? TCG_COND_ALWAYS : TCG_COND_NEVER); | |
789 | c->u.s32.a = cc_op; | |
790 | c->u.s32.b = cc_op; | |
791 | c->g1 = c->g2 = true; | |
792 | c->is_64 = false; | |
793 | return; | |
794 | } | |
795 | ||
796 | /* Find the TCG condition for the mask + cc op. */ | |
797 | switch (old_cc_op) { | |
e023e832 | 798 | case CC_OP_LTGT0_32: |
e023e832 | 799 | case CC_OP_LTGT0_64: |
e023e832 | 800 | case CC_OP_LTGT_32: |
e023e832 | 801 | case CC_OP_LTGT_64: |
3fde06f5 RH |
802 | cond = ltgt_cond[mask]; |
803 | if (cond == TCG_COND_NEVER) { | |
e023e832 AG |
804 | goto do_dynamic; |
805 | } | |
3fde06f5 | 806 | account_inline_branch(s, old_cc_op); |
e023e832 | 807 | break; |
3fde06f5 | 808 | |
e023e832 | 809 | case CC_OP_LTUGTU_32: |
e023e832 | 810 | case CC_OP_LTUGTU_64: |
3fde06f5 RH |
811 | cond = tcg_unsigned_cond(ltgt_cond[mask]); |
812 | if (cond == TCG_COND_NEVER) { | |
e023e832 AG |
813 | goto do_dynamic; |
814 | } | |
3fde06f5 | 815 | account_inline_branch(s, old_cc_op); |
e023e832 | 816 | break; |
3fde06f5 | 817 | |
e023e832 | 818 | case CC_OP_NZ: |
3fde06f5 RH |
819 | cond = nz_cond[mask]; |
820 | if (cond == TCG_COND_NEVER) { | |
e023e832 AG |
821 | goto do_dynamic; |
822 | } | |
3fde06f5 | 823 | account_inline_branch(s, old_cc_op); |
e023e832 | 824 | break; |
e023e832 | 825 | |
3fde06f5 | 826 | case CC_OP_TM_32: |
e023e832 | 827 | case CC_OP_TM_64: |
e023e832 | 828 | switch (mask) { |
3fde06f5 RH |
829 | case 8: |
830 | cond = TCG_COND_EQ; | |
e023e832 | 831 | break; |
3fde06f5 RH |
832 | case 4 | 2 | 1: |
833 | cond = TCG_COND_NE; | |
e023e832 AG |
834 | break; |
835 | default: | |
836 | goto do_dynamic; | |
837 | } | |
3fde06f5 | 838 | account_inline_branch(s, old_cc_op); |
e023e832 | 839 | break; |
3fde06f5 | 840 | |
e023e832 AG |
841 | case CC_OP_ICM: |
842 | switch (mask) { | |
3fde06f5 RH |
843 | case 8: |
844 | cond = TCG_COND_EQ; | |
e023e832 | 845 | break; |
3fde06f5 RH |
846 | case 4 | 2 | 1: |
847 | case 4 | 2: | |
848 | cond = TCG_COND_NE; | |
e023e832 AG |
849 | break; |
850 | default: | |
851 | goto do_dynamic; | |
852 | } | |
3fde06f5 | 853 | account_inline_branch(s, old_cc_op); |
e023e832 | 854 | break; |
3fde06f5 | 855 | |
102bf2c6 RH |
856 | case CC_OP_FLOGR: |
857 | switch (mask & 0xa) { | |
858 | case 8: /* src == 0 -> no one bit found */ | |
859 | cond = TCG_COND_EQ; | |
860 | break; | |
861 | case 2: /* src != 0 -> one bit found */ | |
862 | cond = TCG_COND_NE; | |
863 | break; | |
864 | default: | |
865 | goto do_dynamic; | |
866 | } | |
867 | account_inline_branch(s, old_cc_op); | |
868 | break; | |
869 | ||
e023e832 | 870 | default: |
3fde06f5 RH |
871 | do_dynamic: |
872 | /* Calculate cc value. */ | |
e023e832 | 873 | gen_op_calc_cc(s); |
3fde06f5 | 874 | /* FALLTHRU */ |
e023e832 | 875 | |
3fde06f5 RH |
876 | case CC_OP_STATIC: |
877 | /* Jump based on CC. We'll load up the real cond below; | |
878 | the assignment here merely avoids a compiler warning. */ | |
e023e832 | 879 | account_noninline_branch(s, old_cc_op); |
3fde06f5 RH |
880 | old_cc_op = CC_OP_STATIC; |
881 | cond = TCG_COND_NEVER; | |
882 | break; | |
883 | } | |
e023e832 | 884 | |
3fde06f5 RH |
885 | /* Load up the arguments of the comparison. */ |
886 | c->is_64 = true; | |
887 | c->g1 = c->g2 = false; | |
888 | switch (old_cc_op) { | |
889 | case CC_OP_LTGT0_32: | |
890 | c->is_64 = false; | |
891 | c->u.s32.a = tcg_temp_new_i32(); | |
892 | tcg_gen_trunc_i64_i32(c->u.s32.a, cc_dst); | |
893 | c->u.s32.b = tcg_const_i32(0); | |
894 | break; | |
895 | case CC_OP_LTGT_32: | |
896 | case CC_OP_LTUGTU_32: | |
897 | c->is_64 = false; | |
898 | c->u.s32.a = tcg_temp_new_i32(); | |
899 | tcg_gen_trunc_i64_i32(c->u.s32.a, cc_src); | |
900 | c->u.s32.b = tcg_temp_new_i32(); | |
901 | tcg_gen_trunc_i64_i32(c->u.s32.b, cc_dst); | |
902 | break; | |
903 | ||
904 | case CC_OP_LTGT0_64: | |
905 | case CC_OP_NZ: | |
102bf2c6 | 906 | case CC_OP_FLOGR: |
3fde06f5 RH |
907 | c->u.s64.a = cc_dst; |
908 | c->u.s64.b = tcg_const_i64(0); | |
909 | c->g1 = true; | |
910 | break; | |
911 | case CC_OP_LTGT_64: | |
912 | case CC_OP_LTUGTU_64: | |
913 | c->u.s64.a = cc_src; | |
914 | c->u.s64.b = cc_dst; | |
915 | c->g1 = c->g2 = true; | |
916 | break; | |
917 | ||
918 | case CC_OP_TM_32: | |
919 | case CC_OP_TM_64: | |
58a9e35b | 920 | case CC_OP_ICM: |
3fde06f5 RH |
921 | c->u.s64.a = tcg_temp_new_i64(); |
922 | c->u.s64.b = tcg_const_i64(0); | |
923 | tcg_gen_and_i64(c->u.s64.a, cc_src, cc_dst); | |
924 | break; | |
925 | ||
926 | case CC_OP_STATIC: | |
927 | c->is_64 = false; | |
928 | c->u.s32.a = cc_op; | |
929 | c->g1 = true; | |
e023e832 | 930 | switch (mask) { |
e023e832 | 931 | case 0x8 | 0x4 | 0x2: /* cc != 3 */ |
3fde06f5 RH |
932 | cond = TCG_COND_NE; |
933 | c->u.s32.b = tcg_const_i32(3); | |
e023e832 AG |
934 | break; |
935 | case 0x8 | 0x4 | 0x1: /* cc != 2 */ | |
3fde06f5 RH |
936 | cond = TCG_COND_NE; |
937 | c->u.s32.b = tcg_const_i32(2); | |
e023e832 AG |
938 | break; |
939 | case 0x8 | 0x2 | 0x1: /* cc != 1 */ | |
3fde06f5 RH |
940 | cond = TCG_COND_NE; |
941 | c->u.s32.b = tcg_const_i32(1); | |
e023e832 | 942 | break; |
3fde06f5 RH |
943 | case 0x8 | 0x2: /* cc == 0 || cc == 2 => (cc & 1) == 0 */ |
944 | cond = TCG_COND_EQ; | |
945 | c->g1 = false; | |
946 | c->u.s32.a = tcg_temp_new_i32(); | |
947 | c->u.s32.b = tcg_const_i32(0); | |
948 | tcg_gen_andi_i32(c->u.s32.a, cc_op, 1); | |
e023e832 AG |
949 | break; |
950 | case 0x8 | 0x4: /* cc < 2 */ | |
3fde06f5 RH |
951 | cond = TCG_COND_LTU; |
952 | c->u.s32.b = tcg_const_i32(2); | |
e023e832 AG |
953 | break; |
954 | case 0x8: /* cc == 0 */ | |
3fde06f5 RH |
955 | cond = TCG_COND_EQ; |
956 | c->u.s32.b = tcg_const_i32(0); | |
e023e832 AG |
957 | break; |
958 | case 0x4 | 0x2 | 0x1: /* cc != 0 */ | |
3fde06f5 RH |
959 | cond = TCG_COND_NE; |
960 | c->u.s32.b = tcg_const_i32(0); | |
e023e832 | 961 | break; |
3fde06f5 RH |
962 | case 0x4 | 0x1: /* cc == 1 || cc == 3 => (cc & 1) != 0 */ |
963 | cond = TCG_COND_NE; | |
964 | c->g1 = false; | |
965 | c->u.s32.a = tcg_temp_new_i32(); | |
966 | c->u.s32.b = tcg_const_i32(0); | |
967 | tcg_gen_andi_i32(c->u.s32.a, cc_op, 1); | |
e023e832 AG |
968 | break; |
969 | case 0x4: /* cc == 1 */ | |
3fde06f5 RH |
970 | cond = TCG_COND_EQ; |
971 | c->u.s32.b = tcg_const_i32(1); | |
e023e832 AG |
972 | break; |
973 | case 0x2 | 0x1: /* cc > 1 */ | |
3fde06f5 RH |
974 | cond = TCG_COND_GTU; |
975 | c->u.s32.b = tcg_const_i32(1); | |
e023e832 AG |
976 | break; |
977 | case 0x2: /* cc == 2 */ | |
3fde06f5 RH |
978 | cond = TCG_COND_EQ; |
979 | c->u.s32.b = tcg_const_i32(2); | |
e023e832 AG |
980 | break; |
981 | case 0x1: /* cc == 3 */ | |
3fde06f5 RH |
982 | cond = TCG_COND_EQ; |
983 | c->u.s32.b = tcg_const_i32(3); | |
e023e832 | 984 | break; |
3fde06f5 RH |
985 | default: |
986 | /* CC is masked by something else: (8 >> cc) & mask. */ | |
987 | cond = TCG_COND_NE; | |
988 | c->g1 = false; | |
989 | c->u.s32.a = tcg_const_i32(8); | |
990 | c->u.s32.b = tcg_const_i32(0); | |
991 | tcg_gen_shr_i32(c->u.s32.a, c->u.s32.a, cc_op); | |
992 | tcg_gen_andi_i32(c->u.s32.a, c->u.s32.a, mask); | |
e023e832 AG |
993 | break; |
994 | } | |
995 | break; | |
3fde06f5 RH |
996 | |
997 | default: | |
998 | abort(); | |
e023e832 | 999 | } |
3fde06f5 RH |
1000 | c->cond = cond; |
1001 | } | |
1002 | ||
1003 | static void free_compare(DisasCompare *c) | |
1004 | { | |
1005 | if (!c->g1) { | |
1006 | if (c->is_64) { | |
1007 | tcg_temp_free_i64(c->u.s64.a); | |
1008 | } else { | |
1009 | tcg_temp_free_i32(c->u.s32.a); | |
1010 | } | |
1011 | } | |
1012 | if (!c->g2) { | |
1013 | if (c->is_64) { | |
1014 | tcg_temp_free_i64(c->u.s64.b); | |
1015 | } else { | |
1016 | tcg_temp_free_i32(c->u.s32.b); | |
1017 | } | |
1018 | } | |
1019 | } | |
1020 | ||
46ee3d84 BS |
1021 | static void disas_b2(CPUS390XState *env, DisasContext *s, int op, |
1022 | uint32_t insn) | |
e023e832 | 1023 | { |
4600c994 | 1024 | #ifndef CONFIG_USER_ONLY |
e023e832 | 1025 | TCGv_i64 tmp, tmp2, tmp3; |
4600c994 | 1026 | TCGv_i32 tmp32_1, tmp32_2; |
e023e832 | 1027 | int r1, r2; |
e023e832 | 1028 | int r3, d2, b2; |
e023e832 AG |
1029 | |
1030 | r1 = (insn >> 4) & 0xf; | |
1031 | r2 = insn & 0xf; | |
1032 | ||
1033 | LOG_DISAS("disas_b2: op 0x%x r1 %d r2 %d\n", op, r1, r2); | |
1034 | ||
1035 | switch (op) { | |
e023e832 | 1036 | case 0x79: /* SACF D2(B2) [S] */ |
afd43fec | 1037 | /* Set Address Space Control Fast */ |
d5a103cd | 1038 | check_privileged(s); |
e023e832 AG |
1039 | decode_rs(s, insn, &r1, &r3, &b2, &d2); |
1040 | tmp = get_address(s, 0, b2, d2); | |
1041 | potential_page_fault(s); | |
932385a3 | 1042 | gen_helper_sacf(cpu_env, tmp); |
e023e832 AG |
1043 | tcg_temp_free_i64(tmp); |
1044 | /* addressing mode has changed, so end the block */ | |
d5a103cd | 1045 | s->pc = s->next_pc; |
e023e832 | 1046 | update_psw_addr(s); |
afd43fec | 1047 | s->is_jmp = DISAS_JUMP; |
e023e832 AG |
1048 | break; |
1049 | case 0x7d: /* STSI D2,(B2) [S] */ | |
d5a103cd | 1050 | check_privileged(s); |
e023e832 AG |
1051 | decode_rs(s, insn, &r1, &r3, &b2, &d2); |
1052 | tmp = get_address(s, 0, b2, d2); | |
1053 | tmp32_1 = load_reg32(0); | |
1054 | tmp32_2 = load_reg32(1); | |
1055 | potential_page_fault(s); | |
089f5c06 | 1056 | gen_helper_stsi(cc_op, cpu_env, tmp, tmp32_1, tmp32_2); |
e023e832 AG |
1057 | set_cc_static(s); |
1058 | tcg_temp_free_i64(tmp); | |
1059 | tcg_temp_free_i32(tmp32_1); | |
1060 | tcg_temp_free_i32(tmp32_2); | |
1061 | break; | |
e023e832 AG |
1062 | case 0xb1: /* STFL D2(B2) [S] */ |
1063 | /* Store Facility List (CPU features) at 200 */ | |
d5a103cd | 1064 | check_privileged(s); |
e023e832 AG |
1065 | tmp2 = tcg_const_i64(0xc0000000); |
1066 | tmp = tcg_const_i64(200); | |
1067 | tcg_gen_qemu_st32(tmp2, tmp, get_mem_index(s)); | |
1068 | tcg_temp_free_i64(tmp2); | |
1069 | tcg_temp_free_i64(tmp); | |
1070 | break; | |
1071 | case 0xb2: /* LPSWE D2(B2) [S] */ | |
1072 | /* Load PSW Extended */ | |
d5a103cd | 1073 | check_privileged(s); |
e023e832 AG |
1074 | decode_rs(s, insn, &r1, &r3, &b2, &d2); |
1075 | tmp = get_address(s, 0, b2, d2); | |
1076 | tmp2 = tcg_temp_new_i64(); | |
1077 | tmp3 = tcg_temp_new_i64(); | |
1078 | tcg_gen_qemu_ld64(tmp2, tmp, get_mem_index(s)); | |
1079 | tcg_gen_addi_i64(tmp, tmp, 8); | |
1080 | tcg_gen_qemu_ld64(tmp3, tmp, get_mem_index(s)); | |
932385a3 | 1081 | gen_helper_load_psw(cpu_env, tmp2, tmp3); |
e023e832 AG |
1082 | /* we need to keep cc_op intact */ |
1083 | s->is_jmp = DISAS_JUMP; | |
1084 | tcg_temp_free_i64(tmp); | |
e32a1832 SW |
1085 | tcg_temp_free_i64(tmp2); |
1086 | tcg_temp_free_i64(tmp3); | |
e023e832 AG |
1087 | break; |
1088 | case 0x20: /* SERVC R1,R2 [RRE] */ | |
1089 | /* SCLP Service call (PV hypercall) */ | |
d5a103cd | 1090 | check_privileged(s); |
e023e832 AG |
1091 | potential_page_fault(s); |
1092 | tmp32_1 = load_reg32(r2); | |
1093 | tmp = load_reg(r1); | |
089f5c06 | 1094 | gen_helper_servc(cc_op, cpu_env, tmp32_1, tmp); |
e023e832 AG |
1095 | set_cc_static(s); |
1096 | tcg_temp_free_i32(tmp32_1); | |
1097 | tcg_temp_free_i64(tmp); | |
1098 | break; | |
e023e832 | 1099 | default: |
4600c994 | 1100 | #endif |
e023e832 | 1101 | LOG_DISAS("illegal b2 operation 0x%x\n", op); |
d5a103cd | 1102 | gen_illegal_opcode(s); |
4600c994 | 1103 | #ifndef CONFIG_USER_ONLY |
e023e832 AG |
1104 | break; |
1105 | } | |
4600c994 | 1106 | #endif |
e023e832 AG |
1107 | } |
1108 | ||
46ee3d84 | 1109 | static void disas_s390_insn(CPUS390XState *env, DisasContext *s) |
e023e832 | 1110 | { |
e023e832 AG |
1111 | unsigned char opc; |
1112 | uint64_t insn; | |
8379bfdb | 1113 | int op; |
e023e832 | 1114 | |
46ee3d84 | 1115 | opc = cpu_ldub_code(env, s->pc); |
e023e832 AG |
1116 | LOG_DISAS("opc 0x%x\n", opc); |
1117 | ||
e023e832 | 1118 | switch (opc) { |
e023e832 | 1119 | case 0xb2: |
46ee3d84 | 1120 | insn = ld_code4(env, s->pc); |
e023e832 | 1121 | op = (insn >> 16) & 0xff; |
ea20490f | 1122 | disas_b2(env, s, op, insn); |
e023e832 | 1123 | break; |
e023e832 | 1124 | default: |
71547a3b | 1125 | qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%x\n", opc); |
d5a103cd | 1126 | gen_illegal_opcode(s); |
e023e832 AG |
1127 | break; |
1128 | } | |
ad044d09 RH |
1129 | } |
1130 | ||
1131 | /* ====================================================================== */ | |
1132 | /* Define the insn format enumeration. */ | |
1133 | #define F0(N) FMT_##N, | |
1134 | #define F1(N, X1) F0(N) | |
1135 | #define F2(N, X1, X2) F0(N) | |
1136 | #define F3(N, X1, X2, X3) F0(N) | |
1137 | #define F4(N, X1, X2, X3, X4) F0(N) | |
1138 | #define F5(N, X1, X2, X3, X4, X5) F0(N) | |
1139 | ||
1140 | typedef enum { | |
1141 | #include "insn-format.def" | |
1142 | } DisasFormat; | |
1143 | ||
1144 | #undef F0 | |
1145 | #undef F1 | |
1146 | #undef F2 | |
1147 | #undef F3 | |
1148 | #undef F4 | |
1149 | #undef F5 | |
1150 | ||
1151 | /* Define a structure to hold the decoded fields. We'll store each inside | |
1152 | an array indexed by an enum. In order to conserve memory, we'll arrange | |
1153 | for fields that do not exist at the same time to overlap, thus the "C" | |
1154 | for compact. For checking purposes there is an "O" for original index | |
1155 | as well that will be applied to availability bitmaps. */ | |
1156 | ||
1157 | enum DisasFieldIndexO { | |
1158 | FLD_O_r1, | |
1159 | FLD_O_r2, | |
1160 | FLD_O_r3, | |
1161 | FLD_O_m1, | |
1162 | FLD_O_m3, | |
1163 | FLD_O_m4, | |
1164 | FLD_O_b1, | |
1165 | FLD_O_b2, | |
1166 | FLD_O_b4, | |
1167 | FLD_O_d1, | |
1168 | FLD_O_d2, | |
1169 | FLD_O_d4, | |
1170 | FLD_O_x2, | |
1171 | FLD_O_l1, | |
1172 | FLD_O_l2, | |
1173 | FLD_O_i1, | |
1174 | FLD_O_i2, | |
1175 | FLD_O_i3, | |
1176 | FLD_O_i4, | |
1177 | FLD_O_i5 | |
1178 | }; | |
1179 | ||
1180 | enum DisasFieldIndexC { | |
1181 | FLD_C_r1 = 0, | |
1182 | FLD_C_m1 = 0, | |
1183 | FLD_C_b1 = 0, | |
1184 | FLD_C_i1 = 0, | |
1185 | ||
1186 | FLD_C_r2 = 1, | |
1187 | FLD_C_b2 = 1, | |
1188 | FLD_C_i2 = 1, | |
1189 | ||
1190 | FLD_C_r3 = 2, | |
1191 | FLD_C_m3 = 2, | |
1192 | FLD_C_i3 = 2, | |
1193 | ||
1194 | FLD_C_m4 = 3, | |
1195 | FLD_C_b4 = 3, | |
1196 | FLD_C_i4 = 3, | |
1197 | FLD_C_l1 = 3, | |
1198 | ||
1199 | FLD_C_i5 = 4, | |
1200 | FLD_C_d1 = 4, | |
1201 | ||
1202 | FLD_C_d2 = 5, | |
1203 | ||
1204 | FLD_C_d4 = 6, | |
1205 | FLD_C_x2 = 6, | |
1206 | FLD_C_l2 = 6, | |
1207 | ||
1208 | NUM_C_FIELD = 7 | |
1209 | }; | |
1210 | ||
1211 | struct DisasFields { | |
1212 | unsigned op:8; | |
1213 | unsigned op2:8; | |
1214 | unsigned presentC:16; | |
1215 | unsigned int presentO; | |
1216 | int c[NUM_C_FIELD]; | |
1217 | }; | |
1218 | ||
1219 | /* This is the way fields are to be accessed out of DisasFields. */ | |
1220 | #define have_field(S, F) have_field1((S), FLD_O_##F) | |
1221 | #define get_field(S, F) get_field1((S), FLD_O_##F, FLD_C_##F) | |
1222 | ||
1223 | static bool have_field1(const DisasFields *f, enum DisasFieldIndexO c) | |
1224 | { | |
1225 | return (f->presentO >> c) & 1; | |
1226 | } | |
1227 | ||
1228 | static int get_field1(const DisasFields *f, enum DisasFieldIndexO o, | |
1229 | enum DisasFieldIndexC c) | |
1230 | { | |
1231 | assert(have_field1(f, o)); | |
1232 | return f->c[c]; | |
1233 | } | |
1234 | ||
1235 | /* Describe the layout of each field in each format. */ | |
1236 | typedef struct DisasField { | |
1237 | unsigned int beg:8; | |
1238 | unsigned int size:8; | |
1239 | unsigned int type:2; | |
1240 | unsigned int indexC:6; | |
1241 | enum DisasFieldIndexO indexO:8; | |
1242 | } DisasField; | |
1243 | ||
1244 | typedef struct DisasFormatInfo { | |
1245 | DisasField op[NUM_C_FIELD]; | |
1246 | } DisasFormatInfo; | |
1247 | ||
1248 | #define R(N, B) { B, 4, 0, FLD_C_r##N, FLD_O_r##N } | |
1249 | #define M(N, B) { B, 4, 0, FLD_C_m##N, FLD_O_m##N } | |
1250 | #define BD(N, BB, BD) { BB, 4, 0, FLD_C_b##N, FLD_O_b##N }, \ | |
1251 | { BD, 12, 0, FLD_C_d##N, FLD_O_d##N } | |
1252 | #define BXD(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \ | |
1253 | { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \ | |
1254 | { 20, 12, 0, FLD_C_d##N, FLD_O_d##N } | |
1255 | #define BDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \ | |
1256 | { 20, 20, 2, FLD_C_d##N, FLD_O_d##N } | |
1257 | #define BXDL(N) { 16, 4, 0, FLD_C_b##N, FLD_O_b##N }, \ | |
1258 | { 12, 4, 0, FLD_C_x##N, FLD_O_x##N }, \ | |
1259 | { 20, 20, 2, FLD_C_d##N, FLD_O_d##N } | |
1260 | #define I(N, B, S) { B, S, 1, FLD_C_i##N, FLD_O_i##N } | |
1261 | #define L(N, B, S) { B, S, 0, FLD_C_l##N, FLD_O_l##N } | |
1262 | ||
1263 | #define F0(N) { { } }, | |
1264 | #define F1(N, X1) { { X1 } }, | |
1265 | #define F2(N, X1, X2) { { X1, X2 } }, | |
1266 | #define F3(N, X1, X2, X3) { { X1, X2, X3 } }, | |
1267 | #define F4(N, X1, X2, X3, X4) { { X1, X2, X3, X4 } }, | |
1268 | #define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } }, | |
1269 | ||
1270 | static const DisasFormatInfo format_info[] = { | |
1271 | #include "insn-format.def" | |
1272 | }; | |
1273 | ||
1274 | #undef F0 | |
1275 | #undef F1 | |
1276 | #undef F2 | |
1277 | #undef F3 | |
1278 | #undef F4 | |
1279 | #undef F5 | |
1280 | #undef R | |
1281 | #undef M | |
1282 | #undef BD | |
1283 | #undef BXD | |
1284 | #undef BDL | |
1285 | #undef BXDL | |
1286 | #undef I | |
1287 | #undef L | |
1288 | ||
1289 | /* Generally, we'll extract operands into this structures, operate upon | |
1290 | them, and store them back. See the "in1", "in2", "prep", "wout" sets | |
1291 | of routines below for more details. */ | |
1292 | typedef struct { | |
1293 | bool g_out, g_out2, g_in1, g_in2; | |
1294 | TCGv_i64 out, out2, in1, in2; | |
1295 | TCGv_i64 addr1; | |
1296 | } DisasOps; | |
1297 | ||
1298 | /* Return values from translate_one, indicating the state of the TB. */ | |
1299 | typedef enum { | |
1300 | /* Continue the TB. */ | |
1301 | NO_EXIT, | |
1302 | /* We have emitted one or more goto_tb. No fixup required. */ | |
1303 | EXIT_GOTO_TB, | |
1304 | /* We are not using a goto_tb (for whatever reason), but have updated | |
1305 | the PC (for whatever reason), so there's no need to do it again on | |
1306 | exiting the TB. */ | |
1307 | EXIT_PC_UPDATED, | |
1308 | /* We are exiting the TB, but have neither emitted a goto_tb, nor | |
1309 | updated the PC for the next instruction to be executed. */ | |
1310 | EXIT_PC_STALE, | |
1311 | /* We are ending the TB with a noreturn function call, e.g. longjmp. | |
1312 | No following code will be executed. */ | |
1313 | EXIT_NORETURN, | |
1314 | } ExitStatus; | |
1315 | ||
1316 | typedef enum DisasFacility { | |
1317 | FAC_Z, /* zarch (default) */ | |
1318 | FAC_CASS, /* compare and swap and store */ | |
1319 | FAC_CASS2, /* compare and swap and store 2*/ | |
1320 | FAC_DFP, /* decimal floating point */ | |
1321 | FAC_DFPR, /* decimal floating point rounding */ | |
1322 | FAC_DO, /* distinct operands */ | |
1323 | FAC_EE, /* execute extensions */ | |
1324 | FAC_EI, /* extended immediate */ | |
1325 | FAC_FPE, /* floating point extension */ | |
1326 | FAC_FPSSH, /* floating point support sign handling */ | |
1327 | FAC_FPRGR, /* FPR-GR transfer */ | |
1328 | FAC_GIE, /* general instructions extension */ | |
1329 | FAC_HFP_MA, /* HFP multiply-and-add/subtract */ | |
1330 | FAC_HW, /* high-word */ | |
1331 | FAC_IEEEE_SIM, /* IEEE exception sumilation */ | |
1332 | FAC_LOC, /* load/store on condition */ | |
1333 | FAC_LD, /* long displacement */ | |
1334 | FAC_PC, /* population count */ | |
1335 | FAC_SCF, /* store clock fast */ | |
1336 | FAC_SFLE, /* store facility list extended */ | |
1337 | } DisasFacility; | |
1338 | ||
1339 | struct DisasInsn { | |
1340 | unsigned opc:16; | |
1341 | DisasFormat fmt:6; | |
1342 | DisasFacility fac:6; | |
1343 | ||
1344 | const char *name; | |
1345 | ||
1346 | void (*help_in1)(DisasContext *, DisasFields *, DisasOps *); | |
1347 | void (*help_in2)(DisasContext *, DisasFields *, DisasOps *); | |
1348 | void (*help_prep)(DisasContext *, DisasFields *, DisasOps *); | |
1349 | void (*help_wout)(DisasContext *, DisasFields *, DisasOps *); | |
1350 | void (*help_cout)(DisasContext *, DisasOps *); | |
1351 | ExitStatus (*help_op)(DisasContext *, DisasOps *); | |
1352 | ||
1353 | uint64_t data; | |
1354 | }; | |
1355 | ||
8ac33cdb RH |
1356 | /* ====================================================================== */ |
1357 | /* Miscelaneous helpers, used by several operations. */ | |
1358 | ||
cbe24bfa RH |
1359 | static void help_l2_shift(DisasContext *s, DisasFields *f, |
1360 | DisasOps *o, int mask) | |
1361 | { | |
1362 | int b2 = get_field(f, b2); | |
1363 | int d2 = get_field(f, d2); | |
1364 | ||
1365 | if (b2 == 0) { | |
1366 | o->in2 = tcg_const_i64(d2 & mask); | |
1367 | } else { | |
1368 | o->in2 = get_address(s, 0, b2, d2); | |
1369 | tcg_gen_andi_i64(o->in2, o->in2, mask); | |
1370 | } | |
1371 | } | |
1372 | ||
8ac33cdb RH |
1373 | static ExitStatus help_goto_direct(DisasContext *s, uint64_t dest) |
1374 | { | |
1375 | if (dest == s->next_pc) { | |
1376 | return NO_EXIT; | |
1377 | } | |
1378 | if (use_goto_tb(s, dest)) { | |
1379 | gen_update_cc_op(s); | |
1380 | tcg_gen_goto_tb(0); | |
1381 | tcg_gen_movi_i64(psw_addr, dest); | |
1382 | tcg_gen_exit_tb((tcg_target_long)s->tb); | |
1383 | return EXIT_GOTO_TB; | |
1384 | } else { | |
1385 | tcg_gen_movi_i64(psw_addr, dest); | |
1386 | return EXIT_PC_UPDATED; | |
1387 | } | |
1388 | } | |
1389 | ||
7233f2ed RH |
1390 | static ExitStatus help_branch(DisasContext *s, DisasCompare *c, |
1391 | bool is_imm, int imm, TCGv_i64 cdest) | |
1392 | { | |
1393 | ExitStatus ret; | |
1394 | uint64_t dest = s->pc + 2 * imm; | |
1395 | int lab; | |
1396 | ||
1397 | /* Take care of the special cases first. */ | |
1398 | if (c->cond == TCG_COND_NEVER) { | |
1399 | ret = NO_EXIT; | |
1400 | goto egress; | |
1401 | } | |
1402 | if (is_imm) { | |
1403 | if (dest == s->next_pc) { | |
1404 | /* Branch to next. */ | |
1405 | ret = NO_EXIT; | |
1406 | goto egress; | |
1407 | } | |
1408 | if (c->cond == TCG_COND_ALWAYS) { | |
1409 | ret = help_goto_direct(s, dest); | |
1410 | goto egress; | |
1411 | } | |
1412 | } else { | |
1413 | if (TCGV_IS_UNUSED_I64(cdest)) { | |
1414 | /* E.g. bcr %r0 -> no branch. */ | |
1415 | ret = NO_EXIT; | |
1416 | goto egress; | |
1417 | } | |
1418 | if (c->cond == TCG_COND_ALWAYS) { | |
1419 | tcg_gen_mov_i64(psw_addr, cdest); | |
1420 | ret = EXIT_PC_UPDATED; | |
1421 | goto egress; | |
1422 | } | |
1423 | } | |
1424 | ||
1425 | if (use_goto_tb(s, s->next_pc)) { | |
1426 | if (is_imm && use_goto_tb(s, dest)) { | |
1427 | /* Both exits can use goto_tb. */ | |
1428 | gen_update_cc_op(s); | |
1429 | ||
1430 | lab = gen_new_label(); | |
1431 | if (c->is_64) { | |
1432 | tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab); | |
1433 | } else { | |
1434 | tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab); | |
1435 | } | |
1436 | ||
1437 | /* Branch not taken. */ | |
1438 | tcg_gen_goto_tb(0); | |
1439 | tcg_gen_movi_i64(psw_addr, s->next_pc); | |
1440 | tcg_gen_exit_tb((tcg_target_long)s->tb + 0); | |
1441 | ||
1442 | /* Branch taken. */ | |
1443 | gen_set_label(lab); | |
1444 | tcg_gen_goto_tb(1); | |
1445 | tcg_gen_movi_i64(psw_addr, dest); | |
1446 | tcg_gen_exit_tb((tcg_target_long)s->tb + 1); | |
1447 | ||
1448 | ret = EXIT_GOTO_TB; | |
1449 | } else { | |
1450 | /* Fallthru can use goto_tb, but taken branch cannot. */ | |
1451 | /* Store taken branch destination before the brcond. This | |
1452 | avoids having to allocate a new local temp to hold it. | |
1453 | We'll overwrite this in the not taken case anyway. */ | |
1454 | if (!is_imm) { | |
1455 | tcg_gen_mov_i64(psw_addr, cdest); | |
1456 | } | |
1457 | ||
1458 | lab = gen_new_label(); | |
1459 | if (c->is_64) { | |
1460 | tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab); | |
1461 | } else { | |
1462 | tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab); | |
1463 | } | |
1464 | ||
1465 | /* Branch not taken. */ | |
1466 | gen_update_cc_op(s); | |
1467 | tcg_gen_goto_tb(0); | |
1468 | tcg_gen_movi_i64(psw_addr, s->next_pc); | |
1469 | tcg_gen_exit_tb((tcg_target_long)s->tb + 0); | |
1470 | ||
1471 | gen_set_label(lab); | |
1472 | if (is_imm) { | |
1473 | tcg_gen_movi_i64(psw_addr, dest); | |
1474 | } | |
1475 | ret = EXIT_PC_UPDATED; | |
1476 | } | |
1477 | } else { | |
1478 | /* Fallthru cannot use goto_tb. This by itself is vanishingly rare. | |
1479 | Most commonly we're single-stepping or some other condition that | |
1480 | disables all use of goto_tb. Just update the PC and exit. */ | |
1481 | ||
1482 | TCGv_i64 next = tcg_const_i64(s->next_pc); | |
1483 | if (is_imm) { | |
1484 | cdest = tcg_const_i64(dest); | |
1485 | } | |
1486 | ||
1487 | if (c->is_64) { | |
1488 | tcg_gen_movcond_i64(c->cond, psw_addr, c->u.s64.a, c->u.s64.b, | |
1489 | cdest, next); | |
1490 | } else { | |
1491 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
1492 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
1493 | TCGv_i64 z = tcg_const_i64(0); | |
1494 | tcg_gen_setcond_i32(c->cond, t0, c->u.s32.a, c->u.s32.b); | |
1495 | tcg_gen_extu_i32_i64(t1, t0); | |
1496 | tcg_temp_free_i32(t0); | |
1497 | tcg_gen_movcond_i64(TCG_COND_NE, psw_addr, t1, z, cdest, next); | |
1498 | tcg_temp_free_i64(t1); | |
1499 | tcg_temp_free_i64(z); | |
1500 | } | |
1501 | ||
1502 | if (is_imm) { | |
1503 | tcg_temp_free_i64(cdest); | |
1504 | } | |
1505 | tcg_temp_free_i64(next); | |
1506 | ||
1507 | ret = EXIT_PC_UPDATED; | |
1508 | } | |
1509 | ||
1510 | egress: | |
1511 | free_compare(c); | |
1512 | return ret; | |
1513 | } | |
1514 | ||
ad044d09 RH |
1515 | /* ====================================================================== */ |
1516 | /* The operations. These perform the bulk of the work for any insn, | |
1517 | usually after the operands have been loaded and output initialized. */ | |
1518 | ||
b9bca3e5 RH |
1519 | static ExitStatus op_abs(DisasContext *s, DisasOps *o) |
1520 | { | |
1521 | gen_helper_abs_i64(o->out, o->in2); | |
1522 | return NO_EXIT; | |
1523 | } | |
1524 | ||
5d7fd045 RH |
1525 | static ExitStatus op_absf32(DisasContext *s, DisasOps *o) |
1526 | { | |
1527 | tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffull); | |
1528 | return NO_EXIT; | |
1529 | } | |
1530 | ||
1531 | static ExitStatus op_absf64(DisasContext *s, DisasOps *o) | |
1532 | { | |
1533 | tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull); | |
1534 | return NO_EXIT; | |
1535 | } | |
1536 | ||
1537 | static ExitStatus op_absf128(DisasContext *s, DisasOps *o) | |
1538 | { | |
1539 | tcg_gen_andi_i64(o->out, o->in1, 0x7fffffffffffffffull); | |
1540 | tcg_gen_mov_i64(o->out2, o->in2); | |
1541 | return NO_EXIT; | |
1542 | } | |
1543 | ||
ad044d09 RH |
1544 | static ExitStatus op_add(DisasContext *s, DisasOps *o) |
1545 | { | |
1546 | tcg_gen_add_i64(o->out, o->in1, o->in2); | |
1547 | return NO_EXIT; | |
1548 | } | |
1549 | ||
4e4bb438 RH |
1550 | static ExitStatus op_addc(DisasContext *s, DisasOps *o) |
1551 | { | |
1552 | TCGv_i64 cc; | |
1553 | ||
1554 | tcg_gen_add_i64(o->out, o->in1, o->in2); | |
1555 | ||
1556 | /* XXX possible optimization point */ | |
1557 | gen_op_calc_cc(s); | |
1558 | cc = tcg_temp_new_i64(); | |
1559 | tcg_gen_extu_i32_i64(cc, cc_op); | |
1560 | tcg_gen_shri_i64(cc, cc, 1); | |
1561 | ||
1562 | tcg_gen_add_i64(o->out, o->out, cc); | |
1563 | tcg_temp_free_i64(cc); | |
1564 | return NO_EXIT; | |
1565 | } | |
1566 | ||
587626f8 RH |
1567 | static ExitStatus op_aeb(DisasContext *s, DisasOps *o) |
1568 | { | |
1569 | gen_helper_aeb(o->out, cpu_env, o->in1, o->in2); | |
1570 | return NO_EXIT; | |
1571 | } | |
1572 | ||
1573 | static ExitStatus op_adb(DisasContext *s, DisasOps *o) | |
1574 | { | |
1575 | gen_helper_adb(o->out, cpu_env, o->in1, o->in2); | |
1576 | return NO_EXIT; | |
1577 | } | |
1578 | ||
1579 | static ExitStatus op_axb(DisasContext *s, DisasOps *o) | |
1580 | { | |
1581 | gen_helper_axb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2); | |
1582 | return_low128(o->out2); | |
1583 | return NO_EXIT; | |
1584 | } | |
1585 | ||
3bbfbd1f RH |
1586 | static ExitStatus op_and(DisasContext *s, DisasOps *o) |
1587 | { | |
1588 | tcg_gen_and_i64(o->out, o->in1, o->in2); | |
1589 | return NO_EXIT; | |
1590 | } | |
1591 | ||
facfc864 RH |
1592 | static ExitStatus op_andi(DisasContext *s, DisasOps *o) |
1593 | { | |
1594 | int shift = s->insn->data & 0xff; | |
1595 | int size = s->insn->data >> 8; | |
1596 | uint64_t mask = ((1ull << size) - 1) << shift; | |
1597 | ||
1598 | assert(!o->g_in2); | |
1599 | tcg_gen_shli_i64(o->in2, o->in2, shift); | |
1600 | tcg_gen_ori_i64(o->in2, o->in2, ~mask); | |
1601 | tcg_gen_and_i64(o->out, o->in1, o->in2); | |
1602 | ||
1603 | /* Produce the CC from only the bits manipulated. */ | |
1604 | tcg_gen_andi_i64(cc_dst, o->out, mask); | |
1605 | set_cc_nz_u64(s, cc_dst); | |
1606 | return NO_EXIT; | |
1607 | } | |
1608 | ||
8ac33cdb RH |
1609 | static ExitStatus op_bas(DisasContext *s, DisasOps *o) |
1610 | { | |
1611 | tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc)); | |
1612 | if (!TCGV_IS_UNUSED_I64(o->in2)) { | |
1613 | tcg_gen_mov_i64(psw_addr, o->in2); | |
1614 | return EXIT_PC_UPDATED; | |
1615 | } else { | |
1616 | return NO_EXIT; | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | static ExitStatus op_basi(DisasContext *s, DisasOps *o) | |
1621 | { | |
1622 | tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc)); | |
1623 | return help_goto_direct(s, s->pc + 2 * get_field(s->fields, i2)); | |
1624 | } | |
1625 | ||
7233f2ed RH |
1626 | static ExitStatus op_bc(DisasContext *s, DisasOps *o) |
1627 | { | |
1628 | int m1 = get_field(s->fields, m1); | |
1629 | bool is_imm = have_field(s->fields, i2); | |
1630 | int imm = is_imm ? get_field(s->fields, i2) : 0; | |
1631 | DisasCompare c; | |
1632 | ||
1633 | disas_jcc(s, &c, m1); | |
1634 | return help_branch(s, &c, is_imm, imm, o->in2); | |
1635 | } | |
1636 | ||
c61aad69 RH |
1637 | static ExitStatus op_bct32(DisasContext *s, DisasOps *o) |
1638 | { | |
1639 | int r1 = get_field(s->fields, r1); | |
1640 | bool is_imm = have_field(s->fields, i2); | |
1641 | int imm = is_imm ? get_field(s->fields, i2) : 0; | |
1642 | DisasCompare c; | |
1643 | TCGv_i64 t; | |
1644 | ||
1645 | c.cond = TCG_COND_NE; | |
1646 | c.is_64 = false; | |
1647 | c.g1 = false; | |
1648 | c.g2 = false; | |
1649 | ||
1650 | t = tcg_temp_new_i64(); | |
1651 | tcg_gen_subi_i64(t, regs[r1], 1); | |
1652 | store_reg32_i64(r1, t); | |
1653 | c.u.s32.a = tcg_temp_new_i32(); | |
1654 | c.u.s32.b = tcg_const_i32(0); | |
1655 | tcg_gen_trunc_i64_i32(c.u.s32.a, t); | |
1656 | tcg_temp_free_i64(t); | |
1657 | ||
1658 | return help_branch(s, &c, is_imm, imm, o->in2); | |
1659 | } | |
1660 | ||
1661 | static ExitStatus op_bct64(DisasContext *s, DisasOps *o) | |
1662 | { | |
1663 | int r1 = get_field(s->fields, r1); | |
1664 | bool is_imm = have_field(s->fields, i2); | |
1665 | int imm = is_imm ? get_field(s->fields, i2) : 0; | |
1666 | DisasCompare c; | |
1667 | ||
1668 | c.cond = TCG_COND_NE; | |
1669 | c.is_64 = true; | |
1670 | c.g1 = true; | |
1671 | c.g2 = false; | |
1672 | ||
1673 | tcg_gen_subi_i64(regs[r1], regs[r1], 1); | |
1674 | c.u.s64.a = regs[r1]; | |
1675 | c.u.s64.b = tcg_const_i64(0); | |
1676 | ||
1677 | return help_branch(s, &c, is_imm, imm, o->in2); | |
1678 | } | |
1679 | ||
587626f8 RH |
1680 | static ExitStatus op_ceb(DisasContext *s, DisasOps *o) |
1681 | { | |
1682 | gen_helper_ceb(cc_op, cpu_env, o->in1, o->in2); | |
1683 | set_cc_static(s); | |
1684 | return NO_EXIT; | |
1685 | } | |
1686 | ||
1687 | static ExitStatus op_cdb(DisasContext *s, DisasOps *o) | |
1688 | { | |
1689 | gen_helper_cdb(cc_op, cpu_env, o->in1, o->in2); | |
1690 | set_cc_static(s); | |
1691 | return NO_EXIT; | |
1692 | } | |
1693 | ||
1694 | static ExitStatus op_cxb(DisasContext *s, DisasOps *o) | |
1695 | { | |
1696 | gen_helper_cxb(cc_op, cpu_env, o->out, o->out2, o->in1, o->in2); | |
1697 | set_cc_static(s); | |
1698 | return NO_EXIT; | |
1699 | } | |
1700 | ||
68c8bd93 RH |
1701 | static ExitStatus op_cfeb(DisasContext *s, DisasOps *o) |
1702 | { | |
1703 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1704 | gen_helper_cfeb(o->out, cpu_env, o->in2, m3); | |
1705 | tcg_temp_free_i32(m3); | |
1706 | gen_set_cc_nz_f32(s, o->in2); | |
1707 | return NO_EXIT; | |
1708 | } | |
1709 | ||
1710 | static ExitStatus op_cfdb(DisasContext *s, DisasOps *o) | |
1711 | { | |
1712 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1713 | gen_helper_cfdb(o->out, cpu_env, o->in2, m3); | |
1714 | tcg_temp_free_i32(m3); | |
1715 | gen_set_cc_nz_f64(s, o->in2); | |
1716 | return NO_EXIT; | |
1717 | } | |
1718 | ||
1719 | static ExitStatus op_cfxb(DisasContext *s, DisasOps *o) | |
1720 | { | |
1721 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1722 | gen_helper_cfxb(o->out, cpu_env, o->in1, o->in2, m3); | |
1723 | tcg_temp_free_i32(m3); | |
1724 | gen_set_cc_nz_f128(s, o->in1, o->in2); | |
1725 | return NO_EXIT; | |
1726 | } | |
1727 | ||
1728 | static ExitStatus op_cgeb(DisasContext *s, DisasOps *o) | |
1729 | { | |
1730 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1731 | gen_helper_cgeb(o->out, cpu_env, o->in2, m3); | |
1732 | tcg_temp_free_i32(m3); | |
1733 | gen_set_cc_nz_f32(s, o->in2); | |
1734 | return NO_EXIT; | |
1735 | } | |
1736 | ||
1737 | static ExitStatus op_cgdb(DisasContext *s, DisasOps *o) | |
1738 | { | |
1739 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1740 | gen_helper_cgdb(o->out, cpu_env, o->in2, m3); | |
1741 | tcg_temp_free_i32(m3); | |
1742 | gen_set_cc_nz_f64(s, o->in2); | |
1743 | return NO_EXIT; | |
1744 | } | |
1745 | ||
1746 | static ExitStatus op_cgxb(DisasContext *s, DisasOps *o) | |
1747 | { | |
1748 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1749 | gen_helper_cgxb(o->out, cpu_env, o->in1, o->in2, m3); | |
1750 | tcg_temp_free_i32(m3); | |
1751 | gen_set_cc_nz_f128(s, o->in1, o->in2); | |
1752 | return NO_EXIT; | |
1753 | } | |
1754 | ||
683bb9a8 RH |
1755 | static ExitStatus op_cegb(DisasContext *s, DisasOps *o) |
1756 | { | |
1757 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1758 | gen_helper_cegb(o->out, cpu_env, o->in2, m3); | |
1759 | tcg_temp_free_i32(m3); | |
1760 | return NO_EXIT; | |
1761 | } | |
1762 | ||
1763 | static ExitStatus op_cdgb(DisasContext *s, DisasOps *o) | |
1764 | { | |
1765 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1766 | gen_helper_cdgb(o->out, cpu_env, o->in2, m3); | |
1767 | tcg_temp_free_i32(m3); | |
1768 | return NO_EXIT; | |
1769 | } | |
1770 | ||
1771 | static ExitStatus op_cxgb(DisasContext *s, DisasOps *o) | |
1772 | { | |
1773 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1774 | gen_helper_cxgb(o->out, cpu_env, o->in2, m3); | |
1775 | tcg_temp_free_i32(m3); | |
1776 | return_low128(o->out2); | |
1777 | return NO_EXIT; | |
1778 | } | |
1779 | ||
374724f9 RH |
1780 | static ExitStatus op_cksm(DisasContext *s, DisasOps *o) |
1781 | { | |
1782 | int r2 = get_field(s->fields, r2); | |
1783 | TCGv_i64 len = tcg_temp_new_i64(); | |
1784 | ||
1785 | potential_page_fault(s); | |
1786 | gen_helper_cksm(len, cpu_env, o->in1, o->in2, regs[r2 + 1]); | |
1787 | set_cc_static(s); | |
1788 | return_low128(o->out); | |
1789 | ||
1790 | tcg_gen_add_i64(regs[r2], regs[r2], len); | |
1791 | tcg_gen_sub_i64(regs[r2 + 1], regs[r2 + 1], len); | |
1792 | tcg_temp_free_i64(len); | |
1793 | ||
1794 | return NO_EXIT; | |
1795 | } | |
1796 | ||
4f7403d5 RH |
1797 | static ExitStatus op_clc(DisasContext *s, DisasOps *o) |
1798 | { | |
1799 | int l = get_field(s->fields, l1); | |
1800 | TCGv_i32 vl; | |
1801 | ||
1802 | switch (l + 1) { | |
1803 | case 1: | |
1804 | tcg_gen_qemu_ld8u(cc_src, o->addr1, get_mem_index(s)); | |
1805 | tcg_gen_qemu_ld8u(cc_dst, o->in2, get_mem_index(s)); | |
1806 | break; | |
1807 | case 2: | |
1808 | tcg_gen_qemu_ld16u(cc_src, o->addr1, get_mem_index(s)); | |
1809 | tcg_gen_qemu_ld16u(cc_dst, o->in2, get_mem_index(s)); | |
1810 | break; | |
1811 | case 4: | |
1812 | tcg_gen_qemu_ld32u(cc_src, o->addr1, get_mem_index(s)); | |
1813 | tcg_gen_qemu_ld32u(cc_dst, o->in2, get_mem_index(s)); | |
1814 | break; | |
1815 | case 8: | |
1816 | tcg_gen_qemu_ld64(cc_src, o->addr1, get_mem_index(s)); | |
1817 | tcg_gen_qemu_ld64(cc_dst, o->in2, get_mem_index(s)); | |
1818 | break; | |
1819 | default: | |
1820 | potential_page_fault(s); | |
1821 | vl = tcg_const_i32(l); | |
1822 | gen_helper_clc(cc_op, cpu_env, vl, o->addr1, o->in2); | |
1823 | tcg_temp_free_i32(vl); | |
1824 | set_cc_static(s); | |
1825 | return NO_EXIT; | |
1826 | } | |
1827 | gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, cc_src, cc_dst); | |
1828 | return NO_EXIT; | |
1829 | } | |
1830 | ||
eb66e6a9 RH |
1831 | static ExitStatus op_clcle(DisasContext *s, DisasOps *o) |
1832 | { | |
1833 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
1834 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
1835 | potential_page_fault(s); | |
1836 | gen_helper_clcle(cc_op, cpu_env, r1, o->in2, r3); | |
1837 | tcg_temp_free_i32(r1); | |
1838 | tcg_temp_free_i32(r3); | |
1839 | set_cc_static(s); | |
1840 | return NO_EXIT; | |
1841 | } | |
1842 | ||
32a44d58 RH |
1843 | static ExitStatus op_clm(DisasContext *s, DisasOps *o) |
1844 | { | |
1845 | TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3)); | |
1846 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
1847 | tcg_gen_trunc_i64_i32(t1, o->in1); | |
1848 | potential_page_fault(s); | |
1849 | gen_helper_clm(cc_op, cpu_env, t1, m3, o->in2); | |
1850 | set_cc_static(s); | |
1851 | tcg_temp_free_i32(t1); | |
1852 | tcg_temp_free_i32(m3); | |
1853 | return NO_EXIT; | |
1854 | } | |
1855 | ||
aa31bf60 RH |
1856 | static ExitStatus op_clst(DisasContext *s, DisasOps *o) |
1857 | { | |
1858 | potential_page_fault(s); | |
1859 | gen_helper_clst(o->in1, cpu_env, regs[0], o->in1, o->in2); | |
1860 | set_cc_static(s); | |
1861 | return_low128(o->in2); | |
1862 | return NO_EXIT; | |
1863 | } | |
1864 | ||
f3de39c4 RH |
1865 | static ExitStatus op_cs(DisasContext *s, DisasOps *o) |
1866 | { | |
1867 | int r3 = get_field(s->fields, r3); | |
1868 | potential_page_fault(s); | |
1869 | gen_helper_cs(o->out, cpu_env, o->in1, o->in2, regs[r3]); | |
1870 | set_cc_static(s); | |
1871 | return NO_EXIT; | |
1872 | } | |
1873 | ||
1874 | static ExitStatus op_csg(DisasContext *s, DisasOps *o) | |
1875 | { | |
1876 | int r3 = get_field(s->fields, r3); | |
1877 | potential_page_fault(s); | |
1878 | gen_helper_csg(o->out, cpu_env, o->in1, o->in2, regs[r3]); | |
1879 | set_cc_static(s); | |
1880 | return NO_EXIT; | |
1881 | } | |
1882 | ||
3d596f49 RH |
1883 | #ifndef CONFIG_USER_ONLY |
1884 | static ExitStatus op_csp(DisasContext *s, DisasOps *o) | |
1885 | { | |
1886 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
1887 | check_privileged(s); | |
1888 | gen_helper_csp(cc_op, cpu_env, r1, o->in2); | |
1889 | tcg_temp_free_i32(r1); | |
1890 | set_cc_static(s); | |
1891 | return NO_EXIT; | |
1892 | } | |
1893 | #endif | |
1894 | ||
f3de39c4 RH |
1895 | static ExitStatus op_cds(DisasContext *s, DisasOps *o) |
1896 | { | |
1897 | int r3 = get_field(s->fields, r3); | |
1898 | TCGv_i64 in3 = tcg_temp_new_i64(); | |
1899 | tcg_gen_deposit_i64(in3, regs[r3 + 1], regs[r3], 32, 32); | |
1900 | potential_page_fault(s); | |
1901 | gen_helper_csg(o->out, cpu_env, o->in1, o->in2, in3); | |
1902 | tcg_temp_free_i64(in3); | |
1903 | set_cc_static(s); | |
1904 | return NO_EXIT; | |
1905 | } | |
1906 | ||
1907 | static ExitStatus op_cdsg(DisasContext *s, DisasOps *o) | |
1908 | { | |
1909 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
1910 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
1911 | potential_page_fault(s); | |
1912 | /* XXX rewrite in tcg */ | |
1913 | gen_helper_cdsg(cc_op, cpu_env, r1, o->in2, r3); | |
1914 | set_cc_static(s); | |
1915 | return NO_EXIT; | |
1916 | } | |
1917 | ||
c49daa51 RH |
1918 | static ExitStatus op_cvd(DisasContext *s, DisasOps *o) |
1919 | { | |
1920 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
1921 | TCGv_i32 t2 = tcg_temp_new_i32(); | |
1922 | tcg_gen_trunc_i64_i32(t2, o->in1); | |
1923 | gen_helper_cvd(t1, t2); | |
1924 | tcg_temp_free_i32(t2); | |
1925 | tcg_gen_qemu_st64(t1, o->in2, get_mem_index(s)); | |
1926 | tcg_temp_free_i64(t1); | |
1927 | return NO_EXIT; | |
1928 | } | |
1929 | ||
972e35b9 RH |
1930 | #ifndef CONFIG_USER_ONLY |
1931 | static ExitStatus op_diag(DisasContext *s, DisasOps *o) | |
1932 | { | |
1933 | TCGv_i32 tmp; | |
1934 | ||
1935 | check_privileged(s); | |
1936 | potential_page_fault(s); | |
1937 | ||
1938 | /* We pretend the format is RX_a so that D2 is the field we want. */ | |
1939 | tmp = tcg_const_i32(get_field(s->fields, d2) & 0xfff); | |
1940 | gen_helper_diag(regs[2], cpu_env, tmp, regs[2], regs[1]); | |
1941 | tcg_temp_free_i32(tmp); | |
1942 | return NO_EXIT; | |
1943 | } | |
1944 | #endif | |
1945 | ||
891452e5 RH |
1946 | static ExitStatus op_divs32(DisasContext *s, DisasOps *o) |
1947 | { | |
1948 | gen_helper_divs32(o->out2, cpu_env, o->in1, o->in2); | |
1949 | return_low128(o->out); | |
1950 | return NO_EXIT; | |
1951 | } | |
1952 | ||
1953 | static ExitStatus op_divu32(DisasContext *s, DisasOps *o) | |
1954 | { | |
1955 | gen_helper_divu32(o->out2, cpu_env, o->in1, o->in2); | |
1956 | return_low128(o->out); | |
1957 | return NO_EXIT; | |
1958 | } | |
1959 | ||
1960 | static ExitStatus op_divs64(DisasContext *s, DisasOps *o) | |
1961 | { | |
1962 | gen_helper_divs64(o->out2, cpu_env, o->in1, o->in2); | |
1963 | return_low128(o->out); | |
1964 | return NO_EXIT; | |
1965 | } | |
1966 | ||
1967 | static ExitStatus op_divu64(DisasContext *s, DisasOps *o) | |
1968 | { | |
1969 | gen_helper_divu64(o->out2, cpu_env, o->out, o->out2, o->in2); | |
1970 | return_low128(o->out); | |
1971 | return NO_EXIT; | |
1972 | } | |
1973 | ||
f08a5c31 RH |
1974 | static ExitStatus op_deb(DisasContext *s, DisasOps *o) |
1975 | { | |
1976 | gen_helper_deb(o->out, cpu_env, o->in1, o->in2); | |
1977 | return NO_EXIT; | |
1978 | } | |
1979 | ||
1980 | static ExitStatus op_ddb(DisasContext *s, DisasOps *o) | |
1981 | { | |
1982 | gen_helper_ddb(o->out, cpu_env, o->in1, o->in2); | |
1983 | return NO_EXIT; | |
1984 | } | |
1985 | ||
1986 | static ExitStatus op_dxb(DisasContext *s, DisasOps *o) | |
1987 | { | |
1988 | gen_helper_dxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2); | |
1989 | return_low128(o->out2); | |
1990 | return NO_EXIT; | |
1991 | } | |
1992 | ||
d62a4c97 RH |
1993 | static ExitStatus op_ear(DisasContext *s, DisasOps *o) |
1994 | { | |
1995 | int r2 = get_field(s->fields, r2); | |
1996 | tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, aregs[r2])); | |
1997 | return NO_EXIT; | |
1998 | } | |
1999 | ||
ea20490f RH |
2000 | static ExitStatus op_efpc(DisasContext *s, DisasOps *o) |
2001 | { | |
2002 | tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, fpc)); | |
2003 | return NO_EXIT; | |
2004 | } | |
2005 | ||
6e764e97 RH |
2006 | static ExitStatus op_ex(DisasContext *s, DisasOps *o) |
2007 | { | |
2008 | /* ??? Perhaps a better way to implement EXECUTE is to set a bit in | |
2009 | tb->flags, (ab)use the tb->cs_base field as the address of | |
2010 | the template in memory, and grab 8 bits of tb->flags/cflags for | |
2011 | the contents of the register. We would then recognize all this | |
2012 | in gen_intermediate_code_internal, generating code for exactly | |
2013 | one instruction. This new TB then gets executed normally. | |
2014 | ||
2015 | On the other hand, this seems to be mostly used for modifying | |
2016 | MVC inside of memcpy, which needs a helper call anyway. So | |
2017 | perhaps this doesn't bear thinking about any further. */ | |
2018 | ||
2019 | TCGv_i64 tmp; | |
2020 | ||
2021 | update_psw_addr(s); | |
2022 | gen_op_calc_cc(s); | |
2023 | ||
2024 | tmp = tcg_const_i64(s->next_pc); | |
2025 | gen_helper_ex(cc_op, cpu_env, cc_op, o->in1, o->in2, tmp); | |
2026 | tcg_temp_free_i64(tmp); | |
2027 | ||
2028 | set_cc_static(s); | |
2029 | return NO_EXIT; | |
2030 | } | |
2031 | ||
102bf2c6 RH |
2032 | static ExitStatus op_flogr(DisasContext *s, DisasOps *o) |
2033 | { | |
2034 | /* We'll use the original input for cc computation, since we get to | |
2035 | compare that against 0, which ought to be better than comparing | |
2036 | the real output against 64. It also lets cc_dst be a convenient | |
2037 | temporary during our computation. */ | |
2038 | gen_op_update1_cc_i64(s, CC_OP_FLOGR, o->in2); | |
2039 | ||
2040 | /* R1 = IN ? CLZ(IN) : 64. */ | |
2041 | gen_helper_clz(o->out, o->in2); | |
2042 | ||
2043 | /* R1+1 = IN & ~(found bit). Note that we may attempt to shift this | |
2044 | value by 64, which is undefined. But since the shift is 64 iff the | |
2045 | input is zero, we still get the correct result after and'ing. */ | |
2046 | tcg_gen_movi_i64(o->out2, 0x8000000000000000ull); | |
2047 | tcg_gen_shr_i64(o->out2, o->out2, o->out); | |
2048 | tcg_gen_andc_i64(o->out2, cc_dst, o->out2); | |
2049 | return NO_EXIT; | |
2050 | } | |
2051 | ||
58a9e35b RH |
2052 | static ExitStatus op_icm(DisasContext *s, DisasOps *o) |
2053 | { | |
2054 | int m3 = get_field(s->fields, m3); | |
2055 | int pos, len, base = s->insn->data; | |
2056 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
2057 | uint64_t ccm; | |
2058 | ||
2059 | switch (m3) { | |
2060 | case 0xf: | |
2061 | /* Effectively a 32-bit load. */ | |
2062 | tcg_gen_qemu_ld32u(tmp, o->in2, get_mem_index(s)); | |
2063 | len = 32; | |
2064 | goto one_insert; | |
2065 | ||
2066 | case 0xc: | |
2067 | case 0x6: | |
2068 | case 0x3: | |
2069 | /* Effectively a 16-bit load. */ | |
2070 | tcg_gen_qemu_ld16u(tmp, o->in2, get_mem_index(s)); | |
2071 | len = 16; | |
2072 | goto one_insert; | |
2073 | ||
2074 | case 0x8: | |
2075 | case 0x4: | |
2076 | case 0x2: | |
2077 | case 0x1: | |
2078 | /* Effectively an 8-bit load. */ | |
2079 | tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s)); | |
2080 | len = 8; | |
2081 | goto one_insert; | |
2082 | ||
2083 | one_insert: | |
2084 | pos = base + ctz32(m3) * 8; | |
2085 | tcg_gen_deposit_i64(o->out, o->out, tmp, pos, len); | |
2086 | ccm = ((1ull << len) - 1) << pos; | |
2087 | break; | |
2088 | ||
2089 | default: | |
2090 | /* This is going to be a sequence of loads and inserts. */ | |
2091 | pos = base + 32 - 8; | |
2092 | ccm = 0; | |
2093 | while (m3) { | |
2094 | if (m3 & 0x8) { | |
2095 | tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s)); | |
2096 | tcg_gen_addi_i64(o->in2, o->in2, 1); | |
2097 | tcg_gen_deposit_i64(o->out, o->out, tmp, pos, 8); | |
2098 | ccm |= 0xff << pos; | |
2099 | } | |
2100 | m3 = (m3 << 1) & 0xf; | |
2101 | pos -= 8; | |
2102 | } | |
2103 | break; | |
2104 | } | |
2105 | ||
2106 | tcg_gen_movi_i64(tmp, ccm); | |
2107 | gen_op_update2_cc_i64(s, CC_OP_ICM, tmp, o->out); | |
2108 | tcg_temp_free_i64(tmp); | |
2109 | return NO_EXIT; | |
2110 | } | |
2111 | ||
facfc864 RH |
2112 | static ExitStatus op_insi(DisasContext *s, DisasOps *o) |
2113 | { | |
2114 | int shift = s->insn->data & 0xff; | |
2115 | int size = s->insn->data >> 8; | |
2116 | tcg_gen_deposit_i64(o->out, o->in1, o->in2, shift, size); | |
2117 | return NO_EXIT; | |
2118 | } | |
2119 | ||
6e2704e7 RH |
2120 | static ExitStatus op_ipm(DisasContext *s, DisasOps *o) |
2121 | { | |
2122 | TCGv_i64 t1; | |
2123 | ||
2124 | gen_op_calc_cc(s); | |
2125 | tcg_gen_andi_i64(o->out, o->out, ~0xff000000ull); | |
2126 | ||
2127 | t1 = tcg_temp_new_i64(); | |
2128 | tcg_gen_shli_i64(t1, psw_mask, 20); | |
2129 | tcg_gen_shri_i64(t1, t1, 36); | |
2130 | tcg_gen_or_i64(o->out, o->out, t1); | |
2131 | ||
2132 | tcg_gen_extu_i32_i64(t1, cc_op); | |
2133 | tcg_gen_shli_i64(t1, t1, 28); | |
2134 | tcg_gen_or_i64(o->out, o->out, t1); | |
2135 | tcg_temp_free_i64(t1); | |
2136 | return NO_EXIT; | |
2137 | } | |
2138 | ||
cfef53e3 RH |
2139 | #ifndef CONFIG_USER_ONLY |
2140 | static ExitStatus op_ipte(DisasContext *s, DisasOps *o) | |
2141 | { | |
2142 | check_privileged(s); | |
2143 | gen_helper_ipte(cpu_env, o->in1, o->in2); | |
2144 | return NO_EXIT; | |
2145 | } | |
8026417c RH |
2146 | |
2147 | static ExitStatus op_iske(DisasContext *s, DisasOps *o) | |
2148 | { | |
2149 | check_privileged(s); | |
2150 | gen_helper_iske(o->out, cpu_env, o->in2); | |
2151 | return NO_EXIT; | |
2152 | } | |
cfef53e3 RH |
2153 | #endif |
2154 | ||
587626f8 RH |
2155 | static ExitStatus op_ldeb(DisasContext *s, DisasOps *o) |
2156 | { | |
2157 | gen_helper_ldeb(o->out, cpu_env, o->in2); | |
2158 | return NO_EXIT; | |
2159 | } | |
2160 | ||
2161 | static ExitStatus op_ledb(DisasContext *s, DisasOps *o) | |
2162 | { | |
2163 | gen_helper_ledb(o->out, cpu_env, o->in2); | |
2164 | return NO_EXIT; | |
2165 | } | |
2166 | ||
2167 | static ExitStatus op_ldxb(DisasContext *s, DisasOps *o) | |
2168 | { | |
2169 | gen_helper_ldxb(o->out, cpu_env, o->in1, o->in2); | |
2170 | return NO_EXIT; | |
2171 | } | |
2172 | ||
2173 | static ExitStatus op_lexb(DisasContext *s, DisasOps *o) | |
2174 | { | |
2175 | gen_helper_lexb(o->out, cpu_env, o->in1, o->in2); | |
2176 | return NO_EXIT; | |
2177 | } | |
2178 | ||
2179 | static ExitStatus op_lxdb(DisasContext *s, DisasOps *o) | |
2180 | { | |
2181 | gen_helper_lxdb(o->out, cpu_env, o->in2); | |
2182 | return_low128(o->out2); | |
2183 | return NO_EXIT; | |
2184 | } | |
2185 | ||
2186 | static ExitStatus op_lxeb(DisasContext *s, DisasOps *o) | |
2187 | { | |
2188 | gen_helper_lxeb(o->out, cpu_env, o->in2); | |
2189 | return_low128(o->out2); | |
2190 | return NO_EXIT; | |
2191 | } | |
2192 | ||
7691c23b RH |
2193 | static ExitStatus op_llgt(DisasContext *s, DisasOps *o) |
2194 | { | |
2195 | tcg_gen_andi_i64(o->out, o->in2, 0x7fffffff); | |
2196 | return NO_EXIT; | |
2197 | } | |
2198 | ||
c698d876 RH |
2199 | static ExitStatus op_ld8s(DisasContext *s, DisasOps *o) |
2200 | { | |
2201 | tcg_gen_qemu_ld8s(o->out, o->in2, get_mem_index(s)); | |
2202 | return NO_EXIT; | |
2203 | } | |
2204 | ||
2205 | static ExitStatus op_ld8u(DisasContext *s, DisasOps *o) | |
2206 | { | |
2207 | tcg_gen_qemu_ld8u(o->out, o->in2, get_mem_index(s)); | |
2208 | return NO_EXIT; | |
2209 | } | |
2210 | ||
2211 | static ExitStatus op_ld16s(DisasContext *s, DisasOps *o) | |
2212 | { | |
2213 | tcg_gen_qemu_ld16s(o->out, o->in2, get_mem_index(s)); | |
2214 | return NO_EXIT; | |
2215 | } | |
2216 | ||
2217 | static ExitStatus op_ld16u(DisasContext *s, DisasOps *o) | |
2218 | { | |
2219 | tcg_gen_qemu_ld16u(o->out, o->in2, get_mem_index(s)); | |
2220 | return NO_EXIT; | |
2221 | } | |
2222 | ||
22c37a08 RH |
2223 | static ExitStatus op_ld32s(DisasContext *s, DisasOps *o) |
2224 | { | |
2225 | tcg_gen_qemu_ld32s(o->out, o->in2, get_mem_index(s)); | |
2226 | return NO_EXIT; | |
2227 | } | |
2228 | ||
2229 | static ExitStatus op_ld32u(DisasContext *s, DisasOps *o) | |
2230 | { | |
2231 | tcg_gen_qemu_ld32u(o->out, o->in2, get_mem_index(s)); | |
2232 | return NO_EXIT; | |
2233 | } | |
2234 | ||
2235 | static ExitStatus op_ld64(DisasContext *s, DisasOps *o) | |
2236 | { | |
2237 | tcg_gen_qemu_ld64(o->out, o->in2, get_mem_index(s)); | |
2238 | return NO_EXIT; | |
2239 | } | |
2240 | ||
8b5ff571 | 2241 | #ifndef CONFIG_USER_ONLY |
504488b8 RH |
2242 | static ExitStatus op_lctl(DisasContext *s, DisasOps *o) |
2243 | { | |
2244 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2245 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2246 | check_privileged(s); | |
2247 | potential_page_fault(s); | |
2248 | gen_helper_lctl(cpu_env, r1, o->in2, r3); | |
2249 | tcg_temp_free_i32(r1); | |
2250 | tcg_temp_free_i32(r3); | |
2251 | return NO_EXIT; | |
2252 | } | |
2253 | ||
3e398cf9 RH |
2254 | static ExitStatus op_lctlg(DisasContext *s, DisasOps *o) |
2255 | { | |
2256 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2257 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2258 | check_privileged(s); | |
2259 | potential_page_fault(s); | |
2260 | gen_helper_lctlg(cpu_env, r1, o->in2, r3); | |
2261 | tcg_temp_free_i32(r1); | |
2262 | tcg_temp_free_i32(r3); | |
2263 | return NO_EXIT; | |
2264 | } | |
d8fe4a9c RH |
2265 | static ExitStatus op_lra(DisasContext *s, DisasOps *o) |
2266 | { | |
2267 | check_privileged(s); | |
2268 | potential_page_fault(s); | |
2269 | gen_helper_lra(o->out, cpu_env, o->in2); | |
2270 | set_cc_static(s); | |
2271 | return NO_EXIT; | |
2272 | } | |
2273 | ||
8b5ff571 RH |
2274 | static ExitStatus op_lpsw(DisasContext *s, DisasOps *o) |
2275 | { | |
2276 | TCGv_i64 t1, t2; | |
2277 | ||
2278 | check_privileged(s); | |
2279 | ||
2280 | t1 = tcg_temp_new_i64(); | |
2281 | t2 = tcg_temp_new_i64(); | |
2282 | tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s)); | |
2283 | tcg_gen_addi_i64(o->in2, o->in2, 4); | |
2284 | tcg_gen_qemu_ld32u(t2, o->in2, get_mem_index(s)); | |
2285 | /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK. */ | |
2286 | tcg_gen_shli_i64(t1, t1, 32); | |
2287 | gen_helper_load_psw(cpu_env, t1, t2); | |
2288 | tcg_temp_free_i64(t1); | |
2289 | tcg_temp_free_i64(t2); | |
2290 | return EXIT_NORETURN; | |
2291 | } | |
2292 | #endif | |
2293 | ||
7df3e93a RH |
2294 | static ExitStatus op_lam(DisasContext *s, DisasOps *o) |
2295 | { | |
2296 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2297 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2298 | potential_page_fault(s); | |
2299 | gen_helper_lam(cpu_env, r1, o->in2, r3); | |
2300 | tcg_temp_free_i32(r1); | |
2301 | tcg_temp_free_i32(r3); | |
2302 | return NO_EXIT; | |
2303 | } | |
2304 | ||
77f8d6c3 RH |
2305 | static ExitStatus op_lm32(DisasContext *s, DisasOps *o) |
2306 | { | |
2307 | int r1 = get_field(s->fields, r1); | |
2308 | int r3 = get_field(s->fields, r3); | |
2309 | TCGv_i64 t = tcg_temp_new_i64(); | |
2310 | TCGv_i64 t4 = tcg_const_i64(4); | |
2311 | ||
2312 | while (1) { | |
2313 | tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s)); | |
2314 | store_reg32_i64(r1, t); | |
2315 | if (r1 == r3) { | |
2316 | break; | |
2317 | } | |
2318 | tcg_gen_add_i64(o->in2, o->in2, t4); | |
2319 | r1 = (r1 + 1) & 15; | |
2320 | } | |
2321 | ||
2322 | tcg_temp_free_i64(t); | |
2323 | tcg_temp_free_i64(t4); | |
2324 | return NO_EXIT; | |
2325 | } | |
2326 | ||
2327 | static ExitStatus op_lmh(DisasContext *s, DisasOps *o) | |
2328 | { | |
2329 | int r1 = get_field(s->fields, r1); | |
2330 | int r3 = get_field(s->fields, r3); | |
2331 | TCGv_i64 t = tcg_temp_new_i64(); | |
2332 | TCGv_i64 t4 = tcg_const_i64(4); | |
2333 | ||
2334 | while (1) { | |
2335 | tcg_gen_qemu_ld32u(t, o->in2, get_mem_index(s)); | |
2336 | store_reg32h_i64(r1, t); | |
2337 | if (r1 == r3) { | |
2338 | break; | |
2339 | } | |
2340 | tcg_gen_add_i64(o->in2, o->in2, t4); | |
2341 | r1 = (r1 + 1) & 15; | |
2342 | } | |
2343 | ||
2344 | tcg_temp_free_i64(t); | |
2345 | tcg_temp_free_i64(t4); | |
2346 | return NO_EXIT; | |
2347 | } | |
2348 | ||
2349 | static ExitStatus op_lm64(DisasContext *s, DisasOps *o) | |
2350 | { | |
2351 | int r1 = get_field(s->fields, r1); | |
2352 | int r3 = get_field(s->fields, r3); | |
2353 | TCGv_i64 t8 = tcg_const_i64(8); | |
2354 | ||
2355 | while (1) { | |
2356 | tcg_gen_qemu_ld64(regs[r1], o->in2, get_mem_index(s)); | |
2357 | if (r1 == r3) { | |
2358 | break; | |
2359 | } | |
2360 | tcg_gen_add_i64(o->in2, o->in2, t8); | |
2361 | r1 = (r1 + 1) & 15; | |
2362 | } | |
2363 | ||
2364 | tcg_temp_free_i64(t8); | |
2365 | return NO_EXIT; | |
2366 | } | |
2367 | ||
22c37a08 RH |
2368 | static ExitStatus op_mov2(DisasContext *s, DisasOps *o) |
2369 | { | |
2370 | o->out = o->in2; | |
2371 | o->g_out = o->g_in2; | |
2372 | TCGV_UNUSED_I64(o->in2); | |
2373 | o->g_in2 = false; | |
2374 | return NO_EXIT; | |
2375 | } | |
2376 | ||
d764a8d1 RH |
2377 | static ExitStatus op_movx(DisasContext *s, DisasOps *o) |
2378 | { | |
2379 | o->out = o->in1; | |
2380 | o->out2 = o->in2; | |
2381 | o->g_out = o->g_in1; | |
2382 | o->g_out2 = o->g_in2; | |
2383 | TCGV_UNUSED_I64(o->in1); | |
2384 | TCGV_UNUSED_I64(o->in2); | |
2385 | o->g_in1 = o->g_in2 = false; | |
2386 | return NO_EXIT; | |
2387 | } | |
2388 | ||
af9e5a04 RH |
2389 | static ExitStatus op_mvc(DisasContext *s, DisasOps *o) |
2390 | { | |
2391 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
2392 | potential_page_fault(s); | |
2393 | gen_helper_mvc(cpu_env, l, o->addr1, o->in2); | |
2394 | tcg_temp_free_i32(l); | |
2395 | return NO_EXIT; | |
2396 | } | |
2397 | ||
e1eaada9 RH |
2398 | static ExitStatus op_mvcl(DisasContext *s, DisasOps *o) |
2399 | { | |
2400 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2401 | TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2)); | |
2402 | potential_page_fault(s); | |
2403 | gen_helper_mvcl(cc_op, cpu_env, r1, r2); | |
2404 | tcg_temp_free_i32(r1); | |
2405 | tcg_temp_free_i32(r2); | |
2406 | set_cc_static(s); | |
2407 | return NO_EXIT; | |
2408 | } | |
2409 | ||
eb66e6a9 RH |
2410 | static ExitStatus op_mvcle(DisasContext *s, DisasOps *o) |
2411 | { | |
2412 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2413 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2414 | potential_page_fault(s); | |
2415 | gen_helper_mvcle(cc_op, cpu_env, r1, o->in2, r3); | |
2416 | tcg_temp_free_i32(r1); | |
2417 | tcg_temp_free_i32(r3); | |
2418 | set_cc_static(s); | |
2419 | return NO_EXIT; | |
2420 | } | |
2421 | ||
97c3ab61 RH |
2422 | #ifndef CONFIG_USER_ONLY |
2423 | static ExitStatus op_mvcp(DisasContext *s, DisasOps *o) | |
2424 | { | |
2425 | int r1 = get_field(s->fields, l1); | |
2426 | check_privileged(s); | |
2427 | potential_page_fault(s); | |
2428 | gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2); | |
2429 | set_cc_static(s); | |
2430 | return NO_EXIT; | |
2431 | } | |
2432 | ||
2433 | static ExitStatus op_mvcs(DisasContext *s, DisasOps *o) | |
2434 | { | |
2435 | int r1 = get_field(s->fields, l1); | |
2436 | check_privileged(s); | |
2437 | potential_page_fault(s); | |
2438 | gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2); | |
2439 | set_cc_static(s); | |
2440 | return NO_EXIT; | |
2441 | } | |
2442 | #endif | |
2443 | ||
ee6c38d5 RH |
2444 | static ExitStatus op_mvpg(DisasContext *s, DisasOps *o) |
2445 | { | |
2446 | potential_page_fault(s); | |
2447 | gen_helper_mvpg(cpu_env, regs[0], o->in1, o->in2); | |
2448 | set_cc_static(s); | |
2449 | return NO_EXIT; | |
2450 | } | |
2451 | ||
aa31bf60 RH |
2452 | static ExitStatus op_mvst(DisasContext *s, DisasOps *o) |
2453 | { | |
2454 | potential_page_fault(s); | |
2455 | gen_helper_mvst(o->in1, cpu_env, regs[0], o->in1, o->in2); | |
2456 | set_cc_static(s); | |
2457 | return_low128(o->in2); | |
2458 | return NO_EXIT; | |
2459 | } | |
2460 | ||
d1c04a2b RH |
2461 | static ExitStatus op_mul(DisasContext *s, DisasOps *o) |
2462 | { | |
2463 | tcg_gen_mul_i64(o->out, o->in1, o->in2); | |
2464 | return NO_EXIT; | |
2465 | } | |
2466 | ||
1ac5889f RH |
2467 | static ExitStatus op_mul128(DisasContext *s, DisasOps *o) |
2468 | { | |
2469 | gen_helper_mul128(o->out, cpu_env, o->in1, o->in2); | |
2470 | return_low128(o->out2); | |
2471 | return NO_EXIT; | |
2472 | } | |
2473 | ||
83b00736 RH |
2474 | static ExitStatus op_meeb(DisasContext *s, DisasOps *o) |
2475 | { | |
2476 | gen_helper_meeb(o->out, cpu_env, o->in1, o->in2); | |
2477 | return NO_EXIT; | |
2478 | } | |
2479 | ||
2480 | static ExitStatus op_mdeb(DisasContext *s, DisasOps *o) | |
2481 | { | |
2482 | gen_helper_mdeb(o->out, cpu_env, o->in1, o->in2); | |
2483 | return NO_EXIT; | |
2484 | } | |
2485 | ||
2486 | static ExitStatus op_mdb(DisasContext *s, DisasOps *o) | |
2487 | { | |
2488 | gen_helper_mdb(o->out, cpu_env, o->in1, o->in2); | |
2489 | return NO_EXIT; | |
2490 | } | |
2491 | ||
2492 | static ExitStatus op_mxb(DisasContext *s, DisasOps *o) | |
2493 | { | |
2494 | gen_helper_mxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2); | |
2495 | return_low128(o->out2); | |
2496 | return NO_EXIT; | |
2497 | } | |
2498 | ||
2499 | static ExitStatus op_mxdb(DisasContext *s, DisasOps *o) | |
2500 | { | |
2501 | gen_helper_mxdb(o->out, cpu_env, o->out, o->out2, o->in2); | |
2502 | return_low128(o->out2); | |
2503 | return NO_EXIT; | |
2504 | } | |
2505 | ||
722bfec3 RH |
2506 | static ExitStatus op_maeb(DisasContext *s, DisasOps *o) |
2507 | { | |
2508 | TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3)); | |
2509 | gen_helper_maeb(o->out, cpu_env, o->in1, o->in2, r3); | |
2510 | tcg_temp_free_i64(r3); | |
2511 | return NO_EXIT; | |
2512 | } | |
2513 | ||
2514 | static ExitStatus op_madb(DisasContext *s, DisasOps *o) | |
2515 | { | |
2516 | int r3 = get_field(s->fields, r3); | |
2517 | gen_helper_madb(o->out, cpu_env, o->in1, o->in2, fregs[r3]); | |
2518 | return NO_EXIT; | |
2519 | } | |
2520 | ||
2521 | static ExitStatus op_mseb(DisasContext *s, DisasOps *o) | |
2522 | { | |
2523 | TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3)); | |
2524 | gen_helper_mseb(o->out, cpu_env, o->in1, o->in2, r3); | |
2525 | tcg_temp_free_i64(r3); | |
2526 | return NO_EXIT; | |
2527 | } | |
2528 | ||
2529 | static ExitStatus op_msdb(DisasContext *s, DisasOps *o) | |
2530 | { | |
2531 | int r3 = get_field(s->fields, r3); | |
2532 | gen_helper_msdb(o->out, cpu_env, o->in1, o->in2, fregs[r3]); | |
2533 | return NO_EXIT; | |
2534 | } | |
2535 | ||
b9bca3e5 RH |
2536 | static ExitStatus op_nabs(DisasContext *s, DisasOps *o) |
2537 | { | |
2538 | gen_helper_nabs_i64(o->out, o->in2); | |
2539 | return NO_EXIT; | |
2540 | } | |
2541 | ||
5d7fd045 RH |
2542 | static ExitStatus op_nabsf32(DisasContext *s, DisasOps *o) |
2543 | { | |
2544 | tcg_gen_ori_i64(o->out, o->in2, 0x80000000ull); | |
2545 | return NO_EXIT; | |
2546 | } | |
2547 | ||
2548 | static ExitStatus op_nabsf64(DisasContext *s, DisasOps *o) | |
2549 | { | |
2550 | tcg_gen_ori_i64(o->out, o->in2, 0x8000000000000000ull); | |
2551 | return NO_EXIT; | |
2552 | } | |
2553 | ||
2554 | static ExitStatus op_nabsf128(DisasContext *s, DisasOps *o) | |
2555 | { | |
2556 | tcg_gen_ori_i64(o->out, o->in1, 0x8000000000000000ull); | |
2557 | tcg_gen_mov_i64(o->out2, o->in2); | |
2558 | return NO_EXIT; | |
2559 | } | |
2560 | ||
0a949039 RH |
2561 | static ExitStatus op_nc(DisasContext *s, DisasOps *o) |
2562 | { | |
2563 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
2564 | potential_page_fault(s); | |
2565 | gen_helper_nc(cc_op, cpu_env, l, o->addr1, o->in2); | |
2566 | tcg_temp_free_i32(l); | |
2567 | set_cc_static(s); | |
2568 | return NO_EXIT; | |
2569 | } | |
2570 | ||
b9bca3e5 RH |
2571 | static ExitStatus op_neg(DisasContext *s, DisasOps *o) |
2572 | { | |
2573 | tcg_gen_neg_i64(o->out, o->in2); | |
2574 | return NO_EXIT; | |
2575 | } | |
2576 | ||
5d7fd045 RH |
2577 | static ExitStatus op_negf32(DisasContext *s, DisasOps *o) |
2578 | { | |
2579 | tcg_gen_xori_i64(o->out, o->in2, 0x80000000ull); | |
2580 | return NO_EXIT; | |
2581 | } | |
2582 | ||
2583 | static ExitStatus op_negf64(DisasContext *s, DisasOps *o) | |
2584 | { | |
2585 | tcg_gen_xori_i64(o->out, o->in2, 0x8000000000000000ull); | |
2586 | return NO_EXIT; | |
2587 | } | |
2588 | ||
2589 | static ExitStatus op_negf128(DisasContext *s, DisasOps *o) | |
2590 | { | |
2591 | tcg_gen_xori_i64(o->out, o->in1, 0x8000000000000000ull); | |
2592 | tcg_gen_mov_i64(o->out2, o->in2); | |
2593 | return NO_EXIT; | |
2594 | } | |
2595 | ||
0a949039 RH |
2596 | static ExitStatus op_oc(DisasContext *s, DisasOps *o) |
2597 | { | |
2598 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
2599 | potential_page_fault(s); | |
2600 | gen_helper_oc(cc_op, cpu_env, l, o->addr1, o->in2); | |
2601 | tcg_temp_free_i32(l); | |
2602 | set_cc_static(s); | |
2603 | return NO_EXIT; | |
2604 | } | |
2605 | ||
3bbfbd1f RH |
2606 | static ExitStatus op_or(DisasContext *s, DisasOps *o) |
2607 | { | |
2608 | tcg_gen_or_i64(o->out, o->in1, o->in2); | |
2609 | return NO_EXIT; | |
2610 | } | |
2611 | ||
facfc864 RH |
2612 | static ExitStatus op_ori(DisasContext *s, DisasOps *o) |
2613 | { | |
2614 | int shift = s->insn->data & 0xff; | |
2615 | int size = s->insn->data >> 8; | |
2616 | uint64_t mask = ((1ull << size) - 1) << shift; | |
2617 | ||
2618 | assert(!o->g_in2); | |
2619 | tcg_gen_shli_i64(o->in2, o->in2, shift); | |
2620 | tcg_gen_or_i64(o->out, o->in1, o->in2); | |
2621 | ||
2622 | /* Produce the CC from only the bits manipulated. */ | |
2623 | tcg_gen_andi_i64(cc_dst, o->out, mask); | |
2624 | set_cc_nz_u64(s, cc_dst); | |
2625 | return NO_EXIT; | |
2626 | } | |
2627 | ||
0568d8aa RH |
2628 | #ifndef CONFIG_USER_ONLY |
2629 | static ExitStatus op_ptlb(DisasContext *s, DisasOps *o) | |
2630 | { | |
2631 | check_privileged(s); | |
2632 | gen_helper_ptlb(cpu_env); | |
2633 | return NO_EXIT; | |
2634 | } | |
2635 | #endif | |
2636 | ||
d54f5865 RH |
2637 | static ExitStatus op_rev16(DisasContext *s, DisasOps *o) |
2638 | { | |
2639 | tcg_gen_bswap16_i64(o->out, o->in2); | |
2640 | return NO_EXIT; | |
2641 | } | |
2642 | ||
2643 | static ExitStatus op_rev32(DisasContext *s, DisasOps *o) | |
2644 | { | |
2645 | tcg_gen_bswap32_i64(o->out, o->in2); | |
2646 | return NO_EXIT; | |
2647 | } | |
2648 | ||
2649 | static ExitStatus op_rev64(DisasContext *s, DisasOps *o) | |
2650 | { | |
2651 | tcg_gen_bswap64_i64(o->out, o->in2); | |
2652 | return NO_EXIT; | |
2653 | } | |
2654 | ||
cbe24bfa RH |
2655 | static ExitStatus op_rll32(DisasContext *s, DisasOps *o) |
2656 | { | |
2657 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
2658 | TCGv_i32 t2 = tcg_temp_new_i32(); | |
2659 | TCGv_i32 to = tcg_temp_new_i32(); | |
2660 | tcg_gen_trunc_i64_i32(t1, o->in1); | |
2661 | tcg_gen_trunc_i64_i32(t2, o->in2); | |
2662 | tcg_gen_rotl_i32(to, t1, t2); | |
2663 | tcg_gen_extu_i32_i64(o->out, to); | |
2664 | tcg_temp_free_i32(t1); | |
2665 | tcg_temp_free_i32(t2); | |
2666 | tcg_temp_free_i32(to); | |
2667 | return NO_EXIT; | |
2668 | } | |
2669 | ||
2670 | static ExitStatus op_rll64(DisasContext *s, DisasOps *o) | |
2671 | { | |
2672 | tcg_gen_rotl_i64(o->out, o->in1, o->in2); | |
2673 | return NO_EXIT; | |
2674 | } | |
2675 | ||
5cc69c54 RH |
2676 | #ifndef CONFIG_USER_ONLY |
2677 | static ExitStatus op_rrbe(DisasContext *s, DisasOps *o) | |
2678 | { | |
2679 | check_privileged(s); | |
2680 | gen_helper_rrbe(cc_op, cpu_env, o->in2); | |
2681 | set_cc_static(s); | |
2682 | return NO_EXIT; | |
2683 | } | |
2684 | #endif | |
2685 | ||
d62a4c97 RH |
2686 | static ExitStatus op_sar(DisasContext *s, DisasOps *o) |
2687 | { | |
2688 | int r1 = get_field(s->fields, r1); | |
2689 | tcg_gen_st32_i64(o->in2, cpu_env, offsetof(CPUS390XState, aregs[r1])); | |
2690 | return NO_EXIT; | |
2691 | } | |
2692 | ||
1a800a2d RH |
2693 | static ExitStatus op_seb(DisasContext *s, DisasOps *o) |
2694 | { | |
2695 | gen_helper_seb(o->out, cpu_env, o->in1, o->in2); | |
2696 | return NO_EXIT; | |
2697 | } | |
2698 | ||
2699 | static ExitStatus op_sdb(DisasContext *s, DisasOps *o) | |
2700 | { | |
2701 | gen_helper_sdb(o->out, cpu_env, o->in1, o->in2); | |
2702 | return NO_EXIT; | |
2703 | } | |
2704 | ||
2705 | static ExitStatus op_sxb(DisasContext *s, DisasOps *o) | |
2706 | { | |
2707 | gen_helper_sxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2); | |
2708 | return_low128(o->out2); | |
2709 | return NO_EXIT; | |
2710 | } | |
2711 | ||
16d7b2a4 RH |
2712 | static ExitStatus op_sqeb(DisasContext *s, DisasOps *o) |
2713 | { | |
2714 | gen_helper_sqeb(o->out, cpu_env, o->in2); | |
2715 | return NO_EXIT; | |
2716 | } | |
2717 | ||
2718 | static ExitStatus op_sqdb(DisasContext *s, DisasOps *o) | |
2719 | { | |
2720 | gen_helper_sqdb(o->out, cpu_env, o->in2); | |
2721 | return NO_EXIT; | |
2722 | } | |
2723 | ||
2724 | static ExitStatus op_sqxb(DisasContext *s, DisasOps *o) | |
2725 | { | |
2726 | gen_helper_sqxb(o->out, cpu_env, o->in1, o->in2); | |
2727 | return_low128(o->out2); | |
2728 | return NO_EXIT; | |
2729 | } | |
2730 | ||
0c240015 RH |
2731 | #ifndef CONFIG_USER_ONLY |
2732 | static ExitStatus op_sigp(DisasContext *s, DisasOps *o) | |
2733 | { | |
2734 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2735 | check_privileged(s); | |
2736 | potential_page_fault(s); | |
2737 | gen_helper_sigp(cc_op, cpu_env, o->in2, r1, o->in1); | |
2738 | tcg_temp_free_i32(r1); | |
2739 | return NO_EXIT; | |
2740 | } | |
2741 | #endif | |
2742 | ||
cbe24bfa RH |
2743 | static ExitStatus op_sla(DisasContext *s, DisasOps *o) |
2744 | { | |
2745 | uint64_t sign = 1ull << s->insn->data; | |
2746 | enum cc_op cco = s->insn->data == 31 ? CC_OP_SLA_32 : CC_OP_SLA_64; | |
2747 | gen_op_update2_cc_i64(s, cco, o->in1, o->in2); | |
2748 | tcg_gen_shl_i64(o->out, o->in1, o->in2); | |
2749 | /* The arithmetic left shift is curious in that it does not affect | |
2750 | the sign bit. Copy that over from the source unchanged. */ | |
2751 | tcg_gen_andi_i64(o->out, o->out, ~sign); | |
2752 | tcg_gen_andi_i64(o->in1, o->in1, sign); | |
2753 | tcg_gen_or_i64(o->out, o->out, o->in1); | |
2754 | return NO_EXIT; | |
2755 | } | |
2756 | ||
2757 | static ExitStatus op_sll(DisasContext *s, DisasOps *o) | |
2758 | { | |
2759 | tcg_gen_shl_i64(o->out, o->in1, o->in2); | |
2760 | return NO_EXIT; | |
2761 | } | |
2762 | ||
2763 | static ExitStatus op_sra(DisasContext *s, DisasOps *o) | |
2764 | { | |
2765 | tcg_gen_sar_i64(o->out, o->in1, o->in2); | |
2766 | return NO_EXIT; | |
2767 | } | |
2768 | ||
2769 | static ExitStatus op_srl(DisasContext *s, DisasOps *o) | |
2770 | { | |
2771 | tcg_gen_shr_i64(o->out, o->in1, o->in2); | |
2772 | return NO_EXIT; | |
2773 | } | |
2774 | ||
8379bfdb RH |
2775 | static ExitStatus op_sfpc(DisasContext *s, DisasOps *o) |
2776 | { | |
2777 | gen_helper_sfpc(cpu_env, o->in2); | |
2778 | return NO_EXIT; | |
2779 | } | |
2780 | ||
7d30bb73 | 2781 | #ifndef CONFIG_USER_ONLY |
28d55556 RH |
2782 | static ExitStatus op_spka(DisasContext *s, DisasOps *o) |
2783 | { | |
2784 | check_privileged(s); | |
2785 | tcg_gen_shri_i64(o->in2, o->in2, 4); | |
2786 | tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, PSW_SHIFT_KEY - 4, 4); | |
2787 | return NO_EXIT; | |
2788 | } | |
2789 | ||
2bbde27f RH |
2790 | static ExitStatus op_sske(DisasContext *s, DisasOps *o) |
2791 | { | |
2792 | check_privileged(s); | |
2793 | gen_helper_sske(cpu_env, o->in1, o->in2); | |
2794 | return NO_EXIT; | |
2795 | } | |
2796 | ||
7d30bb73 RH |
2797 | static ExitStatus op_ssm(DisasContext *s, DisasOps *o) |
2798 | { | |
2799 | check_privileged(s); | |
2800 | tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, 56, 8); | |
2801 | return NO_EXIT; | |
2802 | } | |
145cdb40 | 2803 | |
411fea3d RH |
2804 | static ExitStatus op_stap(DisasContext *s, DisasOps *o) |
2805 | { | |
2806 | check_privileged(s); | |
2807 | /* ??? Surely cpu address != cpu number. In any case the previous | |
2808 | version of this stored more than the required half-word, so it | |
2809 | is unlikely this has ever been tested. */ | |
2810 | tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, cpu_num)); | |
2811 | return NO_EXIT; | |
2812 | } | |
2813 | ||
434c91a5 RH |
2814 | static ExitStatus op_stck(DisasContext *s, DisasOps *o) |
2815 | { | |
2816 | gen_helper_stck(o->out, cpu_env); | |
2817 | /* ??? We don't implement clock states. */ | |
2818 | gen_op_movi_cc(s, 0); | |
2819 | return NO_EXIT; | |
39a5003c RH |
2820 | } |
2821 | ||
2822 | static ExitStatus op_stcke(DisasContext *s, DisasOps *o) | |
2823 | { | |
2824 | TCGv_i64 c1 = tcg_temp_new_i64(); | |
2825 | TCGv_i64 c2 = tcg_temp_new_i64(); | |
2826 | gen_helper_stck(c1, cpu_env); | |
2827 | /* Shift the 64-bit value into its place as a zero-extended | |
2828 | 104-bit value. Note that "bit positions 64-103 are always | |
2829 | non-zero so that they compare differently to STCK"; we set | |
2830 | the least significant bit to 1. */ | |
2831 | tcg_gen_shli_i64(c2, c1, 56); | |
2832 | tcg_gen_shri_i64(c1, c1, 8); | |
2833 | tcg_gen_ori_i64(c2, c2, 0x10000); | |
2834 | tcg_gen_qemu_st64(c1, o->in2, get_mem_index(s)); | |
2835 | tcg_gen_addi_i64(o->in2, o->in2, 8); | |
2836 | tcg_gen_qemu_st64(c2, o->in2, get_mem_index(s)); | |
2837 | tcg_temp_free_i64(c1); | |
2838 | tcg_temp_free_i64(c2); | |
2839 | /* ??? We don't implement clock states. */ | |
2840 | gen_op_movi_cc(s, 0); | |
2841 | return NO_EXIT; | |
434c91a5 RH |
2842 | } |
2843 | ||
dd3eb7b5 RH |
2844 | static ExitStatus op_sckc(DisasContext *s, DisasOps *o) |
2845 | { | |
2846 | check_privileged(s); | |
2847 | gen_helper_sckc(cpu_env, o->in2); | |
2848 | return NO_EXIT; | |
2849 | } | |
2850 | ||
2851 | static ExitStatus op_stckc(DisasContext *s, DisasOps *o) | |
2852 | { | |
2853 | check_privileged(s); | |
2854 | gen_helper_stckc(o->out, cpu_env); | |
2855 | return NO_EXIT; | |
2856 | } | |
2857 | ||
3e398cf9 RH |
2858 | static ExitStatus op_stctg(DisasContext *s, DisasOps *o) |
2859 | { | |
2860 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2861 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2862 | check_privileged(s); | |
2863 | potential_page_fault(s); | |
2864 | gen_helper_stctg(cpu_env, r1, o->in2, r3); | |
2865 | tcg_temp_free_i32(r1); | |
2866 | tcg_temp_free_i32(r3); | |
2867 | return NO_EXIT; | |
2868 | } | |
2869 | ||
504488b8 RH |
2870 | static ExitStatus op_stctl(DisasContext *s, DisasOps *o) |
2871 | { | |
2872 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2873 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2874 | check_privileged(s); | |
2875 | potential_page_fault(s); | |
2876 | gen_helper_stctl(cpu_env, r1, o->in2, r3); | |
2877 | tcg_temp_free_i32(r1); | |
2878 | tcg_temp_free_i32(r3); | |
2879 | return NO_EXIT; | |
2880 | } | |
2881 | ||
71bd6669 RH |
2882 | static ExitStatus op_stidp(DisasContext *s, DisasOps *o) |
2883 | { | |
2884 | check_privileged(s); | |
2885 | tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, cpu_num)); | |
2886 | return NO_EXIT; | |
2887 | } | |
2888 | ||
c4f0a863 RH |
2889 | static ExitStatus op_spt(DisasContext *s, DisasOps *o) |
2890 | { | |
2891 | check_privileged(s); | |
2892 | gen_helper_spt(cpu_env, o->in2); | |
2893 | return NO_EXIT; | |
2894 | } | |
2895 | ||
2896 | static ExitStatus op_stpt(DisasContext *s, DisasOps *o) | |
2897 | { | |
2898 | check_privileged(s); | |
2899 | gen_helper_stpt(o->out, cpu_env); | |
2900 | return NO_EXIT; | |
2901 | } | |
2902 | ||
e805a0d3 RH |
2903 | static ExitStatus op_spx(DisasContext *s, DisasOps *o) |
2904 | { | |
2905 | check_privileged(s); | |
2906 | gen_helper_spx(cpu_env, o->in2); | |
2907 | return NO_EXIT; | |
2908 | } | |
2909 | ||
2c423fc0 RH |
2910 | static ExitStatus op_subchannel(DisasContext *s, DisasOps *o) |
2911 | { | |
2912 | check_privileged(s); | |
2913 | /* Not operational. */ | |
2914 | gen_op_movi_cc(s, 3); | |
2915 | return NO_EXIT; | |
2916 | } | |
2917 | ||
e805a0d3 RH |
2918 | static ExitStatus op_stpx(DisasContext *s, DisasOps *o) |
2919 | { | |
2920 | check_privileged(s); | |
2921 | tcg_gen_ld_i64(o->out, cpu_env, offsetof(CPUS390XState, psa)); | |
2922 | tcg_gen_andi_i64(o->out, o->out, 0x7fffe000); | |
2923 | return NO_EXIT; | |
2924 | } | |
2925 | ||
145cdb40 RH |
2926 | static ExitStatus op_stnosm(DisasContext *s, DisasOps *o) |
2927 | { | |
2928 | uint64_t i2 = get_field(s->fields, i2); | |
2929 | TCGv_i64 t; | |
2930 | ||
2931 | check_privileged(s); | |
2932 | ||
2933 | /* It is important to do what the instruction name says: STORE THEN. | |
2934 | If we let the output hook perform the store then if we fault and | |
2935 | restart, we'll have the wrong SYSTEM MASK in place. */ | |
2936 | t = tcg_temp_new_i64(); | |
2937 | tcg_gen_shri_i64(t, psw_mask, 56); | |
2938 | tcg_gen_qemu_st8(t, o->addr1, get_mem_index(s)); | |
2939 | tcg_temp_free_i64(t); | |
2940 | ||
2941 | if (s->fields->op == 0xac) { | |
2942 | tcg_gen_andi_i64(psw_mask, psw_mask, | |
2943 | (i2 << 56) | 0x00ffffffffffffffull); | |
2944 | } else { | |
2945 | tcg_gen_ori_i64(psw_mask, psw_mask, i2 << 56); | |
2946 | } | |
2947 | return NO_EXIT; | |
2948 | } | |
204504e2 RH |
2949 | |
2950 | static ExitStatus op_stura(DisasContext *s, DisasOps *o) | |
2951 | { | |
2952 | check_privileged(s); | |
2953 | potential_page_fault(s); | |
2954 | gen_helper_stura(cpu_env, o->in2, o->in1); | |
2955 | return NO_EXIT; | |
2956 | } | |
7d30bb73 RH |
2957 | #endif |
2958 | ||
2b280b97 RH |
2959 | static ExitStatus op_st8(DisasContext *s, DisasOps *o) |
2960 | { | |
2961 | tcg_gen_qemu_st8(o->in1, o->in2, get_mem_index(s)); | |
2962 | return NO_EXIT; | |
2963 | } | |
2964 | ||
2965 | static ExitStatus op_st16(DisasContext *s, DisasOps *o) | |
2966 | { | |
2967 | tcg_gen_qemu_st16(o->in1, o->in2, get_mem_index(s)); | |
2968 | return NO_EXIT; | |
2969 | } | |
2970 | ||
2971 | static ExitStatus op_st32(DisasContext *s, DisasOps *o) | |
2972 | { | |
2973 | tcg_gen_qemu_st32(o->in1, o->in2, get_mem_index(s)); | |
2974 | return NO_EXIT; | |
2975 | } | |
2976 | ||
2977 | static ExitStatus op_st64(DisasContext *s, DisasOps *o) | |
2978 | { | |
2979 | tcg_gen_qemu_st64(o->in1, o->in2, get_mem_index(s)); | |
2980 | return NO_EXIT; | |
2981 | } | |
2982 | ||
7df3e93a RH |
2983 | static ExitStatus op_stam(DisasContext *s, DisasOps *o) |
2984 | { | |
2985 | TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1)); | |
2986 | TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3)); | |
2987 | potential_page_fault(s); | |
2988 | gen_helper_stam(cpu_env, r1, o->in2, r3); | |
2989 | tcg_temp_free_i32(r1); | |
2990 | tcg_temp_free_i32(r3); | |
2991 | return NO_EXIT; | |
2992 | } | |
2993 | ||
2ae68059 RH |
2994 | static ExitStatus op_stcm(DisasContext *s, DisasOps *o) |
2995 | { | |
2996 | int m3 = get_field(s->fields, m3); | |
2997 | int pos, base = s->insn->data; | |
2998 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
2999 | ||
3000 | pos = base + ctz32(m3) * 8; | |
3001 | switch (m3) { | |
3002 | case 0xf: | |
3003 | /* Effectively a 32-bit store. */ | |
3004 | tcg_gen_shri_i64(tmp, o->in1, pos); | |
3005 | tcg_gen_qemu_st32(tmp, o->in2, get_mem_index(s)); | |
3006 | break; | |
3007 | ||
3008 | case 0xc: | |
3009 | case 0x6: | |
3010 | case 0x3: | |
3011 | /* Effectively a 16-bit store. */ | |
3012 | tcg_gen_shri_i64(tmp, o->in1, pos); | |
3013 | tcg_gen_qemu_st16(tmp, o->in2, get_mem_index(s)); | |
3014 | break; | |
3015 | ||
3016 | case 0x8: | |
3017 | case 0x4: | |
3018 | case 0x2: | |
3019 | case 0x1: | |
3020 | /* Effectively an 8-bit store. */ | |
3021 | tcg_gen_shri_i64(tmp, o->in1, pos); | |
3022 | tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s)); | |
3023 | break; | |
3024 | ||
3025 | default: | |
3026 | /* This is going to be a sequence of shifts and stores. */ | |
3027 | pos = base + 32 - 8; | |
3028 | while (m3) { | |
3029 | if (m3 & 0x8) { | |
3030 | tcg_gen_shri_i64(tmp, o->in1, pos); | |
3031 | tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s)); | |
3032 | tcg_gen_addi_i64(o->in2, o->in2, 1); | |
3033 | } | |
3034 | m3 = (m3 << 1) & 0xf; | |
3035 | pos -= 8; | |
3036 | } | |
3037 | break; | |
3038 | } | |
3039 | tcg_temp_free_i64(tmp); | |
3040 | return NO_EXIT; | |
3041 | } | |
3042 | ||
77f8d6c3 RH |
3043 | static ExitStatus op_stm(DisasContext *s, DisasOps *o) |
3044 | { | |
3045 | int r1 = get_field(s->fields, r1); | |
3046 | int r3 = get_field(s->fields, r3); | |
3047 | int size = s->insn->data; | |
3048 | TCGv_i64 tsize = tcg_const_i64(size); | |
3049 | ||
3050 | while (1) { | |
3051 | if (size == 8) { | |
3052 | tcg_gen_qemu_st64(regs[r1], o->in2, get_mem_index(s)); | |
3053 | } else { | |
3054 | tcg_gen_qemu_st32(regs[r1], o->in2, get_mem_index(s)); | |
3055 | } | |
3056 | if (r1 == r3) { | |
3057 | break; | |
3058 | } | |
3059 | tcg_gen_add_i64(o->in2, o->in2, tsize); | |
3060 | r1 = (r1 + 1) & 15; | |
3061 | } | |
3062 | ||
3063 | tcg_temp_free_i64(tsize); | |
3064 | return NO_EXIT; | |
3065 | } | |
3066 | ||
3067 | static ExitStatus op_stmh(DisasContext *s, DisasOps *o) | |
3068 | { | |
3069 | int r1 = get_field(s->fields, r1); | |
3070 | int r3 = get_field(s->fields, r3); | |
3071 | TCGv_i64 t = tcg_temp_new_i64(); | |
3072 | TCGv_i64 t4 = tcg_const_i64(4); | |
3073 | TCGv_i64 t32 = tcg_const_i64(32); | |
3074 | ||
3075 | while (1) { | |
3076 | tcg_gen_shl_i64(t, regs[r1], t32); | |
3077 | tcg_gen_qemu_st32(t, o->in2, get_mem_index(s)); | |
3078 | if (r1 == r3) { | |
3079 | break; | |
3080 | } | |
3081 | tcg_gen_add_i64(o->in2, o->in2, t4); | |
3082 | r1 = (r1 + 1) & 15; | |
3083 | } | |
3084 | ||
3085 | tcg_temp_free_i64(t); | |
3086 | tcg_temp_free_i64(t4); | |
3087 | tcg_temp_free_i64(t32); | |
3088 | return NO_EXIT; | |
3089 | } | |
3090 | ||
4600c994 RH |
3091 | static ExitStatus op_srst(DisasContext *s, DisasOps *o) |
3092 | { | |
3093 | potential_page_fault(s); | |
3094 | gen_helper_srst(o->in1, cpu_env, regs[0], o->in1, o->in2); | |
3095 | set_cc_static(s); | |
3096 | return_low128(o->in2); | |
3097 | return NO_EXIT; | |
3098 | } | |
3099 | ||
ad044d09 RH |
3100 | static ExitStatus op_sub(DisasContext *s, DisasOps *o) |
3101 | { | |
3102 | tcg_gen_sub_i64(o->out, o->in1, o->in2); | |
3103 | return NO_EXIT; | |
3104 | } | |
3105 | ||
4e4bb438 RH |
3106 | static ExitStatus op_subb(DisasContext *s, DisasOps *o) |
3107 | { | |
3108 | TCGv_i64 cc; | |
3109 | ||
3110 | assert(!o->g_in2); | |
3111 | tcg_gen_not_i64(o->in2, o->in2); | |
3112 | tcg_gen_add_i64(o->out, o->in1, o->in2); | |
3113 | ||
3114 | /* XXX possible optimization point */ | |
3115 | gen_op_calc_cc(s); | |
3116 | cc = tcg_temp_new_i64(); | |
3117 | tcg_gen_extu_i32_i64(cc, cc_op); | |
3118 | tcg_gen_shri_i64(cc, cc, 1); | |
3119 | tcg_gen_add_i64(o->out, o->out, cc); | |
3120 | tcg_temp_free_i64(cc); | |
3121 | return NO_EXIT; | |
3122 | } | |
3123 | ||
b9836c1a RH |
3124 | static ExitStatus op_svc(DisasContext *s, DisasOps *o) |
3125 | { | |
3126 | TCGv_i32 t; | |
3127 | ||
3128 | update_psw_addr(s); | |
3129 | gen_op_calc_cc(s); | |
3130 | ||
3131 | t = tcg_const_i32(get_field(s->fields, i1) & 0xff); | |
3132 | tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_code)); | |
3133 | tcg_temp_free_i32(t); | |
3134 | ||
3135 | t = tcg_const_i32(s->next_pc - s->pc); | |
3136 | tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_ilen)); | |
3137 | tcg_temp_free_i32(t); | |
3138 | ||
3139 | gen_exception(EXCP_SVC); | |
3140 | return EXIT_NORETURN; | |
3141 | } | |
3142 | ||
31aa97d1 RH |
3143 | static ExitStatus op_tceb(DisasContext *s, DisasOps *o) |
3144 | { | |
3145 | gen_helper_tceb(cc_op, o->in1, o->in2); | |
3146 | set_cc_static(s); | |
3147 | return NO_EXIT; | |
3148 | } | |
3149 | ||
3150 | static ExitStatus op_tcdb(DisasContext *s, DisasOps *o) | |
3151 | { | |
3152 | gen_helper_tcdb(cc_op, o->in1, o->in2); | |
3153 | set_cc_static(s); | |
3154 | return NO_EXIT; | |
3155 | } | |
3156 | ||
3157 | static ExitStatus op_tcxb(DisasContext *s, DisasOps *o) | |
3158 | { | |
3159 | gen_helper_tcxb(cc_op, o->out, o->out2, o->in2); | |
3160 | set_cc_static(s); | |
3161 | return NO_EXIT; | |
3162 | } | |
3163 | ||
112bf079 RH |
3164 | #ifndef CONFIG_USER_ONLY |
3165 | static ExitStatus op_tprot(DisasContext *s, DisasOps *o) | |
3166 | { | |
3167 | potential_page_fault(s); | |
3168 | gen_helper_tprot(cc_op, o->addr1, o->in2); | |
3169 | set_cc_static(s); | |
3170 | return NO_EXIT; | |
3171 | } | |
3172 | #endif | |
3173 | ||
0a949039 RH |
3174 | static ExitStatus op_tr(DisasContext *s, DisasOps *o) |
3175 | { | |
3176 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
3177 | potential_page_fault(s); | |
3178 | gen_helper_tr(cpu_env, l, o->addr1, o->in2); | |
3179 | tcg_temp_free_i32(l); | |
3180 | set_cc_static(s); | |
3181 | return NO_EXIT; | |
3182 | } | |
3183 | ||
3184 | static ExitStatus op_unpk(DisasContext *s, DisasOps *o) | |
3185 | { | |
3186 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
3187 | potential_page_fault(s); | |
3188 | gen_helper_unpk(cpu_env, l, o->addr1, o->in2); | |
3189 | tcg_temp_free_i32(l); | |
3190 | return NO_EXIT; | |
3191 | } | |
3192 | ||
3193 | static ExitStatus op_xc(DisasContext *s, DisasOps *o) | |
3194 | { | |
3195 | TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1)); | |
3196 | potential_page_fault(s); | |
3197 | gen_helper_xc(cc_op, cpu_env, l, o->addr1, o->in2); | |
3198 | tcg_temp_free_i32(l); | |
3199 | set_cc_static(s); | |
3200 | return NO_EXIT; | |
3201 | } | |
3202 | ||
3bbfbd1f RH |
3203 | static ExitStatus op_xor(DisasContext *s, DisasOps *o) |
3204 | { | |
3205 | tcg_gen_xor_i64(o->out, o->in1, o->in2); | |
3206 | return NO_EXIT; | |
3207 | } | |
3208 | ||
facfc864 RH |
3209 | static ExitStatus op_xori(DisasContext *s, DisasOps *o) |
3210 | { | |
3211 | int shift = s->insn->data & 0xff; | |
3212 | int size = s->insn->data >> 8; | |
3213 | uint64_t mask = ((1ull << size) - 1) << shift; | |
3214 | ||
3215 | assert(!o->g_in2); | |
3216 | tcg_gen_shli_i64(o->in2, o->in2, shift); | |
3217 | tcg_gen_xor_i64(o->out, o->in1, o->in2); | |
3218 | ||
3219 | /* Produce the CC from only the bits manipulated. */ | |
3220 | tcg_gen_andi_i64(cc_dst, o->out, mask); | |
3221 | set_cc_nz_u64(s, cc_dst); | |
3222 | return NO_EXIT; | |
3223 | } | |
3224 | ||
24db8412 RH |
3225 | static ExitStatus op_zero(DisasContext *s, DisasOps *o) |
3226 | { | |
3227 | o->out = tcg_const_i64(0); | |
3228 | return NO_EXIT; | |
3229 | } | |
3230 | ||
3231 | static ExitStatus op_zero2(DisasContext *s, DisasOps *o) | |
3232 | { | |
3233 | o->out = tcg_const_i64(0); | |
3234 | o->out2 = o->out; | |
3235 | o->g_out2 = true; | |
3236 | return NO_EXIT; | |
3237 | } | |
3238 | ||
ad044d09 RH |
3239 | /* ====================================================================== */ |
3240 | /* The "Cc OUTput" generators. Given the generated output (and in some cases | |
3241 | the original inputs), update the various cc data structures in order to | |
3242 | be able to compute the new condition code. */ | |
3243 | ||
b9bca3e5 RH |
3244 | static void cout_abs32(DisasContext *s, DisasOps *o) |
3245 | { | |
3246 | gen_op_update1_cc_i64(s, CC_OP_ABS_32, o->out); | |
3247 | } | |
3248 | ||
3249 | static void cout_abs64(DisasContext *s, DisasOps *o) | |
3250 | { | |
3251 | gen_op_update1_cc_i64(s, CC_OP_ABS_64, o->out); | |
3252 | } | |
3253 | ||
ad044d09 RH |
3254 | static void cout_adds32(DisasContext *s, DisasOps *o) |
3255 | { | |
3256 | gen_op_update3_cc_i64(s, CC_OP_ADD_32, o->in1, o->in2, o->out); | |
3257 | } | |
3258 | ||
3259 | static void cout_adds64(DisasContext *s, DisasOps *o) | |
3260 | { | |
3261 | gen_op_update3_cc_i64(s, CC_OP_ADD_64, o->in1, o->in2, o->out); | |
3262 | } | |
3263 | ||
3264 | static void cout_addu32(DisasContext *s, DisasOps *o) | |
3265 | { | |
3266 | gen_op_update3_cc_i64(s, CC_OP_ADDU_32, o->in1, o->in2, o->out); | |
3267 | } | |
3268 | ||
3269 | static void cout_addu64(DisasContext *s, DisasOps *o) | |
3270 | { | |
3271 | gen_op_update3_cc_i64(s, CC_OP_ADDU_64, o->in1, o->in2, o->out); | |
3272 | } | |
3273 | ||
4e4bb438 RH |
3274 | static void cout_addc32(DisasContext *s, DisasOps *o) |
3275 | { | |
3276 | gen_op_update3_cc_i64(s, CC_OP_ADDC_32, o->in1, o->in2, o->out); | |
3277 | } | |
3278 | ||
3279 | static void cout_addc64(DisasContext *s, DisasOps *o) | |
3280 | { | |
3281 | gen_op_update3_cc_i64(s, CC_OP_ADDC_64, o->in1, o->in2, o->out); | |
3282 | } | |
3283 | ||
a7e836d5 RH |
3284 | static void cout_cmps32(DisasContext *s, DisasOps *o) |
3285 | { | |
3286 | gen_op_update2_cc_i64(s, CC_OP_LTGT_32, o->in1, o->in2); | |
3287 | } | |
3288 | ||
3289 | static void cout_cmps64(DisasContext *s, DisasOps *o) | |
3290 | { | |
3291 | gen_op_update2_cc_i64(s, CC_OP_LTGT_64, o->in1, o->in2); | |
3292 | } | |
3293 | ||
3294 | static void cout_cmpu32(DisasContext *s, DisasOps *o) | |
3295 | { | |
3296 | gen_op_update2_cc_i64(s, CC_OP_LTUGTU_32, o->in1, o->in2); | |
3297 | } | |
3298 | ||
3299 | static void cout_cmpu64(DisasContext *s, DisasOps *o) | |
3300 | { | |
3301 | gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, o->in1, o->in2); | |
3302 | } | |
3303 | ||
587626f8 RH |
3304 | static void cout_f32(DisasContext *s, DisasOps *o) |
3305 | { | |
3306 | gen_op_update1_cc_i64(s, CC_OP_NZ_F32, o->out); | |
3307 | } | |
3308 | ||
3309 | static void cout_f64(DisasContext *s, DisasOps *o) | |
3310 | { | |
3311 | gen_op_update1_cc_i64(s, CC_OP_NZ_F64, o->out); | |
3312 | } | |
3313 | ||
3314 | static void cout_f128(DisasContext *s, DisasOps *o) | |
3315 | { | |
3316 | gen_op_update2_cc_i64(s, CC_OP_NZ_F128, o->out, o->out2); | |
3317 | } | |
3318 | ||
b9bca3e5 RH |
3319 | static void cout_nabs32(DisasContext *s, DisasOps *o) |
3320 | { | |
3321 | gen_op_update1_cc_i64(s, CC_OP_NABS_32, o->out); | |
3322 | } | |
3323 | ||
3324 | static void cout_nabs64(DisasContext *s, DisasOps *o) | |
3325 | { | |
3326 | gen_op_update1_cc_i64(s, CC_OP_NABS_64, o->out); | |
3327 | } | |
3328 | ||
3329 | static void cout_neg32(DisasContext *s, DisasOps *o) | |
3330 | { | |
3331 | gen_op_update1_cc_i64(s, CC_OP_COMP_32, o->out); | |
3332 | } | |
3333 | ||
3334 | static void cout_neg64(DisasContext *s, DisasOps *o) | |
3335 | { | |
3336 | gen_op_update1_cc_i64(s, CC_OP_COMP_64, o->out); | |
3337 | } | |
3338 | ||
3bbfbd1f RH |
3339 | static void cout_nz32(DisasContext *s, DisasOps *o) |
3340 | { | |
3341 | tcg_gen_ext32u_i64(cc_dst, o->out); | |
3342 | gen_op_update1_cc_i64(s, CC_OP_NZ, cc_dst); | |
3343 | } | |
3344 | ||
3345 | static void cout_nz64(DisasContext *s, DisasOps *o) | |
3346 | { | |
3347 | gen_op_update1_cc_i64(s, CC_OP_NZ, o->out); | |
3348 | } | |
3349 | ||
11bf2d73 RH |
3350 | static void cout_s32(DisasContext *s, DisasOps *o) |
3351 | { | |
3352 | gen_op_update1_cc_i64(s, CC_OP_LTGT0_32, o->out); | |
3353 | } | |
3354 | ||
3355 | static void cout_s64(DisasContext *s, DisasOps *o) | |
3356 | { | |
3357 | gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, o->out); | |
3358 | } | |
3359 | ||
ad044d09 RH |
3360 | static void cout_subs32(DisasContext *s, DisasOps *o) |
3361 | { | |
3362 | gen_op_update3_cc_i64(s, CC_OP_SUB_32, o->in1, o->in2, o->out); | |
3363 | } | |
3364 | ||
3365 | static void cout_subs64(DisasContext *s, DisasOps *o) | |
3366 | { | |
3367 | gen_op_update3_cc_i64(s, CC_OP_SUB_64, o->in1, o->in2, o->out); | |
3368 | } | |
3369 | ||
3370 | static void cout_subu32(DisasContext *s, DisasOps *o) | |
3371 | { | |
3372 | gen_op_update3_cc_i64(s, CC_OP_SUBU_32, o->in1, o->in2, o->out); | |
3373 | } | |
3374 | ||
3375 | static void cout_subu64(DisasContext *s, DisasOps *o) | |
3376 | { | |
3377 | gen_op_update3_cc_i64(s, CC_OP_SUBU_64, o->in1, o->in2, o->out); | |
3378 | } | |
3379 | ||
4e4bb438 RH |
3380 | static void cout_subb32(DisasContext *s, DisasOps *o) |
3381 | { | |
3382 | gen_op_update3_cc_i64(s, CC_OP_SUBB_32, o->in1, o->in2, o->out); | |
3383 | } | |
3384 | ||
3385 | static void cout_subb64(DisasContext *s, DisasOps *o) | |
3386 | { | |
3387 | gen_op_update3_cc_i64(s, CC_OP_SUBB_64, o->in1, o->in2, o->out); | |
3388 | } | |
3389 | ||
00d2dc19 RH |
3390 | static void cout_tm32(DisasContext *s, DisasOps *o) |
3391 | { | |
3392 | gen_op_update2_cc_i64(s, CC_OP_TM_32, o->in1, o->in2); | |
3393 | } | |
3394 | ||
3395 | static void cout_tm64(DisasContext *s, DisasOps *o) | |
3396 | { | |
3397 | gen_op_update2_cc_i64(s, CC_OP_TM_64, o->in1, o->in2); | |
3398 | } | |
3399 | ||
ad044d09 RH |
3400 | /* ====================================================================== */ |
3401 | /* The "PREPeration" generators. These initialize the DisasOps.OUT fields | |
3402 | with the TCG register to which we will write. Used in combination with | |
3403 | the "wout" generators, in some cases we need a new temporary, and in | |
3404 | some cases we can write to a TCG global. */ | |
3405 | ||
3406 | static void prep_new(DisasContext *s, DisasFields *f, DisasOps *o) | |
3407 | { | |
3408 | o->out = tcg_temp_new_i64(); | |
3409 | } | |
3410 | ||
891452e5 RH |
3411 | static void prep_new_P(DisasContext *s, DisasFields *f, DisasOps *o) |
3412 | { | |
3413 | o->out = tcg_temp_new_i64(); | |
3414 | o->out2 = tcg_temp_new_i64(); | |
3415 | } | |
3416 | ||
ad044d09 RH |
3417 | static void prep_r1(DisasContext *s, DisasFields *f, DisasOps *o) |
3418 | { | |
3419 | o->out = regs[get_field(f, r1)]; | |
3420 | o->g_out = true; | |
3421 | } | |
3422 | ||
1ac5889f RH |
3423 | static void prep_r1_P(DisasContext *s, DisasFields *f, DisasOps *o) |
3424 | { | |
3425 | /* ??? Specification exception: r1 must be even. */ | |
3426 | int r1 = get_field(f, r1); | |
3427 | o->out = regs[r1]; | |
3428 | o->out2 = regs[(r1 + 1) & 15]; | |
3429 | o->g_out = o->g_out2 = true; | |
3430 | } | |
3431 | ||
587626f8 RH |
3432 | static void prep_f1(DisasContext *s, DisasFields *f, DisasOps *o) |
3433 | { | |
3434 | o->out = fregs[get_field(f, r1)]; | |
3435 | o->g_out = true; | |
3436 | } | |
3437 | ||
3438 | static void prep_x1(DisasContext *s, DisasFields *f, DisasOps *o) | |
3439 | { | |
3440 | /* ??? Specification exception: r1 must be < 14. */ | |
3441 | int r1 = get_field(f, r1); | |
3442 | o->out = fregs[r1]; | |
3443 | o->out2 = fregs[(r1 + 2) & 15]; | |
3444 | o->g_out = o->g_out2 = true; | |
3445 | } | |
3446 | ||
ad044d09 RH |
3447 | /* ====================================================================== */ |
3448 | /* The "Write OUTput" generators. These generally perform some non-trivial | |
3449 | copy of data to TCG globals, or to main memory. The trivial cases are | |
3450 | generally handled by having a "prep" generator install the TCG global | |
3451 | as the destination of the operation. */ | |
3452 | ||
22c37a08 RH |
3453 | static void wout_r1(DisasContext *s, DisasFields *f, DisasOps *o) |
3454 | { | |
3455 | store_reg(get_field(f, r1), o->out); | |
3456 | } | |
3457 | ||
afdc70be RH |
3458 | static void wout_r1_8(DisasContext *s, DisasFields *f, DisasOps *o) |
3459 | { | |
3460 | int r1 = get_field(f, r1); | |
3461 | tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 8); | |
3462 | } | |
3463 | ||
d54f5865 RH |
3464 | static void wout_r1_16(DisasContext *s, DisasFields *f, DisasOps *o) |
3465 | { | |
3466 | int r1 = get_field(f, r1); | |
3467 | tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 16); | |
3468 | } | |
3469 | ||
ad044d09 RH |
3470 | static void wout_r1_32(DisasContext *s, DisasFields *f, DisasOps *o) |
3471 | { | |
3472 | store_reg32_i64(get_field(f, r1), o->out); | |
3473 | } | |
3474 | ||
891452e5 RH |
3475 | static void wout_r1_P32(DisasContext *s, DisasFields *f, DisasOps *o) |
3476 | { | |
3477 | /* ??? Specification exception: r1 must be even. */ | |
3478 | int r1 = get_field(f, r1); | |
3479 | store_reg32_i64(r1, o->out); | |
3480 | store_reg32_i64((r1 + 1) & 15, o->out2); | |
3481 | } | |
3482 | ||
d87aaf93 RH |
3483 | static void wout_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o) |
3484 | { | |
3485 | /* ??? Specification exception: r1 must be even. */ | |
3486 | int r1 = get_field(f, r1); | |
3487 | store_reg32_i64((r1 + 1) & 15, o->out); | |
3488 | tcg_gen_shri_i64(o->out, o->out, 32); | |
3489 | store_reg32_i64(r1, o->out); | |
3490 | } | |
22c37a08 | 3491 | |
d764a8d1 RH |
3492 | static void wout_e1(DisasContext *s, DisasFields *f, DisasOps *o) |
3493 | { | |
3494 | store_freg32_i64(get_field(f, r1), o->out); | |
3495 | } | |
3496 | ||
3497 | static void wout_f1(DisasContext *s, DisasFields *f, DisasOps *o) | |
3498 | { | |
3499 | store_freg(get_field(f, r1), o->out); | |
3500 | } | |
3501 | ||
3502 | static void wout_x1(DisasContext *s, DisasFields *f, DisasOps *o) | |
3503 | { | |
587626f8 | 3504 | /* ??? Specification exception: r1 must be < 14. */ |
d764a8d1 RH |
3505 | int f1 = get_field(s->fields, r1); |
3506 | store_freg(f1, o->out); | |
3507 | store_freg((f1 + 2) & 15, o->out2); | |
3508 | } | |
3509 | ||
22c37a08 RH |
3510 | static void wout_cond_r1r2_32(DisasContext *s, DisasFields *f, DisasOps *o) |
3511 | { | |
3512 | if (get_field(f, r1) != get_field(f, r2)) { | |
3513 | store_reg32_i64(get_field(f, r1), o->out); | |
3514 | } | |
3515 | } | |
d87aaf93 | 3516 | |
d764a8d1 RH |
3517 | static void wout_cond_e1e2(DisasContext *s, DisasFields *f, DisasOps *o) |
3518 | { | |
3519 | if (get_field(f, r1) != get_field(f, r2)) { | |
3520 | store_freg32_i64(get_field(f, r1), o->out); | |
3521 | } | |
3522 | } | |
3523 | ||
6a04d76a RH |
3524 | static void wout_m1_8(DisasContext *s, DisasFields *f, DisasOps *o) |
3525 | { | |
3526 | tcg_gen_qemu_st8(o->out, o->addr1, get_mem_index(s)); | |
3527 | } | |
3528 | ||
3529 | static void wout_m1_16(DisasContext *s, DisasFields *f, DisasOps *o) | |
3530 | { | |
3531 | tcg_gen_qemu_st16(o->out, o->addr1, get_mem_index(s)); | |
3532 | } | |
3533 | ||
ad044d09 RH |
3534 | static void wout_m1_32(DisasContext *s, DisasFields *f, DisasOps *o) |
3535 | { | |
3536 | tcg_gen_qemu_st32(o->out, o->addr1, get_mem_index(s)); | |
3537 | } | |
3538 | ||
3539 | static void wout_m1_64(DisasContext *s, DisasFields *f, DisasOps *o) | |
3540 | { | |
3541 | tcg_gen_qemu_st64(o->out, o->addr1, get_mem_index(s)); | |
3542 | } | |
3543 | ||
ea20490f RH |
3544 | static void wout_m2_32(DisasContext *s, DisasFields *f, DisasOps *o) |
3545 | { | |
3546 | tcg_gen_qemu_st32(o->out, o->in2, get_mem_index(s)); | |
3547 | } | |
3548 | ||
ad044d09 RH |
3549 | /* ====================================================================== */ |
3550 | /* The "INput 1" generators. These load the first operand to an insn. */ | |
3551 | ||
3552 | static void in1_r1(DisasContext *s, DisasFields *f, DisasOps *o) | |
3553 | { | |
3554 | o->in1 = load_reg(get_field(f, r1)); | |
3555 | } | |
3556 | ||
d1c04a2b RH |
3557 | static void in1_r1_o(DisasContext *s, DisasFields *f, DisasOps *o) |
3558 | { | |
3559 | o->in1 = regs[get_field(f, r1)]; | |
3560 | o->g_in1 = true; | |
3561 | } | |
3562 | ||
cbe24bfa RH |
3563 | static void in1_r1_32s(DisasContext *s, DisasFields *f, DisasOps *o) |
3564 | { | |
3565 | o->in1 = tcg_temp_new_i64(); | |
3566 | tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1)]); | |
3567 | } | |
3568 | ||
3569 | static void in1_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3570 | { | |
3571 | o->in1 = tcg_temp_new_i64(); | |
3572 | tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1)]); | |
3573 | } | |
3574 | ||
32a44d58 RH |
3575 | static void in1_r1_sr32(DisasContext *s, DisasFields *f, DisasOps *o) |
3576 | { | |
3577 | o->in1 = tcg_temp_new_i64(); | |
3578 | tcg_gen_shri_i64(o->in1, regs[get_field(f, r1)], 32); | |
3579 | } | |
3580 | ||
1ac5889f RH |
3581 | static void in1_r1p1(DisasContext *s, DisasFields *f, DisasOps *o) |
3582 | { | |
3583 | /* ??? Specification exception: r1 must be even. */ | |
3584 | int r1 = get_field(f, r1); | |
3585 | o->in1 = load_reg((r1 + 1) & 15); | |
3586 | } | |
3587 | ||
d87aaf93 RH |
3588 | static void in1_r1p1_32s(DisasContext *s, DisasFields *f, DisasOps *o) |
3589 | { | |
3590 | /* ??? Specification exception: r1 must be even. */ | |
3591 | int r1 = get_field(f, r1); | |
3592 | o->in1 = tcg_temp_new_i64(); | |
3593 | tcg_gen_ext32s_i64(o->in1, regs[(r1 + 1) & 15]); | |
3594 | } | |
3595 | ||
3596 | static void in1_r1p1_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3597 | { | |
3598 | /* ??? Specification exception: r1 must be even. */ | |
3599 | int r1 = get_field(f, r1); | |
3600 | o->in1 = tcg_temp_new_i64(); | |
3601 | tcg_gen_ext32u_i64(o->in1, regs[(r1 + 1) & 15]); | |
3602 | } | |
3603 | ||
891452e5 RH |
3604 | static void in1_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o) |
3605 | { | |
3606 | /* ??? Specification exception: r1 must be even. */ | |
3607 | int r1 = get_field(f, r1); | |
3608 | o->in1 = tcg_temp_new_i64(); | |
3609 | tcg_gen_concat32_i64(o->in1, regs[r1 + 1], regs[r1]); | |
3610 | } | |
3611 | ||
ad044d09 RH |
3612 | static void in1_r2(DisasContext *s, DisasFields *f, DisasOps *o) |
3613 | { | |
3614 | o->in1 = load_reg(get_field(f, r2)); | |
3615 | } | |
3616 | ||
3617 | static void in1_r3(DisasContext *s, DisasFields *f, DisasOps *o) | |
3618 | { | |
3619 | o->in1 = load_reg(get_field(f, r3)); | |
3620 | } | |
3621 | ||
cbe24bfa RH |
3622 | static void in1_r3_o(DisasContext *s, DisasFields *f, DisasOps *o) |
3623 | { | |
3624 | o->in1 = regs[get_field(f, r3)]; | |
3625 | o->g_in1 = true; | |
3626 | } | |
3627 | ||
3628 | static void in1_r3_32s(DisasContext *s, DisasFields *f, DisasOps *o) | |
3629 | { | |
3630 | o->in1 = tcg_temp_new_i64(); | |
3631 | tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r3)]); | |
3632 | } | |
3633 | ||
3634 | static void in1_r3_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3635 | { | |
3636 | o->in1 = tcg_temp_new_i64(); | |
3637 | tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r3)]); | |
3638 | } | |
3639 | ||
00574261 RH |
3640 | static void in1_e1(DisasContext *s, DisasFields *f, DisasOps *o) |
3641 | { | |
3642 | o->in1 = load_freg32_i64(get_field(f, r1)); | |
3643 | } | |
3644 | ||
3645 | static void in1_f1_o(DisasContext *s, DisasFields *f, DisasOps *o) | |
3646 | { | |
3647 | o->in1 = fregs[get_field(f, r1)]; | |
3648 | o->g_in1 = true; | |
3649 | } | |
3650 | ||
587626f8 RH |
3651 | static void in1_x1_o(DisasContext *s, DisasFields *f, DisasOps *o) |
3652 | { | |
3653 | /* ??? Specification exception: r1 must be < 14. */ | |
3654 | int r1 = get_field(f, r1); | |
3655 | o->out = fregs[r1]; | |
3656 | o->out2 = fregs[(r1 + 2) & 15]; | |
3657 | o->g_out = o->g_out2 = true; | |
3658 | } | |
3659 | ||
ad044d09 RH |
3660 | static void in1_la1(DisasContext *s, DisasFields *f, DisasOps *o) |
3661 | { | |
3662 | o->addr1 = get_address(s, 0, get_field(f, b1), get_field(f, d1)); | |
3663 | } | |
3664 | ||
e025e52a RH |
3665 | static void in1_la2(DisasContext *s, DisasFields *f, DisasOps *o) |
3666 | { | |
3667 | int x2 = have_field(f, x2) ? get_field(f, x2) : 0; | |
3668 | o->addr1 = get_address(s, x2, get_field(f, b2), get_field(f, d2)); | |
3669 | } | |
3670 | ||
a7e836d5 RH |
3671 | static void in1_m1_8u(DisasContext *s, DisasFields *f, DisasOps *o) |
3672 | { | |
3673 | in1_la1(s, f, o); | |
3674 | o->in1 = tcg_temp_new_i64(); | |
3675 | tcg_gen_qemu_ld8u(o->in1, o->addr1, get_mem_index(s)); | |
3676 | } | |
3677 | ||
3678 | static void in1_m1_16s(DisasContext *s, DisasFields *f, DisasOps *o) | |
3679 | { | |
3680 | in1_la1(s, f, o); | |
3681 | o->in1 = tcg_temp_new_i64(); | |
3682 | tcg_gen_qemu_ld16s(o->in1, o->addr1, get_mem_index(s)); | |
3683 | } | |
3684 | ||
3685 | static void in1_m1_16u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3686 | { | |
3687 | in1_la1(s, f, o); | |
3688 | o->in1 = tcg_temp_new_i64(); | |
3689 | tcg_gen_qemu_ld16u(o->in1, o->addr1, get_mem_index(s)); | |
3690 | } | |
3691 | ||
ad044d09 RH |
3692 | static void in1_m1_32s(DisasContext *s, DisasFields *f, DisasOps *o) |
3693 | { | |
3694 | in1_la1(s, f, o); | |
3695 | o->in1 = tcg_temp_new_i64(); | |
3696 | tcg_gen_qemu_ld32s(o->in1, o->addr1, get_mem_index(s)); | |
3697 | } | |
3698 | ||
e272b3ac RH |
3699 | static void in1_m1_32u(DisasContext *s, DisasFields *f, DisasOps *o) |
3700 | { | |
3701 | in1_la1(s, f, o); | |
3702 | o->in1 = tcg_temp_new_i64(); | |
3703 | tcg_gen_qemu_ld32u(o->in1, o->addr1, get_mem_index(s)); | |
3704 | } | |
3705 | ||
ad044d09 RH |
3706 | static void in1_m1_64(DisasContext *s, DisasFields *f, DisasOps *o) |
3707 | { | |
3708 | in1_la1(s, f, o); | |
3709 | o->in1 = tcg_temp_new_i64(); | |
3710 | tcg_gen_qemu_ld64(o->in1, o->addr1, get_mem_index(s)); | |
3711 | } | |
3712 | ||
3713 | /* ====================================================================== */ | |
3714 | /* The "INput 2" generators. These load the second operand to an insn. */ | |
3715 | ||
e025e52a RH |
3716 | static void in2_r1_o(DisasContext *s, DisasFields *f, DisasOps *o) |
3717 | { | |
3718 | o->in2 = regs[get_field(f, r1)]; | |
3719 | o->g_in2 = true; | |
3720 | } | |
3721 | ||
3722 | static void in2_r1_16u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3723 | { | |
3724 | o->in2 = tcg_temp_new_i64(); | |
3725 | tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r1)]); | |
3726 | } | |
3727 | ||
3728 | static void in2_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3729 | { | |
3730 | o->in2 = tcg_temp_new_i64(); | |
3731 | tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r1)]); | |
3732 | } | |
3733 | ||
ad044d09 RH |
3734 | static void in2_r2(DisasContext *s, DisasFields *f, DisasOps *o) |
3735 | { | |
3736 | o->in2 = load_reg(get_field(f, r2)); | |
3737 | } | |
3738 | ||
d1c04a2b RH |
3739 | static void in2_r2_o(DisasContext *s, DisasFields *f, DisasOps *o) |
3740 | { | |
3741 | o->in2 = regs[get_field(f, r2)]; | |
3742 | o->g_in2 = true; | |
3743 | } | |
3744 | ||
8ac33cdb RH |
3745 | static void in2_r2_nz(DisasContext *s, DisasFields *f, DisasOps *o) |
3746 | { | |
3747 | int r2 = get_field(f, r2); | |
3748 | if (r2 != 0) { | |
3749 | o->in2 = load_reg(r2); | |
3750 | } | |
3751 | } | |
3752 | ||
c698d876 RH |
3753 | static void in2_r2_8s(DisasContext *s, DisasFields *f, DisasOps *o) |
3754 | { | |
3755 | o->in2 = tcg_temp_new_i64(); | |
3756 | tcg_gen_ext8s_i64(o->in2, regs[get_field(f, r2)]); | |
3757 | } | |
3758 | ||
3759 | static void in2_r2_8u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3760 | { | |
3761 | o->in2 = tcg_temp_new_i64(); | |
3762 | tcg_gen_ext8u_i64(o->in2, regs[get_field(f, r2)]); | |
3763 | } | |
3764 | ||
3765 | static void in2_r2_16s(DisasContext *s, DisasFields *f, DisasOps *o) | |
3766 | { | |
3767 | o->in2 = tcg_temp_new_i64(); | |
3768 | tcg_gen_ext16s_i64(o->in2, regs[get_field(f, r2)]); | |
3769 | } | |
3770 | ||
3771 | static void in2_r2_16u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3772 | { | |
3773 | o->in2 = tcg_temp_new_i64(); | |
3774 | tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r2)]); | |
3775 | } | |
3776 | ||
ad044d09 RH |
3777 | static void in2_r3(DisasContext *s, DisasFields *f, DisasOps *o) |
3778 | { | |
3779 | o->in2 = load_reg(get_field(f, r3)); | |
3780 | } | |
3781 | ||
3782 | static void in2_r2_32s(DisasContext *s, DisasFields *f, DisasOps *o) | |
3783 | { | |
3784 | o->in2 = tcg_temp_new_i64(); | |
3785 | tcg_gen_ext32s_i64(o->in2, regs[get_field(f, r2)]); | |
3786 | } | |
3787 | ||
3788 | static void in2_r2_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3789 | { | |
3790 | o->in2 = tcg_temp_new_i64(); | |
3791 | tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r2)]); | |
3792 | } | |
3793 | ||
d764a8d1 RH |
3794 | static void in2_e2(DisasContext *s, DisasFields *f, DisasOps *o) |
3795 | { | |
3796 | o->in2 = load_freg32_i64(get_field(f, r2)); | |
3797 | } | |
3798 | ||
3799 | static void in2_f2_o(DisasContext *s, DisasFields *f, DisasOps *o) | |
3800 | { | |
3801 | o->in2 = fregs[get_field(f, r2)]; | |
3802 | o->g_in2 = true; | |
3803 | } | |
3804 | ||
3805 | static void in2_x2_o(DisasContext *s, DisasFields *f, DisasOps *o) | |
3806 | { | |
587626f8 RH |
3807 | /* ??? Specification exception: r1 must be < 14. */ |
3808 | int r2 = get_field(f, r2); | |
3809 | o->in1 = fregs[r2]; | |
3810 | o->in2 = fregs[(r2 + 2) & 15]; | |
d764a8d1 RH |
3811 | o->g_in1 = o->g_in2 = true; |
3812 | } | |
3813 | ||
374724f9 RH |
3814 | static void in2_ra2(DisasContext *s, DisasFields *f, DisasOps *o) |
3815 | { | |
3816 | o->in2 = get_address(s, 0, get_field(f, r2), 0); | |
3817 | } | |
3818 | ||
ad044d09 RH |
3819 | static void in2_a2(DisasContext *s, DisasFields *f, DisasOps *o) |
3820 | { | |
3821 | int x2 = have_field(f, x2) ? get_field(f, x2) : 0; | |
3822 | o->in2 = get_address(s, x2, get_field(f, b2), get_field(f, d2)); | |
3823 | } | |
3824 | ||
a7e836d5 RH |
3825 | static void in2_ri2(DisasContext *s, DisasFields *f, DisasOps *o) |
3826 | { | |
3827 | o->in2 = tcg_const_i64(s->pc + (int64_t)get_field(f, i2) * 2); | |
3828 | } | |
3829 | ||
cbe24bfa RH |
3830 | static void in2_sh32(DisasContext *s, DisasFields *f, DisasOps *o) |
3831 | { | |
3832 | help_l2_shift(s, f, o, 31); | |
3833 | } | |
3834 | ||
3835 | static void in2_sh64(DisasContext *s, DisasFields *f, DisasOps *o) | |
3836 | { | |
3837 | help_l2_shift(s, f, o, 63); | |
3838 | } | |
3839 | ||
afdc70be RH |
3840 | static void in2_m2_8u(DisasContext *s, DisasFields *f, DisasOps *o) |
3841 | { | |
3842 | in2_a2(s, f, o); | |
3843 | tcg_gen_qemu_ld8u(o->in2, o->in2, get_mem_index(s)); | |
3844 | } | |
3845 | ||
d82287de RH |
3846 | static void in2_m2_16s(DisasContext *s, DisasFields *f, DisasOps *o) |
3847 | { | |
3848 | in2_a2(s, f, o); | |
3849 | tcg_gen_qemu_ld16s(o->in2, o->in2, get_mem_index(s)); | |
3850 | } | |
3851 | ||
d54f5865 RH |
3852 | static void in2_m2_16u(DisasContext *s, DisasFields *f, DisasOps *o) |
3853 | { | |
3854 | in2_a2(s, f, o); | |
3855 | tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s)); | |
3856 | } | |
3857 | ||
ad044d09 RH |
3858 | static void in2_m2_32s(DisasContext *s, DisasFields *f, DisasOps *o) |
3859 | { | |
3860 | in2_a2(s, f, o); | |
3861 | tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s)); | |
3862 | } | |
3863 | ||
3864 | static void in2_m2_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3865 | { | |
3866 | in2_a2(s, f, o); | |
3867 | tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s)); | |
3868 | } | |
3869 | ||
3870 | static void in2_m2_64(DisasContext *s, DisasFields *f, DisasOps *o) | |
3871 | { | |
3872 | in2_a2(s, f, o); | |
3873 | tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s)); | |
3874 | } | |
3875 | ||
a7e836d5 RH |
3876 | static void in2_mri2_16u(DisasContext *s, DisasFields *f, DisasOps *o) |
3877 | { | |
3878 | in2_ri2(s, f, o); | |
3879 | tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s)); | |
3880 | } | |
3881 | ||
3882 | static void in2_mri2_32s(DisasContext *s, DisasFields *f, DisasOps *o) | |
3883 | { | |
3884 | in2_ri2(s, f, o); | |
3885 | tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s)); | |
3886 | } | |
3887 | ||
3888 | static void in2_mri2_32u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3889 | { | |
3890 | in2_ri2(s, f, o); | |
3891 | tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s)); | |
3892 | } | |
3893 | ||
3894 | static void in2_mri2_64(DisasContext *s, DisasFields *f, DisasOps *o) | |
3895 | { | |
3896 | in2_ri2(s, f, o); | |
3897 | tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s)); | |
3898 | } | |
3899 | ||
ad044d09 RH |
3900 | static void in2_i2(DisasContext *s, DisasFields *f, DisasOps *o) |
3901 | { | |
3902 | o->in2 = tcg_const_i64(get_field(f, i2)); | |
3903 | } | |
3904 | ||
a7e836d5 RH |
3905 | static void in2_i2_8u(DisasContext *s, DisasFields *f, DisasOps *o) |
3906 | { | |
3907 | o->in2 = tcg_const_i64((uint8_t)get_field(f, i2)); | |
3908 | } | |
3909 | ||
3910 | static void in2_i2_16u(DisasContext *s, DisasFields *f, DisasOps *o) | |
3911 | { | |
3912 | o->in2 = tcg_const_i64((uint16_t)get_field(f, i2)); | |
3913 | } | |
3914 | ||
ad044d09 RH |
3915 | static void in2_i2_32u(DisasContext *s, DisasFields *f, DisasOps *o) |
3916 | { | |
3917 | o->in2 = tcg_const_i64((uint32_t)get_field(f, i2)); | |
3918 | } | |
3919 | ||
ade9dea4 RH |
3920 | static void in2_i2_16u_shl(DisasContext *s, DisasFields *f, DisasOps *o) |
3921 | { | |
3922 | uint64_t i2 = (uint16_t)get_field(f, i2); | |
3923 | o->in2 = tcg_const_i64(i2 << s->insn->data); | |
3924 | } | |
3925 | ||
3926 | static void in2_i2_32u_shl(DisasContext *s, DisasFields *f, DisasOps *o) | |
3927 | { | |
3928 | uint64_t i2 = (uint32_t)get_field(f, i2); | |
3929 | o->in2 = tcg_const_i64(i2 << s->insn->data); | |
3930 | } | |
3931 | ||
ad044d09 RH |
3932 | /* ====================================================================== */ |
3933 | ||
3934 | /* Find opc within the table of insns. This is formulated as a switch | |
3935 | statement so that (1) we get compile-time notice of cut-paste errors | |
3936 | for duplicated opcodes, and (2) the compiler generates the binary | |
3937 | search tree, rather than us having to post-process the table. */ | |
3938 | ||
3939 | #define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \ | |
3940 | D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0) | |
3941 | ||
3942 | #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM, | |
3943 | ||
3944 | enum DisasInsnEnum { | |
3945 | #include "insn-data.def" | |
3946 | }; | |
3947 | ||
3948 | #undef D | |
3949 | #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) { \ | |
3950 | .opc = OPC, \ | |
3951 | .fmt = FMT_##FT, \ | |
3952 | .fac = FAC_##FC, \ | |
3953 | .name = #NM, \ | |
3954 | .help_in1 = in1_##I1, \ | |
3955 | .help_in2 = in2_##I2, \ | |
3956 | .help_prep = prep_##P, \ | |
3957 | .help_wout = wout_##W, \ | |
3958 | .help_cout = cout_##CC, \ | |
3959 | .help_op = op_##OP, \ | |
3960 | .data = D \ | |
3961 | }, | |
3962 | ||
3963 | /* Allow 0 to be used for NULL in the table below. */ | |
3964 | #define in1_0 NULL | |
3965 | #define in2_0 NULL | |
3966 | #define prep_0 NULL | |
3967 | #define wout_0 NULL | |
3968 | #define cout_0 NULL | |
3969 | #define op_0 NULL | |
3970 | ||
3971 | static const DisasInsn insn_info[] = { | |
3972 | #include "insn-data.def" | |
3973 | }; | |
3974 | ||
3975 | #undef D | |
3976 | #define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \ | |
3977 | case OPC: return &insn_info[insn_ ## NM]; | |
3978 | ||
3979 | static const DisasInsn *lookup_opc(uint16_t opc) | |
3980 | { | |
3981 | switch (opc) { | |
3982 | #include "insn-data.def" | |
3983 | default: | |
3984 | return NULL; | |
3985 | } | |
3986 | } | |
3987 | ||
3988 | #undef D | |
3989 | #undef C | |
3990 | ||
3991 | /* Extract a field from the insn. The INSN should be left-aligned in | |
3992 | the uint64_t so that we can more easily utilize the big-bit-endian | |
3993 | definitions we extract from the Principals of Operation. */ | |
3994 | ||
3995 | static void extract_field(DisasFields *o, const DisasField *f, uint64_t insn) | |
3996 | { | |
3997 | uint32_t r, m; | |
3998 | ||
3999 | if (f->size == 0) { | |
4000 | return; | |
4001 | } | |
4002 | ||
4003 | /* Zero extract the field from the insn. */ | |
4004 | r = (insn << f->beg) >> (64 - f->size); | |
4005 | ||
4006 | /* Sign-extend, or un-swap the field as necessary. */ | |
4007 | switch (f->type) { | |
4008 | case 0: /* unsigned */ | |
4009 | break; | |
4010 | case 1: /* signed */ | |
4011 | assert(f->size <= 32); | |
4012 | m = 1u << (f->size - 1); | |
4013 | r = (r ^ m) - m; | |
4014 | break; | |
4015 | case 2: /* dl+dh split, signed 20 bit. */ | |
4016 | r = ((int8_t)r << 12) | (r >> 8); | |
4017 | break; | |
4018 | default: | |
4019 | abort(); | |
4020 | } | |
4021 | ||
4022 | /* Validate that the "compressed" encoding we selected above is valid. | |
4023 | I.e. we havn't make two different original fields overlap. */ | |
4024 | assert(((o->presentC >> f->indexC) & 1) == 0); | |
4025 | o->presentC |= 1 << f->indexC; | |
4026 | o->presentO |= 1 << f->indexO; | |
4027 | ||
4028 | o->c[f->indexC] = r; | |
4029 | } | |
4030 | ||
4031 | /* Lookup the insn at the current PC, extracting the operands into O and | |
4032 | returning the info struct for the insn. Returns NULL for invalid insn. */ | |
4033 | ||
4034 | static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s, | |
4035 | DisasFields *f) | |
4036 | { | |
4037 | uint64_t insn, pc = s->pc; | |
d5a103cd | 4038 | int op, op2, ilen; |
ad044d09 RH |
4039 | const DisasInsn *info; |
4040 | ||
4041 | insn = ld_code2(env, pc); | |
4042 | op = (insn >> 8) & 0xff; | |
d5a103cd RH |
4043 | ilen = get_ilen(op); |
4044 | s->next_pc = s->pc + ilen; | |
4045 | ||
4046 | switch (ilen) { | |
4047 | case 2: | |
ad044d09 RH |
4048 | insn = insn << 48; |
4049 | break; | |
d5a103cd | 4050 | case 4: |
ad044d09 RH |
4051 | insn = ld_code4(env, pc) << 32; |
4052 | break; | |
d5a103cd | 4053 | case 6: |
ad044d09 RH |
4054 | insn = (insn << 48) | (ld_code4(env, pc + 2) << 16); |
4055 | break; | |
4056 | default: | |
4057 | abort(); | |
4058 | } | |
4059 | ||
4060 | /* We can't actually determine the insn format until we've looked up | |
4061 | the full insn opcode. Which we can't do without locating the | |
4062 | secondary opcode. Assume by default that OP2 is at bit 40; for | |
4063 | those smaller insns that don't actually have a secondary opcode | |
4064 | this will correctly result in OP2 = 0. */ | |
4065 | switch (op) { | |
4066 | case 0x01: /* E */ | |
4067 | case 0x80: /* S */ | |
4068 | case 0x82: /* S */ | |
4069 | case 0x93: /* S */ | |
4070 | case 0xb2: /* S, RRF, RRE */ | |
4071 | case 0xb3: /* RRE, RRD, RRF */ | |
4072 | case 0xb9: /* RRE, RRF */ | |
4073 | case 0xe5: /* SSE, SIL */ | |
4074 | op2 = (insn << 8) >> 56; | |
4075 | break; | |
4076 | case 0xa5: /* RI */ | |
4077 | case 0xa7: /* RI */ | |
4078 | case 0xc0: /* RIL */ | |
4079 | case 0xc2: /* RIL */ | |
4080 | case 0xc4: /* RIL */ | |
4081 | case 0xc6: /* RIL */ | |
4082 | case 0xc8: /* SSF */ | |
4083 | case 0xcc: /* RIL */ | |
4084 | op2 = (insn << 12) >> 60; | |
4085 | break; | |
4086 | case 0xd0 ... 0xdf: /* SS */ | |
4087 | case 0xe1: /* SS */ | |
4088 | case 0xe2: /* SS */ | |
4089 | case 0xe8: /* SS */ | |
4090 | case 0xe9: /* SS */ | |
4091 | case 0xea: /* SS */ | |
4092 | case 0xee ... 0xf3: /* SS */ | |
4093 | case 0xf8 ... 0xfd: /* SS */ | |
4094 | op2 = 0; | |
4095 | break; | |
4096 | default: | |
4097 | op2 = (insn << 40) >> 56; | |
4098 | break; | |
4099 | } | |
4100 | ||
4101 | memset(f, 0, sizeof(*f)); | |
4102 | f->op = op; | |
4103 | f->op2 = op2; | |
4104 | ||
4105 | /* Lookup the instruction. */ | |
4106 | info = lookup_opc(op << 8 | op2); | |
4107 | ||
4108 | /* If we found it, extract the operands. */ | |
4109 | if (info != NULL) { | |
4110 | DisasFormat fmt = info->fmt; | |
4111 | int i; | |
4112 | ||
4113 | for (i = 0; i < NUM_C_FIELD; ++i) { | |
4114 | extract_field(f, &format_info[fmt].op[i], insn); | |
4115 | } | |
4116 | } | |
4117 | return info; | |
4118 | } | |
4119 | ||
4120 | static ExitStatus translate_one(CPUS390XState *env, DisasContext *s) | |
4121 | { | |
4122 | const DisasInsn *insn; | |
4123 | ExitStatus ret = NO_EXIT; | |
4124 | DisasFields f; | |
4125 | DisasOps o; | |
4126 | ||
4127 | insn = extract_insn(env, s, &f); | |
e023e832 | 4128 | |
ad044d09 RH |
4129 | /* If not found, try the old interpreter. This includes ILLOPC. */ |
4130 | if (insn == NULL) { | |
4131 | disas_s390_insn(env, s); | |
4132 | switch (s->is_jmp) { | |
4133 | case DISAS_NEXT: | |
4134 | ret = NO_EXIT; | |
4135 | break; | |
4136 | case DISAS_TB_JUMP: | |
4137 | ret = EXIT_GOTO_TB; | |
4138 | break; | |
4139 | case DISAS_JUMP: | |
4140 | ret = EXIT_PC_UPDATED; | |
4141 | break; | |
4142 | case DISAS_EXCP: | |
4143 | ret = EXIT_NORETURN; | |
4144 | break; | |
4145 | default: | |
4146 | abort(); | |
4147 | } | |
4148 | ||
4149 | s->pc = s->next_pc; | |
4150 | return ret; | |
4151 | } | |
4152 | ||
4153 | /* Set up the strutures we use to communicate with the helpers. */ | |
4154 | s->insn = insn; | |
4155 | s->fields = &f; | |
4156 | o.g_out = o.g_out2 = o.g_in1 = o.g_in2 = false; | |
4157 | TCGV_UNUSED_I64(o.out); | |
4158 | TCGV_UNUSED_I64(o.out2); | |
4159 | TCGV_UNUSED_I64(o.in1); | |
4160 | TCGV_UNUSED_I64(o.in2); | |
4161 | TCGV_UNUSED_I64(o.addr1); | |
4162 | ||
4163 | /* Implement the instruction. */ | |
4164 | if (insn->help_in1) { | |
4165 | insn->help_in1(s, &f, &o); | |
4166 | } | |
4167 | if (insn->help_in2) { | |
4168 | insn->help_in2(s, &f, &o); | |
4169 | } | |
4170 | if (insn->help_prep) { | |
4171 | insn->help_prep(s, &f, &o); | |
4172 | } | |
4173 | if (insn->help_op) { | |
4174 | ret = insn->help_op(s, &o); | |
4175 | } | |
4176 | if (insn->help_wout) { | |
4177 | insn->help_wout(s, &f, &o); | |
4178 | } | |
4179 | if (insn->help_cout) { | |
4180 | insn->help_cout(s, &o); | |
4181 | } | |
4182 | ||
4183 | /* Free any temporaries created by the helpers. */ | |
4184 | if (!TCGV_IS_UNUSED_I64(o.out) && !o.g_out) { | |
4185 | tcg_temp_free_i64(o.out); | |
4186 | } | |
4187 | if (!TCGV_IS_UNUSED_I64(o.out2) && !o.g_out2) { | |
4188 | tcg_temp_free_i64(o.out2); | |
4189 | } | |
4190 | if (!TCGV_IS_UNUSED_I64(o.in1) && !o.g_in1) { | |
4191 | tcg_temp_free_i64(o.in1); | |
4192 | } | |
4193 | if (!TCGV_IS_UNUSED_I64(o.in2) && !o.g_in2) { | |
4194 | tcg_temp_free_i64(o.in2); | |
4195 | } | |
4196 | if (!TCGV_IS_UNUSED_I64(o.addr1)) { | |
4197 | tcg_temp_free_i64(o.addr1); | |
4198 | } | |
4199 | ||
4200 | /* Advance to the next instruction. */ | |
4201 | s->pc = s->next_pc; | |
4202 | return ret; | |
e023e832 AG |
4203 | } |
4204 | ||
a4e3ad19 | 4205 | static inline void gen_intermediate_code_internal(CPUS390XState *env, |
e023e832 AG |
4206 | TranslationBlock *tb, |
4207 | int search_pc) | |
4208 | { | |
4209 | DisasContext dc; | |
4210 | target_ulong pc_start; | |
4211 | uint64_t next_page_start; | |
4212 | uint16_t *gen_opc_end; | |
4213 | int j, lj = -1; | |
4214 | int num_insns, max_insns; | |
4215 | CPUBreakpoint *bp; | |
ad044d09 | 4216 | ExitStatus status; |
d5a103cd | 4217 | bool do_debug; |
e023e832 AG |
4218 | |
4219 | pc_start = tb->pc; | |
4220 | ||
4221 | /* 31-bit mode */ | |
4222 | if (!(tb->flags & FLAG_MASK_64)) { | |
4223 | pc_start &= 0x7fffffff; | |
4224 | } | |
4225 | ||
e023e832 | 4226 | dc.tb = tb; |
ad044d09 | 4227 | dc.pc = pc_start; |
e023e832 | 4228 | dc.cc_op = CC_OP_DYNAMIC; |
d5a103cd | 4229 | do_debug = dc.singlestep_enabled = env->singlestep_enabled; |
ad044d09 | 4230 | dc.is_jmp = DISAS_NEXT; |
e023e832 | 4231 | |
92414b31 | 4232 | gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
e023e832 AG |
4233 | |
4234 | next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; | |
4235 | ||
4236 | num_insns = 0; | |
4237 | max_insns = tb->cflags & CF_COUNT_MASK; | |
4238 | if (max_insns == 0) { | |
4239 | max_insns = CF_COUNT_MASK; | |
4240 | } | |
4241 | ||
4242 | gen_icount_start(); | |
4243 | ||
4244 | do { | |
e023e832 | 4245 | if (search_pc) { |
92414b31 | 4246 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
e023e832 AG |
4247 | if (lj < j) { |
4248 | lj++; | |
4249 | while (lj < j) { | |
ab1103de | 4250 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
e023e832 AG |
4251 | } |
4252 | } | |
25983cad | 4253 | tcg_ctx.gen_opc_pc[lj] = dc.pc; |
e023e832 | 4254 | gen_opc_cc_op[lj] = dc.cc_op; |
ab1103de | 4255 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 4256 | tcg_ctx.gen_opc_icount[lj] = num_insns; |
e023e832 | 4257 | } |
ad044d09 | 4258 | if (++num_insns == max_insns && (tb->cflags & CF_LAST_IO)) { |
e023e832 AG |
4259 | gen_io_start(); |
4260 | } | |
7193b5f6 RH |
4261 | |
4262 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { | |
4263 | tcg_gen_debug_insn_start(dc.pc); | |
4264 | } | |
4265 | ||
d5a103cd RH |
4266 | status = NO_EXIT; |
4267 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { | |
4268 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
4269 | if (bp->pc == dc.pc) { | |
4270 | status = EXIT_PC_STALE; | |
4271 | do_debug = true; | |
4272 | break; | |
4273 | } | |
4274 | } | |
4275 | } | |
4276 | if (status == NO_EXIT) { | |
4277 | status = translate_one(env, &dc); | |
4278 | } | |
ad044d09 RH |
4279 | |
4280 | /* If we reach a page boundary, are single stepping, | |
4281 | or exhaust instruction count, stop generation. */ | |
4282 | if (status == NO_EXIT | |
4283 | && (dc.pc >= next_page_start | |
4284 | || tcg_ctx.gen_opc_ptr >= gen_opc_end | |
4285 | || num_insns >= max_insns | |
4286 | || singlestep | |
4287 | || env->singlestep_enabled)) { | |
4288 | status = EXIT_PC_STALE; | |
e023e832 | 4289 | } |
ad044d09 | 4290 | } while (status == NO_EXIT); |
e023e832 AG |
4291 | |
4292 | if (tb->cflags & CF_LAST_IO) { | |
4293 | gen_io_end(); | |
4294 | } | |
ad044d09 RH |
4295 | |
4296 | switch (status) { | |
4297 | case EXIT_GOTO_TB: | |
4298 | case EXIT_NORETURN: | |
4299 | break; | |
4300 | case EXIT_PC_STALE: | |
4301 | update_psw_addr(&dc); | |
4302 | /* FALLTHRU */ | |
4303 | case EXIT_PC_UPDATED: | |
4304 | if (singlestep && dc.cc_op != CC_OP_DYNAMIC) { | |
4305 | gen_op_calc_cc(&dc); | |
4306 | } else { | |
4307 | /* Next TB starts off with CC_OP_DYNAMIC, | |
4308 | so make sure the cc op type is in env */ | |
4309 | gen_op_set_cc_op(&dc); | |
4310 | } | |
d5a103cd RH |
4311 | if (do_debug) { |
4312 | gen_exception(EXCP_DEBUG); | |
ad044d09 RH |
4313 | } else { |
4314 | /* Generate the return instruction */ | |
4315 | tcg_gen_exit_tb(0); | |
4316 | } | |
4317 | break; | |
4318 | default: | |
4319 | abort(); | |
e023e832 | 4320 | } |
ad044d09 | 4321 | |
e023e832 | 4322 | gen_icount_end(tb, num_insns); |
efd7f486 | 4323 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
e023e832 | 4324 | if (search_pc) { |
92414b31 | 4325 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
e023e832 AG |
4326 | lj++; |
4327 | while (lj <= j) { | |
ab1103de | 4328 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
e023e832 AG |
4329 | } |
4330 | } else { | |
4331 | tb->size = dc.pc - pc_start; | |
4332 | tb->icount = num_insns; | |
4333 | } | |
ad044d09 | 4334 | |
e023e832 | 4335 | #if defined(S390X_DEBUG_DISAS) |
e023e832 AG |
4336 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
4337 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); | |
f4359b9f | 4338 | log_target_disas(env, pc_start, dc.pc - pc_start, 1); |
e023e832 AG |
4339 | qemu_log("\n"); |
4340 | } | |
4341 | #endif | |
4342 | } | |
4343 | ||
a4e3ad19 | 4344 | void gen_intermediate_code (CPUS390XState *env, struct TranslationBlock *tb) |
e023e832 AG |
4345 | { |
4346 | gen_intermediate_code_internal(env, tb, 0); | |
4347 | } | |
4348 | ||
a4e3ad19 | 4349 | void gen_intermediate_code_pc (CPUS390XState *env, struct TranslationBlock *tb) |
e023e832 AG |
4350 | { |
4351 | gen_intermediate_code_internal(env, tb, 1); | |
4352 | } | |
4353 | ||
a4e3ad19 | 4354 | void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb, int pc_pos) |
e023e832 AG |
4355 | { |
4356 | int cc_op; | |
25983cad | 4357 | env->psw.addr = tcg_ctx.gen_opc_pc[pc_pos]; |
e023e832 AG |
4358 | cc_op = gen_opc_cc_op[pc_pos]; |
4359 | if ((cc_op != CC_OP_DYNAMIC) && (cc_op != CC_OP_STATIC)) { | |
4360 | env->cc_op = cc_op; | |
4361 | } | |
10ec5117 | 4362 | } |