Statistics
| Branch: | Revision:

root / tcg / sparc / tcg-target.c @ ba225198

History | View | Annotate | Download (40.5 kB)

1 8289b279 blueswir1
/*
2 8289b279 blueswir1
 * Tiny Code Generator for QEMU
3 8289b279 blueswir1
 *
4 8289b279 blueswir1
 * Copyright (c) 2008 Fabrice Bellard
5 8289b279 blueswir1
 *
6 8289b279 blueswir1
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 8289b279 blueswir1
 * of this software and associated documentation files (the "Software"), to deal
8 8289b279 blueswir1
 * in the Software without restriction, including without limitation the rights
9 8289b279 blueswir1
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 8289b279 blueswir1
 * copies of the Software, and to permit persons to whom the Software is
11 8289b279 blueswir1
 * furnished to do so, subject to the following conditions:
12 8289b279 blueswir1
 *
13 8289b279 blueswir1
 * The above copyright notice and this permission notice shall be included in
14 8289b279 blueswir1
 * all copies or substantial portions of the Software.
15 8289b279 blueswir1
 *
16 8289b279 blueswir1
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 8289b279 blueswir1
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 8289b279 blueswir1
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 8289b279 blueswir1
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 8289b279 blueswir1
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 8289b279 blueswir1
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 8289b279 blueswir1
 * THE SOFTWARE.
23 8289b279 blueswir1
 */
24 8289b279 blueswir1
25 d4a9eb1f blueswir1
#ifndef NDEBUG
26 8289b279 blueswir1
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
27 8289b279 blueswir1
    "%g0",
28 8289b279 blueswir1
    "%g1",
29 8289b279 blueswir1
    "%g2",
30 8289b279 blueswir1
    "%g3",
31 8289b279 blueswir1
    "%g4",
32 8289b279 blueswir1
    "%g5",
33 8289b279 blueswir1
    "%g6",
34 8289b279 blueswir1
    "%g7",
35 8289b279 blueswir1
    "%o0",
36 8289b279 blueswir1
    "%o1",
37 8289b279 blueswir1
    "%o2",
38 8289b279 blueswir1
    "%o3",
39 8289b279 blueswir1
    "%o4",
40 8289b279 blueswir1
    "%o5",
41 8289b279 blueswir1
    "%o6",
42 8289b279 blueswir1
    "%o7",
43 8289b279 blueswir1
    "%l0",
44 8289b279 blueswir1
    "%l1",
45 8289b279 blueswir1
    "%l2",
46 8289b279 blueswir1
    "%l3",
47 8289b279 blueswir1
    "%l4",
48 8289b279 blueswir1
    "%l5",
49 8289b279 blueswir1
    "%l6",
50 8289b279 blueswir1
    "%l7",
51 8289b279 blueswir1
    "%i0",
52 8289b279 blueswir1
    "%i1",
53 8289b279 blueswir1
    "%i2",
54 8289b279 blueswir1
    "%i3",
55 8289b279 blueswir1
    "%i4",
56 8289b279 blueswir1
    "%i5",
57 8289b279 blueswir1
    "%i6",
58 8289b279 blueswir1
    "%i7",
59 8289b279 blueswir1
};
60 d4a9eb1f blueswir1
#endif
61 8289b279 blueswir1
62 0954d0d9 blueswir1
static const int tcg_target_reg_alloc_order[] = {
63 8289b279 blueswir1
    TCG_REG_L0,
64 8289b279 blueswir1
    TCG_REG_L1,
65 8289b279 blueswir1
    TCG_REG_L2,
66 8289b279 blueswir1
    TCG_REG_L3,
67 8289b279 blueswir1
    TCG_REG_L4,
68 8289b279 blueswir1
    TCG_REG_L5,
69 8289b279 blueswir1
    TCG_REG_L6,
70 8289b279 blueswir1
    TCG_REG_L7,
71 8289b279 blueswir1
    TCG_REG_I0,
72 8289b279 blueswir1
    TCG_REG_I1,
73 8289b279 blueswir1
    TCG_REG_I2,
74 8289b279 blueswir1
    TCG_REG_I3,
75 8289b279 blueswir1
    TCG_REG_I4,
76 8289b279 blueswir1
};
77 8289b279 blueswir1
78 8289b279 blueswir1
static const int tcg_target_call_iarg_regs[6] = {
79 8289b279 blueswir1
    TCG_REG_O0,
80 8289b279 blueswir1
    TCG_REG_O1,
81 8289b279 blueswir1
    TCG_REG_O2,
82 8289b279 blueswir1
    TCG_REG_O3,
83 8289b279 blueswir1
    TCG_REG_O4,
84 8289b279 blueswir1
    TCG_REG_O5,
85 8289b279 blueswir1
};
86 8289b279 blueswir1
87 8289b279 blueswir1
static const int tcg_target_call_oarg_regs[2] = {
88 8289b279 blueswir1
    TCG_REG_O0,
89 8289b279 blueswir1
    TCG_REG_O1,
90 8289b279 blueswir1
};
91 8289b279 blueswir1
92 57e49b40 blueswir1
static inline int check_fit_tl(tcg_target_long val, unsigned int bits)
93 f5ef6aac blueswir1
{
94 57e49b40 blueswir1
    return (val << ((sizeof(tcg_target_long) * 8 - bits))
95 57e49b40 blueswir1
            >> (sizeof(tcg_target_long) * 8 - bits)) == val;
96 57e49b40 blueswir1
}
97 57e49b40 blueswir1
98 57e49b40 blueswir1
static inline int check_fit_i32(uint32_t val, unsigned int bits)
99 57e49b40 blueswir1
{
100 57e49b40 blueswir1
    return ((val << (32 - bits)) >> (32 - bits)) == val;
101 f5ef6aac blueswir1
}
102 f5ef6aac blueswir1
103 8289b279 blueswir1
static void patch_reloc(uint8_t *code_ptr, int type,
104 f54b3f92 aurel32
                        tcg_target_long value, tcg_target_long addend)
105 8289b279 blueswir1
{
106 f54b3f92 aurel32
    value += addend;
107 8289b279 blueswir1
    switch (type) {
108 8289b279 blueswir1
    case R_SPARC_32:
109 8289b279 blueswir1
        if (value != (uint32_t)value)
110 8289b279 blueswir1
            tcg_abort();
111 8289b279 blueswir1
        *(uint32_t *)code_ptr = value;
112 8289b279 blueswir1
        break;
113 f5ef6aac blueswir1
    case R_SPARC_WDISP22:
114 f5ef6aac blueswir1
        value -= (long)code_ptr;
115 f5ef6aac blueswir1
        value >>= 2;
116 57e49b40 blueswir1
        if (!check_fit_tl(value, 22))
117 f5ef6aac blueswir1
            tcg_abort();
118 f5ef6aac blueswir1
        *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x3fffff) | value;
119 f5ef6aac blueswir1
        break;
120 1da92db2 blueswir1
    case R_SPARC_WDISP19:
121 1da92db2 blueswir1
        value -= (long)code_ptr;
122 1da92db2 blueswir1
        value >>= 2;
123 1da92db2 blueswir1
        if (!check_fit_tl(value, 19))
124 1da92db2 blueswir1
            tcg_abort();
125 1da92db2 blueswir1
        *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x7ffff) | value;
126 1da92db2 blueswir1
        break;
127 8289b279 blueswir1
    default:
128 8289b279 blueswir1
        tcg_abort();
129 8289b279 blueswir1
    }
130 8289b279 blueswir1
}
131 8289b279 blueswir1
132 8289b279 blueswir1
/* maximum number of register used for input function arguments */
133 8289b279 blueswir1
static inline int tcg_target_get_call_iarg_regs_count(int flags)
134 8289b279 blueswir1
{
135 8289b279 blueswir1
    return 6;
136 8289b279 blueswir1
}
137 8289b279 blueswir1
138 8289b279 blueswir1
/* parse target specific constraints */
139 8289b279 blueswir1
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
140 8289b279 blueswir1
{
141 8289b279 blueswir1
    const char *ct_str;
142 8289b279 blueswir1
143 8289b279 blueswir1
    ct_str = *pct_str;
144 8289b279 blueswir1
    switch (ct_str[0]) {
145 8289b279 blueswir1
    case 'r':
146 8289b279 blueswir1
    case 'L': /* qemu_ld/st constraint */
147 8289b279 blueswir1
        ct->ct |= TCG_CT_REG;
148 8289b279 blueswir1
        tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
149 53c37487 blueswir1
        // Helper args
150 53c37487 blueswir1
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
151 53c37487 blueswir1
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
152 53c37487 blueswir1
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
153 8289b279 blueswir1
        break;
154 8289b279 blueswir1
    case 'I':
155 8289b279 blueswir1
        ct->ct |= TCG_CT_CONST_S11;
156 8289b279 blueswir1
        break;
157 8289b279 blueswir1
    case 'J':
158 8289b279 blueswir1
        ct->ct |= TCG_CT_CONST_S13;
159 8289b279 blueswir1
        break;
160 8289b279 blueswir1
    default:
161 8289b279 blueswir1
        return -1;
162 8289b279 blueswir1
    }
163 8289b279 blueswir1
    ct_str++;
164 8289b279 blueswir1
    *pct_str = ct_str;
165 8289b279 blueswir1
    return 0;
166 8289b279 blueswir1
}
167 8289b279 blueswir1
168 8289b279 blueswir1
/* test if a constant matches the constraint */
169 8289b279 blueswir1
static inline int tcg_target_const_match(tcg_target_long val,
170 8289b279 blueswir1
                                         const TCGArgConstraint *arg_ct)
171 8289b279 blueswir1
{
172 8289b279 blueswir1
    int ct;
173 8289b279 blueswir1
174 8289b279 blueswir1
    ct = arg_ct->ct;
175 8289b279 blueswir1
    if (ct & TCG_CT_CONST)
176 8289b279 blueswir1
        return 1;
177 57e49b40 blueswir1
    else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11))
178 8289b279 blueswir1
        return 1;
179 57e49b40 blueswir1
    else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13))
180 8289b279 blueswir1
        return 1;
181 8289b279 blueswir1
    else
182 8289b279 blueswir1
        return 0;
