174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/*
274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Tiny Code Generator for QEMU
374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt *
474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Copyright (c) 2008 Fabrice Bellard
574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt *
674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * Permission is hereby granted, free of charge, to any person obtaining a copy
774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * of this software and associated documentation files (the "Software"), to deal
874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * in the Software without restriction, including without limitation the rights
974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * copies of the Software, and to permit persons to whom the Software is
1174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * furnished to do so, subject to the following conditions:
1274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt *
1374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * The above copyright notice and this permission notice shall be included in
1474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * all copies or substantial portions of the Software.
1574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt *
1674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt * THE SOFTWARE.
2374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt */
2474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
2574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifndef NDEBUG
2674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
2774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g0",
2874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g1",
2974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g2",
3074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g3",
3174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g4",
3274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g5",
3374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g6",
3474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%g7",
3574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o0",
3674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o1",
3774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o2",
3874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o3",
3974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o4",
4074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o5",
4174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o6",
4274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%o7",
4374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l0",
4474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l1",
4574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l2",
4674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l3",
4774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l4",
4874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l5",
4974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l6",
5074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%l7",
5174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i0",
5274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i1",
5374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i2",
5474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i3",
5574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i4",
5674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i5",
5774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i6",
5874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    "%i7",
5974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
6074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
6174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
6274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_reg_alloc_order[] = {
6374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L0,
6474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L1,
6574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L2,
6674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L3,
6774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L4,
6874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L5,
6974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L6,
7074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_L7,
7174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_I0,
7274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_I1,
7374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_I2,
7474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_I3,
7574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_I4,
7674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
7774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
7874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_call_iarg_regs[6] = {
7974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O0,
8074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O1,
8174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O2,
8274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O3,
8374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O4,
8474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O5,
8574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
8674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
8774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const int tcg_target_call_oarg_regs[2] = {
8874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O0,
8974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCG_REG_O1,
9074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
9174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
9274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline int check_fit_tl(tcg_target_long val, unsigned int bits)
9374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
9474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    return (val << ((sizeof(tcg_target_long) * 8 - bits))
9574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            >> (sizeof(tcg_target_long) * 8 - bits)) == val;
9674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
9774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
9874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline int check_fit_i32(uint32_t val, unsigned int bits)
9974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
10074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    return ((val << (32 - bits)) >> (32 - bits)) == val;
10174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
10274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
10374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void patch_reloc(uint8_t *code_ptr, int type,
10474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                        tcg_target_long value, tcg_target_long addend)
10574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
10674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    value += addend;
10774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (type) {
10874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case R_SPARC_32:
10974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (value != (uint32_t)value)
11074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_abort();
11174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        *(uint32_t *)code_ptr = value;
11274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
11374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case R_SPARC_WDISP22:
11474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        value -= (long)code_ptr;
11574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        value >>= 2;
11674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (!check_fit_tl(value, 22))
11774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_abort();
11874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x3fffff) | value;
11974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
12074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case R_SPARC_WDISP19:
12174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        value -= (long)code_ptr;
12274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        value >>= 2;
12374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (!check_fit_tl(value, 19))
12474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_abort();
12574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x7ffff) | value;
12674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
12774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
12874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_abort();
12974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
13074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
13174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
13274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* maximum number of register used for input function arguments */
13374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline int tcg_target_get_call_iarg_regs_count(int flags)
13474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
13574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    return 6;
13674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
13774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
13874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* parse target specific constraints */
13974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
14074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
14174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    const char *ct_str;
14274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
14374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    ct_str = *pct_str;
14474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (ct_str[0]) {
14574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 'r':
14674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        ct->ct |= TCG_CT_REG;
14774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
14874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
14974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 'L': /* qemu_ld/st constraint */
15074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        ct->ct |= TCG_CT_REG;
15174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
15274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        // Helper args
15374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
15474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
15574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
15674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
15774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 'I':
15874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        ct->ct |= TCG_CT_CONST_S11;
15974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
16074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 'J':
16174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        ct->ct |= TCG_CT_CONST_S13;
16274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
16374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
16474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return -1;
16574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
16674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    ct_str++;
16774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *pct_str = ct_str;
16874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    return 0;
16974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
17074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
17174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* test if a constant matches the constraint */
17274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline int tcg_target_const_match(tcg_target_long val,
17374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                         const TCGArgConstraint *arg_ct)
17474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
17574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int ct;
17674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
17774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    ct = arg_ct->ct;
17874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (ct & TCG_CT_CONST)
17974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return 1;
18074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11))
18174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return 1;
18274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13))
18374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return 1;
18474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else
18574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return 0;
18674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
18774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
18874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OP(x)  ((x) << 30)
18974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OP2(x) ((x) << 22)
19074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OP3(x) ((x) << 19)
19174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OPF(x) ((x) << 5)
19274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_RD(x)  ((x) << 25)
19374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_RS1(x) ((x) << 14)
19474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_RS2(x) (x)
19574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_ASI(x) ((x) << 5)
19674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
19774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_IMM11(x) ((1 << 13) | ((x) & 0x7ff))
19874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff))
19974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OFF19(x) (((x) >> 2) & 0x07ffff)
20074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_OFF22(x) (((x) >> 2) & 0x3fffff)
20174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
20274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define INSN_COND(x, a) (((x) << 25) | ((a) << 29))
20374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_N     0x0
20474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_E     0x1
20574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_LE    0x2
20674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_L     0x3
20774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_LEU   0x4
20874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_CS    0x5
20974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_NEG   0x6
21074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_VS    0x7
21174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_A     0x8
21274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_NE    0x9
21374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_G     0xa
21474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_GE    0xb
21574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_GU    0xc
21674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_CC    0xd
21774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_POS   0xe
21874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define COND_VC    0xf
21974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define BA         (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2))
22074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
22174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define MOVCC_ICC  (1 << 18)
22274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define MOVCC_XCC  (1 << 18 | 1 << 12)
22374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
22474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ADD  (INSN_OP(2) | INSN_OP3(0x00))
22574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ADDCC (INSN_OP(2) | INSN_OP3(0x10))
22674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_AND  (INSN_OP(2) | INSN_OP3(0x01))
22774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ANDN (INSN_OP(2) | INSN_OP3(0x05))
22874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_OR   (INSN_OP(2) | INSN_OP3(0x02))
22974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12))
23074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ORN  (INSN_OP(2) | INSN_OP3(0x06))
23174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_XOR  (INSN_OP(2) | INSN_OP3(0x03))
23274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_SUB  (INSN_OP(2) | INSN_OP3(0x04))
23374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_SUBCC (INSN_OP(2) | INSN_OP3(0x14))
23474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_ADDX (INSN_OP(2) | INSN_OP3(0x10))
23574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_SUBX (INSN_OP(2) | INSN_OP3(0x0c))
23674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_UMUL (INSN_OP(2) | INSN_OP3(0x0a))
23774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_UDIV (INSN_OP(2) | INSN_OP3(0x0e))
23874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_SDIV (INSN_OP(2) | INSN_OP3(0x0f))
23974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_MULX (INSN_OP(2) | INSN_OP3(0x09))
24074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_UDIVX (INSN_OP(2) | INSN_OP3(0x0d))
24174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_SDIVX (INSN_OP(2) | INSN_OP3(0x2d))
24274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ARITH_MOVCC (INSN_OP(2) | INSN_OP3(0x2c))
24374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
24474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SLL  (INSN_OP(2) | INSN_OP3(0x25))
24574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SRL  (INSN_OP(2) | INSN_OP3(0x26))
24674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SRA  (INSN_OP(2) | INSN_OP3(0x27))
24774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
24874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SLLX (INSN_OP(2) | INSN_OP3(0x25) | (1 << 12))
24974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SRLX (INSN_OP(2) | INSN_OP3(0x26) | (1 << 12))
25074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SHIFT_SRAX (INSN_OP(2) | INSN_OP3(0x27) | (1 << 12))
25174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
25274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define RDY        (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(0))
25374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define WRY        (INSN_OP(2) | INSN_OP3(0x30) | INSN_RD(0))
25474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define JMPL       (INSN_OP(2) | INSN_OP3(0x38))
25574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SAVE       (INSN_OP(2) | INSN_OP3(0x3c))
25674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define RESTORE    (INSN_OP(2) | INSN_OP3(0x3d))
25774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define SETHI      (INSN_OP(0) | INSN_OP2(0x4))
25874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define CALL       INSN_OP(1)
25974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUB       (INSN_OP(3) | INSN_OP3(0x01))
26074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSB       (INSN_OP(3) | INSN_OP3(0x09))
26174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUH       (INSN_OP(3) | INSN_OP3(0x02))
26274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSH       (INSN_OP(3) | INSN_OP3(0x0a))
26374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUW       (INSN_OP(3) | INSN_OP3(0x00))
26474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSW       (INSN_OP(3) | INSN_OP3(0x08))
26574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDX        (INSN_OP(3) | INSN_OP3(0x0b))
26674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STB        (INSN_OP(3) | INSN_OP3(0x05))
26774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STH        (INSN_OP(3) | INSN_OP3(0x06))
26874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STW        (INSN_OP(3) | INSN_OP3(0x04))
26974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STX        (INSN_OP(3) | INSN_OP3(0x0e))
27074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUBA      (INSN_OP(3) | INSN_OP3(0x11))
27174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSBA      (INSN_OP(3) | INSN_OP3(0x19))
27274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUHA      (INSN_OP(3) | INSN_OP3(0x12))
27374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSHA      (INSN_OP(3) | INSN_OP3(0x1a))
27474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDUWA      (INSN_OP(3) | INSN_OP3(0x10))
27574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDSWA      (INSN_OP(3) | INSN_OP3(0x18))
27674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define LDXA       (INSN_OP(3) | INSN_OP3(0x1b))
27774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STBA       (INSN_OP(3) | INSN_OP3(0x15))
27874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STHA       (INSN_OP(3) | INSN_OP3(0x16))
27974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STWA       (INSN_OP(3) | INSN_OP3(0x14))
28074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define STXA       (INSN_OP(3) | INSN_OP3(0x1e))
28174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
28274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifndef ASI_PRIMARY_LITTLE
28374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define ASI_PRIMARY_LITTLE 0x88
28474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
28574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
28674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_arith(TCGContext *s, int rd, int rs1, int rs2,
28774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                 int op)
28874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
28974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
29074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_RS2(rs2));
29174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
29274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
29374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_arithi(TCGContext *s, int rd, int rs1,
29474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                  uint32_t offset, int op)
29574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
29674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
29774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_IMM13(offset));
29874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
29974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
30074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_arithc(TCGContext *s, int rd, int rs1,
30174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt			   int val2, int val2const, int op)
30274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
30374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1)
30474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              | (val2const ? INSN_IMM13(val2) : INSN_RS2(val2)));
30574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
30674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
307f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_mov(TCGContext *s, TCGType type, int ret, int arg)
30874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
30974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, ret, arg, TCG_REG_G0, ARITH_OR);
31074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
31174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
31274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_sethi(TCGContext *s, int ret, uint32_t arg)
31374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
31474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, SETHI | INSN_RD(ret) | ((arg & 0xfffffc00) >> 10));
31574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
31674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
31774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_movi_imm13(TCGContext *s, int ret, uint32_t arg)
31874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
31974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR);
32074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
32174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
32274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_movi_imm32(TCGContext *s, int ret, uint32_t arg)
32374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
32474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (check_fit_tl(arg, 13))
32574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, arg);
32674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else {
32774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_sethi(s, ret, arg);
32874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (arg & 0x3ff)
32974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
33074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
33174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
33274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
33374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_movi(TCGContext *s, TCGType type,
33474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                int ret, tcg_target_long arg)
33574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
33674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* All 32-bit constants, as well as 64-bit constants with
33774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       no high bits set go through movi_imm32.  */
33874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (TCG_TARGET_REG_BITS == 32
33974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        || type == TCG_TYPE_I32
34074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        || (arg & ~(tcg_target_long)0xffffffff) == 0) {
34174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm32(s, ret, arg);
34274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else if (check_fit_tl(arg, 13)) {
34374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* A 13-bit constant sign-extended to 64-bits.  */
34474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, arg);
34574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else if (check_fit_tl(arg, 32)) {
34674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* A 32-bit constant sign-extended to 64-bits.  */
34774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_sethi(s, ret, ~arg);
34874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, ret, ret, (arg & 0x3ff) | -0x400, ARITH_XOR);
34974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
35074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm32(s, TCG_REG_I4, arg >> (TCG_TARGET_REG_BITS / 2));
35174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, TCG_REG_I4, TCG_REG_I4, 32, SHIFT_SLLX);
35274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm32(s, ret, arg);
35374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arith(s, ret, ret, TCG_REG_I4, ARITH_OR);
35474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
35574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
35674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
35774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_ld_raw(TCGContext *s, int ret,
35874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                  tcg_target_long arg)
35974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
36074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_sethi(s, ret, arg);
36174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
36274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_IMM13(arg & 0x3ff));
36374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
36474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
36574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_ld_ptr(TCGContext *s, int ret,
36674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                  tcg_target_long arg)
36774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
36874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (!check_fit_tl(arg, 10))
36974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ffULL);
37074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (TCG_TARGET_REG_BITS == 64) {
37174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) |
37274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                  INSN_IMM13(arg & 0x3ff));
37374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
37474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
37574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                  INSN_IMM13(arg & 0x3ff));
37674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
37774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
37874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
37974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op)
38074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
38174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (check_fit_tl(offset, 13))
38274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) |
38374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                  INSN_IMM13(offset));
38474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else {
38574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
38674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
38774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                  INSN_RS2(addr));
38874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
38974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
39074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
39174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_ldst_asi(TCGContext *s, int ret, int addr,
39274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                    int offset, int op, int asi)
39374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
39474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
39574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
39674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_ASI(asi) | INSN_RS2(addr));
39774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
39874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
39974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_ld(TCGContext *s, TCGType type, int ret,
40074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              int arg1, tcg_target_long arg2)
40174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
40274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (type == TCG_TYPE_I32)
40374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, ret, arg1, arg2, LDUW);
40474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else
40574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, ret, arg1, arg2, LDX);
40674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
40774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
40874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
40974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              int arg1, tcg_target_long arg2)
41074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
41174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (type == TCG_TYPE_I32)
41274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, arg, arg1, arg2, STW);
41374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    else
41474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, arg, arg1, arg2, STX);
41574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
41674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
41774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_sety(TCGContext *s, int rs)
41874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
41974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, WRY | INSN_RS1(TCG_REG_G0) | INSN_RS2(rs));
42074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
42174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
42274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_rdy(TCGContext *s, int rd)
42374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
42474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, RDY | INSN_RD(rd));
42574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
42674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
42774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
42874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
42974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (val != 0) {
43074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (check_fit_tl(val, 13))
43174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithi(s, reg, reg, val, ARITH_ADD);
43274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        else {
43374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, val);
43474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_ADD);
43574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
43674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
43774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
43874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
43974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_andi(TCGContext *s, int reg, tcg_target_long val)
44074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
44174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (val != 0) {
44274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (check_fit_tl(val, 13))
44374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithi(s, reg, reg, val, ARITH_AND);
44474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        else {
44574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, val);
44674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_AND);
44774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
44874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
44974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
45074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
45174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_div32(TCGContext *s, int rd, int rs1,
45274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                          int val2, int val2const, int uns)
45374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
45474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* Load Y with the sign/zero extension of RS1 to 64-bits.  */
45574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (uns) {
45674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_sety(s, TCG_REG_G0);
45774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
45874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, TCG_REG_I5, rs1, 31, SHIFT_SRA);
45974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_sety(s, TCG_REG_I5);
46074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
46174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
46274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithc(s, rd, rs1, val2, val2const,
46374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   uns ? ARITH_UDIV : ARITH_SDIV);
46474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
46574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
46674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic inline void tcg_out_nop(TCGContext *s)
46774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
46874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_sethi(s, TCG_REG_G0, 0);
46974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
47074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
47174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_branch_i32(TCGContext *s, int opc, int label_index)
47274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
47374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int32_t val;
47474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCGLabel *l = &s->labels[label_index];
47574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
47674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (l->has_value) {
47774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        val = l->u.value - (tcg_target_long)s->code_ptr;
47874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2)
47974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      | INSN_OFF22(l->u.value - (unsigned long)s->code_ptr)));
48074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
48174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP22, label_index, 0);
48274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2) | 0));
48374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
48474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
48574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
48674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
48774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_branch_i64(TCGContext *s, int opc, int label_index)
48874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
48974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int32_t val;
49074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCGLabel *l = &s->labels[label_index];
49174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
49274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (l->has_value) {
49374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        val = l->u.value - (tcg_target_long)s->code_ptr;
49474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) |
49574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      (0x5 << 19) |
49674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      INSN_OFF19(l->u.value - (unsigned long)s->code_ptr)));
49774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
49874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP19, label_index, 0);
49974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) |
50074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      (0x5 << 19) | 0));
50174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
50274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
50374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
50474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
50574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const uint8_t tcg_cond_to_bcond[10] = {
50674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_EQ] = COND_E,
50774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_NE] = COND_NE,
50874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_LT] = COND_L,
50974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_GE] = COND_GE,
51074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_LE] = COND_LE,
51174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_GT] = COND_G,
51274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_LTU] = COND_CS,
51374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_GEU] = COND_CC,
51474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_LEU] = COND_LEU,
51574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    [TCG_COND_GTU] = COND_GU,
51674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
51774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
51874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_cmp(TCGContext *s, TCGArg c1, TCGArg c2, int c2const)
51974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
52074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC);
52174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
52274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
523f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_brcond_i32(TCGContext *s, TCGCond cond,
52474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                               TCGArg arg1, TCGArg arg2, int const_arg2,
52574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                               int label_index)
52674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
52774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_cmp(s, arg1, arg2, const_arg2);
52874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_branch_i32(s, tcg_cond_to_bcond[cond], label_index);
52974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
53074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
53174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
53274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
533f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_brcond_i64(TCGContext *s, TCGCond cond,
53474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                               TCGArg arg1, TCGArg arg2, int const_arg2,
53574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                               int label_index)
53674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
53774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_cmp(s, arg1, arg2, const_arg2);
53874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_branch_i64(s, tcg_cond_to_bcond[cond], label_index);
53974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
54074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
54174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
542f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_brcond2_i32(TCGContext *s, TCGCond cond,
54374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                TCGArg al, TCGArg ah,
54474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                TCGArg bl, int blconst,
54574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                TCGArg bh, int bhconst, int label_dest)
54674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
54774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int cc, label_next = gen_new_label();
54874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
54974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_cmp(s, ah, bh, bhconst);
55074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
55174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* Note that we fill one of the delay slots with the second compare.  */
55274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (cond) {
55374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_EQ:
55474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
55574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_next);
55674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_cmp(s, al, bl, blconst);
55774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_EQ], 0);
55874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_dest);
55974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
56074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
56174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_NE:
56274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
56374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_dest);
56474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_cmp(s, al, bl, blconst);
56574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_dest);
56674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
56774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
56874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
56974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ??? One could fairly easily special-case 64-bit unsigned
57074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt           compares against 32-bit zero-extended constants.  For instance,
57174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt           we know that (unsigned)AH < 0 is false and need not emit it.
57274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt           Similarly, (unsigned)AH > 0 being true implies AH != 0, so the
57374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt           second branch will never be taken.  */
57474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[cond], 0);
57574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_dest);
57674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_nop(s);
57774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
57874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_next);
57974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_cmp(s, al, bl, blconst);
58074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cc = INSN_COND(tcg_cond_to_bcond[tcg_unsigned_cond(cond)], 0);
58174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, cc, label_dest);
58274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
58374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
58474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
58574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
58674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_label(s, label_next, (tcg_target_long)s->code_ptr);
58774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
58874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
58974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
590f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_setcond_i32(TCGContext *s, TCGCond cond, TCGArg ret,
59174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                TCGArg c1, TCGArg c2, int c2const)
59274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
59374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    TCGArg t;
59474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
59574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* For 32-bit comparisons, we can play games with ADDX/SUBX.  */
59674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (cond) {
59774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_EQ:
59874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_NE:
59974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (c2 != 0) {
60074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithc(s, ret, c1, c2, c2const, ARITH_XOR);
60174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
60274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c1 = TCG_REG_G0, c2 = ret, c2const = 0;
60374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cond = (cond == TCG_COND_EQ ? TCG_COND_LEU : TCG_COND_LTU);
60474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	break;
60574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
60674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_GTU:
60774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_GEU:
60874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (c2const && c2 != 0) {
60974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_movi_imm13(s, TCG_REG_I5, c2);
61074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            c2 = TCG_REG_I5;
61174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
61274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        t = c1, c1 = c2, c2 = t, c2const = 0;
61374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        cond = tcg_swap_cond(cond);
61474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
61574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
61674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_LTU:
61774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_LEU:
61874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
61974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
62074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
62174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_cmp(s, c1, c2, c2const);
62274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
62374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, 0);
62474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32 (s, ARITH_MOVCC | INSN_RD(ret)
62574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   | INSN_RS1(tcg_cond_to_bcond[cond])
62674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   | MOVCC_ICC | INSN_IMM11(1));
62774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
62874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        t = gen_new_label();
62974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, INSN_COND(tcg_cond_to_bcond[cond], 1), t);
63074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, 1);
63174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, 0);
63274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_label(s, t, (tcg_target_long)s->code_ptr);
63374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
63474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        return;
63574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
63674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
63774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_cmp(s, c1, c2, c2const);
63874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    if (cond == TCG_COND_LTU) {
63974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, ret, TCG_REG_G0, 0, ARITH_ADDX);
64074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    } else {
64174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, ret, TCG_REG_G0, -1, ARITH_SUBX);
64274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
64374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
64474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
64574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
646f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_setcond_i64(TCGContext *s, TCGCond cond, TCGArg ret,
64774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                TCGArg c1, TCGArg c2, int c2const)
64874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
64974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_cmp(s, c1, c2, c2const);
65074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi_imm13(s, ret, 0);
65174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32 (s, ARITH_MOVCC | INSN_RD(ret)
65274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt               | INSN_RS1(tcg_cond_to_bcond[cond])
65374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt               | MOVCC_XCC | INSN_IMM11(1));
65474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
65574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
656f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_out_setcond2_i32(TCGContext *s, TCGCond cond, TCGArg ret,
65774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                 TCGArg al, TCGArg ah,
65874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                 TCGArg bl, int blconst,
65974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                 TCGArg bh, int bhconst)
66074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
66174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int lab;
66274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
66374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (cond) {
66474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_EQ:
66574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, TCG_COND_EQ, TCG_REG_I5, al, bl, blconst);
66674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, TCG_COND_EQ, ret, ah, bh, bhconst);
66774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arith(s, ret, ret, TCG_REG_I5, ARITH_AND);
66874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
66974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
67074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case TCG_COND_NE:
67174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, TCG_COND_NE, TCG_REG_I5, al, al, blconst);
67274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, TCG_COND_NE, ret, ah, bh, bhconst);
67374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arith(s, ret, ret, TCG_REG_I5, ARITH_OR);
67474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
67574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
67674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
67774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        lab = gen_new_label();
67874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
67974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_cmp(s, ah, bh, bhconst);
68074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, INSN_COND(tcg_cond_to_bcond[cond], 1), lab);
68174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, 1);
68274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, INSN_COND(COND_NE, 1), lab);
68374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi_imm13(s, ret, 0);
68474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
68574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, tcg_unsigned_cond(cond), ret, al, bl, blconst);
68674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
68774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_label(s, lab, (tcg_target_long)s->code_ptr);
68874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
68974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
69074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
69174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
69274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
69374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt/* Generate global QEMU prologue and epilogue code */
694f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_target_qemu_prologue(TCGContext *s)
69574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
69674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) |
69774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_IMM13(-TCG_TARGET_STACK_MINFRAME));
69874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I0) |
69974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_RS2(TCG_REG_G0));
70074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
70174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
70274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
70374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
70474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
70574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#include "../../softmmu_defs.h"
70674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
70774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const void * const qemu_ld_helpers[4] = {
70874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __ldb_mmu,
70974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __ldw_mmu,
71074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __ldl_mmu,
71174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __ldq_mmu,
71274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
71374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
71474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const void * const qemu_st_helpers[4] = {
71574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __stb_mmu,
71674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __stw_mmu,
71774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __stl_mmu,
71874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    __stq_mmu,
71974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
72074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
72174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
72274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32
72374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define TARGET_LD_OP LDUW
72474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
72574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define TARGET_LD_OP LDX
72674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
72774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
728f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#if defined(CONFIG_SOFTMMU)
729f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#if HOST_LONG_BITS == 32
73074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define TARGET_ADDEND_LD_OP LDUW
73174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
73274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define TARGET_ADDEND_LD_OP LDX
73374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
734f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#endif
73574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
73674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef __arch64__
73774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_LD_OP LDX
73874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_ST_OP STX
73974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_SLL_OP SHIFT_SLLX
74074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_SRA_OP SHIFT_SRAX
74174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
74274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_LD_OP LDUW
74374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_ST_OP STW
74474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_SLL_OP SHIFT_SLL
74574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define HOST_SRA_OP SHIFT_SRA
74674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
74774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
74874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
74974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            int opc)
75074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
75174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
75274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
75374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    uint32_t *label1_ptr, *label2_ptr;
75474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
75574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
75674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    data_reg = *args++;
75774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    addr_reg = *args++;
75874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    mem_index = *args;
75974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    s_bits = opc & 3;
76074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
76174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg0 = TCG_REG_O0;
76274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg1 = TCG_REG_O1;
76374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg2 = TCG_REG_O2;
76474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
76574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
76674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* srl addr_reg, x, arg1 */
76774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
76874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   SHIFT_SRL);
76974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and addr_reg, x, arg0 */
77074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
77174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   ARITH_AND);
77274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
77374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and arg1, x, arg1 */
77474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
77574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
77674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add arg1, x, arg1 */
77774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_addi(s, arg1, offsetof(CPUState,
77874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                   tlb_table[mem_index][0].addr_read));
77974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
78074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add env, arg1, arg1 */
78174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
78274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
78374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* ld [arg1], arg2 */
78474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
78574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_RS2(TCG_REG_G0));
78674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
78774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* subcc arg0, arg2, %g0 */
78874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
78974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
79074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* will become:
79174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       be label1
79274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        or
79374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       be,pt %xcc label1 */
79474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    label1_ptr = (uint32_t *)s->code_ptr;
79574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, 0);
79674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
79774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* mov (delay slot) */
798f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    tcg_out_mov(s, TCG_TYPE_PTR, arg0, addr_reg);
79974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
80074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* mov */
80174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi(s, TCG_TYPE_I32, arg1, mem_index);
80274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
80374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* XXX: move that code at the end of the TB */
80474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* qemu_ld_helper[s_bits](arg0, arg1) */
80574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits]
80674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                           - (tcg_target_ulong)s->code_ptr) >> 2)
80774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                         & 0x3fffffff));
80874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
80974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       global registers */
81074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    // delay slot
81174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
81274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
81374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 sizeof(long), HOST_ST_OP);
81474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
81574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
81674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 sizeof(long), HOST_LD_OP);
81774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
81874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* data_reg = sign_extend(arg0) */
81974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch(opc) {
82074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 0 | 4:
82174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sll arg0, 24/56, data_reg */
82274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8,
82374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       HOST_SLL_OP);
82474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sra data_reg, 24/56, data_reg */
82574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, data_reg,
82674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       (int)sizeof(tcg_target_long) * 8 - 8, HOST_SRA_OP);
82774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
82874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 1 | 4:
82974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sll arg0, 16/48, data_reg */
83074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, arg0,
83174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SLL_OP);
83274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sra data_reg, 16/48, data_reg */
83374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, data_reg,
83474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SRA_OP);
83574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
83674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 2 | 4:
83774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sll arg0, 32, data_reg */
83874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, arg0, 32, HOST_SLL_OP);
83974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sra data_reg, 32, data_reg */
84074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithi(s, data_reg, data_reg, 32, HOST_SRA_OP);
84174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
84274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 0:
84374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 1:
84474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 2:
84574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 3:
84674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
84774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* mov */
848f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner        tcg_out_mov(s, TCG_TYPE_REG, data_reg, arg0);
84974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
85074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
85174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
85274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* will become:
85374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       ba label2 */
85474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    label2_ptr = (uint32_t *)s->code_ptr;
85574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, 0);
85674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
85774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* nop (delay slot */
85874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
85974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
86074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* label1: */
86174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32
86274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* be label1 */
86374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
86474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   INSN_OFF22((unsigned long)s->code_ptr -
86574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label1_ptr));
86674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
86774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* be,pt %xcc label1 */
86874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) |
86974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr -
87074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label1_ptr));
87174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
87274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
87374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* ld [arg1 + x], arg1 */
87474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
87574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 offsetof(CPUTLBEntry, addr_read), TARGET_ADDEND_LD_OP);
87674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
87774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32
87874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and addr_reg, x, arg0 */
87974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff);
88074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND);
88174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add arg0, arg1, arg0 */
88274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD);
88374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
88474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add addr_reg, arg1, arg0 */
88574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
88674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
88774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
88874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
88974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg0 = addr_reg;
89074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
89174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
89274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch(opc) {
89374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 0:
89474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldub [arg0], data_reg */
89574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDUB);
89674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
89774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 0 | 4:
89874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldsb [arg0], data_reg */
89974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDSB);
90074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
90174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 1:
90274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
90374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* lduh [arg0], data_reg */
90474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDUH);
90574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
90674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */
90774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE);
90874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
90974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
91074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 1 | 4:
91174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
91274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldsh [arg0], data_reg */
91374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDSH);
91474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
91574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */
91674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE);
91774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
91874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
91974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 2:
92074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
92174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* lduw [arg0], data_reg */
92274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDUW);
92374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
92474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */
92574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE);
92674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
92774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
92874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 2 | 4:
92974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
93074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldsw [arg0], data_reg */
93174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDSW);
93274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
93374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */
93474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE);
93574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
93674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
93774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 3:
93874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
93974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldx [arg0], data_reg */
94074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, LDX);
94174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
94274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */
94374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE);
94474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
94574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
94674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
94774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_abort();
94874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
94974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
95074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
95174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* label2: */
95274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
95374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   INSN_OFF22((unsigned long)s->code_ptr -
95474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label2_ptr));
95574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
95674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
95774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
95874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
95974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            int opc)
96074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
96174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
96274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
96374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    uint32_t *label1_ptr, *label2_ptr;
96474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
96574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
96674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    data_reg = *args++;
96774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    addr_reg = *args++;
96874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    mem_index = *args;
96974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
97074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    s_bits = opc;
97174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
97274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg0 = TCG_REG_O0;
97374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg1 = TCG_REG_O1;
97474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg2 = TCG_REG_O2;
97574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
97674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
97774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* srl addr_reg, x, arg1 */
97874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
97974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   SHIFT_SRL);
98074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
98174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and addr_reg, x, arg0 */
98274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
98374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   ARITH_AND);
98474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
98574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and arg1, x, arg1 */
98674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
98774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
98874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add arg1, x, arg1 */
98974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_addi(s, arg1, offsetof(CPUState,
99074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                   tlb_table[mem_index][0].addr_write));
99174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
99274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add env, arg1, arg1 */
99374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
99474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
99574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* ld [arg1], arg2 */
99674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
99774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt              INSN_RS2(TCG_REG_G0));
99874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
99974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* subcc arg0, arg2, %g0 */
100074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
100174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
100274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* will become:
100374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       be label1
100474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        or
100574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       be,pt %xcc label1 */
100674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    label1_ptr = (uint32_t *)s->code_ptr;
100774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, 0);
100874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
100974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* mov (delay slot) */
1010f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    tcg_out_mov(s, TCG_TYPE_PTR, arg0, addr_reg);
101174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
101274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* mov */
1013f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    tcg_out_mov(s, TCG_TYPE_REG, arg1, data_reg);
101474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
101574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* mov */
101674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi(s, TCG_TYPE_I32, arg2, mem_index);
101774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
101874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* XXX: move that code at the end of the TB */
101974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* qemu_st_helper[s_bits](arg0, arg1, arg2) */
102074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_st_helpers[s_bits]
102174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                           - (tcg_target_ulong)s->code_ptr) >> 2)
102274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                         & 0x3fffffff));
102374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
102474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       global registers */
102574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    // delay slot
102674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
102774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
102874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 sizeof(long), HOST_ST_OP);
102974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
103074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
103174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 sizeof(long), HOST_LD_OP);
103274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
103374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* will become:
103474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt       ba label2 */
103574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    label2_ptr = (uint32_t *)s->code_ptr;
103674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out32(s, 0);
103774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
103874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* nop (delay slot) */
103974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_nop(s);
104074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
104174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32
104274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* be label1 */
104374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
104474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   INSN_OFF22((unsigned long)s->code_ptr -
104574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label1_ptr));
104674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
104774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* be,pt %xcc label1 */
104874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) |
104974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr -
105074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label1_ptr));
105174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
105274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
105374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* ld [arg1 + x], arg1 */
105474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
105574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                 offsetof(CPUTLBEntry, addr_write), TARGET_ADDEND_LD_OP);
105674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
105774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TARGET_LONG_BITS == 32
105874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* and addr_reg, x, arg0 */
105974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff);
106074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND);
106174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add arg0, arg1, arg0 */
106274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD);
106374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
106474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* add addr_reg, arg1, arg0 */
106574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
106674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
106774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
106874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
106974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    arg0 = addr_reg;
107074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
107174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
107274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch(opc) {
107374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 0:
107474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stb data_reg, [arg0] */
107574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, STB);
107674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
107774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 1:
107874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
107974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* sth data_reg, [arg0] */
108074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, STH);
108174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
108274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stha data_reg, [arg0] ASI_PRIMARY_LITTLE */
108374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, STHA, ASI_PRIMARY_LITTLE);
108474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
108574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
108674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 2:
108774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
108874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stw data_reg, [arg0] */
108974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, STW);
109074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
109174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stwa data_reg, [arg0] ASI_PRIMARY_LITTLE */
109274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, STWA, ASI_PRIMARY_LITTLE);
109374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
109474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
109574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case 3:
109674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#ifdef TARGET_WORDS_BIGENDIAN
109774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stx data_reg, [arg0] */
109874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, data_reg, arg0, 0, STX);
109974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
110074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* stxa data_reg, [arg0] ASI_PRIMARY_LITTLE */
110174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst_asi(s, data_reg, arg0, 0, STXA, ASI_PRIMARY_LITTLE);
110274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
110374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
110474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
110574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_abort();
110674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
110774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
110874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if defined(CONFIG_SOFTMMU)
110974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    /* label2: */
111074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
111174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                   INSN_OFF22((unsigned long)s->code_ptr -
111274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              (unsigned long)label2_ptr));
111374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
111474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
111574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
1116f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic inline void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
111774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                              const int *const_args)
111874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
111974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    int c;
112074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
112174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    switch (opc) {
112274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_exit_tb:
112374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, args[0]);
112474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I7) |
112574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                  INSN_IMM13(8));
112674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out32(s, RESTORE | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_G0) |
112774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      INSN_RS2(TCG_REG_G0));
112874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
112974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_goto_tb:
113074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (s->tb_jmp_offset) {
113174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            /* direct jump method */
113274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_sethi(s, TCG_REG_I5, args[0] & 0xffffe000);
113374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
113474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      INSN_IMM13((args[0] & 0x1fff)));
113574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
113674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        } else {
113774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            /* indirect jump method */
113874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_ld_ptr(s, TCG_REG_I5, (tcg_target_long)(s->tb_next + args[0]));
113974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
114074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      INSN_RS2(TCG_REG_G0));
114174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
114274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_nop(s);
114374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
114474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
114574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_call:
114674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (const_args[0])
114774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out32(s, CALL | ((((tcg_target_ulong)args[0]
114874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                   - (tcg_target_ulong)s->code_ptr) >> 2)
114974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                                 & 0x3fffffff));
115074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        else {
115174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_ld_ptr(s, TCG_REG_I5,
115274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                           (tcg_target_long)(s->tb_next + args[0]));
115374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_I5) |
115474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      INSN_RS2(TCG_REG_G0));
115574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
115674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
115774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt           global registers */
115874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        // delay slot
115974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
116074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
116174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     sizeof(long), HOST_ST_OP);
116274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
116374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
116474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     sizeof(long), HOST_LD_OP);
116574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
116674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_jmp:
116774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_br:
116874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_branch_i32(s, COND_A, args[0]);
116974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_nop(s);
117074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
117174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_movi_i32:
117274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]);
117374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
117474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
117574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
117674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define OP_32_64(x)                             \
117774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        glue(glue(case INDEX_op_, x), _i32):    \
117874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        glue(glue(case INDEX_op_, x), _i64)
117974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#else
118074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#define OP_32_64(x)                             \
118174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        glue(glue(case INDEX_op_, x), _i32)
118274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
118374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(ld8u):
118474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDUB);
118574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
118674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(ld8s):
118774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDSB);
118874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
118974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(ld16u):
119074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDUH);
119174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
119274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(ld16s):
119374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDSH);
119474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
119574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ld_i32:
119674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
119774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ld32u_i64:
119874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
119974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDUW);
120074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
120174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(st8):
120274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], STB);
120374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
120474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(st16):
120574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], STH);
120674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
120774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_st_i32:
120874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
120974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_st32_i64:
121074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
121174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], STW);
121274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
121374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(add):
121474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_ADD;
121574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
121674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(sub):
121774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_SUB;
121874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
121974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(and):
122074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_AND;
122174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
122274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(andc):
122374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_ANDN;
122474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
122574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(or):
122674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_OR;
122774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
122874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(orc):
122974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_ORN;
123074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
123174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(xor):
123274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_XOR;
123374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
123474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_shl_i32:
123574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SLL;
123674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
123774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_shr_i32:
123874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SRL;
123974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
124074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_sar_i32:
124174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SRA;
124274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
124374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_mul_i32:
124474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_UMUL;
124574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
124674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
124774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(neg):
124874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	c = ARITH_SUB;
124974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	goto gen_arith1;
125074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    OP_32_64(not):
125174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	c = ARITH_ORN;
125274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	goto gen_arith1;
125374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
125474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_div_i32:
125574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_div32(s, args[0], args[1], args[2], const_args[2], 0);
125674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
125774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_divu_i32:
125874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_div32(s, args[0], args[1], args[2], const_args[2], 1);
125974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
126074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
126174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_rem_i32:
126274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_remu_i32:
126374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_div32(s, TCG_REG_I5, args[1], args[2], const_args[2],
126474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                      opc == INDEX_op_remu_i32);
126574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, TCG_REG_I5, TCG_REG_I5, args[2], const_args[2],
126674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_UMUL);
126774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arith(s, args[0], args[1], TCG_REG_I5, ARITH_SUB);
126874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
126974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
127074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_brcond_i32:
127174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_brcond_i32(s, args[2], args[0], args[1], const_args[1],
127274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                           args[3]);
127374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
127474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_setcond_i32:
127574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i32(s, args[3], args[0], args[1],
127674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            args[2], const_args[2]);
127774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
127874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
127974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 32
128074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_brcond2_i32:
128174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_brcond2_i32(s, args[4], args[0], args[1],
128274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            args[2], const_args[2],
128374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            args[3], const_args[3], args[5]);
128474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
128574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_setcond2_i32:
128674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond2_i32(s, args[5], args[0], args[1], args[2],
128774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                             args[3], const_args[3],
128874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                             args[4], const_args[4]);
128974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
129074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_add2_i32:
129174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[0], args[2], args[4], const_args[4],
129274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_ADDCC);
129374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[1], args[3], args[5], const_args[5],
129474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_ADDX);
129574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
129674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_sub2_i32:
129774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[0], args[2], args[4], const_args[4],
129874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_SUBCC);
129974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[1], args[3], args[5], const_args[5],
130074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_SUBX);
130174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
130274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_mulu2_i32:
130374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[0], args[2], args[3], const_args[3],
130474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_UMUL);
130574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_rdy(s, args[1]);
130674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
130774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
130874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
130974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld8u:
131074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 0);
131174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
131274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld8s:
131374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 0 | 4);
131474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
131574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld16u:
131674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 1);
131774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
131874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld16s:
131974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 1 | 4);
132074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
1321f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    case INDEX_op_qemu_ld32:
1322f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#if TCG_TARGET_REG_BITS == 64
132374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld32u:
1324f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner#endif
132574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 2);
132674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
132774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
132874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld32s:
132974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 2 | 4);
133074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
133174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
133274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_st8:
133374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_st(s, args, 0);
133474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
133574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_st16:
133674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_st(s, args, 1);
133774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
133874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_st32:
133974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_st(s, args, 2);
134074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
134174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
134274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
134374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_movi_i64:
134474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]);
134574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
134674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ld32s_i64:
134774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDSW);
134874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
134974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ld_i64:
135074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], LDX);
135174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
135274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_st_i64:
135374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_ldst(s, args[0], args[1], args[2], STX);
135474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
135574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_shl_i64:
135674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SLLX;
135774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
135874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_shr_i64:
135974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SRLX;
136074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
136174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_sar_i64:
136274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = SHIFT_SRAX;
136374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
136474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_mul_i64:
136574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_MULX;
136674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
136774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_div_i64:
136874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_SDIVX;
136974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
137074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_divu_i64:
137174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        c = ARITH_UDIVX;
137274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        goto gen_arith;
137374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_rem_i64:
137474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_remu_i64:
137574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, TCG_REG_I5, args[1], args[2], const_args[2],
137674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       opc == INDEX_op_rem_i64 ? ARITH_SDIVX : ARITH_UDIVX);
137774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, TCG_REG_I5, TCG_REG_I5, args[2], const_args[2],
137874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                       ARITH_MULX);
137974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arith(s, args[0], args[1], TCG_REG_I5, ARITH_SUB);
138074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
138174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ext32s_i64:
138274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (const_args[1]) {
138374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_movi(s, TCG_TYPE_I64, args[0], (int32_t)args[1]);
138474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        } else {
138574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithi(s, args[0], args[1], 0, SHIFT_SRA);
138674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
138774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
138874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_ext32u_i64:
138974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        if (const_args[1]) {
139074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_movi_imm32(s, args[0], args[1]);
139174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        } else {
139274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt            tcg_out_arithi(s, args[0], args[1], 0, SHIFT_SRL);
139374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        }
139474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
139574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
139674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_brcond_i64:
139774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_brcond_i64(s, args[2], args[0], args[1], const_args[1],
139874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                           args[3]);
139974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
140074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_setcond_i64:
140174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_setcond_i64(s, args[3], args[0], args[1],
140274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                            args[2], const_args[2]);
140374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
140474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
140574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_ld64:
140674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_ld(s, args, 3);
140774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
140874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    case INDEX_op_qemu_st64:
140974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_qemu_st(s, args, 3);
141074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
141174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
141274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
141374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    gen_arith:
141474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_out_arithc(s, args[0], args[1], args[2], const_args[2], c);
141574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        break;
141674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
141774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    gen_arith1:
141874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	tcg_out_arithc(s, args[0], TCG_REG_G0, args[1], const_args[1], c);
141974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt	break;
142074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
142174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    default:
142274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        fprintf(stderr, "unknown opcode 0x%x\n", opc);
142374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt        tcg_abort();
142474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    }
142574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
142674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
142774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedtstatic const TCGTargetOpDef sparc_op_defs[] = {
142874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_exit_tb, { } },
142974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_goto_tb, { } },
143074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_call, { "ri" } },
143174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_jmp, { "ri" } },
143274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_br, { } },
143374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
143474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_mov_i32, { "r", "r" } },
143574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_movi_i32, { "r" } },
143674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld8u_i32, { "r", "r" } },
143774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld8s_i32, { "r", "r" } },
143874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld16u_i32, { "r", "r" } },
143974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld16s_i32, { "r", "r" } },
144074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld_i32, { "r", "r" } },
144174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st8_i32, { "r", "r" } },
144274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st16_i32, { "r", "r" } },
144374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st_i32, { "r", "r" } },
144474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
144574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_add_i32, { "r", "r", "rJ" } },
144674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_mul_i32, { "r", "r", "rJ" } },
144774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_div_i32, { "r", "r", "rJ" } },
144874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_divu_i32, { "r", "r", "rJ" } },
144974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_rem_i32, { "r", "r", "rJ" } },
145074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_remu_i32, { "r", "r", "rJ" } },
145174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_sub_i32, { "r", "r", "rJ" } },
145274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_and_i32, { "r", "r", "rJ" } },
145374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_andc_i32, { "r", "r", "rJ" } },
145474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_or_i32, { "r", "r", "rJ" } },
145574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_orc_i32, { "r", "r", "rJ" } },
145674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_xor_i32, { "r", "r", "rJ" } },
145774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
145874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_shl_i32, { "r", "r", "rJ" } },
145974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_shr_i32, { "r", "r", "rJ" } },
146074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_sar_i32, { "r", "r", "rJ" } },
146174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
146274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_neg_i32, { "r", "rJ" } },
146374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_not_i32, { "r", "rJ" } },
146474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
146574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_brcond_i32, { "r", "rJ" } },
146674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_setcond_i32, { "r", "r", "rJ" } },
146774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
146874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 32
146974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_brcond2_i32, { "r", "r", "rJ", "rJ" } },
147074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_setcond2_i32, { "r", "r", "r", "rJ", "rJ" } },
147174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_add2_i32, { "r", "r", "r", "r", "rJ", "rJ" } },
147274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_sub2_i32, { "r", "r", "r", "r", "rJ", "rJ" } },
147374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_mulu2_i32, { "r", "r", "r", "rJ" } },
147474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
147574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
147674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld8u, { "r", "L" } },
147774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld8s, { "r", "L" } },
147874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld16u, { "r", "L" } },
147974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld16s, { "r", "L" } },
1480f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    { INDEX_op_qemu_ld32, { "r", "L" } },
148174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
1482f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turner    { INDEX_op_qemu_ld32u, { "r", "L" } },
148374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld32s, { "r", "L" } },
148474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
148574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
148674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_st8, { "L", "L" } },
148774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_st16, { "L", "L" } },
148874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_st32, { "L", "L" } },
148974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
149074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
149174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_mov_i64, { "r", "r" } },
149274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_movi_i64, { "r" } },
149374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld8u_i64, { "r", "r" } },
149474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld8s_i64, { "r", "r" } },
149574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld16u_i64, { "r", "r" } },
149674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld16s_i64, { "r", "r" } },
149774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld32u_i64, { "r", "r" } },
149874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld32s_i64, { "r", "r" } },
149974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ld_i64, { "r", "r" } },
150074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st8_i64, { "r", "r" } },
150174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st16_i64, { "r", "r" } },
150274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st32_i64, { "r", "r" } },
150374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_st_i64, { "r", "r" } },
150474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_ld64, { "L", "L" } },
150574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_qemu_st64, { "L", "L" } },
150674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
150774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_add_i64, { "r", "r", "rJ" } },
150874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_mul_i64, { "r", "r", "rJ" } },
150974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_div_i64, { "r", "r", "rJ" } },
151074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_divu_i64, { "r", "r", "rJ" } },
151174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_rem_i64, { "r", "r", "rJ" } },
151274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_remu_i64, { "r", "r", "rJ" } },
151374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_sub_i64, { "r", "r", "rJ" } },
151474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_and_i64, { "r", "r", "rJ" } },
151574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_andc_i64, { "r", "r", "rJ" } },
151674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_or_i64, { "r", "r", "rJ" } },
151774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_orc_i64, { "r", "r", "rJ" } },
151874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_xor_i64, { "r", "r", "rJ" } },
151974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
152074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_shl_i64, { "r", "r", "rJ" } },
152174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_shr_i64, { "r", "r", "rJ" } },
152274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_sar_i64, { "r", "r", "rJ" } },
152374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
152474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_neg_i64, { "r", "rJ" } },
152574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_not_i64, { "r", "rJ" } },
152674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
152774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ext32s_i64, { "r", "ri" } },
152874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_ext32u_i64, { "r", "ri" } },
152974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
153074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_brcond_i64, { "r", "rJ" } },
153174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { INDEX_op_setcond_i64, { "r", "r", "rJ" } },
153274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
153374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    { -1 },
153474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt};
153574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
1536f1d9bf153726533acf659efd796aa484dfd0b412David 'Digit' Turnerstatic void tcg_target_init(TCGContext *s)
153774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt{
153874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
153974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
154074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
154174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
154274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set32(tcg_target_call_clobber_regs, 0,
154374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G1) |
154474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G2) |
154574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G3) |
154674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G4) |
154774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G5) |
154874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G6) |
154974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_G7) |
155074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O0) |
155174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O1) |
155274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O2) |
155374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O3) |
155474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O4) |
155574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O5) |
155674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt                     (1 << TCG_REG_O7));
155774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt
155874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_clear(s->reserved_regs);
155974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_G0);
156074bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#if TCG_TARGET_REG_BITS == 64
156174bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I4); // for internal use
156274bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt#endif
156374bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I5); // for internal use
156474bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I6);
156574bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I7);
156674bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O6);
156774bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O7);
156874bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt    tcg_add_target_add_op_defs(sparc_op_defs);
156974bdaadb718584b216e29c13b9e1226c9f77205eMarcus Comstedt}
1570