translate.c 169.7 KB
Newer Older
A
Alexander Graf 已提交
1 2 3 4
/*
 *  S/390 translation
 *
 *  Copyright (c) 2009 Ulrich Hecht
5
 *  Copyright (c) 2010 Alexander Graf
A
Alexander Graf 已提交
6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
A
Alexander Graf 已提交
19
 */
20 21 22 23 24 25 26 27 28 29

/* #define DEBUG_INLINE_BRANCHES */
#define S390X_DEBUG_DISAS
/* #define S390X_DEBUG_DISAS_VERBOSE */

#ifdef S390X_DEBUG_DISAS_VERBOSE
#  define LOG_DISAS(...) qemu_log(__VA_ARGS__)
#else
#  define LOG_DISAS(...) do { } while (0)
#endif
A
Alexander Graf 已提交
30

P
Peter Maydell 已提交
31
#include "qemu/osdep.h"
A
Alexander Graf 已提交
32
#include "cpu.h"
33
#include "internal.h"
34
#include "disas/disas.h"
35
#include "exec/exec-all.h"
A
Alexander Graf 已提交
36
#include "tcg-op.h"
37
#include "qemu/log.h"
38
#include "qemu/host-utils.h"
P
Paolo Bonzini 已提交
39
#include "exec/cpu_ldst.h"
40
#include "exec/gen-icount.h"
41 42
#include "exec/helper-proto.h"
#include "exec/helper-gen.h"
43

44
#include "trace-tcg.h"
45
#include "exec/translator.h"
46
#include "exec/log.h"
47

48 49

/* Information that (most) every instruction needs to manipulate.  */
50
typedef struct DisasContext DisasContext;
51 52 53
typedef struct DisasInsn DisasInsn;
typedef struct DisasFields DisasFields;

54
struct DisasContext {
55
    DisasContextBase base;
56 57
    const DisasInsn *insn;
    DisasFields *fields;
58
    uint64_t ex_value;
59 60 61 62 63 64
    /*
     * During translate_one(), pc_tmp is used to determine the instruction
     * to be executed after base.pc_next - e.g. next sequential instruction
     * or a branch target.
     */
    uint64_t pc_tmp;
65
    uint32_t ilen;
66
    enum cc_op cc_op;
67
    bool do_debug;
68 69
};

70 71 72 73 74 75 76 77 78 79 80 81
/* Information carried about a condition to be evaluated.  */
typedef struct {
    TCGCond cond:8;
    bool is_64;
    bool g1;
    bool g2;
    union {
        struct { TCGv_i64 a, b; } s64;
        struct { TCGv_i32 a, b; } s32;
    } u;
} DisasCompare;

82 83 84 85 86
#ifdef DEBUG_INLINE_BRANCHES
static uint64_t inline_branch_hit[CC_OP_MAX];
static uint64_t inline_branch_miss[CC_OP_MAX];
#endif

87
static void pc_to_link_info(TCGv_i64 out, DisasContext *s, uint64_t pc)
88
{
89 90 91 92 93 94
    TCGv_i64 tmp;

    if (s->base.tb->flags & FLAG_MASK_32) {
        if (s->base.tb->flags & FLAG_MASK_64) {
            tcg_gen_movi_i64(out, pc);
            return;
95
        }
96
        pc |= 0x80000000;
97
    }
98 99 100 101
    assert(!(s->base.tb->flags & FLAG_MASK_64));
    tmp = tcg_const_i64(pc);
    tcg_gen_deposit_i64(out, out, tmp, 0, 32);
    tcg_temp_free_i64(tmp);
102 103 104 105
}

static TCGv_i64 psw_addr;
static TCGv_i64 psw_mask;
106
static TCGv_i64 gbea;
107 108 109 110 111 112

static TCGv_i32 cc_op;
static TCGv_i64 cc_src;
static TCGv_i64 cc_dst;
static TCGv_i64 cc_vr;

113
static char cpu_reg_names[32][4];
114
static TCGv_i64 regs[16];
115
static TCGv_i64 fregs[16];
116

117 118
void s390x_translate_init(void)
{
119 120
    int i;

121
    psw_addr = tcg_global_mem_new_i64(cpu_env,
122
                                      offsetof(CPUS390XState, psw.addr),
123
                                      "psw_addr");
124
    psw_mask = tcg_global_mem_new_i64(cpu_env,
125
                                      offsetof(CPUS390XState, psw.mask),
126
                                      "psw_mask");
127
    gbea = tcg_global_mem_new_i64(cpu_env,
128 129
                                  offsetof(CPUS390XState, gbea),
                                  "gbea");
130

131
    cc_op = tcg_global_mem_new_i32(cpu_env, offsetof(CPUS390XState, cc_op),
132
                                   "cc_op");
133
    cc_src = tcg_global_mem_new_i64(cpu_env, offsetof(CPUS390XState, cc_src),
134
                                    "cc_src");
135
    cc_dst = tcg_global_mem_new_i64(cpu_env, offsetof(CPUS390XState, cc_dst),
136
                                    "cc_dst");
137
    cc_vr = tcg_global_mem_new_i64(cpu_env, offsetof(CPUS390XState, cc_vr),
138 139 140
                                   "cc_vr");

    for (i = 0; i < 16; i++) {
141
        snprintf(cpu_reg_names[i], sizeof(cpu_reg_names[0]), "r%d", i);
142
        regs[i] = tcg_global_mem_new(cpu_env,
143 144 145 146 147 148
                                     offsetof(CPUS390XState, regs[i]),
                                     cpu_reg_names[i]);
    }

    for (i = 0; i < 16; i++) {
        snprintf(cpu_reg_names[i + 16], sizeof(cpu_reg_names[0]), "f%d", i);
149
        fregs[i] = tcg_global_mem_new(cpu_env,
E
Eric Farman 已提交
150
                                      offsetof(CPUS390XState, vregs[i][0].d),
151
                                      cpu_reg_names[i + 16]);
152
    }
153 154
}

155
static TCGv_i64 load_reg(int reg)
A
Alexander Graf 已提交
156
{
157 158 159
    TCGv_i64 r = tcg_temp_new_i64();
    tcg_gen_mov_i64(r, regs[reg]);
    return r;
A
Alexander Graf 已提交
160 161
}

162
static TCGv_i64 load_freg32_i64(int reg)
R
Richard Henderson 已提交
163 164 165 166 167 168
{
    TCGv_i64 r = tcg_temp_new_i64();
    tcg_gen_shri_i64(r, fregs[reg], 32);
    return r;
}

169
static void store_reg(int reg, TCGv_i64 v)
170 171 172 173
{
    tcg_gen_mov_i64(regs[reg], v);
}

174
static void store_freg(int reg, TCGv_i64 v)
175
{
176
    tcg_gen_mov_i64(fregs[reg], v);
177 178
}

179
static void store_reg32_i64(int reg, TCGv_i64 v)
180 181 182 183 184
{
    /* 32 bit register writes keep the upper half */
    tcg_gen_deposit_i64(regs[reg], regs[reg], v, 0, 32);
}

185
static void store_reg32h_i64(int reg, TCGv_i64 v)
186 187 188 189
{
    tcg_gen_deposit_i64(regs[reg], regs[reg], v, 32, 32);
}

190
static void store_freg32_i64(int reg, TCGv_i64 v)
R
Richard Henderson 已提交
191 192 193 194
{
    tcg_gen_deposit_i64(fregs[reg], fregs[reg], v, 32, 32);
}

195
static void return_low128(TCGv_i64 dest)
196 197 198 199
{
    tcg_gen_ld_i64(dest, cpu_env, offsetof(CPUS390XState, retxl));
}

200
static void update_psw_addr(DisasContext *s)
201 202
{
    /* psw.addr */
203
    tcg_gen_movi_i64(psw_addr, s->base.pc_next);
204 205
}

206 207 208
static void per_branch(DisasContext *s, bool to_next)
{
#ifndef CONFIG_USER_ONLY
209
    tcg_gen_movi_i64(gbea, s->base.pc_next);
210

211 212
    if (s->base.tb->flags & FLAG_MASK_PER) {
        TCGv_i64 next_pc = to_next ? tcg_const_i64(s->pc_tmp) : psw_addr;
213
        gen_helper_per_branch(cpu_env, gbea, next_pc);
214 215 216 217 218 219 220 221 222 223 224
        if (to_next) {
            tcg_temp_free_i64(next_pc);
        }
    }
#endif
}

static void per_branch_cond(DisasContext *s, TCGCond cond,
                            TCGv_i64 arg1, TCGv_i64 arg2)
{
#ifndef CONFIG_USER_ONLY
225
    if (s->base.tb->flags & FLAG_MASK_PER) {
226 227 228
        TCGLabel *lab = gen_new_label();
        tcg_gen_brcond_i64(tcg_invert_cond(cond), arg1, arg2, lab);

229
        tcg_gen_movi_i64(gbea, s->base.pc_next);
230
        gen_helper_per_branch(cpu_env, gbea, psw_addr);
231 232

        gen_set_label(lab);
233
    } else {
234
        TCGv_i64 pc = tcg_const_i64(s->base.pc_next);
235 236
        tcg_gen_movcond_i64(cond, gbea, arg1, arg2, gbea, pc);
        tcg_temp_free_i64(pc);
237 238 239 240
    }
#endif
}

241 242
static void per_breaking_event(DisasContext *s)
{
243
    tcg_gen_movi_i64(gbea, s->base.pc_next);
244 245
}

246 247 248 249 250 251 252
static void update_cc_op(DisasContext *s)
{
    if (s->cc_op != CC_OP_DYNAMIC && s->cc_op != CC_OP_STATIC) {
        tcg_gen_movi_i32(cc_op, s->cc_op);
    }
}

B
Blue Swirl 已提交
253
static inline uint64_t ld_code2(CPUS390XState *env, uint64_t pc)
254
{
B
Blue Swirl 已提交
255
    return (uint64_t)cpu_lduw_code(env, pc);
256 257
}

B
Blue Swirl 已提交
258
static inline uint64_t ld_code4(CPUS390XState *env, uint64_t pc)
259
{
260
    return (uint64_t)(uint32_t)cpu_ldl_code(env, pc);
261 262
}

263
static int get_mem_index(DisasContext *s)
264
{
265
    if (!(s->base.tb->flags & FLAG_MASK_DAT)) {
266 267 268
        return MMU_REAL_IDX;
    }

269
    switch (s->base.tb->flags & FLAG_MASK_ASC) {
270
    case PSW_ASC_PRIMARY >> FLAG_MASK_PSW_SHIFT:
271
        return MMU_PRIMARY_IDX;
272
    case PSW_ASC_SECONDARY >> FLAG_MASK_PSW_SHIFT:
273
        return MMU_SECONDARY_IDX;
274
    case PSW_ASC_HOME >> FLAG_MASK_PSW_SHIFT:
275
        return MMU_HOME_IDX;
276 277 278 279 280 281
    default:
        tcg_abort();
        break;
    }
}

282
static void gen_exception(int excp)
283
{
284
    TCGv_i32 tmp = tcg_const_i32(excp);
285
    gen_helper_exception(cpu_env, tmp);
286 287 288
    tcg_temp_free_i32(tmp);
}

289
static void gen_program_exception(DisasContext *s, int code)
290 291 292
{
    TCGv_i32 tmp;

293
    /* Remember what pgm exeption this was.  */
294
    tmp = tcg_const_i32(code);
295
    tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_code));
296 297
    tcg_temp_free_i32(tmp);

298
    tmp = tcg_const_i32(s->ilen);
299
    tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUS390XState, int_pgm_ilen));
300 301
    tcg_temp_free_i32(tmp);

302
    /* update the psw */
303 304
    update_psw_addr(s);

305
    /* Save off cc.  */
306
    update_cc_op(s);
307

308 309
    /* Trigger exception.  */
    gen_exception(EXCP_PGM);
310 311
}

312
static inline void gen_illegal_opcode(DisasContext *s)
313
{
314
    gen_program_exception(s, PGM_OPERATION);
315 316
}

317 318 319 320 321 322 323 324 325 326 327 328 329 330
static inline void gen_trap(DisasContext *s)
{
    TCGv_i32 t;

    /* Set DXC to 0xff.  */
    t = tcg_temp_new_i32();
    tcg_gen_ld_i32(t, cpu_env, offsetof(CPUS390XState, fpc));
    tcg_gen_ori_i32(t, t, 0xff00);
    tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, fpc));
    tcg_temp_free_i32(t);

    gen_program_exception(s, PGM_DATA);
}

331 332
#ifndef CONFIG_USER_ONLY
static void check_privileged(DisasContext *s)
333
{
334
    if (s->base.tb->flags & FLAG_MASK_PSTATE) {
335
        gen_program_exception(s, PGM_PRIVILEGED);
336 337
    }
}
338
#endif
339 340 341

static TCGv_i64 get_address(DisasContext *s, int x2, int b2, int d2)
{
342
    TCGv_i64 tmp = tcg_temp_new_i64();
343
    bool need_31 = !(s->base.tb->flags & FLAG_MASK_64);
344

345 346
    /* Note that d2 is limited to 20 bits, signed.  If we crop negative
       displacements early we create larger immedate addends.  */
347

348 349 350 351
    /* Note that addi optimizes the imm==0 case.  */
    if (b2 && x2) {
        tcg_gen_add_i64(tmp, regs[b2], regs[x2]);
        tcg_gen_addi_i64(tmp, tmp, d2);
352
    } else if (b2) {
353 354 355
        tcg_gen_addi_i64(tmp, regs[b2], d2);
    } else if (x2) {
        tcg_gen_addi_i64(tmp, regs[x2], d2);
356
    } else {
357 358 359 360 361
        if (need_31) {
            d2 &= 0x7fffffff;
            need_31 = false;
        }
        tcg_gen_movi_i64(tmp, d2);
362
    }
363 364
    if (need_31) {
        tcg_gen_andi_i64(tmp, tmp, 0x7fffffff);
365 366 367 368 369
    }

    return tmp;
}

370 371 372 373 374 375 376
static inline bool live_cc_data(DisasContext *s)
{
    return (s->cc_op != CC_OP_DYNAMIC
            && s->cc_op != CC_OP_STATIC
            && s->cc_op > 3);
}

377
static inline void gen_op_movi_cc(DisasContext *s, uint32_t val)
378
{
379 380 381 382 383
    if (live_cc_data(s)) {
        tcg_gen_discard_i64(cc_src);
        tcg_gen_discard_i64(cc_dst);
        tcg_gen_discard_i64(cc_vr);
    }
384 385 386 387 388
    s->cc_op = CC_OP_CONST0 + val;
}

static void gen_op_update1_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 dst)
{
389 390 391 392
    if (live_cc_data(s)) {
        tcg_gen_discard_i64(cc_src);
        tcg_gen_discard_i64(cc_vr);
    }
393 394 395 396 397 398 399
    tcg_gen_mov_i64(cc_dst, dst);
    s->cc_op = op;
}

static void gen_op_update2_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
                                  TCGv_i64 dst)
{
400 401 402
    if (live_cc_data(s)) {
        tcg_gen_discard_i64(cc_vr);
    }
403 404 405 406 407 408 409 410 411 412 413 414 415 416
    tcg_gen_mov_i64(cc_src, src);
    tcg_gen_mov_i64(cc_dst, dst);
    s->cc_op = op;
}

static void gen_op_update3_cc_i64(DisasContext *s, enum cc_op op, TCGv_i64 src,
                                  TCGv_i64 dst, TCGv_i64 vr)
{
    tcg_gen_mov_i64(cc_src, src);
    tcg_gen_mov_i64(cc_dst, dst);
    tcg_gen_mov_i64(cc_vr, vr);
    s->cc_op = op;
}

417
static void set_cc_nz_u64(DisasContext *s, TCGv_i64 val)
418 419 420 421
{
    gen_op_update1_cc_i64(s, CC_OP_NZ, val);
}

422
static void gen_set_cc_nz_f32(DisasContext *s, TCGv_i64 val)
423 424 425 426
{
    gen_op_update1_cc_i64(s, CC_OP_NZ_F32, val);
}

427
static void gen_set_cc_nz_f64(DisasContext *s, TCGv_i64 val)
428 429 430 431
{
    gen_op_update1_cc_i64(s, CC_OP_NZ_F64, val);
}

432
static void gen_set_cc_nz_f128(DisasContext *s, TCGv_i64 vh, TCGv_i64 vl)
433 434 435 436
{
    gen_op_update2_cc_i64(s, CC_OP_NZ_F128, vh, vl);
}

437
/* CC value is in env->cc_op */
438
static void set_cc_static(DisasContext *s)
439
{
440 441 442 443 444
    if (live_cc_data(s)) {
        tcg_gen_discard_i64(cc_src);
        tcg_gen_discard_i64(cc_dst);
        tcg_gen_discard_i64(cc_vr);
    }
445 446 447 448 449 450
    s->cc_op = CC_OP_STATIC;
}

/* calculates cc into cc_op */
static void gen_op_calc_cc(DisasContext *s)
{
451 452
    TCGv_i32 local_cc_op = NULL;
    TCGv_i64 dummy = NULL;
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

    switch (s->cc_op) {
    default:
        dummy = tcg_const_i64(0);
        /* FALLTHRU */
    case CC_OP_ADD_64:
    case CC_OP_ADDU_64:
    case CC_OP_ADDC_64:
    case CC_OP_SUB_64:
    case CC_OP_SUBU_64:
    case CC_OP_SUBB_64:
    case CC_OP_ADD_32:
    case CC_OP_ADDU_32:
    case CC_OP_ADDC_32:
    case CC_OP_SUB_32:
    case CC_OP_SUBU_32:
    case CC_OP_SUBB_32:
        local_cc_op = tcg_const_i32(s->cc_op);
        break;
    case CC_OP_CONST0:
    case CC_OP_CONST1:
    case CC_OP_CONST2:
    case CC_OP_CONST3:
    case CC_OP_STATIC:
    case CC_OP_DYNAMIC:
        break;
    }
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

    switch (s->cc_op) {
    case CC_OP_CONST0:
    case CC_OP_CONST1:
    case CC_OP_CONST2:
    case CC_OP_CONST3:
        /* s->cc_op is the cc value */
        tcg_gen_movi_i32(cc_op, s->cc_op - CC_OP_CONST0);
        break;
    case CC_OP_STATIC:
        /* env->cc_op already is the cc value */
        break;
    case CC_OP_NZ:
    case CC_OP_ABS_64:
    case CC_OP_NABS_64:
    case CC_OP_ABS_32:
    case CC_OP_NABS_32:
    case CC_OP_LTGT0_32:
    case CC_OP_LTGT0_64:
    case CC_OP_COMP_32:
    case CC_OP_COMP_64:
    case CC_OP_NZ_F32:
    case CC_OP_NZ_F64:
R
Richard Henderson 已提交
503
    case CC_OP_FLOGR:
504
        /* 1 argument */
505
        gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, dummy, cc_dst, dummy);
506 507 508 509 510 511 512 513
        break;
    case CC_OP_ICM:
    case CC_OP_LTGT_32:
    case CC_OP_LTGT_64:
    case CC_OP_LTUGTU_32:
    case CC_OP_LTUGTU_64:
    case CC_OP_TM_32:
    case CC_OP_TM_64:
514 515
    case CC_OP_SLA_32:
    case CC_OP_SLA_64:
516
    case CC_OP_NZ_F128:
517
        /* 2 arguments */
518
        gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, dummy);
519 520 521
        break;
    case CC_OP_ADD_64:
    case CC_OP_ADDU_64:
522
    case CC_OP_ADDC_64:
523 524
    case CC_OP_SUB_64:
    case CC_OP_SUBU_64:
525
    case CC_OP_SUBB_64:
526 527
    case CC_OP_ADD_32:
    case CC_OP_ADDU_32:
528
    case CC_OP_ADDC_32:
529 530
    case CC_OP_SUB_32:
    case CC_OP_SUBU_32:
531
    case CC_OP_SUBB_32:
532
        /* 3 arguments */
533
        gen_helper_calc_cc(cc_op, cpu_env, local_cc_op, cc_src, cc_dst, cc_vr);
534 535 536
        break;
    case CC_OP_DYNAMIC:
        /* unknown operation - assume 3 arguments and cc_op in env */
537
        gen_helper_calc_cc(cc_op, cpu_env, cc_op, cc_src, cc_dst, cc_vr);
538 539 540 541 542
        break;
    default:
        tcg_abort();
    }

543
    if (local_cc_op) {
544 545
        tcg_temp_free_i32(local_cc_op);
    }
546
    if (dummy) {
547 548
        tcg_temp_free_i64(dummy);
    }
549 550 551 552 553

    /* We now have cc in cc_op as constant */
    set_cc_static(s);
}

554
static bool use_exit_tb(DisasContext *s)
555
{
556 557 558
    return s->base.singlestep_enabled ||
            (tb_cflags(s->base.tb) & CF_LAST_IO) ||
            (s->base.tb->flags & FLAG_MASK_PER);
559 560 561 562 563
}

static bool use_goto_tb(DisasContext *s, uint64_t dest)
{
    if (unlikely(use_exit_tb(s))) {
564 565 566
        return false;
    }
#ifndef CONFIG_USER_ONLY
567 568
    return (dest & TARGET_PAGE_MASK) == (s->base.tb->pc & TARGET_PAGE_MASK) ||
           (dest & TARGET_PAGE_MASK) == (s->base.pc_next & TARGET_PAGE_MASK);
569 570 571
#else
    return true;
#endif
572
}
573

574
static void account_noninline_branch(DisasContext *s, int cc_op)
575 576 577 578 579 580
{
#ifdef DEBUG_INLINE_BRANCHES
    inline_branch_miss[cc_op]++;
#endif
}

581
static void account_inline_branch(DisasContext *s, int cc_op)
582 583
{
#ifdef DEBUG_INLINE_BRANCHES
584
    inline_branch_hit[cc_op]++;
585 586 587
#endif
}

588
/* Table of mask values to comparison codes, given a comparison as input.
589
   For such, CC=3 should not be possible.  */
590 591
static const TCGCond ltgt_cond[16] = {
    TCG_COND_NEVER,  TCG_COND_NEVER,     /*    |    |    | x */
592 593 594 595 596 597
    TCG_COND_GT,     TCG_COND_GT,        /*    |    | GT | x */
    TCG_COND_LT,     TCG_COND_LT,        /*    | LT |    | x */
    TCG_COND_NE,     TCG_COND_NE,        /*    | LT | GT | x */
    TCG_COND_EQ,     TCG_COND_EQ,        /* EQ |    |    | x */
    TCG_COND_GE,     TCG_COND_GE,        /* EQ |    | GT | x */
    TCG_COND_LE,     TCG_COND_LE,        /* EQ | LT |    | x */
598 599 600 601 602 603
    TCG_COND_ALWAYS, TCG_COND_ALWAYS,    /* EQ | LT | GT | x */
};

/* Table of mask values to comparison codes, given a logic op as input.
   For such, only CC=0 and CC=1 should be possible.  */
static const TCGCond nz_cond[16] = {
604 605 606 607 608 609 610 611
    TCG_COND_NEVER, TCG_COND_NEVER,      /*    |    | x | x */
    TCG_COND_NEVER, TCG_COND_NEVER,
    TCG_COND_NE, TCG_COND_NE,            /*    | NE | x | x */
    TCG_COND_NE, TCG_COND_NE,
    TCG_COND_EQ, TCG_COND_EQ,            /* EQ |    | x | x */
    TCG_COND_EQ, TCG_COND_EQ,
    TCG_COND_ALWAYS, TCG_COND_ALWAYS,    /* EQ | NE | x | x */
    TCG_COND_ALWAYS, TCG_COND_ALWAYS,
612 613 614 615 616
};

/* Interpret MASK in terms of S->CC_OP, and fill in C with all the
   details required to generate a TCG comparison.  */