183 8289b279 blueswir1
}
184 8289b279 blueswir1
185 8289b279 blueswir1
#define INSN_OP(x)  ((x) << 30)
186 8289b279 blueswir1
#define INSN_OP2(x) ((x) << 22)
187 8289b279 blueswir1
#define INSN_OP3(x) ((x) << 19)
188 8289b279 blueswir1
#define INSN_OPF(x) ((x) << 5)
189 8289b279 blueswir1
#define INSN_RD(x)  ((x) << 25)
190 8289b279 blueswir1
#define INSN_RS1(x) ((x) << 14)
191 8289b279 blueswir1
#define INSN_RS2(x) (x)
192 8384dd67 blueswir1
#define INSN_ASI(x) ((x) << 5)
193 8289b279 blueswir1
194 8289b279 blueswir1
#define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff))
195 1da92db2 blueswir1
#define INSN_OFF19(x) (((x) >> 2) & 0x07ffff)
196 b3db8758 blueswir1
#define INSN_OFF22(x) (((x) >> 2) & 0x3fffff)
197 8289b279 blueswir1
198 b3db8758 blueswir1
#define INSN_COND(x, a) (((x) << 25) | ((a) << 29))
199 cf7c2ca5 blueswir1
#define COND_N     0x0
200 cf7c2ca5 blueswir1
#define COND_E     0x1
201 cf7c2ca5 blueswir1
#define COND_LE    0x2
202 cf7c2ca5 blueswir1
#define COND_L     0x3
203 cf7c2ca5 blueswir1
#define COND_LEU   0x4
204 cf7c2ca5 blueswir1
#define COND_CS    0x5
205 cf7c2ca5 blueswir1
#define COND_NEG   0x6
206 cf7c2ca5 blueswir1
#define COND_VS    0x7
207 b3db8758 blueswir1
#define COND_A     0x8
208 cf7c2ca5 blueswir1
#define COND_NE    0x9
209 cf7c2ca5 blueswir1
#define COND_G     0xa
210 cf7c2ca5 blueswir1
#define COND_GE    0xb
211 cf7c2ca5 blueswir1
#define COND_GU    0xc
212 cf7c2ca5 blueswir1
#define COND_CC    0xd
213 cf7c2ca5 blueswir1
#define COND_POS   0xe
214 cf7c2ca5 blueswir1
#define COND_VC    0xf
215 b3db8758 blueswir1
#define BA         (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2))
216 8289b279 blueswir1
217 8289b279 blueswir1
#define ARITH_ADD  (INSN_OP(2) | INSN_OP3(0x00))
218 8289b279 blueswir1
#define ARITH_AND  (INSN_OP(2) | INSN_OP3(0x01))
219 8289b279 blueswir1
#define ARITH_OR   (INSN_OP(2) | INSN_OP3(0x02))
220 9a7f3228 blueswir1
#define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12))
221 8289b279 blueswir1
#define ARITH_XOR  (INSN_OP(2) | INSN_OP3(0x03))
222 f5ef6aac blueswir1
#define ARITH_SUB  (INSN_OP(2) | INSN_OP3(0x04))
223 f5ef6aac blueswir1
#define ARITH_SUBCC (INSN_OP(2) | INSN_OP3(0x14))
224 8289b279 blueswir1
#define ARITH_ADDX (INSN_OP(2) | INSN_OP3(0x10))
225 8289b279 blueswir1
#define ARITH_SUBX (INSN_OP(2) | INSN_OP3(0x0c))
226 8289b279 blueswir1
#define ARITH_UMUL (INSN_OP(2) | INSN_OP3(0x0a))
227 8289b279 blueswir1
#define ARITH_UDIV (INSN_OP(2) | INSN_OP3(0x0e))
228 8289b279 blueswir1
#define ARITH_SDIV (INSN_OP(2) | INSN_OP3(0x0f))
229 8289b279 blueswir1
#define ARITH_MULX (INSN_OP(2) | INSN_OP3(0x09))
230 8289b279 blueswir1
#define ARITH_UDIVX (INSN_OP(2) | INSN_OP3(0x0d))
231 8289b279 blueswir1
#define ARITH_SDIVX (INSN_OP(2) | INSN_OP3(0x2d))
232 8289b279 blueswir1
233 8289b279 blueswir1
#define SHIFT_SLL  (INSN_OP(2) | INSN_OP3(0x25))
234 8289b279 blueswir1
#define SHIFT_SRL  (INSN_OP(2) | INSN_OP3(0x26))
235 8289b279 blueswir1
#define SHIFT_SRA  (INSN_OP(2) | INSN_OP3(0x27))
236 8289b279 blueswir1
237 8289b279 blueswir1
#define SHIFT_SLLX (INSN_OP(2) | INSN_OP3(0x25) | (1 << 12))
238 8289b279 blueswir1
#define SHIFT_SRLX (INSN_OP(2) | INSN_OP3(0x26) | (1 << 12))
239 8289b279 blueswir1
#define SHIFT_SRAX (INSN_OP(2) | INSN_OP3(0x27) | (1 << 12))
240 8289b279 blueswir1
241 8289b279 blueswir1
#define WRY        (INSN_OP(2) | INSN_OP3(0x30))
242 8289b279 blueswir1
#define JMPL       (INSN_OP(2) | INSN_OP3(0x38))
243 8289b279 blueswir1
#define SAVE       (INSN_OP(2) | INSN_OP3(0x3c))
244 8289b279 blueswir1
#define RESTORE    (INSN_OP(2) | INSN_OP3(0x3d))
245 8289b279 blueswir1
#define SETHI      (INSN_OP(0) | INSN_OP2(0x4))
246 8289b279 blueswir1
#define CALL       INSN_OP(1)
247 8289b279 blueswir1
#define LDUB       (INSN_OP(3) | INSN_OP3(0x01))
248 8289b279 blueswir1
#define LDSB       (INSN_OP(3) | INSN_OP3(0x09))
249 8289b279 blueswir1
#define LDUH       (INSN_OP(3) | INSN_OP3(0x02))
250 8289b279 blueswir1
#define LDSH       (INSN_OP(3) | INSN_OP3(0x0a))
251 8289b279 blueswir1
#define LDUW       (INSN_OP(3) | INSN_OP3(0x00))
252 8289b279 blueswir1
#define LDSW       (INSN_OP(3) | INSN_OP3(0x08))
253 8289b279 blueswir1
#define LDX        (INSN_OP(3) | INSN_OP3(0x0b))
254 8289b279 blueswir1
#define STB        (INSN_OP(3) | INSN_OP3(0x05))
255 8289b279 blueswir1
#define STH        (INSN_OP(3) | INSN_OP3(0x06))
256 8289b279 blueswir1
#define STW        (INSN_OP(3) | INSN_OP3(0x04))
257 8289b279 blueswir1
#define STX        (INSN_OP(3) | INSN_OP3(0x0e))
258 8384dd67 blueswir1
#define LDUBA      (INSN_OP(3) | INSN_OP3(0x11))
259 8384dd67 blueswir1
#define LDSBA      (INSN_OP(3) | INSN_OP3(0x19))
260 8384dd67 blueswir1
#define LDUHA      (INSN_OP(3) | INSN_OP3(0x12))
261 8384dd67 blueswir1
#define LDSHA      (INSN_OP(3) | INSN_OP3(0x1a))
262 8384dd67 blueswir1
#define LDUWA      (INSN_OP(3) | INSN_OP3(0x10))
263 8384dd67 blueswir1
#define LDSWA      (INSN_OP(3) | INSN_OP3(0x18))
264 8384dd67 blueswir1
#define LDXA       (INSN_OP(3) | INSN_OP3(0x1b))
265 8384dd67 blueswir1
#define STBA       (INSN_OP(3) | INSN_OP3(0x15))
266 8384dd67 blueswir1
#define STHA       (INSN_OP(3) | INSN_OP3(0x16))
267 8384dd67 blueswir1
#define STWA       (INSN_OP(3) | INSN_OP3(0x14))
268 8384dd67 blueswir1
#define STXA       (INSN_OP(3) | INSN_OP3(0x1e))
269 8384dd67 blueswir1
270 8384dd67 blueswir1
#ifndef ASI_PRIMARY_LITTLE
271 8384dd67 blueswir1
#define ASI_PRIMARY_LITTLE 0x88
272 8384dd67 blueswir1
#endif
273 8289b279 blueswir1
274 26cc915c blueswir1
static inline void tcg_out_arith(TCGContext *s, int rd, int rs1, int rs2,
275 26cc915c blueswir1
                                 int op)
276 26cc915c blueswir1
{
277 26cc915c blueswir1
    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
278 26cc915c blueswir1
              INSN_RS2(rs2));
279 26cc915c blueswir1
}
280 26cc915c blueswir1
281 6f41b777 blueswir1
static inline void tcg_out_arithi(TCGContext *s, int rd, int rs1,
282 6f41b777 blueswir1
                                  uint32_t offset, int op)
283 26cc915c blueswir1
{
284 26cc915c blueswir1
    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
285 26cc915c blueswir1
              INSN_IMM13(offset));
286 26cc915c blueswir1
}
287 26cc915c blueswir1
288 ba225198 Richard Henderson
static void tcg_out_arithc(TCGContext *s, int rd, int rs1,
289 ba225198 Richard Henderson
                           int val2, int val2const, int op)
290 ba225198 Richard Henderson
{
291 ba225198 Richard Henderson
    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1)
292 ba225198 Richard Henderson
              | (val2const ? INSN_IMM13(val2) : INSN_RS2(val2)));
293 ba225198 Richard Henderson
}
294 ba225198 Richard Henderson
295 8289b279 blueswir1
static inline void tcg_out_mov(TCGContext *s, int ret, int arg)
296 8289b279 blueswir1
{
297 26cc915c blueswir1
    tcg_out_arith(s, ret, arg, TCG_REG_G0, ARITH_OR);
298 26cc915c blueswir1
}
299 26cc915c blueswir1
300 26cc915c blueswir1
static inline void tcg_out_sethi(TCGContext *s, int ret, uint32_t arg)
301 26cc915c blueswir1
{
302 26cc915c blueswir1
    tcg_out32(s, SETHI | INSN_RD(ret) | ((arg & 0xfffffc00) >> 10));
303 8289b279 blueswir1
}
304 8289b279 blueswir1
305 b101234a blueswir1
static inline void tcg_out_movi_imm13(TCGContext *s, int ret, uint32_t arg)
306 b101234a blueswir1
{
307 b101234a blueswir1
    tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR);
308 b101234a blueswir1
}
309 b101234a blueswir1
310 b101234a blueswir1
static inline void tcg_out_movi_imm32(TCGContext *s, int ret, uint32_t arg)
311 8289b279 blueswir1
{
312 4a09aa89 Richard Henderson
    if (check_fit_tl(arg, 13))
313 b101234a blueswir1
        tcg_out_movi_imm13(s, ret, arg);
314 8289b279 blueswir1
    else {
315 26cc915c blueswir1
        tcg_out_sethi(s, ret, arg);
316 8289b279 blueswir1
        if (arg & 0x3ff)
317 b101234a blueswir1
            tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
318 8289b279 blueswir1
    }
319 8289b279 blueswir1
}
320 8289b279 blueswir1
321 b101234a blueswir1
static inline void tcg_out_movi(TCGContext *s, TCGType type,
322 b101234a blueswir1
                                int ret, tcg_target_long arg)
323 b101234a blueswir1
{
324 43172207 Richard Henderson
    /* All 32-bit constants, as well as 64-bit constants with
325 43172207 Richard Henderson
       no high bits set go through movi_imm32.  */
326 43172207 Richard Henderson
    if (TCG_TARGET_REG_BITS == 32
327 43172207 Richard Henderson
        || type == TCG_TYPE_I32
328 43172207 Richard Henderson
        || (arg & ~(tcg_target_long)0xffffffff) == 0) {
329 43172207 Richard Henderson
        tcg_out_movi_imm32(s, ret, arg);
330 43172207 Richard Henderson
    } else if (check_fit_tl(arg, 13)) {
331 43172207 Richard Henderson
        /* A 13-bit constant sign-extended to 64-bits.  */
332 43172207 Richard Henderson
        tcg_out_movi_imm13(s, ret, arg);
333 43172207 Richard Henderson
    } else if (check_fit_tl(arg, 32)) {
334 43172207 Richard Henderson
        /* A 32-bit constant sign-extended to 64-bits.  */
335 43172207 Richard Henderson
        tcg_out_sethi(s, ret, ~arg);
336 43172207 Richard Henderson
        tcg_out_arithi(s, ret, ret, (arg & 0x3ff) | -0x400, ARITH_XOR);
337 43172207 Richard Henderson
    } else {
338 43172207 Richard Henderson
        tcg_out_movi_imm32(s, TCG_REG_I4, arg >> (TCG_TARGET_REG_BITS / 2));
339 d795eb86 blueswir1
        tcg_out_arithi(s, TCG_REG_I4, TCG_REG_I4, 32, SHIFT_SLLX);
340 b101234a blueswir1
        tcg_out_movi_imm32(s, ret, arg);
341 d795eb86 blueswir1
        tcg_out_arith(s, ret, ret, TCG_REG_I4, ARITH_OR);
342 6f41b777 blueswir1
    }
343 b101234a blueswir1
}
344 b101234a blueswir1
345 8289b279 blueswir1
static inline void tcg_out_ld_raw(TCGContext *s, int ret,
346 8289b279 blueswir1
                                  tcg_target_long arg)
347 8289b279 blueswir1
{
348 26cc915c blueswir1
    tcg_out_sethi(s, ret, arg);
349 8289b279 blueswir1
    tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
350 8289b279 blueswir1
              INSN_IMM13(arg & 0x3ff));
351 8289b279 blueswir1
}
352 8289b279 blueswir1
353 b3db8758 blueswir1
static inline void tcg_out_ld_ptr(TCGContext *s, int ret,
354 b3db8758 blueswir1
                                  tcg_target_long arg)
355 b3db8758 blueswir1
{
356 b101234a blueswir1
    if (!check_fit_tl(arg, 10))
357 b101234a blueswir1
        tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ffULL);
358 a212ea75 Richard Henderson
    if (TCG_TARGET_REG_BITS == 64) {
359 a212ea75 Richard Henderson
        tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) |
360 a212ea75 Richard Henderson
                  INSN_IMM13(arg & 0x3ff));
361 a212ea75 Richard Henderson
    } else {
362 a212ea75 Richard Henderson
        tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
363 a212ea75 Richard Henderson
                  INSN_IMM13(arg & 0x3ff));
364 a212ea75 Richard Henderson
    }
365 b3db8758 blueswir1
}
366 b3db8758 blueswir1
367 8289b279 blueswir1
static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op)
368 8289b279 blueswir1
{
369 57e49b40 blueswir1
    if (check_fit_tl(offset, 13))
370 8289b279 blueswir1
        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) |
371 8289b279 blueswir1
                  INSN_IMM13(offset));
372 cf7c2ca5 blueswir1
    else {
373 cf7c2ca5 blueswir1
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
374 cf7c2ca5 blueswir1
        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
375 cf7c2ca5 blueswir1
                  INSN_RS2(addr));
376 cf7c2ca5 blueswir1
    }
377 8289b279 blueswir1
}
378 8289b279 blueswir1
379 8384dd67 blueswir1
static inline void tcg_out_ldst_asi(TCGContext *s, int ret, int addr,
380 8384dd67 blueswir1
                                    int offset, int op, int asi)
381 8384dd67 blueswir1
{
382 8384dd67 blueswir1
    tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
383 8384dd67 blueswir1
    tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
384 8384dd67 blueswir1
              INSN_ASI(asi) | INSN_RS2(addr));
385 8384dd67 blueswir1
}
386 8384dd67 blueswir1
387 e4d5434c blueswir1
static inline void tcg_out_ld(TCGContext *s, TCGType type, int ret,
388 8289b279 blueswir1
                              int arg1, tcg_target_long arg2)
389 8289b279 blueswir1
{
390 7d551702 blueswir1
    if (type == TCG_TYPE_I32)
391 7d551702 blueswir1
        tcg_out_ldst(s, ret, arg1, arg2, LDUW);
392 7d551702 blueswir1
    else
393 7d551702 blueswir1
        tcg_out_ldst(s, ret, arg1, arg2, LDX);
394 8289b279 blueswir1
}
395 8289b279 blueswir1
396 e4d5434c blueswir1
static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
397 8289b279 blueswir1
                              int arg1, tcg_target_long arg2)
398 8289b279 blueswir1
{
399 7d551702 blueswir1
    if (type == TCG_TYPE_I32)
400 7d551702 blueswir1
        tcg_out_ldst(s, arg, arg1, arg2, STW);
401 7d551702 blueswir1
    else
402 7d551702 blueswir1
        tcg_out_ldst(s, arg, arg1, arg2, STX);
403 8289b279 blueswir1
}
404 8289b279 blueswir1
405 8289b279 blueswir1
static inline void tcg_out_sety(TCGContext *s, tcg_target_long val)
406 8289b279 blueswir1
{
407 8289b279 blueswir1
    if (val == 0 || val == -1)
408 8289b279 blueswir1
        tcg_out32(s, WRY | INSN_IMM13(val));
409 8289b279 blueswir1
    else
410 8289b279 blueswir1
        fprintf(stderr, "unimplemented sety %ld\n", (long)val);
411 8289b279 blueswir1
}
412 8289b279 blueswir1
413 8289b279 blueswir1
static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
414 8289b279 blueswir1
{
415 8289b279 blueswir1
    if (val != 0) {
416 57e49b40 blueswir1
        if (check_fit_tl(val, 13))
417 8289b279 blueswir1
            tcg_out_arithi(s, reg, reg, val, ARITH_ADD);
418 f5ef6aac blueswir1
        else {
419 f5ef6aac blueswir1
            tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, val);
420 f5ef6aac blueswir1
            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_ADD);
421 f5ef6aac blueswir1
        }
422 8289b279 blueswir1
    }
423 8289b279 blueswir1
}
424 8289b279 blueswir1
425 53c37487 blueswir1
static inline void tcg_out_andi(TCGContext *s, int reg, tcg_target_long val)
426 53c37487 blueswir1
{
427 53c37487 blueswir1
    if (val != 0) {
428 53c37487 blueswir1
        if (check_fit_tl(val, 13))
429 53c37487 blueswir1
            tcg_out_arithi(s, reg, reg, val, ARITH_AND);
430 53c37487 blueswir1
        else {
431 53c37487 blueswir1
            tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, val);
432 53c37487 blueswir1
            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_AND);
433 53c37487 blueswir1
        }
434 53c37487 blueswir1
    }
435 53c37487 blueswir1
}
436 53c37487 blueswir1
437 8289b279 blueswir1
static inline void tcg_out_nop(TCGContext *s)
438 8289b279 blueswir1
{
439 26cc915c blueswir1
    tcg_out_sethi(s, TCG_REG_G0, 0);
440 8289b279 blueswir1
}
441 8289b279 blueswir1
442 1da92db2 blueswir1
static void tcg_out_branch_i32(TCGContext *s, int opc, int label_index)
443 cf7c2ca5 blueswir1
{
444 cf7c2ca5 blueswir1
    int32_t val;
445 cf7c2ca5 blueswir1
    TCGLabel *l = &s->labels[label_index];
446 cf7c2ca5 blueswir1
447 cf7c2ca5 blueswir1
    if (l->has_value) {
448 cf7c2ca5 blueswir1
        val = l->u.value - (tcg_target_long)s->code_ptr;
449 f5ef6aac blueswir1
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2)
450 cf7c2ca5 blueswir1
                      | INSN_OFF22(l->u.value - (unsigned long)s->code_ptr)));
451 f5ef6aac blueswir1
    } else {
452 f5ef6aac blueswir1
        tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP22, label_index, 0);
453 f5ef6aac blueswir1
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2) | 0));
454 f5ef6aac blueswir1
    }
455 cf7c2ca5 blueswir1
}
456 cf7c2ca5 blueswir1
457 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
458 1da92db2 blueswir1
static void tcg_out_branch_i64(TCGContext *s, int opc, int label_index)
459 1da92db2 blueswir1
{
460 1da92db2 blueswir1
    int32_t val;
461 1da92db2 blueswir1
    TCGLabel *l = &s->labels[label_index];
462 1da92db2 blueswir1
463 1da92db2 blueswir1
    if (l->has_value) {
464 1da92db2 blueswir1
        val = l->u.value - (tcg_target_long)s->code_ptr;
465 1da92db2 blueswir1
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) |
466 1da92db2 blueswir1
                      (0x5 << 19) |
467 1da92db2 blueswir1
                      INSN_OFF19(l->u.value - (unsigned long)s->code_ptr)));
468 1da92db2 blueswir1
    } else {
469 1da92db2 blueswir1
        tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP19, label_index, 0);
470 1da92db2 blueswir1
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x1) |
471 1da92db2 blueswir1
                      (0x5 << 19) | 0));
472 1da92db2 blueswir1
    }