static void disas_jcc(DisasContext *s, DisasCompare *c, uint32_t mask)
617
{
618 619
    TCGCond cond;
    enum cc_op old_cc_op = s->cc_op;
620

621 622 623 624 625 626 627 628 629 630 631
    if (mask == 15 || mask == 0) {
        c->cond = (mask ? TCG_COND_ALWAYS : TCG_COND_NEVER);
        c->u.s32.a = cc_op;
        c->u.s32.b = cc_op;
        c->g1 = c->g2 = true;
        c->is_64 = false;
        return;
    }

    /* Find the TCG condition for the mask + cc op.  */
    switch (old_cc_op) {
632 633 634 635
    case CC_OP_LTGT0_32:
    case CC_OP_LTGT0_64:
    case CC_OP_LTGT_32:
    case CC_OP_LTGT_64:
636 637
        cond = ltgt_cond[mask];
        if (cond == TCG_COND_NEVER) {
638 639
            goto do_dynamic;
        }
640
        account_inline_branch(s, old_cc_op);
641
        break;
642

643 644
    case CC_OP_LTUGTU_32:
    case CC_OP_LTUGTU_64:
645 646
        cond = tcg_unsigned_cond(ltgt_cond[mask]);
        if (cond == TCG_COND_NEVER) {
647 648
            goto do_dynamic;
        }
649
        account_inline_branch(s, old_cc_op);
650
        break;
651

652
    case CC_OP_NZ:
653 654
        cond = nz_cond[mask];
        if (cond == TCG_COND_NEVER) {
655 656
            goto do_dynamic;
        }
657
        account_inline_branch(s, old_cc_op);
658 659
        break;

660
    case CC_OP_TM_32:
661 662
    case CC_OP_TM_64:
        switch (mask) {
663 664
        case 8:
            cond = TCG_COND_EQ;
665
            break;
666 667
        case 4 | 2 | 1:
            cond = TCG_COND_NE;
668 669 670 671
            break;
        default:
            goto do_dynamic;
        }
672
        account_inline_branch(s, old_cc_op);
673
        break;
674

675 676
    case CC_OP_ICM:
        switch (mask) {
677 678
        case 8:
            cond = TCG_COND_EQ;
679
            break;
680 681 682
        case 4 | 2 | 1:
        case 4 | 2:
            cond = TCG_COND_NE;
683 684 685 686
            break;
        default:
            goto do_dynamic;
        }
687
        account_inline_branch(s, old_cc_op);
688
        break;
689

R
Richard Henderson 已提交
690 691 692 693 694 695 696 697 698 699 700 701 702 703
    case CC_OP_FLOGR:
        switch (mask & 0xa) {
        case 8: /* src == 0 -> no one bit found */
            cond = TCG_COND_EQ;
            break;
        case 2: /* src != 0 -> one bit found */
            cond = TCG_COND_NE;
            break;
        default:
            goto do_dynamic;
        }
        account_inline_branch(s, old_cc_op);
        break;

704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
    case CC_OP_ADDU_32:
    case CC_OP_ADDU_64:
        switch (mask) {
        case 8 | 2: /* vr == 0 */
            cond = TCG_COND_EQ;
            break;
        case 4 | 1: /* vr != 0 */
            cond = TCG_COND_NE;
            break;
        case 8 | 4: /* no carry -> vr >= src */
            cond = TCG_COND_GEU;
            break;
        case 2 | 1: /* carry -> vr < src */
            cond = TCG_COND_LTU;
            break;
        default:
            goto do_dynamic;
        }
        account_inline_branch(s, old_cc_op);
        break;

    case CC_OP_SUBU_32:
    case CC_OP_SUBU_64:
        /* Note that CC=0 is impossible; treat it as dont-care.  */
        switch (mask & 7) {
        case 2: /* zero -> op1 == op2 */
            cond = TCG_COND_EQ;
            break;
        case 4 | 1: /* !zero -> op1 != op2 */
            cond = TCG_COND_NE;
            break;
        case 4: /* borrow (!carry) -> op1 < op2 */
            cond = TCG_COND_LTU;
            break;
        case 2 | 1: /* !borrow (carry) -> op1 >= op2 */
            cond = TCG_COND_GEU;
            break;
        default:
            goto do_dynamic;
        }
        account_inline_branch(s, old_cc_op);
        break;

747
    default:
748 749
    do_dynamic:
        /* Calculate cc value.  */
750
        gen_op_calc_cc(s);
751
        /* FALLTHRU */
752

753 754 755
    case CC_OP_STATIC:
        /* Jump based on CC.  We'll load up the real cond below;
           the assignment here merely avoids a compiler warning.  */
756
        account_noninline_branch(s, old_cc_op);
757 758 759 760
        old_cc_op = CC_OP_STATIC;
        cond = TCG_COND_NEVER;
        break;
    }
761

762 763 764 765 766 767 768
    /* Load up the arguments of the comparison.  */
    c->is_64 = true;
    c->g1 = c->g2 = false;
    switch (old_cc_op) {
    case CC_OP_LTGT0_32:
        c->is_64 = false;
        c->u.s32.a = tcg_temp_new_i32();
769
        tcg_gen_extrl_i64_i32(c->u.s32.a, cc_dst);
770 771 772 773
        c->u.s32.b = tcg_const_i32(0);
        break;
    case CC_OP_LTGT_32:
    case CC_OP_LTUGTU_32:
774
    case CC_OP_SUBU_32:
775 776
        c->is_64 = false;
        c->u.s32.a = tcg_temp_new_i32();
777
        tcg_gen_extrl_i64_i32(c->u.s32.a, cc_src);
778
        c->u.s32.b = tcg_temp_new_i32();
779
        tcg_gen_extrl_i64_i32(c->u.s32.b, cc_dst);
780 781 782 783
        break;

    case CC_OP_LTGT0_64:
    case CC_OP_NZ:
R
Richard Henderson 已提交
784
    case CC_OP_FLOGR:
785 786 787 788 789 790
        c->u.s64.a = cc_dst;
        c->u.s64.b = tcg_const_i64(0);
        c->g1 = true;
        break;
    case CC_OP_LTGT_64:
    case CC_OP_LTUGTU_64:
791
    case CC_OP_SUBU_64:
792 793 794 795 796 797 798
        c->u.s64.a = cc_src;
        c->u.s64.b = cc_dst;
        c->g1 = c->g2 = true;
        break;

    case CC_OP_TM_32:
    case CC_OP_TM_64:
799
    case CC_OP_ICM:
800 801 802 803
        c->u.s64.a = tcg_temp_new_i64();
        c->u.s64.b = tcg_const_i64(0);
        tcg_gen_and_i64(c->u.s64.a, cc_src, cc_dst);
        break;
804 805 806 807 808

    case CC_OP_ADDU_32:
        c->is_64 = false;
        c->u.s32.a = tcg_temp_new_i32();
        c->u.s32.b = tcg_temp_new_i32();
809
        tcg_gen_extrl_i64_i32(c->u.s32.a, cc_vr);
810 811 812
        if (cond == TCG_COND_EQ || cond == TCG_COND_NE) {
            tcg_gen_movi_i32(c->u.s32.b, 0);
        } else {
813
            tcg_gen_extrl_i64_i32(c->u.s32.b, cc_src);
814 815 816 817 818 819 820 821 822 823 824 825 826
        }
        break;

    case CC_OP_ADDU_64:
        c->u.s64.a = cc_vr;
        c->g1 = true;
        if (cond == TCG_COND_EQ || cond == TCG_COND_NE) {
            c->u.s64.b = tcg_const_i64(0);
        } else {
            c->u.s64.b = cc_src;
            c->g2 = true;
        }
        break;
827 828 829 830 831

    case CC_OP_STATIC:
        c->is_64 = false;
        c->u.s32.a = cc_op;
        c->g1 = true;
832 833
        switch (mask) {
        case 0x8 | 0x4 | 0x2: /* cc != 3 */
834 835
            cond = TCG_COND_NE;
            c->u.s32.b = tcg_const_i32(3);
836 837
            break;
        case 0x8 | 0x4 | 0x1: /* cc != 2 */
838 839
            cond = TCG_COND_NE;
            c->u.s32.b = tcg_const_i32(2);
840 841
            break;
        case 0x8 | 0x2 | 0x1: /* cc != 1 */
842 843
            cond = TCG_COND_NE;
            c->u.s32.b = tcg_const_i32(1);
844
            break;
845
        case 0x8 | 0x2: /* cc == 0 || cc == 2 => (cc & 1) == 0 */
846 847 848 849 850
            cond = TCG_COND_EQ;
            c->g1 = false;
            c->u.s32.a = tcg_temp_new_i32();
            c->u.s32.b = tcg_const_i32(0);
            tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
851 852
            break;
        case 0x8 | 0x4: /* cc < 2 */
853 854
            cond = TCG_COND_LTU;
            c->u.s32.b = tcg_const_i32(2);
855 856
            break;
        case 0x8: /* cc == 0 */
857 858
            cond = TCG_COND_EQ;
            c->u.s32.b = tcg_const_i32(0);
859 860
            break;
        case 0x4 | 0x2 | 0x1: /* cc != 0 */
861 862
            cond = TCG_COND_NE;
            c->u.s32.b = tcg_const_i32(0);
863
            break;
864
        case 0x4 | 0x1: /* cc == 1 || cc == 3 => (cc & 1) != 0 */
865 866 867 868 869
            cond = TCG_COND_NE;
            c->g1 = false;
            c->u.s32.a = tcg_temp_new_i32();
            c->u.s32.b = tcg_const_i32(0);
            tcg_gen_andi_i32(c->u.s32.a, cc_op, 1);
870 871
            break;
        case 0x4: /* cc == 1 */
872 873
            cond = TCG_COND_EQ;
            c->u.s32.b = tcg_const_i32(1);
874 875
            break;
        case 0x2 | 0x1: /* cc > 1 */
876 877
            cond = TCG_COND_GTU;
            c->u.s32.b = tcg_const_i32(1);
878 879
            break;
        case 0x2: /* cc == 2 */
880 881
            cond = TCG_COND_EQ;
            c->u.s32.b = tcg_const_i32(2);
882 883
            break;
        case 0x1: /* cc == 3 */
884 885
            cond = TCG_COND_EQ;
            c->u.s32.b = tcg_const_i32(3);
886
            break;
887 888 889 890 891 892 893 894
        default:
            /* CC is masked by something else: (8 >> cc) & mask.  */
            cond = TCG_COND_NE;
            c->g1 = false;
            c->u.s32.a = tcg_const_i32(8);
            c->u.s32.b = tcg_const_i32(0);
            tcg_gen_shr_i32(c->u.s32.a, c->u.s32.a, cc_op);
            tcg_gen_andi_i32(c->u.s32.a, c->u.s32.a, mask);
895 896 897
            break;
        }
        break;
898 899 900

    default:
        abort();
901
    }
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
    c->cond = cond;
}

static void free_compare(DisasCompare *c)
{
    if (!c->g1) {
        if (c->is_64) {
            tcg_temp_free_i64(c->u.s64.a);
        } else {
            tcg_temp_free_i32(c->u.s32.a);
        }
    }
    if (!c->g2) {
        if (c->is_64) {
            tcg_temp_free_i64(c->u.s64.b);
        } else {
            tcg_temp_free_i32(c->u.s32.b);
        }
    }
}

923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
/* ====================================================================== */
/* Define the insn format enumeration.  */
#define F0(N)                         FMT_##N,
#define F1(N, X1)                     F0(N)
#define F2(N, X1, X2)                 F0(N)
#define F3(N, X1, X2, X3)             F0(N)
#define F4(N, X1, X2, X3, X4)         F0(N)
#define F5(N, X1, X2, X3, X4, X5)     F0(N)

typedef enum {
#include "insn-format.def"
} DisasFormat;

#undef F0
#undef F1
#undef F2
#undef F3
#undef F4
#undef F5

/* Define a structure to hold the decoded fields.  We'll store each inside
   an array indexed by an enum.  In order to conserve memory, we'll arrange
   for fields that do not exist at the same time to overlap, thus the "C"
   for compact.  For checking purposes there is an "O" for original index
   as well that will be applied to availability bitmaps.  */

enum DisasFieldIndexO {
    FLD_O_r1,
    FLD_O_r2,
    FLD_O_r3,
    FLD_O_m1,
    FLD_O_m3,
    FLD_O_m4,
    FLD_O_b1,
    FLD_O_b2,
    FLD_O_b4,
    FLD_O_d1,
    FLD_O_d2,
    FLD_O_d4,
    FLD_O_x2,
    FLD_O_l1,
    FLD_O_l2,
    FLD_O_i1,
    FLD_O_i2,
    FLD_O_i3,
    FLD_O_i4,
    FLD_O_i5
};

enum DisasFieldIndexC {
    FLD_C_r1 = 0,
    FLD_C_m1 = 0,
    FLD_C_b1 = 0,
    FLD_C_i1 = 0,

    FLD_C_r2 = 1,
    FLD_C_b2 = 1,
    FLD_C_i2 = 1,

    FLD_C_r3 = 2,
    FLD_C_m3 = 2,
    FLD_C_i3 = 2,

    FLD_C_m4 = 3,
    FLD_C_b4 = 3,
    FLD_C_i4 = 3,
    FLD_C_l1 = 3,

    FLD_C_i5 = 4,
    FLD_C_d1 = 4,

    FLD_C_d2 = 5,

    FLD_C_d4 = 6,
    FLD_C_x2 = 6,
    FLD_C_l2 = 6,

    NUM_C_FIELD = 7
};

struct DisasFields {
1004
    uint64_t raw_insn;
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
    unsigned op:8;
    unsigned op2:8;
    unsigned presentC:16;
    unsigned int presentO;
    int c[NUM_C_FIELD];
};

/* This is the way fields are to be accessed out of DisasFields.  */
#define have_field(S, F)  have_field1((S), FLD_O_##F)
#define get_field(S, F)   get_field1((S), FLD_O_##F, FLD_C_##F)

static bool have_field1(const DisasFields *f, enum DisasFieldIndexO c)
{
    return (f->presentO >> c) & 1;
}

static int get_field1(const DisasFields *f, enum DisasFieldIndexO o,
                      enum DisasFieldIndexC c)
{
    assert(have_field1(f, o));
    return f->c[c];
}

/* Describe the layout of each field in each format.  */
typedef struct DisasField {
    unsigned int beg:8;
    unsigned int size:8;
    unsigned int type:2;
    unsigned int indexC:6;
    enum DisasFieldIndexO indexO:8;
} DisasField;

typedef struct DisasFormatInfo {
    DisasField op[NUM_C_FIELD];
} DisasFormatInfo;

#define R(N, B)       {  B,  4, 0, FLD_C_r##N, FLD_O_r##N }
#define M(N, B)       {  B,  4, 0, FLD_C_m##N, FLD_O_m##N }
#define BD(N, BB, BD) { BB,  4, 0, FLD_C_b##N, FLD_O_b##N }, \
                      { BD, 12, 0, FLD_C_d##N, FLD_O_d##N }
#define BXD(N)        { 16,  4, 0, FLD_C_b##N, FLD_O_b##N }, \
                      { 12,  4, 0, FLD_C_x##N, FLD_O_x##N }, \
                      { 20, 12, 0, FLD_C_d##N, FLD_O_d##N }
#define BDL(N)        { 16,  4, 0, FLD_C_b##N, FLD_O_b##N }, \
                      { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
#define BXDL(N)       { 16,  4, 0, FLD_C_b##N, FLD_O_b##N }, \
                      { 12,  4, 0, FLD_C_x##N, FLD_O_x##N }, \
                      { 20, 20, 2, FLD_C_d##N, FLD_O_d##N }
#define I(N, B, S)    {  B,  S, 1, FLD_C_i##N, FLD_O_i##N }
#define L(N, B, S)    {  B,  S, 0, FLD_C_l##N, FLD_O_l##N }

#define F0(N)                     { { } },
#define F1(N, X1)                 { { X1 } },
#define F2(N, X1, X2)             { { X1, X2 } },
#define F3(N, X1, X2, X3)         { { X1, X2, X3 } },
#define F4(N, X1, X2, X3, X4)     { { X1, X2, X3, X4 } },
#define F5(N, X1, X2, X3, X4, X5) { { X1, X2, X3, X4, X5 } },

static const DisasFormatInfo format_info[] = {
#include "insn-format.def"
};

#undef F0
#undef F1
#undef F2
#undef F3
#undef F4
#undef F5
#undef R
#undef M
#undef BD
#undef BXD
#undef BDL
#undef BXDL
#undef I
#undef L

/* Generally, we'll extract operands into this structures, operate upon
   them, and store them back.  See the "in1", "in2", "prep", "wout" sets
   of routines below for more details.  */
typedef struct {
    bool g_out, g_out2, g_in1, g_in2;
    TCGv_i64 out, out2, in1, in2;
    TCGv_i64 addr1;
} DisasOps;

1091 1092 1093 1094 1095 1096 1097 1098
/* Instructions can place constraints on their operands, raising specification
   exceptions if they are violated.  To make this easy to automate, each "in1",
   "in2", "prep", "wout" helper will have a SPEC_<name> define that equals one
   of the following, or 0.  To make this easy to document, we'll put the
   SPEC_<name> defines next to <name>.  */

#define SPEC_r1_even    1
#define SPEC_r2_even    2
1099 1100 1101
#define SPEC_r3_even    4
#define SPEC_r1_f128    8
#define SPEC_r2_f128    16
1102

1103
/* Return values from translate_one, indicating the state of the TB.  */
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121

/* We are not using a goto_tb (for whatever reason), but have updated
   the PC (for whatever reason), so there's no need to do it again on
   exiting the TB.  */
#define DISAS_PC_UPDATED        DISAS_TARGET_0

/* We have emitted one or more goto_tb.  No fixup required.  */
#define DISAS_GOTO_TB           DISAS_TARGET_1

/* We have updated the PC and CC values.  */
#define DISAS_PC_CC_UPDATED     DISAS_TARGET_2

/* We are exiting the TB, but have neither emitted a goto_tb, nor
   updated the PC for the next instruction to be executed.  */
#define DISAS_PC_STALE          DISAS_TARGET_3

/* We are exiting the TB to the main loop.  */
#define DISAS_PC_STALE_NOCHAIN  DISAS_TARGET_4
1122 1123 1124

struct DisasInsn {
    unsigned opc:16;
1125
    DisasFormat fmt:8;
1126
    unsigned fac:8;
1127
    unsigned spec:8;
1128 1129 1130 1131 1132 1133 1134 1135

    const char *name;

    void (*help_in1)(DisasContext *, DisasFields *, DisasOps *);
    void (*help_in2)(DisasContext *, DisasFields *, DisasOps *);
    void (*help_prep)(DisasContext *, DisasFields *, DisasOps *);
    void (*help_wout)(DisasContext *, DisasFields *, DisasOps *);
    void (*help_cout)(DisasContext *, DisasOps *);
1136
    DisasJumpType (*help_op)(DisasContext *, DisasOps *);
1137 1138 1139 1140

    uint64_t data;
};

1141
/* ====================================================================== */
P
Peter Maydell 已提交
1142
/* Miscellaneous helpers, used by several operations.  */
1143

1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
static void help_l2_shift(DisasContext *s, DisasFields *f,
                          DisasOps *o, int mask)
{
    int b2 = get_field(f, b2);
    int d2 = get_field(f, d2);

    if (b2 == 0) {
        o->in2 = tcg_const_i64(d2 & mask);
    } else {
        o->in2 = get_address(s, 0, b2, d2);
        tcg_gen_andi_i64(o->in2, o->in2, mask);
    }
}

1158
static DisasJumpType help_goto_direct(DisasContext *s, uint64_t dest)
1159
{
1160
    if (dest == s->pc_tmp) {
1161
        per_branch(s, true);
1162
        return DISAS_NEXT;
1163 1164
    }
    if (use_goto_tb(s, dest)) {
1165
        update_cc_op(s);
1166
        per_breaking_event(s);
1167 1168
        tcg_gen_goto_tb(0);
        tcg_gen_movi_i64(psw_addr, dest);
1169
        tcg_gen_exit_tb(s->base.tb, 0);
1170
        return DISAS_GOTO_TB;
1171 1172
    } else {
        tcg_gen_movi_i64(psw_addr, dest);
1173
        per_branch(s, false);
1174
        return DISAS_PC_UPDATED;
1175 1176 1177
    }
}

1178 1179
static DisasJumpType help_branch(DisasContext *s, DisasCompare *c,
                                 bool is_imm, int imm, TCGv_i64 cdest)
1180
{
1181
    DisasJumpType ret;
1182
    uint64_t dest = s->base.pc_next + 2 * imm;
1183
    TCGLabel *lab;
1184 1185 1186

    /* Take care of the special cases first.  */
    if (c->cond == TCG_COND_NEVER) {
1187
        ret = DISAS_NEXT;
1188 1189 1190
        goto egress;
    }
    if (is_imm) {
1191
        if (dest == s->pc_tmp) {
1192
            /* Branch to next.  */
1193
            per_branch(s, true);
1194
            ret = DISAS_NEXT;
1195 1196 1197 1198 1199 1200 1201
            goto egress;
        }
        if (c->cond == TCG_COND_ALWAYS) {
            ret = help_goto_direct(s, dest);
            goto egress;
        }
    } else {
1202
        if (!cdest) {
1203
            /* E.g. bcr %r0 -> no branch.  */
1204
            ret = DISAS_NEXT;
1205 1206 1207 1208
            goto egress;
        }
        if (c->cond == TCG_COND_ALWAYS) {
            tcg_gen_mov_i64(psw_addr, cdest);
1209
            per_branch(s, false);
1210
            ret = DISAS_PC_UPDATED;
1211 1212 1213 1214
            goto egress;
        }
    }

1215
    if (use_goto_tb(s, s->pc_tmp)) {
1216 1217
        if (is_imm && use_goto_tb(s, dest)) {
            /* Both exits can use goto_tb.  */
1218
            update_cc_op(s);
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228

            lab = gen_new_label();
            if (c->is_64) {
                tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
            } else {
                tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
            }

            /* Branch not taken.  */
            tcg_gen_goto_tb(0);
1229
            tcg_gen_movi_i64(psw_addr, s->pc_tmp);
1230
            tcg_gen_exit_tb(s->base.tb, 0);
1231 1232 1233

            /* Branch taken.  */
            gen_set_label(lab);
1234
            per_breaking_event(s);
1235 1236
            tcg_gen_goto_tb(1);
            tcg_gen_movi_i64(psw_addr, dest);
1237
            tcg_gen_exit_tb(s->base.tb, 1);
1238

1239
            ret = DISAS_GOTO_TB;
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256
        } else {
            /* Fallthru can use goto_tb, but taken branch cannot.  */
            /* Store taken branch destination before the brcond.  This
               avoids having to allocate a new local temp to hold it.
               We'll overwrite this in the not taken case anyway.  */
            if (!is_imm) {
                tcg_gen_mov_i64(psw_addr, cdest);
            }

            lab = gen_new_label();
            if (c->is_64) {
                tcg_gen_brcond_i64(c->cond, c->u.s64.a, c->u.s64.b, lab);
            } else {
                tcg_gen_brcond_i32(c->cond, c->u.s32.a, c->u.s32.b, lab);
            }

            /* Branch not taken.  */
1257
            update_cc_op(s);
1258
            tcg_gen_goto_tb(0);
1259
            tcg_gen_movi_i64(psw_addr, s->pc_tmp);
1260
            tcg_gen_exit_tb(s->base.tb, 0);
1261 1262 1263 1264 1265

            gen_set_label(lab);
            if (is_imm) {
                tcg_gen_movi_i64(psw_addr, dest);
            }
1266
            per_breaking_event(s);
1267
            ret = DISAS_PC_UPDATED;
1268 1269 1270 1271 1272 1273
        }
    } else {
        /* Fallthru cannot use goto_tb.  This by itself is vanishingly rare.
           Most commonly we're single-stepping or some other condition that
           disables all use of goto_tb.  Just update the PC and exit.  */

1274
        TCGv_i64 next = tcg_const_i64(s->pc_tmp);
1275 1276 1277 1278 1279 1280 1281
        if (is_imm) {
            cdest = tcg_const_i64(dest);
        }

        if (c->is_64) {
            tcg_gen_movcond_i64(c->cond, psw_addr, c->u.s64.a, c->u.s64.b,
                                cdest, next);
1282
            per_branch_cond(s, c->cond, c->u.s64.a, c->u.s64.b);
1283 1284 1285 1286 1287 1288 1289 1290
        } else {
            TCGv_i32 t0 = tcg_temp_new_i32();
            TCGv_i64 t1 = tcg_temp_new_i64();
            TCGv_i64 z = tcg_const_i64(0);
            tcg_gen_setcond_i32(c->cond, t0, c->u.s32.a, c->u.s32.b);
            tcg_gen_extu_i32_i64(t1, t0);
            tcg_temp_free_i32(t0);
            tcg_gen_movcond_i64(TCG_COND_NE, psw_addr, t1, z, cdest, next);
1291
            per_branch_cond(s, TCG_COND_NE, t1, z);
1292 1293 1294 1295 1296 1297 1298 1299 1300
            tcg_temp_free_i64(t1);
            tcg_temp_free_i64(z);
        }

        if (is_imm) {
            tcg_temp_free_i64(cdest);
        }
        tcg_temp_free_i64(next);

1301
        ret = DISAS_PC_UPDATED;
1302 1303 1304 1305 1306 1307 1308
    }

 egress:
    free_compare(c);
    return ret;
}

1309 1310 1311 1312
/* ====================================================================== */
/* The operations.  These perform the bulk of the work for any insn,
   usually after the operands have been loaded and output initialized.  */

1313
static DisasJumpType op_abs(DisasContext *s, DisasOps *o)
1314
{
1315 1316 1317 1318 1319 1320 1321
    TCGv_i64 z, n;
    z = tcg_const_i64(0);
    n = tcg_temp_new_i64();
    tcg_gen_neg_i64(n, o->in2);
    tcg_gen_movcond_i64(TCG_COND_LT, o->out, o->in2, z, n, o->in2);
    tcg_temp_free_i64(n);
    tcg_temp_free_i64(z);
1322
    return DISAS_NEXT;
1323 1324
}

1325
static DisasJumpType op_absf32(DisasContext *s, DisasOps *o)
1326 1327
{
    tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffull);
1328
    return DISAS_NEXT;
1329 1330
}

1331
static DisasJumpType op_absf64(DisasContext *s, DisasOps *o)
1332 1333
{
    tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull);
1334
    return DISAS_NEXT;
1335 1336
}

1337
static DisasJumpType op_absf128(DisasContext *s, DisasOps *o)
1338 1339 1340
{
    tcg_gen_andi_i64(o->out, o->in1, 0x7fffffffffffffffull);
    tcg_gen_mov_i64(o->out2, o->in2);
1341
    return DISAS_NEXT;
1342 1343
}

1344
static DisasJumpType op_add(DisasContext *s, DisasOps *o)
1345 1346
{
    tcg_gen_add_i64(o->out, o->in1, o->in2);
1347
    return DISAS_NEXT;
1348 1349
}

1350
static DisasJumpType op_addc(DisasContext *s, DisasOps *o)
1351
{
1352 1353
    DisasCompare cmp;
    TCGv_i64 carry;
1354 1355 1356

    tcg_gen_add_i64(o->out, o->in1, o->in2);

1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
    /* The carry flag is the msb of CC, therefore the branch mask that would
       create that comparison is 3.  Feeding the generated comparison to
       setcond produces the carry flag that we desire.  */
    disas_jcc(s, &cmp, 3);
    carry = tcg_temp_new_i64();
    if (cmp.is_64) {
        tcg_gen_setcond_i64(cmp.cond, carry, cmp.u.s64.a, cmp.u.s64.b);
    } else {
        TCGv_i32 t = tcg_temp_new_i32();
        tcg_gen_setcond_i32(cmp.cond, t, cmp.u.s32.a, cmp.u.s32.b);
        tcg_gen_extu_i32_i64(carry, t);
        tcg_temp_free_i32(t);
    }
    free_compare(&cmp);
1371

1372 1373
    tcg_gen_add_i64(o->out, o->out, carry);
    tcg_temp_free_i64(carry);
1374
    return DISAS_NEXT;
1375 1376
}

1377
static DisasJumpType op_asi(DisasContext *s, DisasOps *o)
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
{
    o->in1 = tcg_temp_new_i64();

    if (!s390_has_feat(S390_FEAT_STFLE_45)) {
        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
    } else {
        /* Perform the atomic addition in memory. */
        tcg_gen_atomic_fetch_add_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
                                     s->insn->data);
    }

    /* Recompute also for atomic case: needed for setting CC. */
    tcg_gen_add_i64(o->out, o->in1, o->in2);

    if (!s390_has_feat(S390_FEAT_STFLE_45)) {
        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
    }
1395
    return DISAS_NEXT;
1396 1397
}

1398
static DisasJumpType op_aeb(DisasContext *s, DisasOps *o)
1399 1400
{
    gen_helper_aeb(o->out, cpu_env, o->in1, o->in2);
1401
    return DISAS_NEXT;
1402 1403
}

1404
static DisasJumpType op_adb(DisasContext *s, DisasOps *o)
1405 1406
{
    gen_helper_adb(o->out, cpu_env, o->in1, o->in2);
1407
    return DISAS_NEXT;
1408 1409
}

1410
static DisasJumpType op_axb(DisasContext *s, DisasOps *o)
1411 1412 1413
{
    gen_helper_axb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
    return_low128(o->out2);
1414
    return DISAS_NEXT;
1415 1416
}

1417
static DisasJumpType op_and(DisasContext *s, DisasOps *o)
1418 1419
{
    tcg_gen_and_i64(o->out, o->in1, o->in2);
1420
    return DISAS_NEXT;
1421 1422
}

1423
static DisasJumpType op_andi(DisasContext *s, DisasOps *o)
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
{
    int shift = s->insn->data & 0xff;
    int size = s->insn->data >> 8;
    uint64_t mask = ((1ull << size) - 1) << shift;

    assert(!o->g_in2);
    tcg_gen_shli_i64(o->in2, o->in2, shift);
    tcg_gen_ori_i64(o->in2, o->in2, ~mask);
    tcg_gen_and_i64(o->out, o->in1, o->in2);

    /* Produce the CC from only the bits manipulated.  */
    tcg_gen_andi_i64(cc_dst, o->out, mask);
    set_cc_nz_u64(s, cc_dst);
1437
    return DISAS_NEXT;
1438 1439
}

1440
static DisasJumpType op_ni(DisasContext *s, DisasOps *o)
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
{
    o->in1 = tcg_temp_new_i64();

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
    } else {
        /* Perform the atomic operation in memory. */
        tcg_gen_atomic_fetch_and_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
                                     s->insn->data);
    }

    /* Recompute also for atomic case: needed for setting CC. */
    tcg_gen_and_i64(o->out, o->in1, o->in2);

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
    }
1458
    return DISAS_NEXT;
1459 1460
}

1461
static DisasJumpType op_bas(DisasContext *s, DisasOps *o)
1462
{
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
    pc_to_link_info(o->out, s, s->pc_tmp);
    if (o->in2) {
        tcg_gen_mov_i64(psw_addr, o->in2);
        per_branch(s, false);
        return DISAS_PC_UPDATED;
    } else {
        return DISAS_NEXT;
    }
}

static void save_link_info(DisasContext *s, DisasOps *o)
{
    TCGv_i64 t;

    if (s->base.tb->flags & (FLAG_MASK_32 | FLAG_MASK_64)) {
        pc_to_link_info(o->out, s, s->pc_tmp);
        return;
    }
    gen_op_calc_cc(s);
    tcg_gen_andi_i64(o->out, o->out, 0xffffffff00000000ull);
    tcg_gen_ori_i64(o->out, o->out, ((s->ilen / 2) << 30) | s->pc_tmp);
    t = tcg_temp_new_i64();
    tcg_gen_shri_i64(t, psw_mask, 16);
    tcg_gen_andi_i64(t, t, 0x0f000000);
    tcg_gen_or_i64(o->out, o->out, t);
    tcg_gen_extu_i32_i64(t, cc_op);
    tcg_gen_shli_i64(t, t, 28);
    tcg_gen_or_i64(o->out, o->out, t);
    tcg_temp_free_i64(t);
}

static DisasJumpType op_bal(DisasContext *s, DisasOps *o)
{
    save_link_info(s, o);
1497
    if (o->in2) {
1498
        tcg_gen_mov_i64(psw_addr, o->in2);
1499
        per_branch(s, false);
1500
        return DISAS_PC_UPDATED;
1501
    } else {
1502
        return DISAS_NEXT;
1503 1504 1505
    }
}

1506
static DisasJumpType op_basi(DisasContext *s, DisasOps *o)
1507
{
1508
    pc_to_link_info(o->out, s, s->pc_tmp);
1509
    return help_goto_direct(s, s->base.pc_next + 2 * get_field(s->fields, i2));
1510 1511
}

1512
static DisasJumpType op_bc(DisasContext *s, DisasOps *o)
1513 1514 1515 1516 1517 1518
{
    int m1 = get_field(s->fields, m1);
    bool is_imm = have_field(s->fields, i2);
    int imm = is_imm ? get_field(s->fields, i2) : 0;
    DisasCompare c;

1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
    /* BCR with R2 = 0 causes no branching */
    if (have_field(s->fields, r2) && get_field(s->fields, r2) == 0) {
        if (m1 == 14) {
            /* Perform serialization */
            /* FIXME: check for fast-BCR-serialization facility */
            tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
        }
        if (m1 == 15) {
            /* Perform serialization */
            /* FIXME: perform checkpoint-synchronisation */
            tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
        }
1531
        return DISAS_NEXT;
1532 1533
    }

1534 1535 1536 1537
    disas_jcc(s, &c, m1);
    return help_branch(s, &c, is_imm, imm, o->in2);
}