473 1da92db2 blueswir1
}
474 1da92db2 blueswir1
#endif
475 1da92db2 blueswir1
476 cf7c2ca5 blueswir1
static const uint8_t tcg_cond_to_bcond[10] = {
477 cf7c2ca5 blueswir1
    [TCG_COND_EQ] = COND_E,
478 cf7c2ca5 blueswir1
    [TCG_COND_NE] = COND_NE,
479 cf7c2ca5 blueswir1
    [TCG_COND_LT] = COND_L,
480 cf7c2ca5 blueswir1
    [TCG_COND_GE] = COND_GE,
481 cf7c2ca5 blueswir1
    [TCG_COND_LE] = COND_LE,
482 cf7c2ca5 blueswir1
    [TCG_COND_GT] = COND_G,
483 cf7c2ca5 blueswir1
    [TCG_COND_LTU] = COND_CS,
484 cf7c2ca5 blueswir1
    [TCG_COND_GEU] = COND_CC,
485 cf7c2ca5 blueswir1
    [TCG_COND_LEU] = COND_LEU,
486 cf7c2ca5 blueswir1
    [TCG_COND_GTU] = COND_GU,
487 cf7c2ca5 blueswir1
};
488 cf7c2ca5 blueswir1
489 56f4927e Richard Henderson
static void tcg_out_cmp(TCGContext *s, TCGArg c1, TCGArg c2, int c2const)
490 56f4927e Richard Henderson
{
491 ba225198 Richard Henderson
    tcg_out_arithc(s, TCG_REG_G0, c1, c2, c2const, ARITH_SUBCC);
492 56f4927e Richard Henderson
}
493 56f4927e Richard Henderson
494 1da92db2 blueswir1
static void tcg_out_brcond_i32(TCGContext *s, int cond,
495 1da92db2 blueswir1
                               TCGArg arg1, TCGArg arg2, int const_arg2,
496 1da92db2 blueswir1
                               int label_index)
497 cf7c2ca5 blueswir1
{
498 56f4927e Richard Henderson
    tcg_out_cmp(s, arg1, arg2, const_arg2);
499 1da92db2 blueswir1
    tcg_out_branch_i32(s, tcg_cond_to_bcond[cond], label_index);
500 cf7c2ca5 blueswir1
    tcg_out_nop(s);
501 cf7c2ca5 blueswir1
}
502 cf7c2ca5 blueswir1
503 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
504 1da92db2 blueswir1
static void tcg_out_brcond_i64(TCGContext *s, int cond,
505 1da92db2 blueswir1
                               TCGArg arg1, TCGArg arg2, int const_arg2,
506 1da92db2 blueswir1
                               int label_index)
507 1da92db2 blueswir1
{
508 56f4927e Richard Henderson
    tcg_out_cmp(s, arg1, arg2, const_arg2);
509 1da92db2 blueswir1
    tcg_out_branch_i64(s, tcg_cond_to_bcond[cond], label_index);
510 1da92db2 blueswir1
    tcg_out_nop(s);
511 1da92db2 blueswir1
}
512 56f4927e Richard Henderson
#else
513 56f4927e Richard Henderson
static void tcg_out_brcond2_i32(TCGContext *s, int cond,
514 56f4927e Richard Henderson
                                TCGArg al, TCGArg ah,
515 56f4927e Richard Henderson
                                TCGArg bl, int blconst,
516 56f4927e Richard Henderson
                                TCGArg bh, int bhconst, int label_dest)
517 56f4927e Richard Henderson
{
518 56f4927e Richard Henderson
    int cc, label_next = gen_new_label();
519 56f4927e Richard Henderson
520 56f4927e Richard Henderson
    tcg_out_cmp(s, ah, bh, bhconst);
521 56f4927e Richard Henderson
522 56f4927e Richard Henderson
    /* Note that we fill one of the delay slots with the second compare.  */
523 56f4927e Richard Henderson
    switch (cond) {
524 56f4927e Richard Henderson
    case TCG_COND_EQ:
525 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
526 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_next);
527 56f4927e Richard Henderson
        tcg_out_cmp(s, al, bl, blconst);
528 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_EQ], 0);
529 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_dest);
530 56f4927e Richard Henderson
        break;
531 56f4927e Richard Henderson
532 56f4927e Richard Henderson
    case TCG_COND_NE:
533 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
534 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_dest);
535 56f4927e Richard Henderson
        tcg_out_cmp(s, al, bl, blconst);
536 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_dest);
537 56f4927e Richard Henderson
        break;
538 56f4927e Richard Henderson
539 56f4927e Richard Henderson
    default:
540 56f4927e Richard Henderson
        /* ??? One could fairly easily special-case 64-bit unsigned
541 56f4927e Richard Henderson
           compares against 32-bit zero-extended constants.  For instance,
542 56f4927e Richard Henderson
           we know that (unsigned)AH < 0 is false and need not emit it.
543 56f4927e Richard Henderson
           Similarly, (unsigned)AH > 0 being true implies AH != 0, so the
544 56f4927e Richard Henderson
           second branch will never be taken.  */
545 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[cond], 0);
546 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_dest);
547 56f4927e Richard Henderson
        tcg_out_nop(s);
548 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[TCG_COND_NE], 0);
549 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_next);
550 56f4927e Richard Henderson
        tcg_out_cmp(s, al, bl, blconst);
551 56f4927e Richard Henderson
        cc = INSN_COND(tcg_cond_to_bcond[tcg_unsigned_cond(cond)], 0);
552 56f4927e Richard Henderson
        tcg_out_branch_i32(s, cc, label_dest);
553 56f4927e Richard Henderson
        break;
554 56f4927e Richard Henderson
    }
555 56f4927e Richard Henderson
    tcg_out_nop(s);
556 56f4927e Richard Henderson
557 56f4927e Richard Henderson
    tcg_out_label(s, label_next, (tcg_target_long)s->code_ptr);
558 56f4927e Richard Henderson
}
559 1da92db2 blueswir1
#endif
560 1da92db2 blueswir1
561 7d551702 blueswir1
/* Generate global QEMU prologue and epilogue code */
562 7d551702 blueswir1
void tcg_target_qemu_prologue(TCGContext *s)
563 b3db8758 blueswir1
{
564 b3db8758 blueswir1
    tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) |
565 b3db8758 blueswir1
              INSN_IMM13(-TCG_TARGET_STACK_MINFRAME));
566 cf7c2ca5 blueswir1
    tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I0) |
567 7d551702 blueswir1
              INSN_RS2(TCG_REG_G0));
568 7d551702 blueswir1
    tcg_out_nop(s);
569 b3db8758 blueswir1
}
570 b3db8758 blueswir1
571 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
572 f5ef6aac blueswir1
573 79383c9c blueswir1
#include "../../softmmu_defs.h"
574 f5ef6aac blueswir1
575 9a7f3228 blueswir1
static const void * const qemu_ld_helpers[4] = {
576 f5ef6aac blueswir1
    __ldb_mmu,
577 f5ef6aac blueswir1
    __ldw_mmu,
578 f5ef6aac blueswir1
    __ldl_mmu,
579 f5ef6aac blueswir1
    __ldq_mmu,
580 f5ef6aac blueswir1
};
581 f5ef6aac blueswir1
582 9a7f3228 blueswir1
static const void * const qemu_st_helpers[4] = {
583 f5ef6aac blueswir1
    __stb_mmu,
584 f5ef6aac blueswir1
    __stw_mmu,
585 f5ef6aac blueswir1
    __stl_mmu,
586 f5ef6aac blueswir1
    __stq_mmu,
587 f5ef6aac blueswir1
};
588 f5ef6aac blueswir1
#endif
589 f5ef6aac blueswir1
590 bffe1431 blueswir1
#if TARGET_LONG_BITS == 32
591 bffe1431 blueswir1
#define TARGET_LD_OP LDUW
592 bffe1431 blueswir1
#else
593 bffe1431 blueswir1
#define TARGET_LD_OP LDX
594 bffe1431 blueswir1
#endif
595 bffe1431 blueswir1
596 9d0efc88 blueswir1
#if TARGET_PHYS_ADDR_BITS == 32
597 9d0efc88 blueswir1
#define TARGET_ADDEND_LD_OP LDUW
598 9d0efc88 blueswir1
#else
599 9d0efc88 blueswir1
#define TARGET_ADDEND_LD_OP LDX
600 9d0efc88 blueswir1
#endif
601 9d0efc88 blueswir1
602 bffe1431 blueswir1
#ifdef __arch64__
603 bffe1431 blueswir1
#define HOST_LD_OP LDX
604 bffe1431 blueswir1
#define HOST_ST_OP STX
605 bffe1431 blueswir1
#define HOST_SLL_OP SHIFT_SLLX
606 bffe1431 blueswir1
#define HOST_SRA_OP SHIFT_SRAX
607 bffe1431 blueswir1
#else
608 bffe1431 blueswir1
#define HOST_LD_OP LDUW
609 bffe1431 blueswir1
#define HOST_ST_OP STW
610 bffe1431 blueswir1
#define HOST_SLL_OP SHIFT_SLL
611 bffe1431 blueswir1
#define HOST_SRA_OP SHIFT_SRA
612 bffe1431 blueswir1
#endif
613 bffe1431 blueswir1
614 f5ef6aac blueswir1
static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
615 f5ef6aac blueswir1
                            int opc)
616 f5ef6aac blueswir1
{
617 56fc64df blueswir1
    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
618 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
619 53c37487 blueswir1
    uint32_t *label1_ptr, *label2_ptr;
620 f5ef6aac blueswir1
#endif
621 f5ef6aac blueswir1
622 f5ef6aac blueswir1
    data_reg = *args++;
623 f5ef6aac blueswir1
    addr_reg = *args++;
624 f5ef6aac blueswir1
    mem_index = *args;
625 f5ef6aac blueswir1
    s_bits = opc & 3;
626 f5ef6aac blueswir1
627 53c37487 blueswir1
    arg0 = TCG_REG_O0;
628 53c37487 blueswir1
    arg1 = TCG_REG_O1;
629 56fc64df blueswir1
    arg2 = TCG_REG_O2;
630 f5ef6aac blueswir1
631 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
632 56fc64df blueswir1
    /* srl addr_reg, x, arg1 */
633 56fc64df blueswir1
    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
634 f5ef6aac blueswir1
                   SHIFT_SRL);
635 56fc64df blueswir1
    /* and addr_reg, x, arg0 */
636 56fc64df blueswir1
    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
637 f5ef6aac blueswir1
                   ARITH_AND);
638 f5ef6aac blueswir1
639 56fc64df blueswir1
    /* and arg1, x, arg1 */
640 56fc64df blueswir1
    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
641 f5ef6aac blueswir1
642 56fc64df blueswir1
    /* add arg1, x, arg1 */
643 56fc64df blueswir1
    tcg_out_addi(s, arg1, offsetof(CPUState,
644 56fc64df blueswir1
                                   tlb_table[mem_index][0].addr_read));
645 53c37487 blueswir1
646 56fc64df blueswir1
    /* add env, arg1, arg1 */
647 56fc64df blueswir1
    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
648 f5ef6aac blueswir1
649 56fc64df blueswir1
    /* ld [arg1], arg2 */
650 bffe1431 blueswir1
    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
651 56fc64df blueswir1
              INSN_RS2(TCG_REG_G0));
652 f5ef6aac blueswir1
653 56fc64df blueswir1
    /* subcc arg0, arg2, %g0 */
654 56fc64df blueswir1
    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