1538
static DisasJumpType op_bct32(DisasContext *s, DisasOps *o)
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
{
    int r1 = get_field(s->fields, r1);
    bool is_imm = have_field(s->fields, i2);
    int imm = is_imm ? get_field(s->fields, i2) : 0;
    DisasCompare c;
    TCGv_i64 t;

    c.cond = TCG_COND_NE;
    c.is_64 = false;
    c.g1 = false;
    c.g2 = false;

    t = tcg_temp_new_i64();
    tcg_gen_subi_i64(t, regs[r1], 1);
    store_reg32_i64(r1, t);
    c.u.s32.a = tcg_temp_new_i32();
    c.u.s32.b = tcg_const_i32(0);
1556
    tcg_gen_extrl_i64_i32(c.u.s32.a, t);
1557 1558 1559 1560 1561
    tcg_temp_free_i64(t);

    return help_branch(s, &c, is_imm, imm, o->in2);
}

1562
static DisasJumpType op_bcth(DisasContext *s, DisasOps *o)
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
{
    int r1 = get_field(s->fields, r1);
    int imm = get_field(s->fields, i2);
    DisasCompare c;
    TCGv_i64 t;

    c.cond = TCG_COND_NE;
    c.is_64 = false;
    c.g1 = false;
    c.g2 = false;

    t = tcg_temp_new_i64();
    tcg_gen_shri_i64(t, regs[r1], 32);
    tcg_gen_subi_i64(t, t, 1);
    store_reg32h_i64(r1, t);
    c.u.s32.a = tcg_temp_new_i32();
    c.u.s32.b = tcg_const_i32(0);
1580
    tcg_gen_extrl_i64_i32(c.u.s32.a, t);
1581 1582 1583 1584 1585
    tcg_temp_free_i64(t);

    return help_branch(s, &c, 1, imm, o->in2);
}

1586
static DisasJumpType op_bct64(DisasContext *s, DisasOps *o)
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601
{
    int r1 = get_field(s->fields, r1);
    bool is_imm = have_field(s->fields, i2);
    int imm = is_imm ? get_field(s->fields, i2) : 0;
    DisasCompare c;

    c.cond = TCG_COND_NE;
    c.is_64 = true;
    c.g1 = true;
    c.g2 = false;

    tcg_gen_subi_i64(regs[r1], regs[r1], 1);
    c.u.s64.a = regs[r1];
    c.u.s64.b = tcg_const_i64(0);

1602 1603 1604
    return help_branch(s, &c, is_imm, imm, o->in2);
}

1605
static DisasJumpType op_bx32(DisasContext *s, DisasOps *o)
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    bool is_imm = have_field(s->fields, i2);
    int imm = is_imm ? get_field(s->fields, i2) : 0;
    DisasCompare c;
    TCGv_i64 t;

    c.cond = (s->insn->data ? TCG_COND_LE : TCG_COND_GT);
    c.is_64 = false;
    c.g1 = false;
    c.g2 = false;

    t = tcg_temp_new_i64();
    tcg_gen_add_i64(t, regs[r1], regs[r3]);
    c.u.s32.a = tcg_temp_new_i32();
    c.u.s32.b = tcg_temp_new_i32();
1623 1624
    tcg_gen_extrl_i64_i32(c.u.s32.a, t);
    tcg_gen_extrl_i64_i32(c.u.s32.b, regs[r3 | 1]);
1625 1626 1627 1628 1629 1630
    store_reg32_i64(r1, t);
    tcg_temp_free_i64(t);

    return help_branch(s, &c, is_imm, imm, o->in2);
}

1631
static DisasJumpType op_bx64(DisasContext *s, DisasOps *o)
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    bool is_imm = have_field(s->fields, i2);
    int imm = is_imm ? get_field(s->fields, i2) : 0;
    DisasCompare c;

    c.cond = (s->insn->data ? TCG_COND_LE : TCG_COND_GT);
    c.is_64 = true;

    if (r1 == (r3 | 1)) {
        c.u.s64.b = load_reg(r3 | 1);
        c.g2 = false;
    } else {
        c.u.s64.b = regs[r3 | 1];
        c.g2 = true;
    }

    tcg_gen_add_i64(regs[r1], regs[r1], regs[r3]);
    c.u.s64.a = regs[r1];
    c.g1 = true;

1654 1655 1656
    return help_branch(s, &c, is_imm, imm, o->in2);
}

1657
static DisasJumpType op_cj(DisasContext *s, DisasOps *o)
1658 1659 1660 1661 1662
{
    int imm, m3 = get_field(s->fields, m3);
    bool is_imm;
    DisasCompare c;

1663
    c.cond = ltgt_cond[m3];
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
    if (s->insn->data) {
        c.cond = tcg_unsigned_cond(c.cond);
    }
    c.is_64 = c.g1 = c.g2 = true;
    c.u.s64.a = o->in1;
    c.u.s64.b = o->in2;

    is_imm = have_field(s->fields, i4);
    if (is_imm) {
        imm = get_field(s->fields, i4);
    } else {
        imm = 0;
        o->out = get_address(s, 0, get_field(s->fields, b4),
                             get_field(s->fields, d4));
    }

    return help_branch(s, &c, is_imm, imm, o->out);
}

1683
static DisasJumpType op_ceb(DisasContext *s, DisasOps *o)
1684 1685 1686
{
    gen_helper_ceb(cc_op, cpu_env, o->in1, o->in2);
    set_cc_static(s);
1687
    return DISAS_NEXT;
1688 1689
}

1690
static DisasJumpType op_cdb(DisasContext *s, DisasOps *o)
1691 1692 1693
{
    gen_helper_cdb(cc_op, cpu_env, o->in1, o->in2);
    set_cc_static(s);
1694
    return DISAS_NEXT;
1695 1696
}

1697
static DisasJumpType op_cxb(DisasContext *s, DisasOps *o)
1698 1699 1700
{
    gen_helper_cxb(cc_op, cpu_env, o->out, o->out2, o->in1, o->in2);
    set_cc_static(s);
1701
    return DISAS_NEXT;
1702 1703
}

1704
static DisasJumpType op_cfeb(DisasContext *s, DisasOps *o)
1705 1706 1707 1708 1709
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cfeb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f32(s, o->in2);
1710
    return DISAS_NEXT;
1711 1712
}

1713
static DisasJumpType op_cfdb(DisasContext *s, DisasOps *o)
1714 1715 1716 1717 1718
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cfdb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f64(s, o->in2);
1719
    return DISAS_NEXT;
1720 1721
}

1722
static DisasJumpType op_cfxb(DisasContext *s, DisasOps *o)
1723 1724 1725 1726 1727
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cfxb(o->out, cpu_env, o->in1, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f128(s, o->in1, o->in2);
1728
    return DISAS_NEXT;
1729 1730
}

1731
static DisasJumpType op_cgeb(DisasContext *s, DisasOps *o)
1732 1733 1734 1735 1736
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cgeb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f32(s, o->in2);
1737
    return DISAS_NEXT;
1738 1739
}

1740
static DisasJumpType op_cgdb(DisasContext *s, DisasOps *o)
1741 1742 1743 1744 1745
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cgdb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f64(s, o->in2);
1746
    return DISAS_NEXT;
1747 1748
}

1749
static DisasJumpType op_cgxb(DisasContext *s, DisasOps *o)
1750 1751 1752 1753 1754
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cgxb(o->out, cpu_env, o->in1, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f128(s, o->in1, o->in2);
1755
    return DISAS_NEXT;
1756 1757
}

1758
static DisasJumpType op_clfeb(DisasContext *s, DisasOps *o)
1759 1760 1761 1762 1763
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clfeb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f32(s, o->in2);
1764
    return DISAS_NEXT;
1765 1766
}

1767
static DisasJumpType op_clfdb(DisasContext *s, DisasOps *o)
1768 1769 1770 1771 1772
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clfdb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f64(s, o->in2);
1773
    return DISAS_NEXT;
1774 1775
}

1776
static DisasJumpType op_clfxb(DisasContext *s, DisasOps *o)
1777 1778 1779 1780 1781
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clfxb(o->out, cpu_env, o->in1, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f128(s, o->in1, o->in2);
1782
    return DISAS_NEXT;
1783 1784
}

1785
static DisasJumpType op_clgeb(DisasContext *s, DisasOps *o)
1786 1787 1788 1789 1790
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clgeb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f32(s, o->in2);
1791
    return DISAS_NEXT;
1792 1793
}

1794
static DisasJumpType op_clgdb(DisasContext *s, DisasOps *o)
1795 1796 1797 1798 1799
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clgdb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f64(s, o->in2);
1800
    return DISAS_NEXT;
1801 1802
}

1803
static DisasJumpType op_clgxb(DisasContext *s, DisasOps *o)
1804 1805 1806 1807 1808
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_clgxb(o->out, cpu_env, o->in1, o->in2, m3);
    tcg_temp_free_i32(m3);
    gen_set_cc_nz_f128(s, o->in1, o->in2);
1809
    return DISAS_NEXT;
1810 1811
}

1812
static DisasJumpType op_cegb(DisasContext *s, DisasOps *o)
1813 1814 1815 1816
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cegb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1817
    return DISAS_NEXT;
1818 1819
}

1820
static DisasJumpType op_cdgb(DisasContext *s, DisasOps *o)
1821 1822 1823 1824
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cdgb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1825
    return DISAS_NEXT;
1826 1827
}

1828
static DisasJumpType op_cxgb(DisasContext *s, DisasOps *o)
1829 1830 1831 1832
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cxgb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1833
    return_low128(o->out2);
1834
    return DISAS_NEXT;
1835 1836
}

1837
static DisasJumpType op_celgb(DisasContext *s, DisasOps *o)
1838 1839 1840 1841
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_celgb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1842
    return DISAS_NEXT;
1843 1844
}

1845
static DisasJumpType op_cdlgb(DisasContext *s, DisasOps *o)
1846 1847 1848 1849
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cdlgb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1850
    return DISAS_NEXT;
1851 1852
}

1853
static DisasJumpType op_cxlgb(DisasContext *s, DisasOps *o)
1854 1855 1856 1857
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_cxlgb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
1858
    return_low128(o->out2);
1859
    return DISAS_NEXT;
1860 1861
}

1862
static DisasJumpType op_cksm(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
{
    int r2 = get_field(s->fields, r2);
    TCGv_i64 len = tcg_temp_new_i64();

    gen_helper_cksm(len, cpu_env, o->in1, o->in2, regs[r2 + 1]);
    set_cc_static(s);
    return_low128(o->out);

    tcg_gen_add_i64(regs[r2], regs[r2], len);
    tcg_gen_sub_i64(regs[r2 + 1], regs[r2 + 1], len);
    tcg_temp_free_i64(len);

1875
    return DISAS_NEXT;
R
Richard Henderson 已提交
1876 1877
}

1878
static DisasJumpType op_clc(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
{
    int l = get_field(s->fields, l1);
    TCGv_i32 vl;

    switch (l + 1) {
    case 1:
        tcg_gen_qemu_ld8u(cc_src, o->addr1, get_mem_index(s));
        tcg_gen_qemu_ld8u(cc_dst, o->in2, get_mem_index(s));
        break;
    case 2:
        tcg_gen_qemu_ld16u(cc_src, o->addr1, get_mem_index(s));
        tcg_gen_qemu_ld16u(cc_dst, o->in2, get_mem_index(s));
        break;
    case 4:
        tcg_gen_qemu_ld32u(cc_src, o->addr1, get_mem_index(s));
        tcg_gen_qemu_ld32u(cc_dst, o->in2, get_mem_index(s));
        break;
    case 8:
        tcg_gen_qemu_ld64(cc_src, o->addr1, get_mem_index(s));
        tcg_gen_qemu_ld64(cc_dst, o->in2, get_mem_index(s));
        break;
    default:
        vl = tcg_const_i32(l);
        gen_helper_clc(cc_op, cpu_env, vl, o->addr1, o->in2);
        tcg_temp_free_i32(vl);
        set_cc_static(s);
1905
        return DISAS_NEXT;
R
Richard Henderson 已提交
1906 1907
    }
    gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, cc_src, cc_dst);
1908
    return DISAS_NEXT;
R
Richard Henderson 已提交
1909 1910
}

1911
static DisasJumpType op_clcl(DisasContext *s, DisasOps *o)
1912 1913 1914 1915 1916 1917 1918 1919
{
    int r1 = get_field(s->fields, r1);
    int r2 = get_field(s->fields, r2);
    TCGv_i32 t1, t2;

    /* r1 and r2 must be even.  */
    if (r1 & 1 || r2 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
1920
        return DISAS_NORETURN;
1921 1922 1923 1924 1925 1926 1927 1928
    }

    t1 = tcg_const_i32(r1);
    t2 = tcg_const_i32(r2);
    gen_helper_clcl(cc_op, cpu_env, t1, t2);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t2);
    set_cc_static(s);
1929
    return DISAS_NEXT;
1930 1931
}

1932
static DisasJumpType op_clcle(DisasContext *s, DisasOps *o)
1933
{
1934 1935 1936 1937 1938 1939 1940
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    TCGv_i32 t1, t3;

    /* r1 and r3 must be even.  */
    if (r1 & 1 || r3 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
1941
        return DISAS_NORETURN;
1942 1943 1944 1945 1946 1947 1948
    }

    t1 = tcg_const_i32(r1);
    t3 = tcg_const_i32(r3);
    gen_helper_clcle(cc_op, cpu_env, t1, o->in2, t3);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t3);
1949
    set_cc_static(s);
1950
    return DISAS_NEXT;
1951 1952
}

1953
static DisasJumpType op_clclu(DisasContext *s, DisasOps *o)
1954 1955 1956 1957 1958 1959 1960 1961
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    TCGv_i32 t1, t3;

    /* r1 and r3 must be even.  */
    if (r1 & 1 || r3 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
1962
        return DISAS_NORETURN;
1963 1964 1965 1966 1967 1968 1969 1970
    }

    t1 = tcg_const_i32(r1);
    t3 = tcg_const_i32(r3);
    gen_helper_clclu(cc_op, cpu_env, t1, o->in2, t3);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t3);
    set_cc_static(s);
1971
    return DISAS_NEXT;
1972 1973
}

1974
static DisasJumpType op_clm(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
1975 1976 1977
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    TCGv_i32 t1 = tcg_temp_new_i32();
1978
    tcg_gen_extrl_i64_i32(t1, o->in1);
R
Richard Henderson 已提交
1979 1980 1981 1982
    gen_helper_clm(cc_op, cpu_env, t1, m3, o->in2);
    set_cc_static(s);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(m3);
1983
    return DISAS_NEXT;
R
Richard Henderson 已提交
1984 1985
}

1986
static DisasJumpType op_clst(DisasContext *s, DisasOps *o)
1987 1988 1989 1990
{
    gen_helper_clst(o->in1, cpu_env, regs[0], o->in1, o->in2);
    set_cc_static(s);
    return_low128(o->in2);
1991
    return DISAS_NEXT;
1992 1993
}

1994
static DisasJumpType op_cps(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
1995 1996 1997 1998 1999 2000
{
    TCGv_i64 t = tcg_temp_new_i64();
    tcg_gen_andi_i64(t, o->in1, 0x8000000000000000ull);
    tcg_gen_andi_i64(o->out, o->in2, 0x7fffffffffffffffull);
    tcg_gen_or_i64(o->out, o->out, t);
    tcg_temp_free_i64(t);
2001
    return DISAS_NEXT;
R
Richard Henderson 已提交
2002 2003
}

2004
static DisasJumpType op_cs(DisasContext *s, DisasOps *o)
2005
{
2006 2007
    int d2 = get_field(s->fields, d2);
    int b2 = get_field(s->fields, b2);
2008
    TCGv_i64 addr, cc;
2009 2010 2011 2012 2013

    /* Note that in1 = R3 (new value) and
       in2 = (zero-extended) R1 (expected value).  */

    addr = get_address(s, 0, b2, d2);
2014 2015 2016
    tcg_gen_atomic_cmpxchg_i64(o->out, addr, o->in2, o->in1,
                               get_mem_index(s), s->insn->data | MO_ALIGN);
    tcg_temp_free_i64(addr);
2017 2018 2019 2020 2021

    /* Are the memory and expected values (un)equal?  Note that this setcond
       produces the output CC value, thus the NE sense of the test.  */
    cc = tcg_temp_new_i64();
    tcg_gen_setcond_i64(TCG_COND_NE, cc, o->in2, o->out);
2022
    tcg_gen_extrl_i64_i32(cc_op, cc);
2023
    tcg_temp_free_i64(cc);
2024
    set_cc_static(s);
2025

2026
    return DISAS_NEXT;
2027 2028
}

2029
static DisasJumpType op_cdsg(DisasContext *s, DisasOps *o)
2030
{
2031
    int r1 = get_field(s->fields, r1);
2032
    int r3 = get_field(s->fields, r3);
2033 2034
    int d2 = get_field(s->fields, d2);
    int b2 = get_field(s->fields, b2);
2035 2036
    TCGv_i64 addr;
    TCGv_i32 t_r1, t_r3;
2037 2038

    /* Note that R1:R1+1 = expected value and R3:R3+1 = new value.  */
2039 2040 2041
    addr = get_address(s, 0, b2, d2);
    t_r1 = tcg_const_i32(r1);
    t_r3 = tcg_const_i32(r3);
2042
    if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2043 2044 2045 2046
        gen_helper_cdsg_parallel(cpu_env, addr, t_r1, t_r3);
    } else {
        gen_helper_cdsg(cpu_env, addr, t_r1, t_r3);
    }
2047 2048 2049
    tcg_temp_free_i64(addr);
    tcg_temp_free_i32(t_r1);
    tcg_temp_free_i32(t_r3);
2050

2051
    set_cc_static(s);
2052
    return DISAS_NEXT;
2053 2054
}

2055
static DisasJumpType op_csst(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2056 2057 2058 2059
{
    int r3 = get_field(s->fields, r3);
    TCGv_i32 t_r3 = tcg_const_i32(r3);

2060
    if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2061
        gen_helper_csst_parallel(cc_op, cpu_env, t_r3, o->addr1, o->in2);
2062
    } else {
2063
        gen_helper_csst(cc_op, cpu_env, t_r3, o->addr1, o->in2);
2064
    }
R
Richard Henderson 已提交
2065 2066 2067
    tcg_temp_free_i32(t_r3);

    set_cc_static(s);
2068
    return DISAS_NEXT;
R
Richard Henderson 已提交
2069 2070
}

R
Richard Henderson 已提交
2071
#ifndef CONFIG_USER_ONLY
2072
static DisasJumpType op_csp(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2073
{
2074 2075 2076 2077 2078 2079 2080
    TCGMemOp mop = s->insn->data;
    TCGv_i64 addr, old, cc;
    TCGLabel *lab = gen_new_label();

    /* Note that in1 = R1 (zero-extended expected value),
       out = R1 (original reg), out2 = R1+1 (new value).  */

R
Richard Henderson 已提交
2081
    check_privileged(s);
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112
    addr = tcg_temp_new_i64();
    old = tcg_temp_new_i64();
    tcg_gen_andi_i64(addr, o->in2, -1ULL << (mop & MO_SIZE));
    tcg_gen_atomic_cmpxchg_i64(old, addr, o->in1, o->out2,
                               get_mem_index(s), mop | MO_ALIGN);
    tcg_temp_free_i64(addr);

    /* Are the memory and expected values (un)equal?  */
    cc = tcg_temp_new_i64();
    tcg_gen_setcond_i64(TCG_COND_NE, cc, o->in1, old);
    tcg_gen_extrl_i64_i32(cc_op, cc);

    /* Write back the output now, so that it happens before the
       following branch, so that we don't need local temps.  */
    if ((mop & MO_SIZE) == MO_32) {
        tcg_gen_deposit_i64(o->out, o->out, old, 0, 32);
    } else {
        tcg_gen_mov_i64(o->out, old);
    }
    tcg_temp_free_i64(old);

    /* If the comparison was equal, and the LSB of R2 was set,
       then we need to flush the TLB (for all cpus).  */
    tcg_gen_xori_i64(cc, cc, 1);
    tcg_gen_and_i64(cc, cc, o->in2);
    tcg_gen_brcondi_i64(TCG_COND_EQ, cc, 0, lab);
    tcg_temp_free_i64(cc);

    gen_helper_purge(cpu_env);
    gen_set_label(lab);

2113
    return DISAS_NEXT;
R
Richard Henderson 已提交
2114 2115 2116
}
#endif

2117
static DisasJumpType op_cvd(DisasContext *s, DisasOps *o)
2118 2119 2120
{
    TCGv_i64 t1 = tcg_temp_new_i64();
    TCGv_i32 t2 = tcg_temp_new_i32();
2121
    tcg_gen_extrl_i64_i32(t2, o->in1);
2122 2123 2124 2125
    gen_helper_cvd(t1, t2);
    tcg_temp_free_i32(t2);
    tcg_gen_qemu_st64(t1, o->in2, get_mem_index(s));
    tcg_temp_free_i64(t1);
2126
    return DISAS_NEXT;
2127 2128
}

2129
static DisasJumpType op_ct(DisasContext *s, DisasOps *o)
2130 2131
{
    int m3 = get_field(s->fields, m3);
2132
    TCGLabel *lab = gen_new_label();
2133 2134
    TCGCond c;

2135
    c = tcg_invert_cond(ltgt_cond[m3]);
2136 2137 2138 2139 2140 2141
    if (s->insn->data) {
        c = tcg_unsigned_cond(c);
    }
    tcg_gen_brcond_i64(c, o->in1, o->in2, lab);

    /* Trap.  */
2142
    gen_trap(s);
2143 2144

    gen_set_label(lab);
2145
    return DISAS_NEXT;
2146 2147
}

2148
static DisasJumpType op_cuXX(DisasContext *s, DisasOps *o)
2149 2150 2151 2152 2153 2154 2155 2156 2157
{
    int m3 = get_field(s->fields, m3);
    int r1 = get_field(s->fields, r1);
    int r2 = get_field(s->fields, r2);
    TCGv_i32 tr1, tr2, chk;

    /* R1 and R2 must both be even.  */
    if ((r1 | r2) & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
2158
        return DISAS_NORETURN;
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194
    }
    if (!s390_has_feat(S390_FEAT_ETF3_ENH)) {
        m3 = 0;
    }

    tr1 = tcg_const_i32(r1);
    tr2 = tcg_const_i32(r2);
    chk = tcg_const_i32(m3);

    switch (s->insn->data) {
    case 12:
        gen_helper_cu12(cc_op, cpu_env, tr1, tr2, chk);
        break;
    case 14:
        gen_helper_cu14(cc_op, cpu_env, tr1, tr2, chk);
        break;
    case 21:
        gen_helper_cu21(cc_op, cpu_env, tr1, tr2, chk);
        break;
    case 24:
        gen_helper_cu24(cc_op, cpu_env, tr1, tr2, chk);
        break;
    case 41:
        gen_helper_cu41(cc_op, cpu_env, tr1, tr2, chk);
        break;
    case 42:
        gen_helper_cu42(cc_op, cpu_env, tr1, tr2, chk);
        break;
    default:
        g_assert_not_reached();
    }

    tcg_temp_free_i32(tr1);
    tcg_temp_free_i32(tr2);
    tcg_temp_free_i32(chk);
    set_cc_static(s);
2195
    return DISAS_NEXT;
2196 2197
}

2198
#ifndef CONFIG_USER_ONLY
2199
static DisasJumpType op_diag(DisasContext *s, DisasOps *o)
2200
{
2201 2202 2203
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    TCGv_i32 func_code = tcg_const_i32(get_field(s->fields, i2));
2204 2205

    check_privileged(s);
2206 2207 2208 2209 2210
    gen_helper_diag(cpu_env, r1, r3, func_code);

    tcg_temp_free_i32(func_code);
    tcg_temp_free_i32(r3);
    tcg_temp_free_i32(r1);
2211
    return DISAS_NEXT;
2212 2213 2214
}
#endif

2215
static DisasJumpType op_divs32(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2216 2217 2218
{
    gen_helper_divs32(o->out2, cpu_env, o->in1, o->in2);
    return_low128(o->out);
2219
    return DISAS_NEXT;
R
Richard Henderson 已提交
2220 2221
}

2222
static DisasJumpType op_divu32(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2223 2224 2225
{
    gen_helper_divu32(o->out2, cpu_env, o->in1, o->in2);
    return_low128(o->out);
2226
    return DISAS_NEXT;
R
Richard Henderson 已提交
2227 2228
}

2229
static DisasJumpType op_divs64(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2230 2231 2232
{
    gen_helper_divs64(o->out2, cpu_env, o->in1, o->in2);
    return_low128(o->out);
2233
    return DISAS_NEXT;
R
Richard Henderson 已提交
2234 2235
}

2236
static DisasJumpType op_divu64(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2237 2238 2239
{
    gen_helper_divu64(o->out2, cpu_env, o->out, o->out2, o->in2);
    return_low128(o->out);
2240
    return DISAS_NEXT;
R
Richard Henderson 已提交
2241 2242
}

2243
static DisasJumpType op_deb(DisasContext *s, DisasOps *o)
2244 2245
{
    gen_helper_deb(o->out, cpu_env, o->in1, o->in2);
2246
    return DISAS_NEXT;
2247 2248
}

2249
static DisasJumpType op_ddb(DisasContext *s, DisasOps *o)
2250 2251
{
    gen_helper_ddb(o->out, cpu_env, o->in1, o->in2);
2252
    return DISAS_NEXT;
2253 2254
}

2255
static DisasJumpType op_dxb(DisasContext *s, DisasOps *o)
2256 2257 2258
{
    gen_helper_dxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
    return_low128(o->out2);
2259
    return DISAS_NEXT;
2260 2261
}

2262
static DisasJumpType op_ear(DisasContext *s, DisasOps *o)
2263 2264 2265
{
    int r2 = get_field(s->fields, r2);
    tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, aregs[r2]));
2266
    return DISAS_NEXT;
2267 2268
}

2269
static DisasJumpType op_ecag(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2270 2271 2272
{
    /* No cache information provided.  */
    tcg_gen_movi_i64(o->out, -1);
2273
    return DISAS_NEXT;
R
Richard Henderson 已提交
2274 2275
}

2276
static DisasJumpType op_efpc(DisasContext *s, DisasOps *o)
2277 2278
{
    tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, fpc));
2279
    return DISAS_NEXT;
2280 2281
}

2282
static DisasJumpType op_epsw(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
{
    int r1 = get_field(s->fields, r1);
    int r2 = get_field(s->fields, r2);
    TCGv_i64 t = tcg_temp_new_i64();

    /* Note the "subsequently" in the PoO, which implies a defined result
       if r1 == r2.  Thus we cannot defer these writes to an output hook.  */
    tcg_gen_shri_i64(t, psw_mask, 32);
    store_reg32_i64(r1, t);
    if (r2 != 0) {
        store_reg32_i64(r2, psw_mask);
    }

    tcg_temp_free_i64(t);
2297
    return DISAS_NEXT;
R
Richard Henderson 已提交
2298 2299
}

2300
static DisasJumpType op_ex(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2301
{
2302
    int r1 = get_field(s->fields, r1);
2303
    TCGv_i32 ilen;
2304
    TCGv_i64 v1;
R
Richard Henderson 已提交
2305

2306 2307 2308
    /* Nested EXECUTE is not allowed.  */
    if (unlikely(s->ex_value)) {
        gen_program_exception(s, PGM_EXECUTE);
2309
        return DISAS_NORETURN;
2310 2311
    }

R
Richard Henderson 已提交
2312
    update_psw_addr(s);
2313
    update_cc_op(s);
R
Richard Henderson 已提交
2314

2315 2316 2317 2318 2319 2320
    if (r1 == 0) {
        v1 = tcg_const_i64(0);
    } else {
        v1 = regs[r1];
    }

2321
    ilen = tcg_const_i32(s->ilen);
2322
    gen_helper_ex(cpu_env, ilen, v1, o->in2);
2323
    tcg_temp_free_i32(ilen);
R
Richard Henderson 已提交
2324

2325 2326 2327 2328
    if (r1 == 0) {
        tcg_temp_free_i64(v1);
    }

2329
    return DISAS_PC_CC_UPDATED;
R
Richard Henderson 已提交
2330 2331
}

2332
static DisasJumpType op_fieb(DisasContext *s, DisasOps *o)
2333 2334 2335 2336
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_fieb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
2337
    return DISAS_NEXT;
2338 2339
}

2340
static DisasJumpType op_fidb(DisasContext *s, DisasOps *o)
2341 2342 2343 2344
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_fidb(o->out, cpu_env, o->in2, m3);
    tcg_temp_free_i32(m3);
2345
    return DISAS_NEXT;
2346 2347
}

2348
static DisasJumpType op_fixb(DisasContext *s, DisasOps *o)
2349 2350 2351 2352 2353
{
    TCGv_i32 m3 = tcg_const_i32(get_field(s->fields, m3));
    gen_helper_fixb(o->out, cpu_env, o->in1, o->in2, m3);
    return_low128(o->out2);
    tcg_temp_free_i32(m3);
2354
    return DISAS_NEXT;
2355 2356
}

2357
static DisasJumpType op_flogr(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2358 2359 2360 2361 2362 2363 2364 2365
{
    /* We'll use the original input for cc computation, since we get to
       compare that against 0, which ought to be better than comparing
       the real output against 64.  It also lets cc_dst be a convenient
       temporary during our computation.  */
    gen_op_update1_cc_i64(s, CC_OP_FLOGR, o->in2);

    /* R1 = IN ? CLZ(IN) : 64.  */
R
Richard Henderson 已提交
2366
    tcg_gen_clzi_i64(o->out, o->in2, 64);
R
Richard Henderson 已提交
2367 2368 2369 2370 2371 2372 2373

    /* R1+1 = IN & ~(found bit).  Note that we may attempt to shift this
       value by 64, which is undefined.  But since the shift is 64 iff the
       input is zero, we still get the correct result after and'ing.  */
    tcg_gen_movi_i64(o->out2, 0x8000000000000000ull);
    tcg_gen_shr_i64(o->out2, o->out2, o->out);
    tcg_gen_andc_i64(o->out2, cc_dst, o->out2);
2374
    return DISAS_NEXT;
R
Richard Henderson 已提交
2375 2376
}

2377
static DisasJumpType op_icm(DisasContext *s, DisasOps *o)
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433
{
    int m3 = get_field(s->fields, m3);
    int pos, len, base = s->insn->data;
    TCGv_i64 tmp = tcg_temp_new_i64();
    uint64_t ccm;

    switch (m3) {
    case 0xf:
        /* Effectively a 32-bit load.  */
        tcg_gen_qemu_ld32u(tmp, o->in2, get_mem_index(s));
        len = 32;
        goto one_insert;

    case 0xc:
    case 0x6:
    case 0x3:
        /* Effectively a 16-bit load.  */
        tcg_gen_qemu_ld16u(tmp, o->in2, get_mem_index(s));
        len = 16;
        goto one_insert;

    case 0x8:
    case 0x4:
    case 0x2:
    case 0x1:
        /* Effectively an 8-bit load.  */
        tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
        len = 8;
        goto one_insert;

    one_insert:
        pos = base + ctz32(m3) * 8;
        tcg_gen_deposit_i64(o->out, o->out, tmp, pos, len);
        ccm = ((1ull << len) - 1) << pos;
        break;

    default:
        /* This is going to be a sequence of loads and inserts.  */
        pos = base + 32 - 8;
        ccm = 0;
        while (m3) {
            if (m3 & 0x8) {
                tcg_gen_qemu_ld8u(tmp, o->in2, get_mem_index(s));
                tcg_gen_addi_i64(o->in2, o->in2, 1);
                tcg_gen_deposit_i64(o->out, o->out, tmp, pos, 8);
                ccm |= 0xff << pos;
            }
            m3 = (m3 << 1) & 0xf;
            pos -= 8;
        }
        break;
    }

    tcg_gen_movi_i64(tmp, ccm);
    gen_op_update2_cc_i64(s, CC_OP_ICM, tmp, o->out);
    tcg_temp_free_i64(tmp);
2434
    return DISAS_NEXT;
2435 2436
}

2437
static DisasJumpType op_insi(DisasContext *s, DisasOps *o)
2438 2439 2440 2441
{
    int shift = s->insn->data & 0xff;
    int size = s->insn->data >> 8;
    tcg_gen_deposit_i64(o->out, o->in1, o->in2, shift, size);
2442
    return DISAS_NEXT;
2443 2444
}

2445
static DisasJumpType op_ipm(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2446
{
2447
    TCGv_i64 t1, t2;
R
Richard Henderson 已提交
2448 2449 2450

    gen_op_calc_cc(s);
    t1 = tcg_temp_new_i64();
2451 2452 2453 2454 2455
    tcg_gen_extract_i64(t1, psw_mask, 40, 4);
    t2 = tcg_temp_new_i64();
    tcg_gen_extu_i32_i64(t2, cc_op);
    tcg_gen_deposit_i64(t1, t1, t2, 4, 60);
    tcg_gen_deposit_i64(o->out, o->out, t1, 24, 8);
R
Richard Henderson 已提交
2456
    tcg_temp_free_i64(t1);
2457
    tcg_temp_free_i64(t2);
2458
    return DISAS_NEXT;
R
Richard Henderson 已提交
2459 2460
}

R
Richard Henderson 已提交
2461
#ifndef CONFIG_USER_ONLY
2462
static DisasJumpType op_idte(DisasContext *s, DisasOps *o)
2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
{
    TCGv_i32 m4;

    check_privileged(s);
    if (s390_has_feat(S390_FEAT_LOCAL_TLB_CLEARING)) {
        m4 = tcg_const_i32(get_field(s->fields, m4));
    } else {
        m4 = tcg_const_i32(0);
    }
    gen_helper_idte(cpu_env, o->in1, o->in2, m4);
    tcg_temp_free_i32(m4);
2474
    return DISAS_NEXT;
2475 2476
}

2477
static DisasJumpType op_ipte(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2478
{
2479 2480
    TCGv_i32 m4;

R
Richard Henderson 已提交
2481
    check_privileged(s);
2482 2483 2484 2485 2486
    if (s390_has_feat(S390_FEAT_LOCAL_TLB_CLEARING)) {
        m4 = tcg_const_i32(get_field(s->fields, m4));
    } else {
        m4 = tcg_const_i32(0);
    }
2487 2488
    gen_helper_ipte(cpu_env, o->in1, o->in2, m4);
    tcg_temp_free_i32(m4);
2489
    return DISAS_NEXT;
R
Richard Henderson 已提交
2490
}
R
Richard Henderson 已提交
2491

2492
static DisasJumpType op_iske(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2493 2494 2495
{
    check_privileged(s);
    gen_helper_iske(o->out, cpu_env, o->in2);
2496
    return DISAS_NEXT;
R
Richard Henderson 已提交
2497
}
R
Richard Henderson 已提交
2498 2499
#endif

2500
static DisasJumpType op_msa(DisasContext *s, DisasOps *o)
2501 2502 2503 2504 2505 2506 2507 2508 2509 2510
{
    int r1 = have_field(s->fields, r1) ? get_field(s->fields, r1) : 0;
    int r2 = have_field(s->fields, r2) ? get_field(s->fields, r2) : 0;
    int r3 = have_field(s->fields, r3) ? get_field(s->fields, r3) : 0;
    TCGv_i32 t_r1, t_r2, t_r3, type;

    switch (s->insn->data) {
    case S390_FEAT_TYPE_KMCTR:
        if (r3 & 1 || !r3) {
            gen_program_exception(s, PGM_SPECIFICATION);
2511
            return DISAS_NORETURN;
2512 2513 2514 2515 2516 2517 2518 2519 2520
        }
        /* FALL THROUGH */
    case S390_FEAT_TYPE_PPNO:
    case S390_FEAT_TYPE_KMF:
    case S390_FEAT_TYPE_KMC:
    case S390_FEAT_TYPE_KMO:
    case S390_FEAT_TYPE_KM:
        if (r1 & 1 || !r1) {
            gen_program_exception(s, PGM_SPECIFICATION);
2521
            return DISAS_NORETURN;
2522 2523 2524 2525 2526 2527 2528
        }
        /* FALL THROUGH */
    case S390_FEAT_TYPE_KMAC:
    case S390_FEAT_TYPE_KIMD:
    case S390_FEAT_TYPE_KLMD:
        if (r2 & 1 || !r2) {
            gen_program_exception(s, PGM_SPECIFICATION);
2529
            return DISAS_NORETURN;
2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548
        }
        /* FALL THROUGH */
    case S390_FEAT_TYPE_PCKMO:
    case S390_FEAT_TYPE_PCC:
        break;
    default:
        g_assert_not_reached();
    };

    t_r1 = tcg_const_i32(r1);
    t_r2 = tcg_const_i32(r2);
    t_r3 = tcg_const_i32(r3);
    type = tcg_const_i32(s->insn->data);
    gen_helper_msa(cc_op, cpu_env, t_r1, t_r2, t_r3, type);
    set_cc_static(s);
    tcg_temp_free_i32(t_r1);
    tcg_temp_free_i32(t_r2);
    tcg_temp_free_i32(t_r3);
    tcg_temp_free_i32(type);
2549
    return DISAS_NEXT;
2550 2551
}

2552
static DisasJumpType op_keb(DisasContext *s, DisasOps *o)
2553 2554 2555
{
    gen_helper_keb(cc_op, cpu_env, o->in1, o->in2);
    set_cc_static(s);
2556
    return DISAS_NEXT;
2557 2558
}

2559
static DisasJumpType op_kdb(DisasContext *s, DisasOps *o)
2560 2561 2562
{
    gen_helper_kdb(cc_op, cpu_env, o->in1, o->in2);
    set_cc_static(s);
2563
    return DISAS_NEXT;
2564 2565
}

2566
static DisasJumpType op_kxb(DisasContext *s, DisasOps *o)
2567 2568 2569
{
    gen_helper_kxb(cc_op, cpu_env, o->out, o->out2, o->in1, o->in2);
    set_cc_static(s);
2570
    return DISAS_NEXT;
2571 2572
}

2573
static DisasJumpType op_laa(DisasContext *s, DisasOps *o)
2574 2575 2576 2577 2578 2579 2580
{
    /* The real output is indeed the original value in memory;
       recompute the addition for the computation of CC.  */
    tcg_gen_atomic_fetch_add_i64(o->in2, o->in2, o->in1, get_mem_index(s),
                                 s->insn->data | MO_ALIGN);
    /* However, we need to recompute the addition for setting CC.  */
    tcg_gen_add_i64(o->out, o->in1, o->in2);
2581
    return DISAS_NEXT;
2582 2583
}

2584
static DisasJumpType op_lan(DisasContext *s, DisasOps *o)
2585 2586 2587 2588 2589 2590 2591
{
    /* The real output is indeed the original value in memory;
       recompute the addition for the computation of CC.  */
    tcg_gen_atomic_fetch_and_i64(o->in2, o->in2, o->in1, get_mem_index(s),
                                 s->insn->data | MO_ALIGN);
    /* However, we need to recompute the operation for setting CC.  */
    tcg_gen_and_i64(o->out, o->in1, o->in2);
2592
    return DISAS_NEXT;
2593 2594
}

2595
static DisasJumpType op_lao(DisasContext *s, DisasOps *o)
2596 2597 2598 2599 2600 2601 2602
{
    /* The real output is indeed the original value in memory;
       recompute the addition for the computation of CC.  */
    tcg_gen_atomic_fetch_or_i64(o->in2, o->in2, o->in1, get_mem_index(s),
                                s->insn->data | MO_ALIGN);
    /* However, we need to recompute the operation for setting CC.  */
    tcg_gen_or_i64(o->out, o->in1, o->in2);
2603
    return DISAS_NEXT;
2604 2605
}

2606
static DisasJumpType op_lax(DisasContext *s, DisasOps *o)
2607 2608 2609 2610 2611 2612 2613
{
    /* The real output is indeed the original value in memory;
       recompute the addition for the computation of CC.  */
    tcg_gen_atomic_fetch_xor_i64(o->in2, o->in2, o->in1, get_mem_index(s),
                                 s->insn->data | MO_ALIGN);
    /* However, we need to recompute the operation for setting CC.  */
    tcg_gen_xor_i64(o->out, o->in1, o->in2);
2614
    return DISAS_NEXT;
2615 2616
}

2617
static DisasJumpType op_ldeb(DisasContext *s, DisasOps *o)
2618 2619
{
    gen_helper_ldeb(o->out, cpu_env, o->in2);
2620
    return DISAS_NEXT;
2621 2622
}

2623
static DisasJumpType op_ledb(DisasContext *s, DisasOps *o)
2624 2625
{
    gen_helper_ledb(o->out, cpu_env, o->in2);
2626
    return DISAS_NEXT;
2627 2628
}

2629
static DisasJumpType op_ldxb(DisasContext *s, DisasOps *o)
2630 2631
{
    gen_helper_ldxb(o->out, cpu_env, o->in1, o->in2);
2632
    return DISAS_NEXT;
2633 2634
}

2635
static DisasJumpType op_lexb(DisasContext *s, DisasOps *o)
2636 2637
{
    gen_helper_lexb(o->out, cpu_env, o->in1, o->in2);
2638
    return DISAS_NEXT;
2639 2640
}

2641
static DisasJumpType op_lxdb(DisasContext *s, DisasOps *o)
2642 2643 2644
{
    gen_helper_lxdb(o->out, cpu_env, o->in2);
    return_low128(o->out2);
2645
    return DISAS_NEXT;
2646 2647
}

2648
static DisasJumpType op_lxeb(DisasContext *s, DisasOps *o)
2649 2650 2651
{
    gen_helper_lxeb(o->out, cpu_env, o->in2);
    return_low128(o->out2);
2652
    return DISAS_NEXT;
2653 2654
}

2655
static DisasJumpType op_llgt(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2656 2657
{
    tcg_gen_andi_i64(o->out, o->in2, 0x7fffffff);
2658
    return DISAS_NEXT;
R
Richard Henderson 已提交
2659 2660
}

2661
static DisasJumpType op_ld8s(DisasContext *s, DisasOps *o)
2662 2663
{
    tcg_gen_qemu_ld8s(o->out, o->in2, get_mem_index(s));
2664
    return DISAS_NEXT;
2665 2666
}

2667
static DisasJumpType op_ld8u(DisasContext *s, DisasOps *o)
2668 2669
{
    tcg_gen_qemu_ld8u(o->out, o->in2, get_mem_index(s));
2670
    return DISAS_NEXT;
2671 2672
}

2673
static DisasJumpType op_ld16s(DisasContext *s, DisasOps *o)
2674 2675
{
    tcg_gen_qemu_ld16s(o->out, o->in2, get_mem_index(s));
2676
    return DISAS_NEXT;
2677 2678
}

2679
static DisasJumpType op_ld16u(DisasContext *s, DisasOps *o)
2680 2681
{
    tcg_gen_qemu_ld16u(o->out, o->in2, get_mem_index(s));
2682
    return DISAS_NEXT;
2683 2684
}

2685
static DisasJumpType op_ld32s(DisasContext *s, DisasOps *o)
2686 2687
{
    tcg_gen_qemu_ld32s(o->out, o->in2, get_mem_index(s));
2688
    return DISAS_NEXT;
2689 2690
}

2691
static DisasJumpType op_ld32u(DisasContext *s, DisasOps *o)
2692 2693
{
    tcg_gen_qemu_ld32u(o->out, o->in2, get_mem_index(s));
2694
    return DISAS_NEXT;
2695 2696
}

2697
static DisasJumpType op_ld64(DisasContext *s, DisasOps *o)
2698 2699
{
    tcg_gen_qemu_ld64(o->out, o->in2, get_mem_index(s));
2700
    return DISAS_NEXT;
2701 2702
}

2703
static DisasJumpType op_lat(DisasContext *s, DisasOps *o)
2704 2705 2706 2707 2708 2709 2710
{
    TCGLabel *lab = gen_new_label();
    store_reg32_i64(get_field(s->fields, r1), o->in2);
    /* The value is stored even in case of trap. */
    tcg_gen_brcondi_i64(TCG_COND_NE, o->in2, 0, lab);
    gen_trap(s);
    gen_set_label(lab);
2711
    return DISAS_NEXT;
2712 2713
}

2714
static DisasJumpType op_lgat(DisasContext *s, DisasOps *o)
2715 2716 2717 2718 2719 2720 2721
{
    TCGLabel *lab = gen_new_label();
    tcg_gen_qemu_ld64(o->out, o->in2, get_mem_index(s));
    /* The value is stored even in case of trap. */
    tcg_gen_brcondi_i64(TCG_COND_NE, o->out, 0, lab);
    gen_trap(s);
    gen_set_label(lab);
2722
    return DISAS_NEXT;
2723 2724
}

2725
static DisasJumpType op_lfhat(DisasContext *s, DisasOps *o)
2726 2727 2728 2729 2730 2731 2732
{
    TCGLabel *lab = gen_new_label();
    store_reg32h_i64(get_field(s->fields, r1), o->in2);
    /* The value is stored even in case of trap. */
    tcg_gen_brcondi_i64(TCG_COND_NE, o->in2, 0, lab);
    gen_trap(s);
    gen_set_label(lab);
2733
    return DISAS_NEXT;
2734 2735
}

2736
static DisasJumpType op_llgfat(DisasContext *s, DisasOps *o)
2737 2738 2739 2740 2741 2742 2743
{
    TCGLabel *lab = gen_new_label();
    tcg_gen_qemu_ld32u(o->out, o->in2, get_mem_index(s));
    /* The value is stored even in case of trap. */
    tcg_gen_brcondi_i64(TCG_COND_NE, o->out, 0, lab);
    gen_trap(s);
    gen_set_label(lab);
2744
    return DISAS_NEXT;
2745 2746
}

2747
static DisasJumpType op_llgtat(DisasContext *s, DisasOps *o)
2748 2749 2750 2751 2752 2753 2754
{
    TCGLabel *lab = gen_new_label();
    tcg_gen_andi_i64(o->out, o->in2, 0x7fffffff);
    /* The value is stored even in case of trap. */
    tcg_gen_brcondi_i64(TCG_COND_NE, o->out, 0, lab);
    gen_trap(s);
    gen_set_label(lab);
2755
    return DISAS_NEXT;
2756 2757
}

2758
static DisasJumpType op_loc(DisasContext *s, DisasOps *o)
2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784
{
    DisasCompare c;

    disas_jcc(s, &c, get_field(s->fields, m3));

    if (c.is_64) {
        tcg_gen_movcond_i64(c.cond, o->out, c.u.s64.a, c.u.s64.b,
                            o->in2, o->in1);
        free_compare(&c);
    } else {
        TCGv_i32 t32 = tcg_temp_new_i32();
        TCGv_i64 t, z;

        tcg_gen_setcond_i32(c.cond, t32, c.u.s32.a, c.u.s32.b);
        free_compare(&c);

        t = tcg_temp_new_i64();
        tcg_gen_extu_i32_i64(t, t32);
        tcg_temp_free_i32(t32);

        z = tcg_const_i64(0);
        tcg_gen_movcond_i64(TCG_COND_NE, o->out, t, z, o->in2, o->in1);
        tcg_temp_free_i64(t);
        tcg_temp_free_i64(z);
    }

2785
    return DISAS_NEXT;
2786 2787
}

2788
#ifndef CONFIG_USER_ONLY
2789
static DisasJumpType op_lctl(DisasContext *s, DisasOps *o)
2790 2791 2792 2793 2794 2795 2796
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    check_privileged(s);
    gen_helper_lctl(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
2797
    /* Exit to main loop to reevaluate s390_cpu_exec_interrupt.  */
2798
    return DISAS_PC_STALE_NOCHAIN;
2799 2800
}

2801
static DisasJumpType op_lctlg(DisasContext *s, DisasOps *o)
2802 2803 2804 2805 2806 2807 2808
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    check_privileged(s);
    gen_helper_lctlg(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
2809
    /* Exit to main loop to reevaluate s390_cpu_exec_interrupt.  */
2810
    return DISAS_PC_STALE_NOCHAIN;
2811
}
2812

2813
static DisasJumpType op_lra(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2814 2815 2816 2817
{
    check_privileged(s);
    gen_helper_lra(o->out, cpu_env, o->in2);
    set_cc_static(s);
2818
    return DISAS_NEXT;
R
Richard Henderson 已提交
2819 2820
}

2821
static DisasJumpType op_lpp(DisasContext *s, DisasOps *o)
2822 2823 2824 2825
{
    check_privileged(s);

    tcg_gen_st_i64(o->in2, cpu_env, offsetof(CPUS390XState, pp));
2826
    return DISAS_NEXT;
2827 2828
}

2829
static DisasJumpType op_lpsw(DisasContext *s, DisasOps *o)
2830 2831 2832 2833
{
    TCGv_i64 t1, t2;

    check_privileged(s);
2834
    per_breaking_event(s);
2835 2836 2837

    t1 = tcg_temp_new_i64();
    t2 = tcg_temp_new_i64();
2838 2839
    tcg_gen_qemu_ld_i64(t1, o->in2, get_mem_index(s),
                        MO_TEUL | MO_ALIGN_8);
2840 2841 2842 2843 2844 2845 2846
    tcg_gen_addi_i64(o->in2, o->in2, 4);
    tcg_gen_qemu_ld32u(t2, o->in2, get_mem_index(s));
    /* Convert the 32-bit PSW_MASK into the 64-bit PSW_MASK.  */
    tcg_gen_shli_i64(t1, t1, 32);
    gen_helper_load_psw(cpu_env, t1, t2);
    tcg_temp_free_i64(t1);
    tcg_temp_free_i64(t2);
2847
    return DISAS_NORETURN;
2848
}
R
Richard Henderson 已提交
2849

2850
static DisasJumpType op_lpswe(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
2851 2852 2853 2854
{
    TCGv_i64 t1, t2;

    check_privileged(s);
2855
    per_breaking_event(s);
R
Richard Henderson 已提交
2856 2857 2858

    t1 = tcg_temp_new_i64();
    t2 = tcg_temp_new_i64();
2859 2860
    tcg_gen_qemu_ld_i64(t1, o->in2, get_mem_index(s),
                        MO_TEQ | MO_ALIGN_8);
R
Richard Henderson 已提交
2861 2862 2863 2864 2865
    tcg_gen_addi_i64(o->in2, o->in2, 8);
    tcg_gen_qemu_ld64(t2, o->in2, get_mem_index(s));
    gen_helper_load_psw(cpu_env, t1, t2);
    tcg_temp_free_i64(t1);
    tcg_temp_free_i64(t2);
2866
    return DISAS_NORETURN;
R
Richard Henderson 已提交
2867
}
2868 2869
#endif

2870
static DisasJumpType op_lam(DisasContext *s, DisasOps *o)
2871 2872 2873 2874 2875 2876
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    gen_helper_lam(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
2877
    return DISAS_NEXT;
2878 2879
}

2880
static DisasJumpType op_lm32(DisasContext *s, DisasOps *o)
2881 2882 2883
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
2884
    TCGv_i64 t1, t2;
2885

2886 2887 2888 2889 2890 2891
    /* Only one register to read. */
    t1 = tcg_temp_new_i64();
    if (unlikely(r1 == r3)) {
        tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
        store_reg32_i64(r1, t1);
        tcg_temp_free(t1);
2892
        return DISAS_NEXT;
2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907
    }

    /* First load the values of the first and last registers to trigger
       possible page faults. */
    t2 = tcg_temp_new_i64();
    tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
    tcg_gen_addi_i64(t2, o->in2, 4 * ((r3 - r1) & 15));
    tcg_gen_qemu_ld32u(t2, t2, get_mem_index(s));
    store_reg32_i64(r1, t1);
    store_reg32_i64(r3, t2);

    /* Only two registers to read. */
    if (((r1 + 1) & 15) == r3) {
        tcg_temp_free(t2);
        tcg_temp_free(t1);
2908
        return DISAS_NEXT;
2909 2910 2911 2912 2913 2914
    }

    /* Then load the remaining registers. Page fault can't occur. */
    r3 = (r3 - 1) & 15;
    tcg_gen_movi_i64(t2, 4);
    while (r1 != r3) {
2915
        r1 = (r1 + 1) & 15;
2916 2917 2918
        tcg_gen_add_i64(o->in2, o->in2, t2);
        tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
        store_reg32_i64(r1, t1);
2919
    }
2920 2921
    tcg_temp_free(t2);
    tcg_temp_free(t1);
2922

2923
    return DISAS_NEXT;
2924 2925
}

2926
static DisasJumpType op_lmh(DisasContext *s, DisasOps *o)
2927 2928 2929
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
2930
    TCGv_i64 t1, t2;
2931

2932 2933 2934 2935 2936 2937
    /* Only one register to read. */
    t1 = tcg_temp_new_i64();
    if (unlikely(r1 == r3)) {
        tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
        store_reg32h_i64(r1, t1);
        tcg_temp_free(t1);
2938
        return DISAS_NEXT;
2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953
    }

    /* First load the values of the first and last registers to trigger
       possible page faults. */
    t2 = tcg_temp_new_i64();
    tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
    tcg_gen_addi_i64(t2, o->in2, 4 * ((r3 - r1) & 15));
    tcg_gen_qemu_ld32u(t2, t2, get_mem_index(s));
    store_reg32h_i64(r1, t1);
    store_reg32h_i64(r3, t2);

    /* Only two registers to read. */
    if (((r1 + 1) & 15) == r3) {
        tcg_temp_free(t2);
        tcg_temp_free(t1);
2954
        return DISAS_NEXT;
2955 2956 2957 2958 2959 2960
    }

    /* Then load the remaining registers. Page fault can't occur. */
    r3 = (r3 - 1) & 15;
    tcg_gen_movi_i64(t2, 4);
    while (r1 != r3) {
2961
        r1 = (r1 + 1) & 15;
2962 2963 2964
        tcg_gen_add_i64(o->in2, o->in2, t2);
        tcg_gen_qemu_ld32u(t1, o->in2, get_mem_index(s));
        store_reg32h_i64(r1, t1);
2965
    }
2966 2967
    tcg_temp_free(t2);
    tcg_temp_free(t1);
2968

2969
    return DISAS_NEXT;
2970 2971
}

2972
static DisasJumpType op_lm64(DisasContext *s, DisasOps *o)
2973 2974 2975
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
2976
    TCGv_i64 t1, t2;
2977

2978 2979
    /* Only one register to read. */
    if (unlikely(r1 == r3)) {
2980
        tcg_gen_qemu_ld64(regs[r1], o->in2, get_mem_index(s));
2981
        return DISAS_NEXT;
2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996
    }

    /* First load the values of the first and last registers to trigger
       possible page faults. */
    t1 = tcg_temp_new_i64();
    t2 = tcg_temp_new_i64();
    tcg_gen_qemu_ld64(t1, o->in2, get_mem_index(s));
    tcg_gen_addi_i64(t2, o->in2, 8 * ((r3 - r1) & 15));
    tcg_gen_qemu_ld64(regs[r3], t2, get_mem_index(s));
    tcg_gen_mov_i64(regs[r1], t1);
    tcg_temp_free(t2);

    /* Only two registers to read. */
    if (((r1 + 1) & 15) == r3) {
        tcg_temp_free(t1);
2997
        return DISAS_NEXT;
2998 2999 3000 3001 3002 3003
    }

    /* Then load the remaining registers. Page fault can't occur. */
    r3 = (r3 - 1) & 15;
    tcg_gen_movi_i64(t1, 8);
    while (r1 != r3) {
3004
        r1 = (r1 + 1) & 15;
3005 3006
        tcg_gen_add_i64(o->in2, o->in2, t1);
        tcg_gen_qemu_ld64(regs[r1], o->in2, get_mem_index(s));
3007
    }
3008
    tcg_temp_free(t1);
3009

3010
    return DISAS_NEXT;
3011 3012
}

3013
static DisasJumpType op_lpd(DisasContext *s, DisasOps *o)
3014 3015 3016 3017 3018
{
    TCGv_i64 a1, a2;
    TCGMemOp mop = s->insn->data;

    /* In a parallel context, stop the world and single step.  */
3019
    if (tb_cflags(s->base.tb) & CF_PARALLEL) {
3020 3021
        update_psw_addr(s);
        update_cc_op(s);
3022
        gen_exception(EXCP_ATOMIC);
3023
        return DISAS_NORETURN;
3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035
    }

    /* In a serial context, perform the two loads ... */
    a1 = get_address(s, 0, get_field(s->fields, b1), get_field(s->fields, d1));
    a2 = get_address(s, 0, get_field(s->fields, b2), get_field(s->fields, d2));
    tcg_gen_qemu_ld_i64(o->out, a1, get_mem_index(s), mop | MO_ALIGN);
    tcg_gen_qemu_ld_i64(o->out2, a2, get_mem_index(s), mop | MO_ALIGN);
    tcg_temp_free_i64(a1);
    tcg_temp_free_i64(a2);

    /* ... and indicate that we performed them while interlocked.  */
    gen_op_movi_cc(s, 0);
3036
    return DISAS_NEXT;
3037 3038
}

3039
static DisasJumpType op_lpq(DisasContext *s, DisasOps *o)
3040
{
3041
    if (tb_cflags(s->base.tb) & CF_PARALLEL) {
3042 3043 3044 3045
        gen_helper_lpq_parallel(o->out, cpu_env, o->in2);
    } else {
        gen_helper_lpq(o->out, cpu_env, o->in2);
    }
3046
    return_low128(o->out2);
3047
    return DISAS_NEXT;
3048 3049
}

3050
#ifndef CONFIG_USER_ONLY
3051
static DisasJumpType op_lura(DisasContext *s, DisasOps *o)
3052 3053 3054
{
    check_privileged(s);
    gen_helper_lura(o->out, cpu_env, o->in2);
3055
    return DISAS_NEXT;
3056 3057
}

3058
static DisasJumpType op_lurag(DisasContext *s, DisasOps *o)
3059 3060 3061
{
    check_privileged(s);
    gen_helper_lurag(o->out, cpu_env, o->in2);
3062
    return DISAS_NEXT;
3063 3064 3065
}
#endif

3066
static DisasJumpType op_lzrb(DisasContext *s, DisasOps *o)
3067 3068
{
    tcg_gen_andi_i64(o->out, o->in2, -256);
3069
    return DISAS_NEXT;
3070 3071
}

3072
static DisasJumpType op_mov2(DisasContext *s, DisasOps *o)
3073 3074 3075
{
    o->out = o->in2;
    o->g_out = o->g_in2;
3076
    o->in2 = NULL;
3077
    o->g_in2 = false;
3078
    return DISAS_NEXT;
3079 3080
}

3081
static DisasJumpType op_mov2e(DisasContext *s, DisasOps *o)
3082 3083 3084 3085 3086 3087
{
    int b2 = get_field(s->fields, b2);
    TCGv ar1 = tcg_temp_new_i64();

    o->out = o->in2;
    o->g_out = o->g_in2;
3088
    o->in2 = NULL;
3089 3090
    o->g_in2 = false;

3091
    switch (s->base.tb->flags & FLAG_MASK_ASC) {
3092
    case PSW_ASC_PRIMARY >> FLAG_MASK_PSW_SHIFT:
3093 3094
        tcg_gen_movi_i64(ar1, 0);
        break;
3095
    case PSW_ASC_ACCREG >> FLAG_MASK_PSW_SHIFT:
3096 3097
        tcg_gen_movi_i64(ar1, 1);
        break;
3098
    case PSW_ASC_SECONDARY >> FLAG_MASK_PSW_SHIFT:
3099 3100 3101 3102 3103 3104
        if (b2) {
            tcg_gen_ld32u_i64(ar1, cpu_env, offsetof(CPUS390XState, aregs[b2]));
        } else {
            tcg_gen_movi_i64(ar1, 0);
        }
        break;
3105
    case PSW_ASC_HOME >> FLAG_MASK_PSW_SHIFT:
3106 3107 3108 3109 3110 3111 3112
        tcg_gen_movi_i64(ar1, 2);
        break;
    }

    tcg_gen_st32_i64(ar1, cpu_env, offsetof(CPUS390XState, aregs[1]));
    tcg_temp_free_i64(ar1);

3113
    return DISAS_NEXT;
3114 3115
}

3116
static DisasJumpType op_movx(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3117 3118 3119 3120 3121
{
    o->out = o->in1;
    o->out2 = o->in2;
    o->g_out = o->g_in1;
    o->g_out2 = o->g_in2;
3122 3123
    o->in1 = NULL;
    o->in2 = NULL;
R
Richard Henderson 已提交
3124
    o->g_in1 = o->g_in2 = false;
3125
    return DISAS_NEXT;
R
Richard Henderson 已提交
3126 3127
}

3128
static DisasJumpType op_mvc(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3129 3130 3131 3132
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_mvc(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3133
    return DISAS_NEXT;
R
Richard Henderson 已提交
3134 3135
}

3136
static DisasJumpType op_mvcin(DisasContext *s, DisasOps *o)
3137 3138 3139 3140
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_mvcin(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3141
    return DISAS_NEXT;
3142 3143
}

3144
static DisasJumpType op_mvcl(DisasContext *s, DisasOps *o)
3145
{
3146 3147 3148 3149 3150 3151 3152
    int r1 = get_field(s->fields, r1);
    int r2 = get_field(s->fields, r2);
    TCGv_i32 t1, t2;

    /* r1 and r2 must be even.  */
    if (r1 & 1 || r2 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
3153
        return DISAS_NORETURN;
3154 3155 3156 3157 3158 3159 3160
    }

    t1 = tcg_const_i32(r1);
    t2 = tcg_const_i32(r2);
    gen_helper_mvcl(cc_op, cpu_env, t1, t2);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t2);
3161
    set_cc_static(s);
3162
    return DISAS_NEXT;
3163 3164
}

3165
static DisasJumpType op_mvcle(DisasContext *s, DisasOps *o)
3166
{
3167 3168 3169 3170 3171 3172 3173
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    TCGv_i32 t1, t3;

    /* r1 and r3 must be even.  */
    if (r1 & 1 || r3 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
3174
        return DISAS_NORETURN;
3175 3176 3177 3178 3179 3180 3181
    }

    t1 = tcg_const_i32(r1);
    t3 = tcg_const_i32(r3);
    gen_helper_mvcle(cc_op, cpu_env, t1, o->in2, t3);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t3);
3182
    set_cc_static(s);
3183
    return DISAS_NEXT;
3184 3185
}

3186
static DisasJumpType op_mvclu(DisasContext *s, DisasOps *o)
3187 3188 3189 3190 3191 3192 3193 3194
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    TCGv_i32 t1, t3;

    /* r1 and r3 must be even.  */
    if (r1 & 1 || r3 & 1) {
        gen_program_exception(s, PGM_SPECIFICATION);
3195
        return DISAS_NORETURN;
3196 3197 3198 3199 3200 3201 3202 3203
    }

    t1 = tcg_const_i32(r1);
    t3 = tcg_const_i32(r3);
    gen_helper_mvclu(cc_op, cpu_env, t1, o->in2, t3);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t3);
    set_cc_static(s);
3204
    return DISAS_NEXT;
3205 3206
}

3207
static DisasJumpType op_mvcos(DisasContext *s, DisasOps *o)
3208 3209 3210 3211
{
    int r3 = get_field(s->fields, r3);
    gen_helper_mvcos(cc_op, cpu_env, o->addr1, o->in2, regs[r3]);
    set_cc_static(s);
3212
    return DISAS_NEXT;
3213 3214
}

3215
#ifndef CONFIG_USER_ONLY
3216
static DisasJumpType op_mvcp(DisasContext *s, DisasOps *o)
3217 3218 3219 3220 3221
{
    int r1 = get_field(s->fields, l1);
    check_privileged(s);
    gen_helper_mvcp(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
    set_cc_static(s);
3222
    return DISAS_NEXT;
3223 3224
}

3225
static DisasJumpType op_mvcs(DisasContext *s, DisasOps *o)
3226 3227 3228 3229 3230
{
    int r1 = get_field(s->fields, l1);
    check_privileged(s);
    gen_helper_mvcs(cc_op, cpu_env, regs[r1], o->addr1, o->in2);
    set_cc_static(s);
3231
    return DISAS_NEXT;
3232 3233 3234
}
#endif

3235
static DisasJumpType op_mvn(DisasContext *s, DisasOps *o)
3236 3237 3238 3239
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_mvn(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3240
    return DISAS_NEXT;
3241 3242
}

3243
static DisasJumpType op_mvo(DisasContext *s, DisasOps *o)
3244 3245 3246 3247
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_mvo(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3248
    return DISAS_NEXT;
3249 3250
}

3251
static DisasJumpType op_mvpg(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3252
{
3253
    gen_helper_mvpg(cc_op, cpu_env, regs[0], o->in1, o->in2);
R
Richard Henderson 已提交
3254
    set_cc_static(s);
3255
    return DISAS_NEXT;
R
Richard Henderson 已提交
3256 3257
}

3258
static DisasJumpType op_mvst(DisasContext *s, DisasOps *o)
3259 3260 3261 3262
{
    gen_helper_mvst(o->in1, cpu_env, regs[0], o->in1, o->in2);
    set_cc_static(s);
    return_low128(o->in2);
3263
    return DISAS_NEXT;
3264 3265
}

3266
static DisasJumpType op_mvz(DisasContext *s, DisasOps *o)
3267 3268 3269 3270
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_mvz(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3271
    return DISAS_NEXT;
3272 3273
}

3274
static DisasJumpType op_mul(DisasContext *s, DisasOps *o)
3275 3276
{
    tcg_gen_mul_i64(o->out, o->in1, o->in2);
3277
    return DISAS_NEXT;
3278 3279
}

3280
static DisasJumpType op_mul128(DisasContext *s, DisasOps *o)
3281
{
3282
    tcg_gen_mulu2_i64(o->out2, o->out, o->in1, o->in2);
3283
    return DISAS_NEXT;
3284 3285
}

3286
static DisasJumpType op_meeb(DisasContext *s, DisasOps *o)
3287 3288
{
    gen_helper_meeb(o->out, cpu_env, o->in1, o->in2);
3289
    return DISAS_NEXT;
3290 3291
}

3292
static DisasJumpType op_mdeb(DisasContext *s, DisasOps *o)
3293 3294
{
    gen_helper_mdeb(o->out, cpu_env, o->in1, o->in2);
3295
    return DISAS_NEXT;
3296 3297
}

3298
static DisasJumpType op_mdb(DisasContext *s, DisasOps *o)
3299 3300
{
    gen_helper_mdb(o->out, cpu_env, o->in1, o->in2);
3301
    return DISAS_NEXT;
3302 3303
}

3304
static DisasJumpType op_mxb(DisasContext *s, DisasOps *o)
3305 3306 3307
{
    gen_helper_mxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
    return_low128(o->out2);
3308
    return DISAS_NEXT;
3309 3310
}

3311
static DisasJumpType op_mxdb(DisasContext *s, DisasOps *o)
3312 3313 3314
{
    gen_helper_mxdb(o->out, cpu_env, o->out, o->out2, o->in2);
    return_low128(o->out2);
3315
    return DISAS_NEXT;
3316 3317
}

3318
static DisasJumpType op_maeb(DisasContext *s, DisasOps *o)
3319 3320 3321 3322
{
    TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
    gen_helper_maeb(o->out, cpu_env, o->in1, o->in2, r3);
    tcg_temp_free_i64(r3);
3323
    return DISAS_NEXT;
3324 3325
}

3326
static DisasJumpType op_madb(DisasContext *s, DisasOps *o)
3327 3328 3329
{
    int r3 = get_field(s->fields, r3);
    gen_helper_madb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
3330
    return DISAS_NEXT;
3331 3332
}

3333
static DisasJumpType op_mseb(DisasContext *s, DisasOps *o)
3334 3335 3336 3337
{
    TCGv_i64 r3 = load_freg32_i64(get_field(s->fields, r3));
    gen_helper_mseb(o->out, cpu_env, o->in1, o->in2, r3);
    tcg_temp_free_i64(r3);
3338
    return DISAS_NEXT;
3339 3340
}

3341
static DisasJumpType op_msdb(DisasContext *s, DisasOps *o)
3342 3343 3344
{
    int r3 = get_field(s->fields, r3);
    gen_helper_msdb(o->out, cpu_env, o->in1, o->in2, fregs[r3]);
3345
    return DISAS_NEXT;
3346 3347
}

3348
static DisasJumpType op_nabs(DisasContext *s, DisasOps *o)
3349
{
3350 3351 3352 3353 3354 3355 3356
    TCGv_i64 z, n;
    z = tcg_const_i64(0);
    n = tcg_temp_new_i64();
    tcg_gen_neg_i64(n, o->in2);
    tcg_gen_movcond_i64(TCG_COND_GE, o->out, o->in2, z, n, o->in2);
    tcg_temp_free_i64(n);
    tcg_temp_free_i64(z);
3357
    return DISAS_NEXT;
3358 3359
}

3360
static DisasJumpType op_nabsf32(DisasContext *s, DisasOps *o)
3361 3362
{
    tcg_gen_ori_i64(o->out, o->in2, 0x80000000ull);
3363
    return DISAS_NEXT;
3364 3365
}

3366
static DisasJumpType op_nabsf64(DisasContext *s, DisasOps *o)
3367 3368
{
    tcg_gen_ori_i64(o->out, o->in2, 0x8000000000000000ull);
3369
    return DISAS_NEXT;
3370 3371
}

3372
static DisasJumpType op_nabsf128(DisasContext *s, DisasOps *o)
3373 3374 3375
{
    tcg_gen_ori_i64(o->out, o->in1, 0x8000000000000000ull);
    tcg_gen_mov_i64(o->out2, o->in2);
3376
    return DISAS_NEXT;
3377 3378
}

3379
static DisasJumpType op_nc(DisasContext *s, DisasOps *o)
3380 3381 3382 3383 3384
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_nc(cc_op, cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
3385
    return DISAS_NEXT;
3386 3387
}

3388
static DisasJumpType op_neg(DisasContext *s, DisasOps *o)
3389 3390
{
    tcg_gen_neg_i64(o->out, o->in2);
3391
    return DISAS_NEXT;
3392 3393
}

3394
static DisasJumpType op_negf32(DisasContext *s, DisasOps *o)
3395 3396
{
    tcg_gen_xori_i64(o->out, o->in2, 0x80000000ull);
3397
    return DISAS_NEXT;
3398 3399
}

3400
static DisasJumpType op_negf64(DisasContext *s, DisasOps *o)
3401 3402
{
    tcg_gen_xori_i64(o->out, o->in2, 0x8000000000000000ull);
3403
    return DISAS_NEXT;
3404 3405
}

3406
static DisasJumpType op_negf128(DisasContext *s, DisasOps *o)
3407 3408 3409
{
    tcg_gen_xori_i64(o->out, o->in1, 0x8000000000000000ull);
    tcg_gen_mov_i64(o->out2, o->in2);
3410
    return DISAS_NEXT;
3411 3412
}

3413
static DisasJumpType op_oc(DisasContext *s, DisasOps *o)
3414 3415 3416 3417 3418
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_oc(cc_op, cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
3419
    return DISAS_NEXT;
3420 3421
}

3422
static DisasJumpType op_or(DisasContext *s, DisasOps *o)
3423 3424
{
    tcg_gen_or_i64(o->out, o->in1, o->in2);
3425
    return DISAS_NEXT;
3426 3427
}

3428
static DisasJumpType op_ori(DisasContext *s, DisasOps *o)
3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440
{
    int shift = s->insn->data & 0xff;
    int size = s->insn->data >> 8;
    uint64_t mask = ((1ull << size) - 1) << shift;

    assert(!o->g_in2);
    tcg_gen_shli_i64(o->in2, o->in2, shift);
    tcg_gen_or_i64(o->out, o->in1, o->in2);

    /* Produce the CC from only the bits manipulated.  */
    tcg_gen_andi_i64(cc_dst, o->out, mask);
    set_cc_nz_u64(s, cc_dst);
3441
    return DISAS_NEXT;
3442 3443
}

3444
static DisasJumpType op_oi(DisasContext *s, DisasOps *o)
3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461
{
    o->in1 = tcg_temp_new_i64();

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
    } else {
        /* Perform the atomic operation in memory. */
        tcg_gen_atomic_fetch_or_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
                                    s->insn->data);
    }

    /* Recompute also for atomic case: needed for setting CC. */
    tcg_gen_or_i64(o->out, o->in1, o->in2);

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
    }
3462
    return DISAS_NEXT;
3463 3464
}

3465
static DisasJumpType op_pack(DisasContext *s, DisasOps *o)
A
Aurelien Jarno 已提交
3466 3467 3468 3469
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_pack(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
3470
    return DISAS_NEXT;
A
Aurelien Jarno 已提交
3471 3472
}

3473
static DisasJumpType op_pka(DisasContext *s, DisasOps *o)
3474 3475 3476 3477 3478 3479 3480
{
    int l2 = get_field(s->fields, l2) + 1;
    TCGv_i32 l;

    /* The length must not exceed 32 bytes.  */
    if (l2 > 32) {
        gen_program_exception(s, PGM_SPECIFICATION);
3481
        return DISAS_NORETURN;
3482 3483 3484 3485
    }
    l = tcg_const_i32(l2);
    gen_helper_pka(cpu_env, o->addr1, o->in2, l);
    tcg_temp_free_i32(l);
3486
    return DISAS_NEXT;
3487 3488
}

3489
static DisasJumpType op_pku(DisasContext *s, DisasOps *o)
3490 3491 3492 3493 3494 3495 3496
{
    int l2 = get_field(s->fields, l2) + 1;
    TCGv_i32 l;

    /* The length must be even and should not exceed 64 bytes.  */
    if ((l2 & 1) || (l2 > 64)) {
        gen_program_exception(s, PGM_SPECIFICATION);
3497
        return DISAS_NORETURN;
3498 3499 3500 3501
    }
    l = tcg_const_i32(l2);
    gen_helper_pku(cpu_env, o->addr1, o->in2, l);
    tcg_temp_free_i32(l);
3502
    return DISAS_NEXT;
3503 3504
}

3505
static DisasJumpType op_popcnt(DisasContext *s, DisasOps *o)
3506 3507
{
    gen_helper_popcnt(o->out, o->in2);
3508
    return DISAS_NEXT;
3509 3510
}

R
Richard Henderson 已提交
3511
#ifndef CONFIG_USER_ONLY
3512
static DisasJumpType op_ptlb(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3513 3514 3515
{
    check_privileged(s);
    gen_helper_ptlb(cpu_env);
3516
    return DISAS_NEXT;
R
Richard Henderson 已提交
3517 3518 3519
}
#endif

3520
static DisasJumpType op_risbg(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531
{
    int i3 = get_field(s->fields, i3);
    int i4 = get_field(s->fields, i4);
    int i5 = get_field(s->fields, i5);
    int do_zero = i4 & 0x80;
    uint64_t mask, imask, pmask;
    int pos, len, rot;

    /* Adjust the arguments for the specific insn.  */
    switch (s->fields->op2) {
    case 0x55: /* risbg */
3532
    case 0x59: /* risbgn */
R
Richard Henderson 已提交
3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547
        i3 &= 63;
        i4 &= 63;
        pmask = ~0;
        break;
    case 0x5d: /* risbhg */
        i3 &= 31;
        i4 &= 31;
        pmask = 0xffffffff00000000ull;
        break;
    case 0x51: /* risblg */
        i3 &= 31;
        i4 &= 31;
        pmask = 0x00000000ffffffffull;
        break;
    default:
3548
        g_assert_not_reached();
R
Richard Henderson 已提交
3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564
    }

    /* MASK is the set of bits to be inserted from R2.
       Take care for I3/I4 wraparound.  */
    mask = pmask >> i3;
    if (i3 <= i4) {
        mask ^= pmask >> i4 >> 1;
    } else {
        mask |= ~(pmask >> i4 >> 1);
    }
    mask &= pmask;

    /* IMASK is the set of bits to be kept from R1.  In the case of the high/low
       insns, we need to keep the other half of the register.  */
    imask = ~mask | ~pmask;
    if (do_zero) {
3565
        imask = ~pmask;
R
Richard Henderson 已提交
3566 3567
    }

3568 3569 3570 3571 3572 3573 3574 3575
    len = i4 - i3 + 1;
    pos = 63 - i4;
    rot = i5 & 63;
    if (s->fields->op2 == 0x5d) {
        pos += 32;
    }

    /* In some cases we can implement this with extract.  */
3576 3577
    if (imask == 0 && pos == 0 && len > 0 && len <= rot) {
        tcg_gen_extract_i64(o->out, o->in2, 64 - rot, len);
3578
        return DISAS_NEXT;
3579 3580 3581 3582
    }

    /* In some cases we can implement this with deposit.  */
    if (len > 0 && (imask == 0 || ~mask == imask)) {
R
Richard Henderson 已提交
3583 3584
        /* Note that we rotate the bits to be inserted to the lsb, not to
           the position as described in the PoO.  */
3585
        rot = (rot - pos) & 63;
R
Richard Henderson 已提交
3586
    } else {
3587
        pos = -1;
R
Richard Henderson 已提交
3588 3589 3590 3591 3592 3593 3594
    }

    /* Rotate the input as necessary.  */
    tcg_gen_rotli_i64(o->in2, o->in2, rot);

    /* Insert the selected bits into the output.  */
    if (pos >= 0) {
3595 3596 3597 3598 3599
        if (imask == 0) {
            tcg_gen_deposit_z_i64(o->out, o->in2, pos, len);
        } else {
            tcg_gen_deposit_i64(o->out, o->out, o->in2, pos, len);
        }
R
Richard Henderson 已提交
3600 3601 3602 3603 3604 3605 3606
    } else if (imask == 0) {
        tcg_gen_andi_i64(o->out, o->in2, mask);
    } else {
        tcg_gen_andi_i64(o->in2, o->in2, mask);
        tcg_gen_andi_i64(o->out, o->out, imask);
        tcg_gen_or_i64(o->out, o->out, o->in2);
    }
3607
    return DISAS_NEXT;
3608 3609
}

3610
static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o)
3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659
{
    int i3 = get_field(s->fields, i3);
    int i4 = get_field(s->fields, i4);
    int i5 = get_field(s->fields, i5);
    uint64_t mask;

    /* If this is a test-only form, arrange to discard the result.  */
    if (i3 & 0x80) {
        o->out = tcg_temp_new_i64();
        o->g_out = false;
    }

    i3 &= 63;
    i4 &= 63;
    i5 &= 63;

    /* MASK is the set of bits to be operated on from R2.
       Take care for I3/I4 wraparound.  */
    mask = ~0ull >> i3;
    if (i3 <= i4) {
        mask ^= ~0ull >> i4 >> 1;
    } else {
        mask |= ~(~0ull >> i4 >> 1);
    }

    /* Rotate the input as necessary.  */
    tcg_gen_rotli_i64(o->in2, o->in2, i5);

    /* Operate.  */
    switch (s->fields->op2) {
    case 0x55: /* AND */
        tcg_gen_ori_i64(o->in2, o->in2, ~mask);
        tcg_gen_and_i64(o->out, o->out, o->in2);
        break;
    case 0x56: /* OR */
        tcg_gen_andi_i64(o->in2, o->in2, mask);
        tcg_gen_or_i64(o->out, o->out, o->in2);
        break;
    case 0x57: /* XOR */
        tcg_gen_andi_i64(o->in2, o->in2, mask);
        tcg_gen_xor_i64(o->out, o->out, o->in2);
        break;
    default:
        abort();
    }

    /* Set the CC.  */
    tcg_gen_andi_i64(cc_dst, o->out, mask);
    set_cc_nz_u64(s, cc_dst);
3660
    return DISAS_NEXT;
R
Richard Henderson 已提交
3661 3662
}

3663
static DisasJumpType op_rev16(DisasContext *s, DisasOps *o)
3664 3665
{
    tcg_gen_bswap16_i64(o->out, o->in2);
3666
    return DISAS_NEXT;
3667 3668
}

3669
static DisasJumpType op_rev32(DisasContext *s, DisasOps *o)
3670 3671
{
    tcg_gen_bswap32_i64(o->out, o->in2);
3672
    return DISAS_NEXT;
3673 3674
}

3675
static DisasJumpType op_rev64(DisasContext *s, DisasOps *o)
3676 3677
{
    tcg_gen_bswap64_i64(o->out, o->in2);
3678
    return DISAS_NEXT;
3679 3680
}

3681
static DisasJumpType op_rll32(DisasContext *s, DisasOps *o)
3682 3683 3684 3685
{
    TCGv_i32 t1 = tcg_temp_new_i32();
    TCGv_i32 t2 = tcg_temp_new_i32();
    TCGv_i32 to = tcg_temp_new_i32();
3686 3687
    tcg_gen_extrl_i64_i32(t1, o->in1);
    tcg_gen_extrl_i64_i32(t2, o->in2);
3688 3689 3690 3691 3692
    tcg_gen_rotl_i32(to, t1, t2);
    tcg_gen_extu_i32_i64(o->out, to);
    tcg_temp_free_i32(t1);
    tcg_temp_free_i32(t2);
    tcg_temp_free_i32(to);
3693
    return DISAS_NEXT;
3694 3695
}

3696
static DisasJumpType op_rll64(DisasContext *s, DisasOps *o)
3697 3698
{
    tcg_gen_rotl_i64(o->out, o->in1, o->in2);
3699
    return DISAS_NEXT;
3700 3701
}

R
Richard Henderson 已提交
3702
#ifndef CONFIG_USER_ONLY
3703
static DisasJumpType op_rrbe(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3704 3705 3706 3707
{
    check_privileged(s);
    gen_helper_rrbe(cc_op, cpu_env, o->in2);
    set_cc_static(s);
3708
    return DISAS_NEXT;
R
Richard Henderson 已提交
3709
}
R
Richard Henderson 已提交
3710

3711
static DisasJumpType op_sacf(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3712 3713 3714 3715
{
    check_privileged(s);
    gen_helper_sacf(cpu_env, o->in2);
    /* Addressing mode has changed, so end the block.  */
3716
    return DISAS_PC_STALE;
R
Richard Henderson 已提交
3717
}
3718
#endif
A
Alexander Graf 已提交
3719

3720
static DisasJumpType op_sam(DisasContext *s, DisasOps *o)
A
Alexander Graf 已提交
3721 3722
{
    int sam = s->insn->data;
3723 3724
    TCGv_i64 tsam;
    uint64_t mask;
A
Alexander Graf 已提交
3725

3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737
    switch (sam) {
    case 0:
        mask = 0xffffff;
        break;
    case 1:
        mask = 0x7fffffff;
        break;
    default:
        mask = -1;
        break;
    }

S
Stefan Weil 已提交
3738
    /* Bizarre but true, we check the address of the current insn for the
3739 3740
       specification exception, not the next to be executed.  Thus the PoO
       documents that Bad Things Happen two bytes before the end.  */
3741
    if (s->base.pc_next & ~mask) {
3742
        gen_program_exception(s, PGM_SPECIFICATION);
3743
        return DISAS_NORETURN;
3744
    }
3745
    s->pc_tmp &= mask;
A
Alexander Graf 已提交
3746

3747 3748
    tsam = tcg_const_i64(sam);
    tcg_gen_deposit_i64(psw_mask, psw_mask, tsam, 31, 2);
A
Alexander Graf 已提交
3749
    tcg_temp_free_i64(tsam);
3750 3751

    /* Always exit the TB, since we (may have) changed execution mode.  */
3752
    return DISAS_PC_STALE;
A
Alexander Graf 已提交
3753
}
R
Richard Henderson 已提交
3754

3755
static DisasJumpType op_sar(DisasContext *s, DisasOps *o)
3756 3757 3758
{
    int r1 = get_field(s->fields, r1);
    tcg_gen_st32_i64(o->in2, cpu_env, offsetof(CPUS390XState, aregs[r1]));
3759
    return DISAS_NEXT;
3760 3761
}

3762
static DisasJumpType op_seb(DisasContext *s, DisasOps *o)
3763 3764
{
    gen_helper_seb(o->out, cpu_env, o->in1, o->in2);
3765
    return DISAS_NEXT;
3766 3767
}

3768
static DisasJumpType op_sdb(DisasContext *s, DisasOps *o)
3769 3770
{
    gen_helper_sdb(o->out, cpu_env, o->in1, o->in2);
3771
    return DISAS_NEXT;
3772 3773
}

3774
static DisasJumpType op_sxb(DisasContext *s, DisasOps *o)
3775 3776 3777
{
    gen_helper_sxb(o->out, cpu_env, o->out, o->out2, o->in1, o->in2);
    return_low128(o->out2);
3778
    return DISAS_NEXT;
3779 3780
}

3781
static DisasJumpType op_sqeb(DisasContext *s, DisasOps *o)
3782 3783
{
    gen_helper_sqeb(o->out, cpu_env, o->in2);
3784
    return DISAS_NEXT;
3785 3786
}

3787
static DisasJumpType op_sqdb(DisasContext *s, DisasOps *o)
3788 3789
{
    gen_helper_sqdb(o->out, cpu_env, o->in2);
3790
    return DISAS_NEXT;
3791 3792
}

3793
static DisasJumpType op_sqxb(DisasContext *s, DisasOps *o)
3794 3795 3796
{
    gen_helper_sqxb(o->out, cpu_env, o->in1, o->in2);
    return_low128(o->out2);
3797
    return DISAS_NEXT;
3798 3799
}

R
Richard Henderson 已提交
3800
#ifndef CONFIG_USER_ONLY
3801
static DisasJumpType op_servc(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3802 3803 3804 3805
{
    check_privileged(s);
    gen_helper_servc(cc_op, cpu_env, o->in2, o->in1);
    set_cc_static(s);
3806
    return DISAS_NEXT;
R
Richard Henderson 已提交
3807 3808
}

3809
static DisasJumpType op_sigp(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3810 3811
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
3812
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
R
Richard Henderson 已提交
3813
    check_privileged(s);
3814
    gen_helper_sigp(cc_op, cpu_env, o->in2, r1, r3);
3815
    set_cc_static(s);
R
Richard Henderson 已提交
3816
    tcg_temp_free_i32(r1);
3817
    tcg_temp_free_i32(r3);
3818
    return DISAS_NEXT;
R
Richard Henderson 已提交
3819 3820 3821
}
#endif

3822
static DisasJumpType op_soc(DisasContext *s, DisasOps *o)
3823 3824
{
    DisasCompare c;
3825
    TCGv_i64 a, h;
3826 3827
    TCGLabel *lab;
    int r1;
3828 3829 3830

    disas_jcc(s, &c, get_field(s->fields, m3));

A
Alexander Graf 已提交
3831 3832 3833 3834
    /* We want to store when the condition is fulfilled, so branch
       out when it's not */
    c.cond = tcg_invert_cond(c.cond);

3835 3836 3837 3838 3839 3840 3841 3842 3843 3844
    lab = gen_new_label();
    if (c.is_64) {
        tcg_gen_brcond_i64(c.cond, c.u.s64.a, c.u.s64.b, lab);
    } else {
        tcg_gen_brcond_i32(c.cond, c.u.s32.a, c.u.s32.b, lab);
    }
    free_compare(&c);

    r1 = get_field(s->fields, r1);
    a = get_address(s, 0, get_field(s->fields, b2), get_field(s->fields, d2));
3845 3846
    switch (s->insn->data) {
    case 1: /* STOCG */
3847
        tcg_gen_qemu_st64(regs[r1], a, get_mem_index(s));
3848 3849
        break;
    case 0: /* STOC */
3850
        tcg_gen_qemu_st32(regs[r1], a, get_mem_index(s));
3851 3852 3853 3854 3855 3856 3857 3858 3859
        break;
    case 2: /* STOCFH */
        h = tcg_temp_new_i64();
        tcg_gen_shri_i64(h, regs[r1], 32);
        tcg_gen_qemu_st32(h, a, get_mem_index(s));
        tcg_temp_free_i64(h);
        break;
    default:
        g_assert_not_reached();
3860 3861 3862 3863
    }
    tcg_temp_free_i64(a);

    gen_set_label(lab);
3864
    return DISAS_NEXT;
3865 3866
}

3867
static DisasJumpType op_sla(DisasContext *s, DisasOps *o)
3868 3869 3870 3871 3872 3873 3874 3875 3876 3877
{
    uint64_t sign = 1ull << s->insn->data;
    enum cc_op cco = s->insn->data == 31 ? CC_OP_SLA_32 : CC_OP_SLA_64;
    gen_op_update2_cc_i64(s, cco, o->in1, o->in2);
    tcg_gen_shl_i64(o->out, o->in1, o->in2);
    /* The arithmetic left shift is curious in that it does not affect
       the sign bit.  Copy that over from the source unchanged.  */
    tcg_gen_andi_i64(o->out, o->out, ~sign);
    tcg_gen_andi_i64(o->in1, o->in1, sign);
    tcg_gen_or_i64(o->out, o->out, o->in1);
3878
    return DISAS_NEXT;
3879 3880
}

3881
static DisasJumpType op_sll(DisasContext *s, DisasOps *o)
3882 3883
{
    tcg_gen_shl_i64(o->out, o->in1, o->in2);
3884
    return DISAS_NEXT;
3885 3886
}

3887
static DisasJumpType op_sra(DisasContext *s, DisasOps *o)
3888 3889
{
    tcg_gen_sar_i64(o->out, o->in1, o->in2);
3890
    return DISAS_NEXT;
3891 3892
}

3893
static DisasJumpType op_srl(DisasContext *s, DisasOps *o)
3894 3895
{
    tcg_gen_shr_i64(o->out, o->in1, o->in2);
3896
    return DISAS_NEXT;
3897 3898
}

3899
static DisasJumpType op_sfpc(DisasContext *s, DisasOps *o)
3900 3901
{
    gen_helper_sfpc(cpu_env, o->in2);
3902
    return DISAS_NEXT;
3903 3904
}

3905
static DisasJumpType op_sfas(DisasContext *s, DisasOps *o)
3906 3907
{
    gen_helper_sfas(cpu_env, o->in2);
3908
    return DISAS_NEXT;
3909 3910
}

3911
static DisasJumpType op_srnm(DisasContext *s, DisasOps *o)
3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927
{
    int b2 = get_field(s->fields, b2);
    int d2 = get_field(s->fields, d2);
    TCGv_i64 t1 = tcg_temp_new_i64();
    TCGv_i64 t2 = tcg_temp_new_i64();
    int mask, pos, len;

    switch (s->fields->op2) {
    case 0x99: /* SRNM */
        pos = 0, len = 2;
        break;
    case 0xb8: /* SRNMB */
        pos = 0, len = 3;
        break;
    case 0xb9: /* SRNMT */
        pos = 4, len = 3;
R
Richard Henderson 已提交
3928
        break;
3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947
    default:
        tcg_abort();
    }
    mask = (1 << len) - 1;

    /* Insert the value into the appropriate field of the FPC.  */
    if (b2 == 0) {
        tcg_gen_movi_i64(t1, d2 & mask);
    } else {
        tcg_gen_addi_i64(t1, regs[b2], d2);
        tcg_gen_andi_i64(t1, t1, mask);
    }
    tcg_gen_ld32u_i64(t2, cpu_env, offsetof(CPUS390XState, fpc));
    tcg_gen_deposit_i64(t2, t2, t1, pos, len);
    tcg_temp_free_i64(t1);

    /* Then install the new FPC to set the rounding mode in fpu_status.  */
    gen_helper_sfpc(cpu_env, t2);
    tcg_temp_free_i64(t2);
3948
    return DISAS_NEXT;
3949 3950
}

3951
static DisasJumpType op_spm(DisasContext *s, DisasOps *o)
3952 3953 3954 3955 3956 3957 3958
{
    tcg_gen_extrl_i64_i32(cc_op, o->in1);
    tcg_gen_extract_i32(cc_op, cc_op, 28, 2);
    set_cc_static(s);

    tcg_gen_shri_i64(o->in1, o->in1, 24);
    tcg_gen_deposit_i64(psw_mask, psw_mask, o->in1, PSW_SHIFT_MASK_PM, 4);
3959
    return DISAS_NEXT;
3960 3961
}

3962
static DisasJumpType op_ectg(DisasContext *s, DisasOps *o)
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988
{
    int b1 = get_field(s->fields, b1);
    int d1 = get_field(s->fields, d1);
    int b2 = get_field(s->fields, b2);
    int d2 = get_field(s->fields, d2);
    int r3 = get_field(s->fields, r3);
    TCGv_i64 tmp = tcg_temp_new_i64();

    /* fetch all operands first */
    o->in1 = tcg_temp_new_i64();
    tcg_gen_addi_i64(o->in1, regs[b1], d1);
    o->in2 = tcg_temp_new_i64();
    tcg_gen_addi_i64(o->in2, regs[b2], d2);
    o->addr1 = get_address(s, 0, r3, 0);

    /* load the third operand into r3 before modifying anything */
    tcg_gen_qemu_ld64(regs[r3], o->addr1, get_mem_index(s));

    /* subtract CPU timer from first operand and store in GR0 */
    gen_helper_stpt(tmp, cpu_env);
    tcg_gen_sub_i64(regs[0], o->in1, tmp);

    /* store second operand in GR1 */
    tcg_gen_mov_i64(regs[1], o->in2);

    tcg_temp_free_i64(tmp);
3989
    return DISAS_NEXT;
3990 3991
}

3992
#ifndef CONFIG_USER_ONLY
3993
static DisasJumpType op_spka(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
3994 3995 3996
{
    check_privileged(s);
    tcg_gen_shri_i64(o->in2, o->in2, 4);
3997
    tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, PSW_SHIFT_KEY, 4);
3998
    return DISAS_NEXT;
R
Richard Henderson 已提交
3999 4000
}

4001
static DisasJumpType op_sske(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4002 4003 4004
{
    check_privileged(s);
    gen_helper_sske(cpu_env, o->in1, o->in2);
4005
    return DISAS_NEXT;
R
Richard Henderson 已提交
4006 4007
}

4008
static DisasJumpType op_ssm(DisasContext *s, DisasOps *o)
4009 4010 4011
{
    check_privileged(s);
    tcg_gen_deposit_i64(psw_mask, psw_mask, o->in2, 56, 8);
4012
    /* Exit to main loop to reevaluate s390_cpu_exec_interrupt.  */
4013
    return DISAS_PC_STALE_NOCHAIN;
4014
}
4015

4016
static DisasJumpType op_stap(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4017 4018
{
    check_privileged(s);
4019
    tcg_gen_ld32u_i64(o->out, cpu_env, offsetof(CPUS390XState, core_id));
4020
    return DISAS_NEXT;
R
Richard Henderson 已提交
4021 4022
}

4023
static DisasJumpType op_stck(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4024 4025 4026 4027
{
    gen_helper_stck(o->out, cpu_env);
    /* ??? We don't implement clock states.  */
    gen_op_movi_cc(s, 0);
4028
    return DISAS_NEXT;
R
Richard Henderson 已提交
4029 4030
}

4031
static DisasJumpType op_stcke(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4032 4033 4034
{
    TCGv_i64 c1 = tcg_temp_new_i64();
    TCGv_i64 c2 = tcg_temp_new_i64();
4035
    TCGv_i64 todpr = tcg_temp_new_i64();
R
Richard Henderson 已提交
4036
    gen_helper_stck(c1, cpu_env);
4037 4038
    /* 16 bit value store in an uint32_t (only valid bits set) */
    tcg_gen_ld32u_i64(todpr, cpu_env, offsetof(CPUS390XState, todpr));
R
Richard Henderson 已提交
4039 4040 4041 4042 4043 4044 4045
    /* Shift the 64-bit value into its place as a zero-extended
       104-bit value.  Note that "bit positions 64-103 are always
       non-zero so that they compare differently to STCK"; we set
       the least significant bit to 1.  */
    tcg_gen_shli_i64(c2, c1, 56);
    tcg_gen_shri_i64(c1, c1, 8);
    tcg_gen_ori_i64(c2, c2, 0x10000);
4046
    tcg_gen_or_i64(c2, c2, todpr);
R
Richard Henderson 已提交
4047 4048 4049 4050 4051
    tcg_gen_qemu_st64(c1, o->in2, get_mem_index(s));
    tcg_gen_addi_i64(o->in2, o->in2, 8);
    tcg_gen_qemu_st64(c2, o->in2, get_mem_index(s));
    tcg_temp_free_i64(c1);
    tcg_temp_free_i64(c2);
4052
    tcg_temp_free_i64(todpr);
R
Richard Henderson 已提交
4053 4054
    /* ??? We don't implement clock states.  */
    gen_op_movi_cc(s, 0);
4055
    return DISAS_NEXT;
R
Richard Henderson 已提交
4056 4057
}

4058 4059 4060 4061 4062 4063 4064 4065 4066
static DisasJumpType op_sck(DisasContext *s, DisasOps *o)
{
    check_privileged(s);
    tcg_gen_qemu_ld_i64(o->in1, o->addr1, get_mem_index(s), MO_TEQ | MO_ALIGN);
    gen_helper_sck(cc_op, cpu_env, o->in1);
    set_cc_static(s);
    return DISAS_NEXT;
}

4067
static DisasJumpType op_sckc(DisasContext *s, DisasOps *o)
4068 4069 4070
{
    check_privileged(s);
    gen_helper_sckc(cpu_env, o->in2);
4071
    return DISAS_NEXT;
4072 4073
}

4074
static DisasJumpType op_sckpf(DisasContext *s, DisasOps *o)
4075 4076 4077
{
    check_privileged(s);
    gen_helper_sckpf(cpu_env, regs[0]);
4078
    return DISAS_NEXT;
4079 4080
}

4081
static DisasJumpType op_stckc(DisasContext *s, DisasOps *o)
4082 4083 4084
{
    check_privileged(s);
    gen_helper_stckc(o->out, cpu_env);
4085
    return DISAS_NEXT;
4086 4087
}

4088
static DisasJumpType op_stctg(DisasContext *s, DisasOps *o)
4089 4090 4091 4092 4093 4094 4095
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    check_privileged(s);
    gen_helper_stctg(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
4096
    return DISAS_NEXT;
4097 4098
}

4099
static DisasJumpType op_stctl(DisasContext *s, DisasOps *o)
4100 4101 4102 4103 4104 4105 4106
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    check_privileged(s);
    gen_helper_stctl(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
4107
    return DISAS_NEXT;
4108 4109
}

4110
static DisasJumpType op_stidp(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4111 4112
{
    check_privileged(s);
4113
    tcg_gen_ld_i64(o->out, cpu_env, offsetof(CPUS390XState, cpuid));
4114
    return DISAS_NEXT;
R
Richard Henderson 已提交
4115 4116
}

4117
static DisasJumpType op_spt(DisasContext *s, DisasOps *o)
4118 4119 4120
{
    check_privileged(s);
    gen_helper_spt(cpu_env, o->in2);
4121
    return DISAS_NEXT;
4122 4123
}

4124
static DisasJumpType op_stfl(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4125 4126
{
    check_privileged(s);
4127
    gen_helper_stfl(cpu_env);
4128
    return DISAS_NEXT;
R
Richard Henderson 已提交
4129 4130
}

4131
static DisasJumpType op_stpt(DisasContext *s, DisasOps *o)
4132 4133 4134
{
    check_privileged(s);
    gen_helper_stpt(o->out, cpu_env);
4135
    return DISAS_NEXT;
4136 4137
}

4138
static DisasJumpType op_stsi(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4139 4140 4141 4142
{
    check_privileged(s);
    gen_helper_stsi(cc_op, cpu_env, o->in2, regs[0], regs[1]);
    set_cc_static(s);
4143
    return DISAS_NEXT;
R
Richard Henderson 已提交
4144 4145
}

4146
static DisasJumpType op_spx(DisasContext *s, DisasOps *o)
4147 4148 4149
{
    check_privileged(s);
    gen_helper_spx(cpu_env, o->in2);
4150
    return DISAS_NEXT;
4151 4152
}

4153
static DisasJumpType op_xsch(DisasContext *s, DisasOps *o)
4154 4155
{
    check_privileged(s);
4156 4157
    gen_helper_xsch(cpu_env, regs[1]);
    set_cc_static(s);
4158
    return DISAS_NEXT;
4159 4160
}

4161
static DisasJumpType op_csch(DisasContext *s, DisasOps *o)
4162 4163 4164 4165
{
    check_privileged(s);
    gen_helper_csch(cpu_env, regs[1]);
    set_cc_static(s);
4166
    return DISAS_NEXT;
4167 4168
}

4169
static DisasJumpType op_hsch(DisasContext *s, DisasOps *o)
4170 4171 4172 4173
{
    check_privileged(s);
    gen_helper_hsch(cpu_env, regs[1]);
    set_cc_static(s);
4174
    return DISAS_NEXT;
4175 4176
}

4177
static DisasJumpType op_msch(DisasContext *s, DisasOps *o)
4178 4179 4180 4181
{
    check_privileged(s);
    gen_helper_msch(cpu_env, regs[1], o->in2);
    set_cc_static(s);
4182
    return DISAS_NEXT;
4183 4184
}

4185
static DisasJumpType op_rchp(DisasContext *s, DisasOps *o)
4186 4187 4188 4189
{
    check_privileged(s);
    gen_helper_rchp(cpu_env, regs[1]);
    set_cc_static(s);
4190
    return DISAS_NEXT;
4191 4192
}

4193
static DisasJumpType op_rsch(DisasContext *s, DisasOps *o)
4194 4195 4196 4197
{
    check_privileged(s);
    gen_helper_rsch(cpu_env, regs[1]);
    set_cc_static(s);
4198
    return DISAS_NEXT;
4199 4200
}

4201
static DisasJumpType op_sal(DisasContext *s, DisasOps *o)
4202 4203 4204
{
    check_privileged(s);
    gen_helper_sal(cpu_env, regs[1]);
4205
    return DISAS_NEXT;
4206 4207
}

4208
static DisasJumpType op_schm(DisasContext *s, DisasOps *o)
4209 4210 4211
{
    check_privileged(s);
    gen_helper_schm(cpu_env, regs[1], regs[2], o->in2);
4212
    return DISAS_NEXT;
4213 4214
}

4215
static DisasJumpType op_siga(DisasContext *s, DisasOps *o)
4216 4217 4218 4219
{
    check_privileged(s);
    /* From KVM code: Not provided, set CC = 3 for subchannel not operational */
    gen_op_movi_cc(s, 3);
4220
    return DISAS_NEXT;
4221 4222
}

4223
static DisasJumpType op_stcps(DisasContext *s, DisasOps *o)
4224 4225 4226
{
    check_privileged(s);
    /* The instruction is suppressed if not provided. */
4227
    return DISAS_NEXT;
4228 4229
}

4230
static DisasJumpType op_ssch(DisasContext *s, DisasOps *o)
4231 4232 4233 4234
{
    check_privileged(s);
    gen_helper_ssch(cpu_env, regs[1], o->in2);
    set_cc_static(s);
4235
    return DISAS_NEXT;
4236 4237
}

4238
static DisasJumpType op_stsch(DisasContext *s, DisasOps *o)
4239 4240 4241 4242
{
    check_privileged(s);
    gen_helper_stsch(cpu_env, regs[1], o->in2);
    set_cc_static(s);
4243
    return DISAS_NEXT;
4244 4245
}

4246
static DisasJumpType op_stcrw(DisasContext *s, DisasOps *o)
4247 4248 4249 4250
{
    check_privileged(s);
    gen_helper_stcrw(cpu_env, o->in2);
    set_cc_static(s);
4251
    return DISAS_NEXT;
4252 4253
}

4254
static DisasJumpType op_tpi(DisasContext *s, DisasOps *o)
4255 4256 4257 4258
{
    check_privileged(s);
    gen_helper_tpi(cc_op, cpu_env, o->addr1);
    set_cc_static(s);
4259
    return DISAS_NEXT;
4260 4261
}

4262
static DisasJumpType op_tsch(DisasContext *s, DisasOps *o)
4263 4264 4265 4266
{
    check_privileged(s);
    gen_helper_tsch(cpu_env, regs[1], o->in2);
    set_cc_static(s);
4267
    return DISAS_NEXT;
4268 4269
}

4270
static DisasJumpType op_chsc(DisasContext *s, DisasOps *o)
4271 4272 4273 4274
{
    check_privileged(s);
    gen_helper_chsc(cpu_env, o->in2);
    set_cc_static(s);
4275
    return DISAS_NEXT;
4276 4277
}

4278
static DisasJumpType op_stpx(DisasContext *s, DisasOps *o)
4279 4280 4281 4282
{
    check_privileged(s);
    tcg_gen_ld_i64(o->out, cpu_env, offsetof(CPUS390XState, psa));
    tcg_gen_andi_i64(o->out, o->out, 0x7fffe000);
4283
    return DISAS_NEXT;
4284 4285
}

4286
static DisasJumpType op_stnosm(DisasContext *s, DisasOps *o)
4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306
{
    uint64_t i2 = get_field(s->fields, i2);
    TCGv_i64 t;

    check_privileged(s);

    /* It is important to do what the instruction name says: STORE THEN.
       If we let the output hook perform the store then if we fault and
       restart, we'll have the wrong SYSTEM MASK in place.  */
    t = tcg_temp_new_i64();
    tcg_gen_shri_i64(t, psw_mask, 56);
    tcg_gen_qemu_st8(t, o->addr1, get_mem_index(s));
    tcg_temp_free_i64(t);

    if (s->fields->op == 0xac) {
        tcg_gen_andi_i64(psw_mask, psw_mask,
                         (i2 << 56) | 0x00ffffffffffffffull);
    } else {
        tcg_gen_ori_i64(psw_mask, psw_mask, i2 << 56);
    }
4307 4308

    /* Exit to main loop to reevaluate s390_cpu_exec_interrupt.  */
4309
    return DISAS_PC_STALE_NOCHAIN;
4310
}
R
Richard Henderson 已提交
4311

4312
static DisasJumpType op_stura(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4313 4314 4315
{
    check_privileged(s);
    gen_helper_stura(cpu_env, o->in2, o->in1);
4316
    return DISAS_NEXT;
R
Richard Henderson 已提交
4317
}
4318

4319
static DisasJumpType op_sturg(DisasContext *s, DisasOps *o)
4320 4321 4322
{
    check_privileged(s);
    gen_helper_sturg(cpu_env, o->in2, o->in1);
4323
    return DISAS_NEXT;
4324
}
4325 4326
#endif

4327
static DisasJumpType op_stfle(DisasContext *s, DisasOps *o)
4328 4329 4330
{
    gen_helper_stfle(cc_op, cpu_env, o->in2);
    set_cc_static(s);
4331
    return DISAS_NEXT;
4332 4333
}

4334
static DisasJumpType op_st8(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4335 4336
{
    tcg_gen_qemu_st8(o->in1, o->in2, get_mem_index(s));
4337
    return DISAS_NEXT;
R
Richard Henderson 已提交
4338 4339
}

4340
static DisasJumpType op_st16(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4341 4342
{
    tcg_gen_qemu_st16(o->in1, o->in2, get_mem_index(s));
4343
    return DISAS_NEXT;
R
Richard Henderson 已提交
4344 4345
}

4346
static DisasJumpType op_st32(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4347 4348
{
    tcg_gen_qemu_st32(o->in1, o->in2, get_mem_index(s));
4349
    return DISAS_NEXT;
R
Richard Henderson 已提交
4350 4351
}

4352
static DisasJumpType op_st64(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4353 4354
{
    tcg_gen_qemu_st64(o->in1, o->in2, get_mem_index(s));
4355
    return DISAS_NEXT;
R
Richard Henderson 已提交
4356 4357
}

4358
static DisasJumpType op_stam(DisasContext *s, DisasOps *o)
4359 4360 4361 4362 4363 4364
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    gen_helper_stam(cpu_env, r1, o->in2, r3);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
4365
    return DISAS_NEXT;
4366 4367
}

4368
static DisasJumpType op_stcm(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413
{
    int m3 = get_field(s->fields, m3);
    int pos, base = s->insn->data;
    TCGv_i64 tmp = tcg_temp_new_i64();

    pos = base + ctz32(m3) * 8;
    switch (m3) {
    case 0xf:
        /* Effectively a 32-bit store.  */
        tcg_gen_shri_i64(tmp, o->in1, pos);
        tcg_gen_qemu_st32(tmp, o->in2, get_mem_index(s));
        break;

    case 0xc:
    case 0x6:
    case 0x3:
        /* Effectively a 16-bit store.  */
        tcg_gen_shri_i64(tmp, o->in1, pos);
        tcg_gen_qemu_st16(tmp, o->in2, get_mem_index(s));
        break;

    case 0x8:
    case 0x4:
    case 0x2:
    case 0x1:
        /* Effectively an 8-bit store.  */
        tcg_gen_shri_i64(tmp, o->in1, pos);
        tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
        break;

    default:
        /* This is going to be a sequence of shifts and stores.  */
        pos = base + 32 - 8;
        while (m3) {
            if (m3 & 0x8) {
                tcg_gen_shri_i64(tmp, o->in1, pos);
                tcg_gen_qemu_st8(tmp, o->in2, get_mem_index(s));
                tcg_gen_addi_i64(o->in2, o->in2, 1);
            }
            m3 = (m3 << 1) & 0xf;
            pos -= 8;
        }
        break;
    }
    tcg_temp_free_i64(tmp);
4414
    return DISAS_NEXT;
R
Richard Henderson 已提交
4415 4416
}

4417
static DisasJumpType op_stm(DisasContext *s, DisasOps *o)
4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    int size = s->insn->data;
    TCGv_i64 tsize = tcg_const_i64(size);

    while (1) {
        if (size == 8) {
            tcg_gen_qemu_st64(regs[r1], o->in2, get_mem_index(s));
        } else {
            tcg_gen_qemu_st32(regs[r1], o->in2, get_mem_index(s));
        }
        if (r1 == r3) {
            break;
        }
        tcg_gen_add_i64(o->in2, o->in2, tsize);
        r1 = (r1 + 1) & 15;
    }

    tcg_temp_free_i64(tsize);
4438
    return DISAS_NEXT;
4439 4440
}

4441
static DisasJumpType op_stmh(DisasContext *s, DisasOps *o)
4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461
{
    int r1 = get_field(s->fields, r1);
    int r3 = get_field(s->fields, r3);
    TCGv_i64 t = tcg_temp_new_i64();
    TCGv_i64 t4 = tcg_const_i64(4);
    TCGv_i64 t32 = tcg_const_i64(32);

    while (1) {
        tcg_gen_shl_i64(t, regs[r1], t32);
        tcg_gen_qemu_st32(t, o->in2, get_mem_index(s));
        if (r1 == r3) {
            break;
        }
        tcg_gen_add_i64(o->in2, o->in2, t4);
        r1 = (r1 + 1) & 15;
    }

    tcg_temp_free_i64(t);
    tcg_temp_free_i64(t4);
    tcg_temp_free_i64(t32);
4462
    return DISAS_NEXT;
4463 4464
}

4465
static DisasJumpType op_stpq(DisasContext *s, DisasOps *o)
4466
{
4467
    if (tb_cflags(s->base.tb) & CF_PARALLEL) {
4468 4469 4470 4471
        gen_helper_stpq_parallel(cpu_env, o->in2, o->out2, o->out);
    } else {
        gen_helper_stpq(cpu_env, o->in2, o->out2, o->out);
    }
4472
    return DISAS_NEXT;
4473 4474
}

4475
static DisasJumpType op_srst(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4476
{
R
Richard Henderson 已提交
4477 4478 4479 4480 4481 4482 4483
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    gen_helper_srst(cpu_env, r1, r2);

    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
R
Richard Henderson 已提交
4484
    set_cc_static(s);
4485
    return DISAS_NEXT;
R
Richard Henderson 已提交
4486 4487
}

4488
static DisasJumpType op_srstu(DisasContext *s, DisasOps *o)
4489 4490 4491 4492 4493 4494 4495 4496 4497
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    gen_helper_srstu(cpu_env, r1, r2);

    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
    set_cc_static(s);
4498
    return DISAS_NEXT;
4499 4500
}

4501
static DisasJumpType op_sub(DisasContext *s, DisasOps *o)
4502 4503
{
    tcg_gen_sub_i64(o->out, o->in1, o->in2);
4504
    return DISAS_NEXT;
4505 4506
}

4507
static DisasJumpType op_subb(DisasContext *s, DisasOps *o)
4508
{
4509 4510
    DisasCompare cmp;
    TCGv_i64 borrow;
4511

4512
    tcg_gen_sub_i64(o->out, o->in1, o->in2);
4513

4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529
    /* The !borrow flag is the msb of CC.  Since we want the inverse of
       that, we ask for a comparison of CC=0 | CC=1 -> mask of 8 | 4.  */
    disas_jcc(s, &cmp, 8 | 4);
    borrow = tcg_temp_new_i64();
    if (cmp.is_64) {
        tcg_gen_setcond_i64(cmp.cond, borrow, cmp.u.s64.a, cmp.u.s64.b);
    } else {
        TCGv_i32 t = tcg_temp_new_i32();
        tcg_gen_setcond_i32(cmp.cond, t, cmp.u.s32.a, cmp.u.s32.b);
        tcg_gen_extu_i32_i64(borrow, t);
        tcg_temp_free_i32(t);
    }
    free_compare(&cmp);

    tcg_gen_sub_i64(o->out, o->out, borrow);
    tcg_temp_free_i64(borrow);
4530
    return DISAS_NEXT;
4531 4532
}

4533
static DisasJumpType op_svc(DisasContext *s, DisasOps *o)
4534 4535 4536 4537
{
    TCGv_i32 t;

    update_psw_addr(s);
4538
    update_cc_op(s);
4539 4540 4541 4542 4543

    t = tcg_const_i32(get_field(s->fields, i1) & 0xff);
    tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_code));
    tcg_temp_free_i32(t);

4544
    t = tcg_const_i32(s->ilen);
4545 4546 4547 4548
    tcg_gen_st_i32(t, cpu_env, offsetof(CPUS390XState, int_svc_ilen));
    tcg_temp_free_i32(t);

    gen_exception(EXCP_SVC);
4549
    return DISAS_NORETURN;
4550 4551
}

4552
static DisasJumpType op_tam(DisasContext *s, DisasOps *o)
4553 4554 4555
{
    int cc = 0;

4556 4557
    cc |= (s->base.tb->flags & FLAG_MASK_64) ? 2 : 0;
    cc |= (s->base.tb->flags & FLAG_MASK_32) ? 1 : 0;
4558
    gen_op_movi_cc(s, cc);
4559
    return DISAS_NEXT;
4560 4561
}

4562
static DisasJumpType op_tceb(DisasContext *s, DisasOps *o)
4563
{
4564
    gen_helper_tceb(cc_op, cpu_env, o->in1, o->in2);
4565
    set_cc_static(s);
4566
    return DISAS_NEXT;
4567 4568
}

4569
static DisasJumpType op_tcdb(DisasContext *s, DisasOps *o)
4570
{
4571
    gen_helper_tcdb(cc_op, cpu_env, o->in1, o->in2);
4572
    set_cc_static(s);
4573
    return DISAS_NEXT;
4574 4575
}

4576
static DisasJumpType op_tcxb(DisasContext *s, DisasOps *o)
4577
{
4578
    gen_helper_tcxb(cc_op, cpu_env, o->out, o->out2, o->in2);
4579
    set_cc_static(s);
4580
    return DISAS_NEXT;
4581 4582
}

R
Richard Henderson 已提交
4583
#ifndef CONFIG_USER_ONLY
4584

4585
static DisasJumpType op_testblock(DisasContext *s, DisasOps *o)
4586 4587 4588 4589
{
    check_privileged(s);
    gen_helper_testblock(cc_op, cpu_env, o->in2);
    set_cc_static(s);
4590
    return DISAS_NEXT;
4591 4592
}

4593
static DisasJumpType op_tprot(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4594
{
4595
    gen_helper_tprot(cc_op, cpu_env, o->addr1, o->in2);
R
Richard Henderson 已提交
4596
    set_cc_static(s);
4597
    return DISAS_NEXT;
R
Richard Henderson 已提交
4598
}
4599

R
Richard Henderson 已提交
4600 4601
#endif

4602
static DisasJumpType op_tp(DisasContext *s, DisasOps *o)
4603 4604 4605 4606 4607
{
    TCGv_i32 l1 = tcg_const_i32(get_field(s->fields, l1) + 1);
    gen_helper_tp(cc_op, cpu_env, o->addr1, l1);
    tcg_temp_free_i32(l1);
    set_cc_static(s);
4608
    return DISAS_NEXT;
4609 4610
}

4611
static DisasJumpType op_tr(DisasContext *s, DisasOps *o)
4612 4613 4614 4615 4616
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_tr(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
4617
    return DISAS_NEXT;
4618 4619
}

4620
static DisasJumpType op_tre(DisasContext *s, DisasOps *o)
4621 4622 4623 4624
{
    gen_helper_tre(o->out, cpu_env, o->out, o->out2, o->in2);
    return_low128(o->out2);
    set_cc_static(s);
4625
    return DISAS_NEXT;
4626 4627
}

4628
static DisasJumpType op_trt(DisasContext *s, DisasOps *o)
4629 4630 4631 4632 4633
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_trt(cc_op, cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
4634
    return DISAS_NEXT;
4635 4636
}

4637
static DisasJumpType op_trtr(DisasContext *s, DisasOps *o)
R
Richard Henderson 已提交
4638 4639 4640 4641 4642
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_trtr(cc_op, cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
4643
    return DISAS_NEXT;
R
Richard Henderson 已提交
4644 4645
}

4646
static DisasJumpType op_trXX(DisasContext *s, DisasOps *o)
4647 4648 4649 4650 4651 4652 4653
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));
    TCGv_i32 sizes = tcg_const_i32(s->insn->opc & 3);
    TCGv_i32 tst = tcg_temp_new_i32();
    int m3 = get_field(s->fields, m3);

4654 4655 4656
    if (!s390_has_feat(S390_FEAT_ETF2_ENH)) {
        m3 = 0;
    }
4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673
    if (m3 & 1) {
        tcg_gen_movi_i32(tst, -1);
    } else {
        tcg_gen_extrl_i64_i32(tst, regs[0]);
        if (s->insn->opc & 3) {
            tcg_gen_ext8u_i32(tst, tst);
        } else {
            tcg_gen_ext16u_i32(tst, tst);
        }
    }
    gen_helper_trXX(cc_op, cpu_env, r1, r2, tst, sizes);

    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
    tcg_temp_free_i32(sizes);
    tcg_temp_free_i32(tst);
    set_cc_static(s);
4674
    return DISAS_NEXT;
4675 4676
}

4677
static DisasJumpType op_ts(DisasContext *s, DisasOps *o)
4678 4679 4680 4681 4682 4683
{
    TCGv_i32 t1 = tcg_const_i32(0xff);
    tcg_gen_atomic_xchg_i32(t1, o->in2, t1, get_mem_index(s), MO_UB);
    tcg_gen_extract_i32(cc_op, t1, 7, 1);
    tcg_temp_free_i32(t1);
    set_cc_static(s);
4684
    return DISAS_NEXT;
4685 4686
}

4687
static DisasJumpType op_unpk(DisasContext *s, DisasOps *o)
4688 4689 4690 4691
{
    TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
    gen_helper_unpk(cpu_env, l, o->addr1, o->in2);
    tcg_temp_free_i32(l);
4692
    return DISAS_NEXT;
4693 4694
}

4695
static DisasJumpType op_unpka(DisasContext *s, DisasOps *o)
4696 4697 4698 4699 4700 4701 4702
{
    int l1 = get_field(s->fields, l1) + 1;
    TCGv_i32 l;

    /* The length must not exceed 32 bytes.  */
    if (l1 > 32) {
        gen_program_exception(s, PGM_SPECIFICATION);
4703
        return DISAS_NORETURN;
4704 4705 4706 4707 4708
    }
    l = tcg_const_i32(l1);
    gen_helper_unpka(cc_op, cpu_env, o->addr1, l, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
4709
    return DISAS_NEXT;
4710 4711
}

4712
static DisasJumpType op_unpku(DisasContext *s, DisasOps *o)
4713 4714 4715 4716 4717 4718 4719
{
    int l1 = get_field(s->fields, l1) + 1;
    TCGv_i32 l;

    /* The length must be even and should not exceed 64 bytes.  */
    if ((l1 & 1) || (l1 > 64)) {
        gen_program_exception(s, PGM_SPECIFICATION);
4720
        return DISAS_NORETURN;
4721 4722 4723 4724 4725
    }
    l = tcg_const_i32(l1);
    gen_helper_unpku(cc_op, cpu_env, o->addr1, l, o->in2);
    tcg_temp_free_i32(l);
    set_cc_static(s);
4726
    return DISAS_NEXT;
4727 4728 4729
}


4730
static DisasJumpType op_xc(DisasContext *s, DisasOps *o)
4731
{
R
Richard Henderson 已提交
4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770
    int d1 = get_field(s->fields, d1);
    int d2 = get_field(s->fields, d2);
    int b1 = get_field(s->fields, b1);
    int b2 = get_field(s->fields, b2);
    int l = get_field(s->fields, l1);
    TCGv_i32 t32;

    o->addr1 = get_address(s, 0, b1, d1);

    /* If the addresses are identical, this is a store/memset of zero.  */
    if (b1 == b2 && d1 == d2 && (l + 1) <= 32) {
        o->in2 = tcg_const_i64(0);

        l++;
        while (l >= 8) {
            tcg_gen_qemu_st64(o->in2, o->addr1, get_mem_index(s));
            l -= 8;
            if (l > 0) {
                tcg_gen_addi_i64(o->addr1, o->addr1, 8);
            }
        }
        if (l >= 4) {
            tcg_gen_qemu_st32(o->in2, o->addr1, get_mem_index(s));
            l -= 4;
            if (l > 0) {
                tcg_gen_addi_i64(o->addr1, o->addr1, 4);
            }
        }
        if (l >= 2) {
            tcg_gen_qemu_st16(o->in2, o->addr1, get_mem_index(s));
            l -= 2;
            if (l > 0) {
                tcg_gen_addi_i64(o->addr1, o->addr1, 2);
            }
        }
        if (l) {
            tcg_gen_qemu_st8(o->in2, o->addr1, get_mem_index(s));
        }
        gen_op_movi_cc(s, 0);
4771
        return DISAS_NEXT;
R
Richard Henderson 已提交
4772 4773 4774 4775 4776 4777 4778
    }

    /* But in general we'll defer to a helper.  */
    o->in2 = get_address(s, 0, b2, d2);
    t32 = tcg_const_i32(l);
    gen_helper_xc(cc_op, cpu_env, t32, o->addr1, o->in2);
    tcg_temp_free_i32(t32);
4779
    set_cc_static(s);
4780
    return DISAS_NEXT;
4781 4782
}

4783
static DisasJumpType op_xor(DisasContext *s, DisasOps *o)
4784 4785
{
    tcg_gen_xor_i64(o->out, o->in1, o->in2);
4786
    return DISAS_NEXT;
4787 4788
}

4789
static DisasJumpType op_xori(DisasContext *s, DisasOps *o)
4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801
{
    int shift = s->insn->data & 0xff;
    int size = s->insn->data >> 8;
    uint64_t mask = ((1ull << size) - 1) << shift;

    assert(!o->g_in2);
    tcg_gen_shli_i64(o->in2, o->in2, shift);
    tcg_gen_xor_i64(o->out, o->in1, o->in2);

    /* Produce the CC from only the bits manipulated.  */
    tcg_gen_andi_i64(cc_dst, o->out, mask);
    set_cc_nz_u64(s, cc_dst);
4802
    return DISAS_NEXT;
4803 4804
}

4805
static DisasJumpType op_xi(DisasContext *s, DisasOps *o)
4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822
{
    o->in1 = tcg_temp_new_i64();

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
    } else {
        /* Perform the atomic operation in memory. */
        tcg_gen_atomic_fetch_xor_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
                                     s->insn->data);
    }

    /* Recompute also for atomic case: needed for setting CC. */
    tcg_gen_xor_i64(o->out, o->in1, o->in2);

    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
    }
4823
    return DISAS_NEXT;
4824 4825
}

4826
static DisasJumpType op_zero(DisasContext *s, DisasOps *o)
4827 4828
{
    o->out = tcg_const_i64(0);
4829
    return DISAS_NEXT;
4830 4831
}

4832
static DisasJumpType op_zero2(DisasContext *s, DisasOps *o)
4833 4834 4835 4836
{
    o->out = tcg_const_i64(0);
    o->out2 = o->out;
    o->g_out2 = true;
4837
    return DISAS_NEXT;
4838 4839
}

4840
#ifndef CONFIG_USER_ONLY
4841
static DisasJumpType op_clp(DisasContext *s, DisasOps *o)
4842 4843 4844 4845 4846 4847 4848
{
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    check_privileged(s);
    gen_helper_clp(cpu_env, r2);
    tcg_temp_free_i32(r2);
    set_cc_static(s);
4849
    return DISAS_NEXT;
4850 4851
}

4852
static DisasJumpType op_pcilg(DisasContext *s, DisasOps *o)
4853 4854 4855 4856 4857 4858 4859 4860 4861
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    check_privileged(s);
    gen_helper_pcilg(cpu_env, r1, r2);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
    set_cc_static(s);
4862
    return DISAS_NEXT;
4863 4864
}

4865
static DisasJumpType op_pcistg(DisasContext *s, DisasOps *o)
4866 4867 4868 4869 4870 4871 4872 4873 4874
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    check_privileged(s);
    gen_helper_pcistg(cpu_env, r1, r2);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
    set_cc_static(s);
4875
    return DISAS_NEXT;
4876 4877
}

4878
static DisasJumpType op_stpcifc(DisasContext *s, DisasOps *o)
4879 4880 4881 4882 4883 4884 4885 4886 4887
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 ar = tcg_const_i32(get_field(s->fields, b2));

    check_privileged(s);
    gen_helper_stpcifc(cpu_env, r1, o->addr1, ar);
    tcg_temp_free_i32(ar);
    tcg_temp_free_i32(r1);
    set_cc_static(s);
4888
    return DISAS_NEXT;
4889 4890
}

4891
static DisasJumpType op_sic(DisasContext *s, DisasOps *o)
4892 4893 4894
{
    check_privileged(s);
    gen_helper_sic(cpu_env, o->in1, o->in2);
4895
    return DISAS_NEXT;
4896 4897
}

4898
static DisasJumpType op_rpcit(DisasContext *s, DisasOps *o)
4899 4900 4901 4902 4903 4904 4905 4906 4907
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r2 = tcg_const_i32(get_field(s->fields, r2));

    check_privileged(s);
    gen_helper_rpcit(cpu_env, r1, r2);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r2);
    set_cc_static(s);
4908
    return DISAS_NEXT;
4909 4910
}

4911
static DisasJumpType op_pcistb(DisasContext *s, DisasOps *o)
4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 r3 = tcg_const_i32(get_field(s->fields, r3));
    TCGv_i32 ar = tcg_const_i32(get_field(s->fields, b2));

    check_privileged(s);
    gen_helper_pcistb(cpu_env, r1, r3, o->addr1, ar);
    tcg_temp_free_i32(ar);
    tcg_temp_free_i32(r1);
    tcg_temp_free_i32(r3);
    set_cc_static(s);
4923
    return DISAS_NEXT;
4924 4925
}

4926
static DisasJumpType op_mpcifc(DisasContext *s, DisasOps *o)
4927 4928 4929 4930 4931 4932 4933 4934 4935
{
    TCGv_i32 r1 = tcg_const_i32(get_field(s->fields, r1));
    TCGv_i32 ar = tcg_const_i32(get_field(s->fields, b2));

    check_privileged(s);
    gen_helper_mpcifc(cpu_env, r1, o->addr1, ar);
    tcg_temp_free_i32(ar);
    tcg_temp_free_i32(r1);
    set_cc_static(s);
4936
    return DISAS_NEXT;
4937 4938 4939
}
#endif

4940 4941 4942 4943 4944
/* ====================================================================== */
/* The "Cc OUTput" generators.  Given the generated output (and in some cases
   the original inputs), update the various cc data structures in order to
   be able to compute the new condition code.  */

4945 4946 4947 4948 4949 4950 4951 4952 4953 4954
static void cout_abs32(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_ABS_32, o->out);
}

static void cout_abs64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_ABS_64, o->out);
}

4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974
static void cout_adds32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADD_32, o->in1, o->in2, o->out);
}

static void cout_adds64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADD_64, o->in1, o->in2, o->out);
}