655 f5ef6aac blueswir1
656 f5ef6aac blueswir1
    /* will become:
657 1da92db2 blueswir1
       be label1
658 1da92db2 blueswir1
        or
659 1da92db2 blueswir1
       be,pt %xcc label1 */
660 53c37487 blueswir1
    label1_ptr = (uint32_t *)s->code_ptr;
661 f5ef6aac blueswir1
    tcg_out32(s, 0);
662 f5ef6aac blueswir1
663 53c37487 blueswir1
    /* mov (delay slot) */
664 53c37487 blueswir1
    tcg_out_mov(s, arg0, addr_reg);
665 f5ef6aac blueswir1
666 bffe1431 blueswir1
    /* mov */
667 bffe1431 blueswir1
    tcg_out_movi(s, TCG_TYPE_I32, arg1, mem_index);
668 bffe1431 blueswir1
669 f5ef6aac blueswir1
    /* XXX: move that code at the end of the TB */
670 53c37487 blueswir1
    /* qemu_ld_helper[s_bits](arg0, arg1) */
671 f5ef6aac blueswir1
    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits]
672 f5ef6aac blueswir1
                           - (tcg_target_ulong)s->code_ptr) >> 2)
673 f5ef6aac blueswir1
                         & 0x3fffffff));
674 bffe1431 blueswir1
    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
675 bffe1431 blueswir1
       global registers */
676 bffe1431 blueswir1
    // delay slot
677 bffe1431 blueswir1
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
678 f843e528 blueswir1
                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
679 f843e528 blueswir1
                 sizeof(long), HOST_ST_OP);
680 bffe1431 blueswir1
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
681 f843e528 blueswir1
                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
682 f843e528 blueswir1
                 sizeof(long), HOST_LD_OP);
683 f5ef6aac blueswir1
684 53c37487 blueswir1
    /* data_reg = sign_extend(arg0) */
685 f5ef6aac blueswir1
    switch(opc) {
686 f5ef6aac blueswir1
    case 0 | 4:
687 53c37487 blueswir1
        /* sll arg0, 24/56, data_reg */
688 56fc64df blueswir1
        tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8,
689 bffe1431 blueswir1
                       HOST_SLL_OP);
690 53c37487 blueswir1
        /* sra data_reg, 24/56, data_reg */
691 56fc64df blueswir1
        tcg_out_arithi(s, data_reg, data_reg,
692 bffe1431 blueswir1
                       (int)sizeof(tcg_target_long) * 8 - 8, HOST_SRA_OP);
693 f5ef6aac blueswir1
        break;
694 f5ef6aac blueswir1
    case 1 | 4:
695 53c37487 blueswir1
        /* sll arg0, 16/48, data_reg */
696 56fc64df blueswir1
        tcg_out_arithi(s, data_reg, arg0,
697 bffe1431 blueswir1
                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SLL_OP);
698 53c37487 blueswir1
        /* sra data_reg, 16/48, data_reg */
699 56fc64df blueswir1
        tcg_out_arithi(s, data_reg, data_reg,
700 bffe1431 blueswir1
                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SRA_OP);
701 f5ef6aac blueswir1
        break;
702 f5ef6aac blueswir1
    case 2 | 4:
703 53c37487 blueswir1
        /* sll arg0, 32, data_reg */
704 bffe1431 blueswir1
        tcg_out_arithi(s, data_reg, arg0, 32, HOST_SLL_OP);
705 53c37487 blueswir1
        /* sra data_reg, 32, data_reg */
706 bffe1431 blueswir1
        tcg_out_arithi(s, data_reg, data_reg, 32, HOST_SRA_OP);
707 f5ef6aac blueswir1
        break;
708 f5ef6aac blueswir1
    case 0:
709 f5ef6aac blueswir1
    case 1:
710 f5ef6aac blueswir1
    case 2:
711 f5ef6aac blueswir1
    case 3:
712 f5ef6aac blueswir1
    default:
713 f5ef6aac blueswir1
        /* mov */
714 53c37487 blueswir1
        tcg_out_mov(s, data_reg, arg0);
715 f5ef6aac blueswir1
        break;
716 f5ef6aac blueswir1
    }
717 f5ef6aac blueswir1
718 f5ef6aac blueswir1
    /* will become:
719 f5ef6aac blueswir1
       ba label2 */
720 53c37487 blueswir1
    label2_ptr = (uint32_t *)s->code_ptr;
721 f5ef6aac blueswir1
    tcg_out32(s, 0);
722 f5ef6aac blueswir1
723 53c37487 blueswir1
    /* nop (delay slot */
724 53c37487 blueswir1
    tcg_out_nop(s);
725 53c37487 blueswir1
726 f5ef6aac blueswir1
    /* label1: */
727 1da92db2 blueswir1
#if TARGET_LONG_BITS == 32
728 1da92db2 blueswir1
    /* be label1 */
729 53c37487 blueswir1
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
730 53c37487 blueswir1
                   INSN_OFF22((unsigned long)s->code_ptr -
731 53c37487 blueswir1
                              (unsigned long)label1_ptr));
732 1da92db2 blueswir1
#else
733 1da92db2 blueswir1
    /* be,pt %xcc label1 */
734 1da92db2 blueswir1
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) |
735 1da92db2 blueswir1
                   (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr -
736 1da92db2 blueswir1
                              (unsigned long)label1_ptr));
737 1da92db2 blueswir1
#endif
738 f5ef6aac blueswir1
739 56fc64df blueswir1
    /* ld [arg1 + x], arg1 */
740 56fc64df blueswir1
    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
741 9d0efc88 blueswir1
                 offsetof(CPUTLBEntry, addr_read), TARGET_ADDEND_LD_OP);
742 90cbed46 blueswir1
743 90cbed46 blueswir1
#if TARGET_LONG_BITS == 32
744 90cbed46 blueswir1
    /* and addr_reg, x, arg0 */
745 90cbed46 blueswir1
    tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff);
746 90cbed46 blueswir1
    tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND);
747 90cbed46 blueswir1
    /* add arg0, arg1, arg0 */
748 90cbed46 blueswir1
    tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD);
749 90cbed46 blueswir1
#else
750 56fc64df blueswir1
    /* add addr_reg, arg1, arg0 */
751 56fc64df blueswir1
    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
752 90cbed46 blueswir1
#endif
753 90cbed46 blueswir1
754 f5ef6aac blueswir1
#else
755 56fc64df blueswir1
    arg0 = addr_reg;
756 f5ef6aac blueswir1
#endif
757 f5ef6aac blueswir1
758 f5ef6aac blueswir1
    switch(opc) {
759 f5ef6aac blueswir1
    case 0:
760 56fc64df blueswir1
        /* ldub [arg0], data_reg */
761 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDUB);
762 f5ef6aac blueswir1
        break;
763 f5ef6aac blueswir1
    case 0 | 4:
764 56fc64df blueswir1
        /* ldsb [arg0], data_reg */
765 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDSB);
766 f5ef6aac blueswir1
        break;
767 f5ef6aac blueswir1
    case 1:
768 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
769 56fc64df blueswir1
        /* lduh [arg0], data_reg */
770 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDUH);
771 8384dd67 blueswir1
#else
772 56fc64df blueswir1
        /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */
773 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE);
774 8384dd67 blueswir1
#endif
775 f5ef6aac blueswir1
        break;
776 f5ef6aac blueswir1
    case 1 | 4:
777 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
778 56fc64df blueswir1
        /* ldsh [arg0], data_reg */
779 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDSH);
780 8384dd67 blueswir1
#else
781 56fc64df blueswir1
        /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */
782 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE);
783 8384dd67 blueswir1
#endif
784 f5ef6aac blueswir1
        break;
785 f5ef6aac blueswir1
    case 2:
786 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
787 56fc64df blueswir1
        /* lduw [arg0], data_reg */
788 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDUW);
789 8384dd67 blueswir1
#else
790 56fc64df blueswir1
        /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */
791 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE);
792 8384dd67 blueswir1
#endif
793 f5ef6aac blueswir1
        break;
794 f5ef6aac blueswir1
    case 2 | 4:
795 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
796 56fc64df blueswir1
        /* ldsw [arg0], data_reg */
797 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDSW);
798 8384dd67 blueswir1
#else
799 56fc64df blueswir1
        /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */
800 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE);
801 8384dd67 blueswir1
#endif
802 f5ef6aac blueswir1
        break;
803 f5ef6aac blueswir1
    case 3:
804 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
805 56fc64df blueswir1
        /* ldx [arg0], data_reg */
806 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, LDX);
807 8384dd67 blueswir1
#else
808 56fc64df blueswir1
        /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */
809 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE);
810 8384dd67 blueswir1
#endif
811 f5ef6aac blueswir1
        break;
812 f5ef6aac blueswir1
    default:
813 f5ef6aac blueswir1
        tcg_abort();
814 f5ef6aac blueswir1
    }
815 f5ef6aac blueswir1
816 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
817 f5ef6aac blueswir1
    /* label2: */
818 9a7f3228 blueswir1
    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
819 53c37487 blueswir1
                   INSN_OFF22((unsigned long)s->code_ptr -
820 53c37487 blueswir1
                              (unsigned long)label2_ptr));
821 f5ef6aac blueswir1
#endif
822 f5ef6aac blueswir1
}
823 f5ef6aac blueswir1
824 f5ef6aac blueswir1
static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
825 f5ef6aac blueswir1
                            int opc)
826 f5ef6aac blueswir1
{
827 56fc64df blueswir1
    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
828 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
829 53c37487 blueswir1
    uint32_t *label1_ptr, *label2_ptr;
830 f5ef6aac blueswir1
#endif
831 f5ef6aac blueswir1
832 f5ef6aac blueswir1
    data_reg = *args++;
833 f5ef6aac blueswir1
    addr_reg = *args++;
834 f5ef6aac blueswir1
    mem_index = *args;
835 f5ef6aac blueswir1
836 f5ef6aac blueswir1
    s_bits = opc;
837 f5ef6aac blueswir1
838 53c37487 blueswir1
    arg0 = TCG_REG_O0;
839 53c37487 blueswir1
    arg1 = TCG_REG_O1;
840 53c37487 blueswir1
    arg2 = TCG_REG_O2;
841 f5ef6aac blueswir1
842 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
843 56fc64df blueswir1
    /* srl addr_reg, x, arg1 */
844 56fc64df blueswir1
    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
845 f5ef6aac blueswir1
                   SHIFT_SRL);
846 53c37487 blueswir1
847 56fc64df blueswir1
    /* and addr_reg, x, arg0 */
848 56fc64df blueswir1
    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
849 f5ef6aac blueswir1
                   ARITH_AND);
850 f5ef6aac blueswir1
851 56fc64df blueswir1
    /* and arg1, x, arg1 */
852 56fc64df blueswir1
    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
853 f5ef6aac blueswir1
854 56fc64df blueswir1
    /* add arg1, x, arg1 */
855 56fc64df blueswir1
    tcg_out_addi(s, arg1, offsetof(CPUState,
856 56fc64df blueswir1
                                   tlb_table[mem_index][0].addr_write));
857 f5ef6aac blueswir1
858 56fc64df blueswir1
    /* add env, arg1, arg1 */
859 56fc64df blueswir1
    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
860 f5ef6aac blueswir1
861 56fc64df blueswir1
    /* ld [arg1], arg2 */
862 bffe1431 blueswir1
    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
863 56fc64df blueswir1
              INSN_RS2(TCG_REG_G0));
864 53c37487 blueswir1
865 56fc64df blueswir1
    /* subcc arg0, arg2, %g0 */
866 56fc64df blueswir1
    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
867 f5ef6aac blueswir1
868 f5ef6aac blueswir1
    /* will become:
869 1da92db2 blueswir1
       be label1
870 1da92db2 blueswir1
        or
871 1da92db2 blueswir1
       be,pt %xcc label1 */
872 53c37487 blueswir1
    label1_ptr = (uint32_t *)s->code_ptr;
873 f5ef6aac blueswir1
    tcg_out32(s, 0);
874 f5ef6aac blueswir1
875 53c37487 blueswir1
    /* mov (delay slot) */
876 53c37487 blueswir1
    tcg_out_mov(s, arg0, addr_reg);
877 53c37487 blueswir1
878 53c37487 blueswir1
    /* mov */
879 56fc64df blueswir1
    tcg_out_mov(s, arg1, data_reg);
880 53c37487 blueswir1
881 bffe1431 blueswir1
    /* mov */
882 bffe1431 blueswir1
    tcg_out_movi(s, TCG_TYPE_I32, arg2, mem_index);
883 bffe1431 blueswir1
884 53c37487 blueswir1
    /* XXX: move that code at the end of the TB */
885 53c37487 blueswir1
    /* qemu_st_helper[s_bits](arg0, arg1, arg2) */
886 f5ef6aac blueswir1
    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_st_helpers[s_bits]
887 f5ef6aac blueswir1
                           - (tcg_target_ulong)s->code_ptr) >> 2)
888 f5ef6aac blueswir1
                         & 0x3fffffff));
889 bffe1431 blueswir1
    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
890 bffe1431 blueswir1
       global registers */
891 bffe1431 blueswir1
    // delay slot
892 bffe1431 blueswir1
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
893 f843e528 blueswir1
                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
894 f843e528 blueswir1
                 sizeof(long), HOST_ST_OP);
895 bffe1431 blueswir1
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
896 f843e528 blueswir1
                 TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
897 f843e528 blueswir1
                 sizeof(long), HOST_LD_OP);
898 f5ef6aac blueswir1
899 f5ef6aac blueswir1
    /* will become:
900 f5ef6aac blueswir1
       ba label2 */
901 53c37487 blueswir1
    label2_ptr = (uint32_t *)s->code_ptr;
902 f5ef6aac blueswir1
    tcg_out32(s, 0);
903 f5ef6aac blueswir1
904 53c37487 blueswir1
    /* nop (delay slot) */
905 53c37487 blueswir1
    tcg_out_nop(s);
906 53c37487 blueswir1
907 1da92db2 blueswir1
#if TARGET_LONG_BITS == 32
908 1da92db2 blueswir1
    /* be label1 */
909 53c37487 blueswir1
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
910 53c37487 blueswir1
                   INSN_OFF22((unsigned long)s->code_ptr -
911 53c37487 blueswir1
                              (unsigned long)label1_ptr));
912 1da92db2 blueswir1
#else
913 1da92db2 blueswir1
    /* be,pt %xcc label1 */
914 1da92db2 blueswir1
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x1) |
915 1da92db2 blueswir1
                   (0x5 << 19) | INSN_OFF19((unsigned long)s->code_ptr -
916 1da92db2 blueswir1
                              (unsigned long)label1_ptr));
917 1da92db2 blueswir1
#endif
918 f5ef6aac blueswir1
919 56fc64df blueswir1
    /* ld [arg1 + x], arg1 */
920 56fc64df blueswir1
    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
921 9d0efc88 blueswir1
                 offsetof(CPUTLBEntry, addr_write), TARGET_ADDEND_LD_OP);
922 53c37487 blueswir1
923 90cbed46 blueswir1
#if TARGET_LONG_BITS == 32
924 90cbed46 blueswir1
    /* and addr_reg, x, arg0 */
925 90cbed46 blueswir1
    tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, 0xffffffff);
926 90cbed46 blueswir1
    tcg_out_arith(s, arg0, addr_reg, TCG_REG_I5, ARITH_AND);
927 90cbed46 blueswir1
    /* add arg0, arg1, arg0 */
928 90cbed46 blueswir1
    tcg_out_arith(s, arg0, arg0, arg1, ARITH_ADD);
929 90cbed46 blueswir1
#else
930 56fc64df blueswir1
    /* add addr_reg, arg1, arg0 */
931 56fc64df blueswir1
    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
932 90cbed46 blueswir1
#endif
933 90cbed46 blueswir1
934 f5ef6aac blueswir1
#else
935 56fc64df blueswir1
    arg0 = addr_reg;
936 f5ef6aac blueswir1
#endif
937 f5ef6aac blueswir1
938 f5ef6aac blueswir1
    switch(opc) {
939 f5ef6aac blueswir1
    case 0:
940 56fc64df blueswir1
        /* stb data_reg, [arg0] */
941 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, STB);
942 f5ef6aac blueswir1
        break;
943 f5ef6aac blueswir1
    case 1:
944 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
945 56fc64df blueswir1
        /* sth data_reg, [arg0] */
946 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, STH);
947 8384dd67 blueswir1
#else
948 56fc64df blueswir1
        /* stha data_reg, [arg0] ASI_PRIMARY_LITTLE */
949 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STHA, ASI_PRIMARY_LITTLE);
950 8384dd67 blueswir1
#endif
951 f5ef6aac blueswir1
        break;
952 f5ef6aac blueswir1
    case 2:
953 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
954 56fc64df blueswir1
        /* stw data_reg, [arg0] */
955 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, STW);
956 8384dd67 blueswir1
#else
957 56fc64df blueswir1
        /* stwa data_reg, [arg0] ASI_PRIMARY_LITTLE */
958 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STWA, ASI_PRIMARY_LITTLE);
959 8384dd67 blueswir1
#endif
960 f5ef6aac blueswir1
        break;
961 f5ef6aac blueswir1
    case 3:
962 8384dd67 blueswir1
#ifdef TARGET_WORDS_BIGENDIAN
963 56fc64df blueswir1
        /* stx data_reg, [arg0] */
964 56fc64df blueswir1
        tcg_out_ldst(s, data_reg, arg0, 0, STX);
965 8384dd67 blueswir1
#else
966 56fc64df blueswir1
        /* stxa data_reg, [arg0] ASI_PRIMARY_LITTLE */
967 56fc64df blueswir1
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STXA, ASI_PRIMARY_LITTLE);
968 8384dd67 blueswir1
#endif
969 f5ef6aac blueswir1
        break;
970 f5ef6aac blueswir1
    default:
971 f5ef6aac blueswir1
        tcg_abort();
972 f5ef6aac blueswir1
    }
973 f5ef6aac blueswir1
974 f5ef6aac blueswir1
#if defined(CONFIG_SOFTMMU)
975 f5ef6aac blueswir1
    /* label2: */
976 9a7f3228 blueswir1
    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
977 53c37487 blueswir1
                   INSN_OFF22((unsigned long)s->code_ptr -
978 53c37487 blueswir1
                              (unsigned long)label2_ptr));
979 f5ef6aac blueswir1
#endif
980 f5ef6aac blueswir1
}
981 f5ef6aac blueswir1
982 8289b279 blueswir1
static inline void tcg_out_op(TCGContext *s, int opc, const TCGArg *args,
983 8289b279 blueswir1
                              const int *const_args)
984 8289b279 blueswir1
{
985 8289b279 blueswir1
    int c;
986 8289b279 blueswir1
987 8289b279 blueswir1
    switch (opc) {
988 8289b279 blueswir1
    case INDEX_op_exit_tb:
989 b3db8758 blueswir1
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, args[0]);
990 b3db8758 blueswir1
        tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I7) |
991 8289b279 blueswir1
                  INSN_IMM13(8));
992 b3db8758 blueswir1
        tcg_out32(s, RESTORE | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_G0) |
993 b3db8758 blueswir1
                      INSN_RS2(TCG_REG_G0));
994 8289b279 blueswir1
        break;
995 8289b279 blueswir1
    case INDEX_op_goto_tb:
996 8289b279 blueswir1
        if (s->tb_jmp_offset) {
997 8289b279 blueswir1
            /* direct jump method */
998 26cc915c blueswir1
            tcg_out_sethi(s, TCG_REG_I5, args[0] & 0xffffe000);
999 cf7c2ca5 blueswir1
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
1000 cf7c2ca5 blueswir1
                      INSN_IMM13((args[0] & 0x1fff)));
1001 8289b279 blueswir1
            s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
1002 8289b279 blueswir1
        } else {
1003 8289b279 blueswir1
            /* indirect jump method */
1004 b3db8758 blueswir1
            tcg_out_ld_ptr(s, TCG_REG_I5, (tcg_target_long)(s->tb_next + args[0]));
1005 b3db8758 blueswir1
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
1006 b3db8758 blueswir1
                      INSN_RS2(TCG_REG_G0));
1007 8289b279 blueswir1
        }
1008 53cd9273 blueswir1
        tcg_out_nop(s);
1009 8289b279 blueswir1
        s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
1010 8289b279 blueswir1
        break;
1011 8289b279 blueswir1
    case INDEX_op_call:
1012 bffe1431 blueswir1
        if (const_args[0])
1013 bffe1431 blueswir1
            tcg_out32(s, CALL | ((((tcg_target_ulong)args[0]
1014 bffe1431 blueswir1
                                   - (tcg_target_ulong)s->code_ptr) >> 2)
1015 bffe1431 blueswir1
                                 & 0x3fffffff));
1016 bffe1431 blueswir1
        else {
1017 bffe1431 blueswir1
            tcg_out_ld_ptr(s, TCG_REG_I5,
1018 bffe1431 blueswir1
                           (tcg_target_long)(s->tb_next + args[0]));
1019 bffe1431 blueswir1
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_I5) |
1020 bffe1431 blueswir1
                      INSN_RS2(TCG_REG_G0));
1021 8289b279 blueswir1
        }