static void cout_addu32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADDU_32, o->in1, o->in2, o->out);
}

static void cout_addu64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADDU_64, o->in1, o->in2, o->out);
}

4975 4976 4977 4978 4979 4980 4981 4982 4983 4984
static void cout_addc32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADDC_32, o->in1, o->in2, o->out);
}

static void cout_addc64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_ADDC_64, o->in1, o->in2, o->out);
}

4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004
static void cout_cmps32(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_LTGT_32, o->in1, o->in2);
}

static void cout_cmps64(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_LTGT_64, o->in1, o->in2);
}

static void cout_cmpu32(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_LTUGTU_32, o->in1, o->in2);
}

static void cout_cmpu64(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_LTUGTU_64, o->in1, o->in2);
}

5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019
static void cout_f32(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_NZ_F32, o->out);
}

static void cout_f64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_NZ_F64, o->out);
}

static void cout_f128(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_NZ_F128, o->out, o->out2);
}

5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039
static void cout_nabs32(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_NABS_32, o->out);
}

static void cout_nabs64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_NABS_64, o->out);
}

static void cout_neg32(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_COMP_32, o->out);
}

static void cout_neg64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_COMP_64, o->out);
}

5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050
static void cout_nz32(DisasContext *s, DisasOps *o)
{
    tcg_gen_ext32u_i64(cc_dst, o->out);
    gen_op_update1_cc_i64(s, CC_OP_NZ, cc_dst);
}