1022 bffe1431 blueswir1
        /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
1023 bffe1431 blueswir1
           global registers */
1024 bffe1431 blueswir1
        // delay slot
1025 bffe1431 blueswir1
        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
1026 f843e528 blueswir1
                     TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
1027 f843e528 blueswir1
                     sizeof(long), HOST_ST_OP);
1028 bffe1431 blueswir1
        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
1029 f843e528 blueswir1
                     TCG_TARGET_CALL_STACK_OFFSET - TCG_STATIC_CALL_ARGS_SIZE -
1030 f843e528 blueswir1
                     sizeof(long), HOST_LD_OP);
1031 8289b279 blueswir1
        break;
1032 8289b279 blueswir1
    case INDEX_op_jmp:
1033 8289b279 blueswir1
    case INDEX_op_br:
1034 1da92db2 blueswir1
        tcg_out_branch_i32(s, COND_A, args[0]);
1035 f5ef6aac blueswir1
        tcg_out_nop(s);
1036 8289b279 blueswir1
        break;
1037 8289b279 blueswir1
    case INDEX_op_movi_i32:
1038 8289b279 blueswir1
        tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]);
1039 8289b279 blueswir1
        break;
1040 8289b279 blueswir1
1041 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1042 8289b279 blueswir1
#define OP_32_64(x)                             \
1043 ba225198 Richard Henderson
        glue(glue(case INDEX_op_, x), _i32):    \
1044 ba225198 Richard Henderson
        glue(glue(case INDEX_op_, x), _i64)
1045 8289b279 blueswir1
#else
1046 8289b279 blueswir1
#define OP_32_64(x)                             \
1047 ba225198 Richard Henderson
        glue(glue(case INDEX_op_, x), _i32)
1048 8289b279 blueswir1
#endif
1049 ba225198 Richard Henderson
    OP_32_64(ld8u):
1050 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDUB);
1051 8289b279 blueswir1
        break;
1052 ba225198 Richard Henderson
    OP_32_64(ld8s):
1053 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDSB);
1054 8289b279 blueswir1
        break;
1055 ba225198 Richard Henderson
    OP_32_64(ld16u):
1056 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDUH);
1057 8289b279 blueswir1
        break;
1058 ba225198 Richard Henderson
    OP_32_64(ld16s):
1059 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDSH);
1060 8289b279 blueswir1
        break;
1061 8289b279 blueswir1
    case INDEX_op_ld_i32:
1062 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1063 53cd9273 blueswir1
    case INDEX_op_ld32u_i64:
1064 8289b279 blueswir1
#endif
1065 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDUW);
1066 8289b279 blueswir1
        break;
1067 ba225198 Richard Henderson
    OP_32_64(st8):
1068 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], STB);
1069 8289b279 blueswir1
        break;
1070 ba225198 Richard Henderson
    OP_32_64(st16):
1071 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], STH);
1072 8289b279 blueswir1
        break;
1073 8289b279 blueswir1
    case INDEX_op_st_i32:
1074 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1075 53cd9273 blueswir1
    case INDEX_op_st32_i64:
1076 8289b279 blueswir1
#endif
1077 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], STW);
1078 8289b279 blueswir1
        break;
1079 ba225198 Richard Henderson
    OP_32_64(add):
1080 53cd9273 blueswir1
        c = ARITH_ADD;
1081 ba225198 Richard Henderson
        goto gen_arith;
1082 ba225198 Richard Henderson
    OP_32_64(sub):
1083 8289b279 blueswir1
        c = ARITH_SUB;
1084 ba225198 Richard Henderson
        goto gen_arith;
1085 ba225198 Richard Henderson
    OP_32_64(and):
1086 8289b279 blueswir1
        c = ARITH_AND;
1087 ba225198 Richard Henderson
        goto gen_arith;
1088 ba225198 Richard Henderson
    OP_32_64(or):
1089 8289b279 blueswir1
        c = ARITH_OR;
1090 ba225198 Richard Henderson
        goto gen_arith;
1091 ba225198 Richard Henderson
    OP_32_64(xor):
1092 8289b279 blueswir1
        c = ARITH_XOR;
1093 ba225198 Richard Henderson
        goto gen_arith;
1094 8289b279 blueswir1
    case INDEX_op_shl_i32:
1095 8289b279 blueswir1
        c = SHIFT_SLL;
1096 ba225198 Richard Henderson
        goto gen_arith;
1097 8289b279 blueswir1
    case INDEX_op_shr_i32:
1098 8289b279 blueswir1
        c = SHIFT_SRL;
1099 ba225198 Richard Henderson
        goto gen_arith;
1100 8289b279 blueswir1
    case INDEX_op_sar_i32:
1101 8289b279 blueswir1
        c = SHIFT_SRA;
1102 ba225198 Richard Henderson
        goto gen_arith;
1103 8289b279 blueswir1
    case INDEX_op_mul_i32:
1104 8289b279 blueswir1
        c = ARITH_UMUL;
1105 ba225198 Richard Henderson
        goto gen_arith;
1106 8289b279 blueswir1
    case INDEX_op_div2_i32:
1107 8289b279 blueswir1
#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
1108 8289b279 blueswir1
        c = ARITH_SDIVX;
1109 ba225198 Richard Henderson
        goto gen_arith;
1110 8289b279 blueswir1
#else
1111 8289b279 blueswir1
        tcg_out_sety(s, 0);
1112 8289b279 blueswir1
        c = ARITH_SDIV;
1113 ba225198 Richard Henderson
        goto gen_arith;
1114 8289b279 blueswir1
#endif
1115 8289b279 blueswir1
    case INDEX_op_divu2_i32:
1116 8289b279 blueswir1
#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
1117 8289b279 blueswir1
        c = ARITH_UDIVX;
1118 ba225198 Richard Henderson
        goto gen_arith;
1119 8289b279 blueswir1
#else
1120 8289b279 blueswir1
        tcg_out_sety(s, 0);
1121 8289b279 blueswir1
        c = ARITH_UDIV;
1122 ba225198 Richard Henderson
        goto gen_arith;
1123 8289b279 blueswir1
#endif
1124 8289b279 blueswir1
1125 8289b279 blueswir1
    case INDEX_op_brcond_i32:
1126 1da92db2 blueswir1
        tcg_out_brcond_i32(s, args[2], args[0], args[1], const_args[1],
1127 1da92db2 blueswir1
                           args[3]);
1128 8289b279 blueswir1
        break;
1129 56f4927e Richard Henderson
#if TCG_TARGET_REG_BITS == 32
1130 56f4927e Richard Henderson
    case INDEX_op_brcond2_i32:
1131 56f4927e Richard Henderson
        tcg_out_brcond2_i32(s, args[4], args[0], args[1],
1132 56f4927e Richard Henderson
                            args[2], const_args[2],
1133 56f4927e Richard Henderson
                            args[3], const_args[3], args[5]);
1134 56f4927e Richard Henderson
        break;
1135 56f4927e Richard Henderson
#endif
1136 8289b279 blueswir1
1137 8289b279 blueswir1
    case INDEX_op_qemu_ld8u:
1138 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 0);
1139 8289b279 blueswir1
        break;
1140 8289b279 blueswir1
    case INDEX_op_qemu_ld8s:
1141 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 0 | 4);
1142 8289b279 blueswir1
        break;
1143 8289b279 blueswir1
    case INDEX_op_qemu_ld16u:
1144 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 1);
1145 8289b279 blueswir1
        break;
1146 8289b279 blueswir1
    case INDEX_op_qemu_ld16s:
1147 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 1 | 4);
1148 8289b279 blueswir1
        break;
1149 8289b279 blueswir1
    case INDEX_op_qemu_ld32u:
1150 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 2);
1151 8289b279 blueswir1
        break;
1152 8289b279 blueswir1
    case INDEX_op_qemu_ld32s:
1153 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 2 | 4);
1154 8289b279 blueswir1
        break;
1155 8289b279 blueswir1
    case INDEX_op_qemu_st8:
1156 f5ef6aac blueswir1
        tcg_out_qemu_st(s, args, 0);
1157 8289b279 blueswir1
        break;
1158 8289b279 blueswir1
    case INDEX_op_qemu_st16:
1159 f5ef6aac blueswir1
        tcg_out_qemu_st(s, args, 1);
1160 8289b279 blueswir1
        break;
1161 8289b279 blueswir1
    case INDEX_op_qemu_st32:
1162 f5ef6aac blueswir1
        tcg_out_qemu_st(s, args, 2);
1163 8289b279 blueswir1
        break;
1164 8289b279 blueswir1
1165 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1166 8289b279 blueswir1
    case INDEX_op_movi_i64:
1167 8289b279 blueswir1
        tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]);
1168 8289b279 blueswir1
        break;
1169 53cd9273 blueswir1
    case INDEX_op_ld32s_i64:
1170 53cd9273 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDSW);
1171 53cd9273 blueswir1
        break;
1172 8289b279 blueswir1
    case INDEX_op_ld_i64:
1173 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], LDX);
1174 8289b279 blueswir1
        break;
1175 8289b279 blueswir1
    case INDEX_op_st_i64:
1176 8289b279 blueswir1
        tcg_out_ldst(s, args[0], args[1], args[2], STX);
1177 8289b279 blueswir1
        break;
1178 8289b279 blueswir1
    case INDEX_op_shl_i64:
1179 8289b279 blueswir1
        c = SHIFT_SLLX;
1180 ba225198 Richard Henderson
        goto gen_arith;
1181 8289b279 blueswir1
    case INDEX_op_shr_i64:
1182 8289b279 blueswir1
        c = SHIFT_SRLX;
1183 ba225198 Richard Henderson
        goto gen_arith;
1184 8289b279 blueswir1
    case INDEX_op_sar_i64:
1185 8289b279 blueswir1
        c = SHIFT_SRAX;
1186 ba225198 Richard Henderson
        goto gen_arith;
1187 8289b279 blueswir1
    case INDEX_op_mul_i64:
1188 8289b279 blueswir1
        c = ARITH_MULX;
1189 ba225198 Richard Henderson
        goto gen_arith;
1190 8289b279 blueswir1
    case INDEX_op_div2_i64:
1191 53cd9273 blueswir1
        c = ARITH_SDIVX;
1192 ba225198 Richard Henderson
        goto gen_arith;
1193 8289b279 blueswir1
    case INDEX_op_divu2_i64:
1194 8289b279 blueswir1
        c = ARITH_UDIVX;
1195 ba225198 Richard Henderson
        goto gen_arith;
1196 8289b279 blueswir1
1197 8289b279 blueswir1
    case INDEX_op_brcond_i64:
1198 1da92db2 blueswir1
        tcg_out_brcond_i64(s, args[2], args[0], args[1], const_args[1],
1199 1da92db2 blueswir1
                           args[3]);
1200 8289b279 blueswir1
        break;
1201 8289b279 blueswir1
    case INDEX_op_qemu_ld64:
1202 f5ef6aac blueswir1
        tcg_out_qemu_ld(s, args, 3);
1203 8289b279 blueswir1
        break;
1204 8289b279 blueswir1
    case INDEX_op_qemu_st64:
1205 f5ef6aac blueswir1
        tcg_out_qemu_st(s, args, 3);
1206 8289b279 blueswir1
        break;
1207 8289b279 blueswir1
1208 8289b279 blueswir1
#endif
1209 ba225198 Richard Henderson
    gen_arith:
1210 ba225198 Richard Henderson
        tcg_out_arithc(s, args[0], args[1], args[2], const_args[2], c);
1211 53cd9273 blueswir1
        break;
1212 53cd9273 blueswir1
1213 8289b279 blueswir1
    default:
1214 8289b279 blueswir1
        fprintf(stderr, "unknown opcode 0x%x\n", opc);
1215 8289b279 blueswir1
        tcg_abort();
1216 8289b279 blueswir1
    }
1217 8289b279 blueswir1
}
1218 8289b279 blueswir1
1219 8289b279 blueswir1
static const TCGTargetOpDef sparc_op_defs[] = {
1220 8289b279 blueswir1
    { INDEX_op_exit_tb, { } },
1221 b3db8758 blueswir1
    { INDEX_op_goto_tb, { } },
1222 8289b279 blueswir1
    { INDEX_op_call, { "ri" } },
1223 8289b279 blueswir1
    { INDEX_op_jmp, { "ri" } },
1224 8289b279 blueswir1
    { INDEX_op_br, { } },
1225 8289b279 blueswir1
1226 8289b279 blueswir1
    { INDEX_op_mov_i32, { "r", "r" } },
1227 8289b279 blueswir1
    { INDEX_op_movi_i32, { "r" } },
1228 8289b279 blueswir1
    { INDEX_op_ld8u_i32, { "r", "r" } },
1229 8289b279 blueswir1
    { INDEX_op_ld8s_i32, { "r", "r" } },
1230 8289b279 blueswir1
    { INDEX_op_ld16u_i32, { "r", "r" } },
1231 8289b279 blueswir1
    { INDEX_op_ld16s_i32, { "r", "r" } },
1232 8289b279 blueswir1
    { INDEX_op_ld_i32, { "r", "r" } },
1233 8289b279 blueswir1
    { INDEX_op_st8_i32, { "r", "r" } },
1234 8289b279 blueswir1
    { INDEX_op_st16_i32, { "r", "r" } },
1235 8289b279 blueswir1
    { INDEX_op_st_i32, { "r", "r" } },
1236 8289b279 blueswir1
1237 53cd9273 blueswir1
    { INDEX_op_add_i32, { "r", "r", "rJ" } },
1238 53cd9273 blueswir1
    { INDEX_op_mul_i32, { "r", "r", "rJ" } },
1239 8289b279 blueswir1
    { INDEX_op_div2_i32, { "r", "r", "0", "1", "r" } },
1240 8289b279 blueswir1
    { INDEX_op_divu2_i32, { "r", "r", "0", "1", "r" } },
1241 53cd9273 blueswir1
    { INDEX_op_sub_i32, { "r", "r", "rJ" } },
1242 53cd9273 blueswir1
    { INDEX_op_and_i32, { "r", "r", "rJ" } },
1243 53cd9273 blueswir1
    { INDEX_op_or_i32, { "r", "r", "rJ" } },
1244 53cd9273 blueswir1
    { INDEX_op_xor_i32, { "r", "r", "rJ" } },
1245 8289b279 blueswir1
1246 53cd9273 blueswir1
    { INDEX_op_shl_i32, { "r", "r", "rJ" } },
1247 53cd9273 blueswir1
    { INDEX_op_shr_i32, { "r", "r", "rJ" } },
1248 53cd9273 blueswir1
    { INDEX_op_sar_i32, { "r", "r", "rJ" } },
1249 8289b279 blueswir1
1250 56f4927e Richard Henderson
    { INDEX_op_brcond_i32, { "r", "rJ" } },
1251 56f4927e Richard Henderson
#if TCG_TARGET_REG_BITS == 32
1252 56f4927e Richard Henderson
    { INDEX_op_brcond2_i32, { "r", "r", "rJ", "rJ" } },
1253 56f4927e Richard Henderson
#endif
1254 8289b279 blueswir1
1255 8289b279 blueswir1
    { INDEX_op_qemu_ld8u, { "r", "L" } },
1256 8289b279 blueswir1
    { INDEX_op_qemu_ld8s, { "r", "L" } },
1257 8289b279 blueswir1
    { INDEX_op_qemu_ld16u, { "r", "L" } },
1258 8289b279 blueswir1
    { INDEX_op_qemu_ld16s, { "r", "L" } },
1259 8289b279 blueswir1
    { INDEX_op_qemu_ld32u, { "r", "L" } },
1260 8289b279 blueswir1
    { INDEX_op_qemu_ld32s, { "r", "L" } },
1261 8289b279 blueswir1
1262 8289b279 blueswir1
    { INDEX_op_qemu_st8, { "L", "L" } },
1263 8289b279 blueswir1
    { INDEX_op_qemu_st16, { "L", "L" } },
1264 8289b279 blueswir1
    { INDEX_op_qemu_st32, { "L", "L" } },
1265 8289b279 blueswir1
1266 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1267 8289b279 blueswir1
    { INDEX_op_mov_i64, { "r", "r" } },
1268 8289b279 blueswir1
    { INDEX_op_movi_i64, { "r" } },
1269 8289b279 blueswir1
    { INDEX_op_ld8u_i64, { "r", "r" } },
1270 8289b279 blueswir1
    { INDEX_op_ld8s_i64, { "r", "r" } },
1271 8289b279 blueswir1
    { INDEX_op_ld16u_i64, { "r", "r" } },
1272 8289b279 blueswir1
    { INDEX_op_ld16s_i64, { "r", "r" } },
1273 8289b279 blueswir1
    { INDEX_op_ld32u_i64, { "r", "r" } },
1274 8289b279 blueswir1
    { INDEX_op_ld32s_i64, { "r", "r" } },
1275 8289b279 blueswir1
    { INDEX_op_ld_i64, { "r", "r" } },
1276 8289b279 blueswir1
    { INDEX_op_st8_i64, { "r", "r" } },
1277 8289b279 blueswir1
    { INDEX_op_st16_i64, { "r", "r" } },
1278 8289b279 blueswir1
    { INDEX_op_st32_i64, { "r", "r" } },
1279 8289b279 blueswir1
    { INDEX_op_st_i64, { "r", "r" } },
1280 56fc64df blueswir1
    { INDEX_op_qemu_ld64, { "L", "L" } },
1281 56fc64df blueswir1
    { INDEX_op_qemu_st64, { "L", "L" } },
1282 8289b279 blueswir1
1283 53cd9273 blueswir1
    { INDEX_op_add_i64, { "r", "r", "rJ" } },
1284 53cd9273 blueswir1
    { INDEX_op_mul_i64, { "r", "r", "rJ" } },
1285 8289b279 blueswir1
    { INDEX_op_div2_i64, { "r", "r", "0", "1", "r" } },
1286 8289b279 blueswir1
    { INDEX_op_divu2_i64, { "r", "r", "0", "1", "r" } },
1287 53cd9273 blueswir1
    { INDEX_op_sub_i64, { "r", "r", "rJ" } },
1288 53cd9273 blueswir1
    { INDEX_op_and_i64, { "r", "r", "rJ" } },
1289 53cd9273 blueswir1
    { INDEX_op_or_i64, { "r", "r", "rJ" } },
1290 53cd9273 blueswir1
    { INDEX_op_xor_i64, { "r", "r", "rJ" } },
1291 8289b279 blueswir1
1292 53cd9273 blueswir1
    { INDEX_op_shl_i64, { "r", "r", "rJ" } },
1293 53cd9273 blueswir1
    { INDEX_op_shr_i64, { "r", "r", "rJ" } },
1294 53cd9273 blueswir1
    { INDEX_op_sar_i64, { "r", "r", "rJ" } },
1295 8289b279 blueswir1
1296 56f4927e Richard Henderson
    { INDEX_op_brcond_i64, { "r", "rJ" } },
1297 8289b279 blueswir1
#endif
1298 8289b279 blueswir1
    { -1 },
1299 8289b279 blueswir1
};
1300 8289b279 blueswir1
1301 8289b279 blueswir1
void tcg_target_init(TCGContext *s)
1302 8289b279 blueswir1
{
1303 8289b279 blueswir1
    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
1304 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1305 8289b279 blueswir1
    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
1306 8289b279 blueswir1
#endif
1307 8289b279 blueswir1
    tcg_regset_set32(tcg_target_call_clobber_regs, 0,
1308 b3db8758 blueswir1
                     (1 << TCG_REG_G1) |
1309 b3db8758 blueswir1
                     (1 << TCG_REG_G2) |
1310 b3db8758 blueswir1
                     (1 << TCG_REG_G3) |
1311 b3db8758 blueswir1
                     (1 << TCG_REG_G4) |
1312 b3db8758 blueswir1
                     (1 << TCG_REG_G5) |
1313 b3db8758 blueswir1
                     (1 << TCG_REG_G6) |
1314 b3db8758 blueswir1
                     (1 << TCG_REG_G7) |
1315 8289b279 blueswir1
                     (1 << TCG_REG_O0) |
1316 8289b279 blueswir1
                     (1 << TCG_REG_O1) |
1317 8289b279 blueswir1
                     (1 << TCG_REG_O2) |
1318 8289b279 blueswir1
                     (1 << TCG_REG_O3) |
1319 8289b279 blueswir1
                     (1 << TCG_REG_O4) |
1320 8289b279 blueswir1
                     (1 << TCG_REG_O5) |
1321 8289b279 blueswir1
                     (1 << TCG_REG_O7));
1322 8289b279 blueswir1
1323 8289b279 blueswir1
    tcg_regset_clear(s->reserved_regs);
1324 8289b279 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_G0);
1325 a212ea75 Richard Henderson
#if TCG_TARGET_REG_BITS == 64
1326 d795eb86 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I4); // for internal use
1327 d795eb86 blueswir1
#endif
1328 53cd9273 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I5); // for internal use
1329 8289b279 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I6);
1330 8289b279 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I7);
1331 8289b279 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O6);
1332 8289b279 blueswir1
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O7);
1333 8289b279 blueswir1
    tcg_add_target_add_op_defs(sparc_op_defs);
1334 8289b279 blueswir1
}