static void cout_nz64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_NZ, o->out);
}

5051 5052 5053 5054 5055 5056 5057 5058 5059 5060
static void cout_s32(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_LTGT0_32, o->out);
}

static void cout_s64(DisasContext *s, DisasOps *o)
{
    gen_op_update1_cc_i64(s, CC_OP_LTGT0_64, o->out);
}

5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080
static void cout_subs32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUB_32, o->in1, o->in2, o->out);
}

static void cout_subs64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUB_64, o->in1, o->in2, o->out);
}

static void cout_subu32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUBU_32, o->in1, o->in2, o->out);
}

static void cout_subu64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUBU_64, o->in1, o->in2, o->out);
}

5081 5082 5083 5084 5085 5086 5087 5088 5089 5090
static void cout_subb32(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUBB_32, o->in1, o->in2, o->out);
}

static void cout_subb64(DisasContext *s, DisasOps *o)
{
    gen_op_update3_cc_i64(s, CC_OP_SUBB_64, o->in1, o->in2, o->out);
}

5091 5092 5093 5094 5095 5096 5097 5098 5099 5100
static void cout_tm32(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_TM_32, o->in1, o->in2);
}

static void cout_tm64(DisasContext *s, DisasOps *o)
{
    gen_op_update2_cc_i64(s, CC_OP_TM_64, o->in1, o->in2);
}

5101
/* ====================================================================== */
S
Stefan Weil 已提交
5102
/* The "PREParation" generators.  These initialize the DisasOps.OUT fields
5103 5104 5105 5106 5107 5108 5109 5110
   with the TCG register to which we will write.  Used in combination with
   the "wout" generators, in some cases we need a new temporary, and in
   some cases we can write to a TCG global.  */

static void prep_new(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->out = tcg_temp_new_i64();
}
5111
#define SPEC_prep_new 0
5112

R
Richard Henderson 已提交
5113 5114 5115 5116 5117
static void prep_new_P(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->out = tcg_temp_new_i64();
    o->out2 = tcg_temp_new_i64();
}
5118
#define SPEC_prep_new_P 0
R
Richard Henderson 已提交
5119

5120 5121 5122 5123 5124
static void prep_r1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->out = regs[get_field(f, r1)];
    o->g_out = true;
}
5125
#define SPEC_prep_r1 0
5126

5127 5128 5129 5130
static void prep_r1_P(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    o->out = regs[r1];
5131
    o->out2 = regs[r1 + 1];
5132 5133
    o->g_out = o->g_out2 = true;
}
5134
#define SPEC_prep_r1_P SPEC_r1_even
5135

5136 5137 5138 5139 5140
static void prep_f1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->out = fregs[get_field(f, r1)];
    o->g_out = true;
}
5141
#define SPEC_prep_f1 0
5142 5143 5144 5145 5146

static void prep_x1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    o->out = fregs[r1];
5147
    o->out2 = fregs[r1 + 2];
5148 5149
    o->g_out = o->g_out2 = true;
}
5150
#define SPEC_prep_x1 SPEC_r1_f128
5151

5152 5153 5154 5155 5156 5157
/* ====================================================================== */
/* The "Write OUTput" generators.  These generally perform some non-trivial
   copy of data to TCG globals, or to main memory.  The trivial cases are
   generally handled by having a "prep" generator install the TCG global
   as the destination of the operation.  */

5158 5159 5160 5161
static void wout_r1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    store_reg(get_field(f, r1), o->out);
}
5162
#define SPEC_wout_r1 0
5163

5164 5165 5166 5167 5168
static void wout_r1_8(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 8);
}
5169
#define SPEC_wout_r1_8 0
5170

5171 5172 5173 5174 5175
static void wout_r1_16(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    tcg_gen_deposit_i64(regs[r1], regs[r1], o->out, 0, 16);
}
5176
#define SPEC_wout_r1_16 0
5177

5178 5179 5180 5181
static void wout_r1_32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    store_reg32_i64(get_field(f, r1), o->out);
}
5182
#define SPEC_wout_r1_32 0
5183

5184 5185 5186 5187 5188 5189
static void wout_r1_32h(DisasContext *s, DisasFields *f, DisasOps *o)
{
    store_reg32h_i64(get_field(f, r1), o->out);
}
#define SPEC_wout_r1_32h 0

R
Richard Henderson 已提交
5190 5191 5192 5193
static void wout_r1_P32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    store_reg32_i64(r1, o->out);
5194
    store_reg32_i64(r1 + 1, o->out2);
R
Richard Henderson 已提交
5195
}
5196
#define SPEC_wout_r1_P32 SPEC_r1_even
R
Richard Henderson 已提交
5197

5198 5199 5200
static void wout_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
5201
    store_reg32_i64(r1 + 1, o->out);
5202 5203 5204
    tcg_gen_shri_i64(o->out, o->out, 32);
    store_reg32_i64(r1, o->out);
}
5205
#define SPEC_wout_r1_D32 SPEC_r1_even
5206

5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222
static void wout_r3_P32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r3 = get_field(f, r3);
    store_reg32_i64(r3, o->out);
    store_reg32_i64(r3 + 1, o->out2);
}
#define SPEC_wout_r3_P32 SPEC_r3_even

static void wout_r3_P64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r3 = get_field(f, r3);
    store_reg(r3, o->out);
    store_reg(r3 + 1, o->out2);
}
#define SPEC_wout_r3_P64 SPEC_r3_even

R
Richard Henderson 已提交
5223 5224 5225 5226
static void wout_e1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    store_freg32_i64(get_field(f, r1), o->out);
}
5227
#define SPEC_wout_e1 0
R
Richard Henderson 已提交
5228 5229 5230 5231 5232

static void wout_f1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    store_freg(get_field(f, r1), o->out);
}
5233
#define SPEC_wout_f1 0
R
Richard Henderson 已提交
5234 5235 5236 5237 5238

static void wout_x1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int f1 = get_field(s->fields, r1);
    store_freg(f1, o->out);
5239
    store_freg(f1 + 2, o->out2);
R
Richard Henderson 已提交
5240
}
5241
#define SPEC_wout_x1 SPEC_r1_f128
R
Richard Henderson 已提交
5242

5243 5244 5245 5246 5247 5248
static void wout_cond_r1r2_32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    if (get_field(f, r1) != get_field(f, r2)) {
        store_reg32_i64(get_field(f, r1), o->out);
    }
}
5249
#define SPEC_wout_cond_r1r2_32 0
5250

R
Richard Henderson 已提交
5251 5252 5253 5254 5255 5256
static void wout_cond_e1e2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    if (get_field(f, r1) != get_field(f, r2)) {
        store_freg32_i64(get_field(f, r1), o->out);
    }
}
5257
#define SPEC_wout_cond_e1e2 0
R
Richard Henderson 已提交
5258

R
Richard Henderson 已提交
5259 5260 5261 5262
static void wout_m1_8(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st8(o->out, o->addr1, get_mem_index(s));
}
5263
#define SPEC_wout_m1_8 0
R
Richard Henderson 已提交
5264 5265 5266 5267 5268

static void wout_m1_16(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st16(o->out, o->addr1, get_mem_index(s));
}
5269
#define SPEC_wout_m1_16 0
R
Richard Henderson 已提交
5270

5271 5272 5273 5274 5275 5276 5277 5278
#ifndef CONFIG_USER_ONLY
static void wout_m1_16a(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), MO_TEUW | MO_ALIGN);
}
#define SPEC_wout_m1_16a 0
#endif

5279 5280 5281 5282
static void wout_m1_32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st32(o->out, o->addr1, get_mem_index(s));
}
5283
#define SPEC_wout_m1_32 0
5284

5285 5286 5287 5288 5289 5290 5291 5292
#ifndef CONFIG_USER_ONLY
static void wout_m1_32a(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), MO_TEUL | MO_ALIGN);
}
#define SPEC_wout_m1_32a 0
#endif

5293 5294 5295 5296
static void wout_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st64(o->out, o->addr1, get_mem_index(s));
}
5297
#define SPEC_wout_m1_64 0
5298

5299 5300 5301 5302 5303 5304 5305 5306
#ifndef CONFIG_USER_ONLY
static void wout_m1_64a(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st_i64(o->out, o->addr1, get_mem_index(s), MO_TEQ | MO_ALIGN);
}
#define SPEC_wout_m1_64a 0
#endif

5307 5308 5309 5310
static void wout_m2_32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    tcg_gen_qemu_st32(o->out, o->in2, get_mem_index(s));
}
5311
#define SPEC_wout_m2_32 0
5312

5313
static void wout_in2_r1(DisasContext *s, DisasFields *f, DisasOps *o)
5314
{
5315
    store_reg(get_field(f, r1), o->in2);
5316
}
5317
#define SPEC_wout_in2_r1 0
5318

5319
static void wout_in2_r1_32(DisasContext *s, DisasFields *f, DisasOps *o)
5320
{
5321
    store_reg32_i64(get_field(f, r1), o->in2);
5322
}
5323
#define SPEC_wout_in2_r1_32 0
5324

5325 5326 5327 5328 5329 5330 5331
/* ====================================================================== */
/* The "INput 1" generators.  These load the first operand to an insn.  */

static void in1_r1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = load_reg(get_field(f, r1));
}
5332
#define SPEC_in1_r1 0
5333

5334 5335 5336 5337 5338
static void in1_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = regs[get_field(f, r1)];
    o->g_in1 = true;
}
5339
#define SPEC_in1_r1_o 0
5340

5341 5342 5343 5344 5345
static void in1_r1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1)]);
}
5346
#define SPEC_in1_r1_32s 0
5347 5348 5349 5350 5351 5352

static void in1_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1)]);
}
5353
#define SPEC_in1_r1_32u 0
5354

R
Richard Henderson 已提交
5355 5356 5357 5358 5359
static void in1_r1_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_shri_i64(o->in1, regs[get_field(f, r1)], 32);
}
5360
#define SPEC_in1_r1_sr32 0
R
Richard Henderson 已提交
5361

5362 5363
static void in1_r1p1(DisasContext *s, DisasFields *f, DisasOps *o)
{
5364
    o->in1 = load_reg(get_field(f, r1) + 1);
5365
}
5366
#define SPEC_in1_r1p1 SPEC_r1_even
5367

5368 5369 5370
static void in1_r1p1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
5371
    tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r1) + 1]);
5372
}
5373
#define SPEC_in1_r1p1_32s SPEC_r1_even
5374 5375 5376 5377

static void in1_r1p1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
5378
    tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r1) + 1]);
5379
}
5380
#define SPEC_in1_r1p1_32u SPEC_r1_even
5381

R
Richard Henderson 已提交
5382 5383 5384 5385 5386 5387
static void in1_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_concat32_i64(o->in1, regs[r1 + 1], regs[r1]);
}
5388
#define SPEC_in1_r1_D32 SPEC_r1_even
R
Richard Henderson 已提交
5389

5390 5391 5392 5393
static void in1_r2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = load_reg(get_field(f, r2));
}
5394
#define SPEC_in1_r2 0
5395

5396 5397 5398 5399 5400 5401 5402
static void in1_r2_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_shri_i64(o->in1, regs[get_field(f, r2)], 32);
}
#define SPEC_in1_r2_sr32 0

5403 5404 5405 5406
static void in1_r3(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = load_reg(get_field(f, r3));
}
5407
#define SPEC_in1_r3 0
5408

5409 5410 5411 5412 5413
static void in1_r3_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = regs[get_field(f, r3)];
    o->g_in1 = true;
}
5414
#define SPEC_in1_r3_o 0
5415 5416 5417 5418 5419 5420

static void in1_r3_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_ext32s_i64(o->in1, regs[get_field(f, r3)]);
}
5421
#define SPEC_in1_r3_32s 0
5422 5423 5424 5425 5426 5427

static void in1_r3_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = tcg_temp_new_i64();
    tcg_gen_ext32u_i64(o->in1, regs[get_field(f, r3)]);
}
5428
#define SPEC_in1_r3_32u 0
5429

5430 5431 5432 5433 5434 5435 5436 5437
static void in1_r3_D32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r3 = get_field(f, r3);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_concat32_i64(o->in1, regs[r3 + 1], regs[r3]);
}
#define SPEC_in1_r3_D32 SPEC_r3_even

5438 5439 5440 5441
static void in1_e1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = load_freg32_i64(get_field(f, r1));
}
5442
#define SPEC_in1_e1 0
5443 5444 5445 5446 5447 5448

static void in1_f1_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = fregs[get_field(f, r1)];
    o->g_in1 = true;
}
5449
#define SPEC_in1_f1_o 0
5450

5451 5452 5453 5454
static void in1_x1_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    o->out = fregs[r1];
5455
    o->out2 = fregs[r1 + 2];
5456 5457
    o->g_out = o->g_out2 = true;
}
5458
#define SPEC_in1_x1_o SPEC_r1_f128
5459

R
Richard Henderson 已提交
5460 5461 5462 5463 5464
static void in1_f3_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in1 = fregs[get_field(f, r3)];
    o->g_in1 = true;
}
5465
#define SPEC_in1_f3_o 0
R
Richard Henderson 已提交
5466

5467 5468 5469 5470
static void in1_la1(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->addr1 = get_address(s, 0, get_field(f, b1), get_field(f, d1));
}
5471
#define SPEC_in1_la1 0
5472

5473 5474 5475 5476 5477
static void in1_la2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
    o->addr1 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
}
5478
#define SPEC_in1_la2 0
5479

5480 5481 5482 5483 5484 5485
static void in1_m1_8u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld8u(o->in1, o->addr1, get_mem_index(s));
}
5486
#define SPEC_in1_m1_8u 0
5487 5488 5489 5490 5491 5492 5493

static void in1_m1_16s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld16s(o->in1, o->addr1, get_mem_index(s));
}
5494
#define SPEC_in1_m1_16s 0
5495 5496 5497 5498 5499 5500 5501

static void in1_m1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld16u(o->in1, o->addr1, get_mem_index(s));
}
5502
#define SPEC_in1_m1_16u 0
5503

5504 5505 5506 5507 5508 5509
static void in1_m1_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld32s(o->in1, o->addr1, get_mem_index(s));
}
5510
#define SPEC_in1_m1_32s 0
5511

5512 5513 5514 5515 5516 5517
static void in1_m1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld32u(o->in1, o->addr1, get_mem_index(s));
}
5518
#define SPEC_in1_m1_32u 0
5519

5520 5521 5522 5523 5524 5525
static void in1_m1_64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in1_la1(s, f, o);
    o->in1 = tcg_temp_new_i64();
    tcg_gen_qemu_ld64(o->in1, o->addr1, get_mem_index(s));
}
5526
#define SPEC_in1_m1_64 0
5527 5528 5529 5530

/* ====================================================================== */
/* The "INput 2" generators.  These load the second operand to an insn.  */

5531 5532 5533 5534 5535
static void in2_r1_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = regs[get_field(f, r1)];
    o->g_in2 = true;
}
5536
#define SPEC_in2_r1_o 0
5537 5538 5539 5540 5541 5542

static void in2_r1_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r1)]);
}
5543
#define SPEC_in2_r1_16u 0
5544 5545 5546 5547 5548 5549

static void in2_r1_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r1)]);
}
5550
#define SPEC_in2_r1_32u 0
5551

5552 5553 5554 5555 5556 5557 5558 5559
static void in2_r1_D32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r1 = get_field(f, r1);
    o->in2 = tcg_temp_new_i64();
    tcg_gen_concat32_i64(o->in2, regs[r1 + 1], regs[r1]);
}
#define SPEC_in2_r1_D32 SPEC_r1_even

5560 5561 5562 5563
static void in2_r2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = load_reg(get_field(f, r2));
}
5564
#define SPEC_in2_r2 0
5565

5566 5567 5568 5569 5570
static void in2_r2_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = regs[get_field(f, r2)];
    o->g_in2 = true;
}
5571
#define SPEC_in2_r2_o 0
5572

5573 5574 5575 5576 5577 5578 5579
static void in2_r2_nz(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int r2 = get_field(f, r2);
    if (r2 != 0) {
        o->in2 = load_reg(r2);
    }
}
5580
#define SPEC_in2_r2_nz 0
5581

5582 5583 5584 5585 5586
static void in2_r2_8s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext8s_i64(o->in2, regs[get_field(f, r2)]);
}
5587
#define SPEC_in2_r2_8s 0
5588 5589 5590 5591 5592 5593

static void in2_r2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext8u_i64(o->in2, regs[get_field(f, r2)]);
}
5594
#define SPEC_in2_r2_8u 0
5595 5596 5597 5598 5599 5600

static void in2_r2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext16s_i64(o->in2, regs[get_field(f, r2)]);
}
5601
#define SPEC_in2_r2_16s 0
5602 5603 5604 5605 5606 5607

static void in2_r2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext16u_i64(o->in2, regs[get_field(f, r2)]);
}
5608
#define SPEC_in2_r2_16u 0
5609

5610 5611 5612 5613
static void in2_r3(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = load_reg(get_field(f, r3));
}
5614
#define SPEC_in2_r3 0
5615

5616 5617 5618 5619 5620 5621 5622
static void in2_r3_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_shri_i64(o->in2, regs[get_field(f, r3)], 32);
}
#define SPEC_in2_r3_sr32 0

5623 5624 5625 5626 5627
static void in2_r2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext32s_i64(o->in2, regs[get_field(f, r2)]);
}
5628
#define SPEC_in2_r2_32s 0
5629 5630 5631 5632 5633 5634

static void in2_r2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_ext32u_i64(o->in2, regs[get_field(f, r2)]);
}
5635
#define SPEC_in2_r2_32u 0
5636

5637 5638 5639 5640 5641 5642 5643
static void in2_r2_sr32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_temp_new_i64();
    tcg_gen_shri_i64(o->in2, regs[get_field(f, r2)], 32);
}
#define SPEC_in2_r2_sr32 0

R
Richard Henderson 已提交
5644 5645 5646 5647
static void in2_e2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = load_freg32_i64(get_field(f, r2));
}
5648
#define SPEC_in2_e2 0
R
Richard Henderson 已提交
5649 5650 5651 5652 5653 5654

static void in2_f2_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = fregs[get_field(f, r2)];
    o->g_in2 = true;
}
5655
#define SPEC_in2_f2_o 0
R
Richard Henderson 已提交
5656 5657 5658

static void in2_x2_o(DisasContext *s, DisasFields *f, DisasOps *o)
{
5659 5660
    int r2 = get_field(f, r2);
    o->in1 = fregs[r2];
5661
    o->in2 = fregs[r2 + 2];
R
Richard Henderson 已提交
5662 5663
    o->g_in1 = o->g_in2 = true;
}
5664
#define SPEC_in2_x2_o SPEC_r2_f128
R
Richard Henderson 已提交
5665

R
Richard Henderson 已提交
5666 5667 5668 5669
static void in2_ra2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = get_address(s, 0, get_field(f, r2), 0);
}
5670
#define SPEC_in2_ra2 0
R
Richard Henderson 已提交
5671

5672 5673 5674 5675 5676
static void in2_a2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    int x2 = have_field(f, x2) ? get_field(f, x2) : 0;
    o->in2 = get_address(s, x2, get_field(f, b2), get_field(f, d2));
}
5677
#define SPEC_in2_a2 0
5678

5679 5680
static void in2_ri2(DisasContext *s, DisasFields *f, DisasOps *o)
{
5681
    o->in2 = tcg_const_i64(s->base.pc_next + (int64_t)get_field(f, i2) * 2);
5682
}
5683
#define SPEC_in2_ri2 0
5684

5685 5686 5687 5688
static void in2_sh32(DisasContext *s, DisasFields *f, DisasOps *o)
{
    help_l2_shift(s, f, o, 31);
}
5689
#define SPEC_in2_sh32 0
5690 5691 5692 5693 5694

static void in2_sh64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    help_l2_shift(s, f, o, 63);
}
5695
#define SPEC_in2_sh64 0
5696

5697 5698 5699 5700 5701
static void in2_m2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld8u(o->in2, o->in2, get_mem_index(s));
}
5702
#define SPEC_in2_m2_8u 0
5703

5704 5705 5706 5707 5708
static void in2_m2_16s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld16s(o->in2, o->in2, get_mem_index(s));
}
5709
#define SPEC_in2_m2_16s 0
5710

5711 5712 5713 5714 5715
static void in2_m2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
}
5716
#define SPEC_in2_m2_16u 0
5717

5718 5719 5720 5721 5722
static void in2_m2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
}
5723
#define SPEC_in2_m2_32s 0
5724 5725 5726 5727 5728 5729

static void in2_m2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
}
5730
#define SPEC_in2_m2_32u 0
5731

5732 5733 5734 5735 5736 5737 5738 5739 5740
#ifndef CONFIG_USER_ONLY
static void in2_m2_32ua(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld_tl(o->in2, o->in2, get_mem_index(s), MO_TEUL | MO_ALIGN);
}
#define SPEC_in2_m2_32ua 0
#endif

5741 5742 5743 5744 5745
static void in2_m2_64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
}
5746
#define SPEC_in2_m2_64 0
5747

5748 5749 5750 5751 5752 5753 5754 5755 5756
#ifndef CONFIG_USER_ONLY
static void in2_m2_64a(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_a2(s, f, o);
    tcg_gen_qemu_ld_i64(o->in2, o->in2, get_mem_index(s), MO_TEQ | MO_ALIGN);
}
#define SPEC_in2_m2_64a 0
#endif

5757 5758 5759 5760 5761
static void in2_mri2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_ri2(s, f, o);
    tcg_gen_qemu_ld16u(o->in2, o->in2, get_mem_index(s));
}
5762
#define SPEC_in2_mri2_16u 0
5763 5764 5765 5766 5767 5768

static void in2_mri2_32s(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_ri2(s, f, o);
    tcg_gen_qemu_ld32s(o->in2, o->in2, get_mem_index(s));
}
5769
#define SPEC_in2_mri2_32s 0
5770 5771 5772 5773 5774 5775

static void in2_mri2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_ri2(s, f, o);
    tcg_gen_qemu_ld32u(o->in2, o->in2, get_mem_index(s));
}
5776
#define SPEC_in2_mri2_32u 0
5777 5778 5779 5780 5781 5782

static void in2_mri2_64(DisasContext *s, DisasFields *f, DisasOps *o)
{
    in2_ri2(s, f, o);
    tcg_gen_qemu_ld64(o->in2, o->in2, get_mem_index(s));
}
5783
#define SPEC_in2_mri2_64 0
5784

5785 5786 5787 5788
static void in2_i2(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_const_i64(get_field(f, i2));
}
5789
#define SPEC_in2_i2 0
5790

5791 5792 5793 5794
static void in2_i2_8u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_const_i64((uint8_t)get_field(f, i2));
}
5795
#define SPEC_in2_i2_8u 0
5796 5797 5798 5799 5800

static void in2_i2_16u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_const_i64((uint16_t)get_field(f, i2));
}
5801
#define SPEC_in2_i2_16u 0
5802

5803 5804 5805 5806
static void in2_i2_32u(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_const_i64((uint32_t)get_field(f, i2));
}
5807
#define SPEC_in2_i2_32u 0
5808

5809 5810 5811 5812 5813
static void in2_i2_16u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
{
    uint64_t i2 = (uint16_t)get_field(f, i2);
    o->in2 = tcg_const_i64(i2 << s->insn->data);
}
5814
#define SPEC_in2_i2_16u_shl 0
5815 5816 5817 5818 5819 5820

static void in2_i2_32u_shl(DisasContext *s, DisasFields *f, DisasOps *o)
{
    uint64_t i2 = (uint32_t)get_field(f, i2);
    o->in2 = tcg_const_i64(i2 << s->insn->data);
}
5821
#define SPEC_in2_i2_32u_shl 0
5822

5823 5824 5825 5826 5827 5828 5829 5830
#ifndef CONFIG_USER_ONLY
static void in2_insn(DisasContext *s, DisasFields *f, DisasOps *o)
{
    o->in2 = tcg_const_i64(s->fields->raw_insn);
}
#define SPEC_in2_insn 0
#endif

5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847
/* ====================================================================== */

/* Find opc within the table of insns.  This is formulated as a switch
   statement so that (1) we get compile-time notice of cut-paste errors
   for duplicated opcodes, and (2) the compiler generates the binary
   search tree, rather than us having to post-process the table.  */

#define C(OPC, NM, FT, FC, I1, I2, P, W, OP, CC) \
    D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, 0)

#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) insn_ ## NM,

enum DisasInsnEnum {
#include "insn-data.def"
};

#undef D
5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860
#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) {                       \
    .opc = OPC,                                                             \
    .fmt = FMT_##FT,                                                        \
    .fac = FAC_##FC,                                                        \
    .spec = SPEC_in1_##I1 | SPEC_in2_##I2 | SPEC_prep_##P | SPEC_wout_##W,  \
    .name = #NM,                                                            \
    .help_in1 = in1_##I1,                                                   \
    .help_in2 = in2_##I2,                                                   \
    .help_prep = prep_##P,                                                  \
    .help_wout = wout_##W,                                                  \
    .help_cout = cout_##CC,                                                 \
    .help_op = op_##OP,                                                     \
    .data = D                                                               \
5861 5862 5863 5864 5865 5866 5867 5868 5869 5870
 },

/* Allow 0 to be used for NULL in the table below.  */
#define in1_0  NULL
#define in2_0  NULL
#define prep_0  NULL
#define wout_0  NULL
#define cout_0  NULL
#define op_0  NULL

5871 5872 5873 5874 5875
#define SPEC_in1_0 0
#define SPEC_in2_0 0
#define SPEC_prep_0 0
#define SPEC_wout_0 0

5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893
/* Give smaller names to the various facilities.  */
#define FAC_Z           S390_FEAT_ZARCH
#define FAC_CASS        S390_FEAT_COMPARE_AND_SWAP_AND_STORE
#define FAC_DFP         S390_FEAT_DFP
#define FAC_DFPR        S390_FEAT_FLOATING_POINT_SUPPPORT_ENH /* DFP-rounding */
#define FAC_DO          S390_FEAT_STFLE_45 /* distinct-operands */
#define FAC_EE          S390_FEAT_EXECUTE_EXT
#define FAC_EI          S390_FEAT_EXTENDED_IMMEDIATE
#define FAC_FPE         S390_FEAT_FLOATING_POINT_EXT
#define FAC_FPSSH       S390_FEAT_FLOATING_POINT_SUPPPORT_ENH /* FPS-sign-handling */
#define FAC_FPRGR       S390_FEAT_FLOATING_POINT_SUPPPORT_ENH /* FPR-GR-transfer */
#define FAC_GIE         S390_FEAT_GENERAL_INSTRUCTIONS_EXT
#define FAC_HFP_MA      S390_FEAT_HFP_MADDSUB
#define FAC_HW          S390_FEAT_STFLE_45 /* high-word */
#define FAC_IEEEE_SIM   S390_FEAT_FLOATING_POINT_SUPPPORT_ENH /* IEEE-exception-simulation */
#define FAC_MIE         S390_FEAT_STFLE_49 /* misc-instruction-extensions */
#define FAC_LAT         S390_FEAT_STFLE_49 /* load-and-trap */
#define FAC_LOC         S390_FEAT_STFLE_45 /* load/store on condition 1 */
5894
#define FAC_LOC2        S390_FEAT_STFLE_53 /* load/store on condition 2 */
5895 5896 5897 5898 5899
#define FAC_LD          S390_FEAT_LONG_DISPLACEMENT
#define FAC_PC          S390_FEAT_STFLE_45 /* population count */
#define FAC_SCF         S390_FEAT_STORE_CLOCK_FAST
#define FAC_SFLE        S390_FEAT_STFLE
#define FAC_ILA         S390_FEAT_STFLE_45 /* interlocked-access-facility 1 */
5900
#define FAC_MVCOS       S390_FEAT_MOVE_WITH_OPTIONAL_SPEC
5901 5902 5903
#define FAC_LPP         S390_FEAT_SET_PROGRAM_PARAMETERS /* load-program-parameter */
#define FAC_DAT_ENH     S390_FEAT_DAT_ENH
#define FAC_E2          S390_FEAT_EXTENDED_TRANSLATION_2
5904
#define FAC_EH          S390_FEAT_STFLE_49 /* execution-hint */
5905
#define FAC_PPA         S390_FEAT_STFLE_49 /* processor-assist */
5906
#define FAC_LZRB        S390_FEAT_STFLE_53 /* load-and-zero-rightmost-byte */
5907
#define FAC_ETF3        S390_FEAT_EXTENDED_TRANSLATION_3
5908 5909 5910 5911
#define FAC_MSA         S390_FEAT_MSA /* message-security-assist facility */
#define FAC_MSA3        S390_FEAT_MSA_EXT_3 /* msa-extension-3 facility */
#define FAC_MSA4        S390_FEAT_MSA_EXT_4 /* msa-extension-4 facility */
#define FAC_MSA5        S390_FEAT_MSA_EXT_5 /* msa-extension-5 facility */
5912
#define FAC_ECT         S390_FEAT_EXTRACT_CPU_TIME
5913 5914
#define FAC_PCI         S390_FEAT_ZPCI /* z/PCI facility */
#define FAC_AIS         S390_FEAT_ADAPTER_INT_SUPPRESSION
5915

5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981
static const DisasInsn insn_info[] = {
#include "insn-data.def"
};

#undef D
#define D(OPC, NM, FT, FC, I1, I2, P, W, OP, CC, D) \
    case OPC: return &insn_info[insn_ ## NM];

static const DisasInsn *lookup_opc(uint16_t opc)
{
    switch (opc) {
#include "insn-data.def"
    default:
        return NULL;
    }
}

#undef D
#undef C

/* Extract a field from the insn.  The INSN should be left-aligned in
   the uint64_t so that we can more easily utilize the big-bit-endian
   definitions we extract from the Principals of Operation.  */

static void extract_field(DisasFields *o, const DisasField *f, uint64_t insn)
{
    uint32_t r, m;

    if (f->size == 0) {
        return;
    }

    /* Zero extract the field from the insn.  */
    r = (insn << f->beg) >> (64 - f->size);

    /* Sign-extend, or un-swap the field as necessary.  */
    switch (f->type) {
    case 0: /* unsigned */
        break;
    case 1: /* signed */
        assert(f->size <= 32);
        m = 1u << (f->size - 1);
        r = (r ^ m) - m;
        break;
    case 2: /* dl+dh split, signed 20 bit. */
        r = ((int8_t)r << 12) | (r >> 8);
        break;
    default:
        abort();
    }

    /* Validate that the "compressed" encoding we selected above is valid.
       I.e. we havn't make two different original fields overlap.  */
    assert(((o->presentC >> f->indexC) & 1) == 0);
    o->presentC |= 1 << f->indexC;
    o->presentO |= 1 << f->indexO;

    o->c[f->indexC] = r;
}

/* Lookup the insn at the current PC, extracting the operands into O and
   returning the info struct for the insn.  Returns NULL for invalid insn.  */

static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s,
                                     DisasFields *f)
{
5982
    uint64_t insn, pc = s->base.pc_next;
5983
    int op, op2, ilen;
5984 5985
    const DisasInsn *info;

5986 5987 5988 5989 5990
    if (unlikely(s->ex_value)) {
        /* Drop the EX data now, so that it's clear on exception paths.  */
        TCGv_i64 zero = tcg_const_i64(0);
        tcg_gen_st_i64(zero, cpu_env, offsetof(CPUS390XState, ex_value));
        tcg_temp_free_i64(zero);
5991

5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012
        /* Extract the values saved by EXECUTE.  */
        insn = s->ex_value & 0xffffffffffff0000ull;
        ilen = s->ex_value & 0xf;
        op = insn >> 56;
    } else {
        insn = ld_code2(env, pc);
        op = (insn >> 8) & 0xff;
        ilen = get_ilen(op);
        switch (ilen) {
        case 2:
            insn = insn << 48;
            break;
        case 4:
            insn = ld_code4(env, pc) << 32;
            break;
        case 6:
            insn = (insn << 48) | (ld_code4(env, pc + 2) << 16);
            break;
        default:
            g_assert_not_reached();
        }
6013
    }
6014
    s->pc_tmp = s->base.pc_next + ilen;
6015
    s->ilen = ilen;
6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026

    /* We can't actually determine the insn format until we've looked up
       the full insn opcode.  Which we can't do without locating the
       secondary opcode.  Assume by default that OP2 is at bit 40; for
       those smaller insns that don't actually have a secondary opcode
       this will correctly result in OP2 = 0. */
    switch (op) {
    case 0x01: /* E */
    case 0x80: /* S */
    case 0x82: /* S */
    case 0x93: /* S */
6027
    case 0xb2: /* S, RRF, RRE, IE */
6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042
    case 0xb3: /* RRE, RRD, RRF */
    case 0xb9: /* RRE, RRF */
    case 0xe5: /* SSE, SIL */
        op2 = (insn << 8) >> 56;
        break;
    case 0xa5: /* RI */
    case 0xa7: /* RI */
    case 0xc0: /* RIL */
    case 0xc2: /* RIL */
    case 0xc4: /* RIL */
    case 0xc6: /* RIL */
    case 0xc8: /* SSF */
    case 0xcc: /* RIL */
        op2 = (insn << 12) >> 60;
        break;
6043 6044
    case 0xc5: /* MII */
    case 0xc7: /* SMI */
6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060
    case 0xd0 ... 0xdf: /* SS */
    case 0xe1: /* SS */
    case 0xe2: /* SS */
    case 0xe8: /* SS */
    case 0xe9: /* SS */
    case 0xea: /* SS */
    case 0xee ... 0xf3: /* SS */
    case 0xf8 ... 0xfd: /* SS */
        op2 = 0;
        break;
    default:
        op2 = (insn << 40) >> 56;
        break;
    }

    memset(f, 0, sizeof(*f));
6061
    f->raw_insn = insn;
6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079
    f->op = op;
    f->op2 = op2;

    /* Lookup the instruction.  */
    info = lookup_opc(op << 8 | op2);

    /* If we found it, extract the operands.  */
    if (info != NULL) {
        DisasFormat fmt = info->fmt;
        int i;

        for (i = 0; i < NUM_C_FIELD; ++i) {
            extract_field(f, &format_info[fmt].op[i], insn);
        }
    }
    return info;
}

6080
static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)
6081 6082
{
    const DisasInsn *insn;
6083
    DisasJumpType ret = DISAS_NEXT;
6084 6085 6086
    DisasFields f;
    DisasOps o;

6087
    /* Search for the insn in the table.  */
6088
    insn = extract_insn(env, s, &f);
6089

6090
    /* Not found means unimplemented/illegal opcode.  */
6091
    if (insn == NULL) {
6092 6093 6094
        qemu_log_mask(LOG_UNIMP, "unimplemented opcode 0x%02x%02x\n",
                      f.op, f.op2);
        gen_illegal_opcode(s);
6095
        return DISAS_NORETURN;
6096 6097
    }

6098
#ifndef CONFIG_USER_ONLY
6099 6100
    if (s->base.tb->flags & FLAG_MASK_PER) {
        TCGv_i64 addr = tcg_const_i64(s->base.pc_next);
6101 6102 6103 6104 6105
        gen_helper_per_ifetch(cpu_env, addr);
        tcg_temp_free_i64(addr);
    }
#endif

6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118
    /* Check for insn specification exceptions.  */
    if (insn->spec) {
        int spec = insn->spec, excp = 0, r;

        if (spec & SPEC_r1_even) {
            r = get_field(&f, r1);
            if (r & 1) {
                excp = PGM_SPECIFICATION;
            }
        }
        if (spec & SPEC_r2_even) {
            r = get_field(&f, r2);
            if (r & 1) {
6119 6120 6121 6122 6123 6124
                excp = PGM_SPECIFICATION;
            }
        }
        if (spec & SPEC_r3_even) {
            r = get_field(&f, r3);
            if (r & 1) {
6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141
                excp = PGM_SPECIFICATION;
            }
        }
        if (spec & SPEC_r1_f128) {
            r = get_field(&f, r1);
            if (r > 13) {
                excp = PGM_SPECIFICATION;
            }
        }
        if (spec & SPEC_r2_f128) {
            r = get_field(&f, r2);
            if (r > 13) {
                excp = PGM_SPECIFICATION;
            }
        }
        if (excp) {
            gen_program_exception(s, excp);
6142
            return DISAS_NORETURN;
6143 6144 6145
        }
    }

6146 6147 6148 6149
    /* Set up the strutures we use to communicate with the helpers. */
    s->insn = insn;
    s->fields = &f;
    o.g_out = o.g_out2 = o.g_in1 = o.g_in2 = false;
6150 6151 6152 6153 6154
    o.out = NULL;
    o.out2 = NULL;
    o.in1 = NULL;
    o.in2 = NULL;
    o.addr1 = NULL;
6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176

    /* Implement the instruction.  */
    if (insn->help_in1) {
        insn->help_in1(s, &f, &o);
    }
    if (insn->help_in2) {
        insn->help_in2(s, &f, &o);
    }
    if (insn->help_prep) {
        insn->help_prep(s, &f, &o);
    }
    if (insn->help_op) {
        ret = insn->help_op(s, &o);
    }
    if (insn->help_wout) {
        insn->help_wout(s, &f, &o);
    }
    if (insn->help_cout) {
        insn->help_cout(s, &o);
    }

    /* Free any temporaries created by the helpers.  */
6177
    if (o.out && !o.g_out) {
6178 6179
        tcg_temp_free_i64(o.out);
    }
6180
    if (o.out2 && !o.g_out2) {
6181 6182
        tcg_temp_free_i64(o.out2);
    }
6183
    if (o.in1 && !o.g_in1) {
6184 6185
        tcg_temp_free_i64(o.in1);
    }
6186
    if (o.in2 && !o.g_in2) {
6187 6188
        tcg_temp_free_i64(o.in2);
    }
6189
    if (o.addr1) {
6190 6191 6192
        tcg_temp_free_i64(o.addr1);
    }

6193
#ifndef CONFIG_USER_ONLY
6194
    if (s->base.tb->flags & FLAG_MASK_PER) {
6195
        /* An exception might be triggered, save PSW if not already done.  */
6196
        if (ret == DISAS_NEXT || ret == DISAS_PC_STALE) {
6197
            tcg_gen_movi_i64(psw_addr, s->pc_tmp);
6198 6199 6200 6201 6202 6203 6204
        }

        /* Call the helper to check for a possible PER exception.  */
        gen_helper_per_check_exception(cpu_env);
    }
#endif

6205
    /* Advance to the next instruction.  */
6206
    s->base.pc_next = s->pc_tmp;
6207
    return ret;
6208 6209
}

6210
static void s390x_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
6211
{
6212
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6213 6214

    /* 31-bit mode */
6215 6216 6217
    if (!(dc->base.tb->flags & FLAG_MASK_64)) {
        dc->base.pc_first &= 0x7fffffff;
        dc->base.pc_next = dc->base.pc_first;
6218 6219
    }

6220 6221 6222 6223
    dc->cc_op = CC_OP_DYNAMIC;
    dc->ex_value = dc->base.tb->cs_base;
    dc->do_debug = dc->base.singlestep_enabled;
}
6224

6225 6226 6227
static void s390x_tr_tb_start(DisasContextBase *db, CPUState *cs)
{
}
6228

6229 6230 6231
static void s390x_tr_insn_start(DisasContextBase *dcbase, CPUState *cs)
{
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6232

6233 6234
    tcg_gen_insn_start(dc->base.pc_next, dc->cc_op);
}
6235

6236 6237 6238 6239
static bool s390x_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs,
                                      const CPUBreakpoint *bp)
{
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6240

6241 6242 6243 6244 6245 6246 6247 6248 6249
    dc->base.is_jmp = DISAS_PC_STALE;
    dc->do_debug = true;
    /* The address covered by the breakpoint must be included in
       [tb->pc, tb->pc + tb->size) in order to for it to be
       properly cleared -- thus we increment the PC here so that
       the logic setting tb->size does the right thing.  */
    dc->base.pc_next += 2;
    return true;
}
6250

6251 6252 6253 6254
static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
{
    CPUS390XState *env = cs->env_ptr;
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6255

6256 6257 6258
    dc->base.is_jmp = translate_one(env, dc);
    if (dc->base.is_jmp == DISAS_NEXT) {
        uint64_t page_start;
6259

6260 6261 6262 6263
        page_start = dc->base.pc_first & TARGET_PAGE_MASK;
        if (dc->base.pc_next - page_start >= TARGET_PAGE_SIZE || dc->ex_value) {
            dc->base.is_jmp = DISAS_TOO_MANY;
        }
6264
    }
6265 6266 6267 6268 6269
}

static void s390x_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
{
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6270

6271
    switch (dc->base.is_jmp) {
6272 6273
    case DISAS_GOTO_TB:
    case DISAS_NORETURN:
6274
        break;
6275 6276 6277
    case DISAS_TOO_MANY:
    case DISAS_PC_STALE:
    case DISAS_PC_STALE_NOCHAIN:
6278
        update_psw_addr(dc);
6279
        /* FALLTHRU */
6280
    case DISAS_PC_UPDATED:
6281 6282
        /* Next TB starts off with CC_OP_DYNAMIC, so make sure the
           cc op type is in env */
6283
        update_cc_op(dc);
6284
        /* FALLTHRU */
6285
    case DISAS_PC_CC_UPDATED:
6286
        /* Exit the TB, either by raising a debug exception or by return.  */
6287
        if (dc->do_debug) {
6288
            gen_exception(EXCP_DEBUG);
6289 6290
        } else if (use_exit_tb(dc) ||
                   dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) {
6291
            tcg_gen_exit_tb(NULL, 0);
6292
        } else {
6293
            tcg_gen_lookup_and_goto_ptr();
6294 6295 6296
        }
        break;
    default:
6297
        g_assert_not_reached();
6298
    }
6299
}
6300

6301 6302 6303
static void s390x_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs)
{
    DisasContext *dc = container_of(dcbase, DisasContext, base);
6304

6305 6306 6307 6308 6309 6310
    if (unlikely(dc->ex_value)) {
        /* ??? Unfortunately log_target_disas can't use host memory.  */
        qemu_log("IN: EXECUTE %016" PRIx64, dc->ex_value);
    } else {
        qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first));
        log_target_disas(cs, dc->base.pc_first, dc->base.tb->size);
6311
    }
6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328
}

static const TranslatorOps s390x_tr_ops = {
    .init_disas_context = s390x_tr_init_disas_context,
    .tb_start           = s390x_tr_tb_start,
    .insn_start         = s390x_tr_insn_start,
    .breakpoint_check   = s390x_tr_breakpoint_check,
    .translate_insn     = s390x_tr_translate_insn,
    .tb_stop            = s390x_tr_tb_stop,
    .disas_log          = s390x_tr_disas_log,
};

void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)
{
    DisasContext dc;

    translator_loop(&s390x_tr_ops, &dc.base, cs, tb);
6329 6330
}

6331 6332
void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb,
                          target_ulong *data)
6333
{
6334 6335
    int cc_op = data[1];
    env->psw.addr = data[0];
6336 6337 6338
    if ((cc_op != CC_OP_DYNAMIC) && (cc_op != CC_OP_STATIC)) {
        env->cc_op = cc_op;
    }
A
Alexander Graf 已提交
6339
}