Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (35.4 kB)

1
/*
2
 * Tiny Code Generator for QEMU
3
 *
4
 * Copyright (c) 2008 Fabrice Bellard
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24

    
25
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
26
    "%g0",
27
    "%g1",
28
    "%g2",
29
    "%g3",
30
    "%g4",
31
    "%g5",
32
    "%g6",
33
    "%g7",
34
    "%o0",
35
    "%o1",
36
    "%o2",
37
    "%o3",
38
    "%o4",
39
    "%o5",
40
    "%o6",
41
    "%o7",
42
    "%l0",
43
    "%l1",
44
    "%l2",
45
    "%l3",
46
    "%l4",
47
    "%l5",
48
    "%l6",
49
    "%l7",
50
    "%i0",
51
    "%i1",
52
    "%i2",
53
    "%i3",
54
    "%i4",
55
    "%i5",
56
    "%i6",
57
    "%i7",
58
};
59

    
60
static const int tcg_target_reg_alloc_order[] = {
61
    TCG_REG_L0,
62
    TCG_REG_L1,
63
    TCG_REG_L2,
64
    TCG_REG_L3,
65
    TCG_REG_L4,
66
    TCG_REG_L5,
67
    TCG_REG_L6,
68
    TCG_REG_L7,
69
    TCG_REG_I0,
70
    TCG_REG_I1,
71
    TCG_REG_I2,
72
    TCG_REG_I3,
73
    TCG_REG_I4,
74
};
75

    
76
static const int tcg_target_call_iarg_regs[6] = {
77
    TCG_REG_O0,
78
    TCG_REG_O1,
79
    TCG_REG_O2,
80
    TCG_REG_O3,
81
    TCG_REG_O4,
82
    TCG_REG_O5,
83
};
84

    
85
static const int tcg_target_call_oarg_regs[2] = {
86
    TCG_REG_O0,
87
    TCG_REG_O1,
88
};
89

    
90
static inline int check_fit_tl(tcg_target_long val, unsigned int bits)
91
{
92
    return (val << ((sizeof(tcg_target_long) * 8 - bits))
93
            >> (sizeof(tcg_target_long) * 8 - bits)) == val;
94
}
95

    
96
static inline int check_fit_i32(uint32_t val, unsigned int bits)
97
{
98
    return ((val << (32 - bits)) >> (32 - bits)) == val;
99
}
100

    
101
static void patch_reloc(uint8_t *code_ptr, int type,
102
                        tcg_target_long value, tcg_target_long addend)
103
{
104
    value += addend;
105
    switch (type) {
106
    case R_SPARC_32:
107
        if (value != (uint32_t)value)
108
            tcg_abort();
109
        *(uint32_t *)code_ptr = value;
110
        break;
111
    case R_SPARC_WDISP22:
112
        value -= (long)code_ptr;
113
        value >>= 2;
114
        if (!check_fit_tl(value, 22))
115
            tcg_abort();
116
        *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x3fffff) | value;
117
        break;
118
    default:
119
        tcg_abort();
120
    }
121
}
122

    
123
/* maximum number of register used for input function arguments */
124
static inline int tcg_target_get_call_iarg_regs_count(int flags)
125
{
126
    return 6;
127
}
128

    
129
/* parse target specific constraints */
130
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
131
{
132
    const char *ct_str;
133

    
134
    ct_str = *pct_str;
135
    switch (ct_str[0]) {
136
    case 'r':
137
    case 'L': /* qemu_ld/st constraint */
138
        ct->ct |= TCG_CT_REG;
139
        tcg_regset_set32(ct->u.regs, 0, 0xffffffff);
140
        // Helper args
141
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O0);
142
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O1);
143
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_O2);
144
        break;
145
    case 'I':
146
        ct->ct |= TCG_CT_CONST_S11;
147
        break;
148
    case 'J':
149
        ct->ct |= TCG_CT_CONST_S13;
150
        break;
151
    default:
152
        return -1;
153
    }
154
    ct_str++;
155
    *pct_str = ct_str;
156
    return 0;
157
}
158

    
159
/* test if a constant matches the constraint */
160
static inline int tcg_target_const_match(tcg_target_long val,
161
                                         const TCGArgConstraint *arg_ct)
162
{
163
    int ct;
164

    
165
    ct = arg_ct->ct;
166
    if (ct & TCG_CT_CONST)
167
        return 1;
168
    else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11))
169
        return 1;
170
    else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13))
171
        return 1;
172
    else
173
        return 0;
174
}
175

    
176
#define INSN_OP(x)  ((x) << 30)
177
#define INSN_OP2(x) ((x) << 22)
178
#define INSN_OP3(x) ((x) << 19)
179
#define INSN_OPF(x) ((x) << 5)
180
#define INSN_RD(x)  ((x) << 25)
181
#define INSN_RS1(x) ((x) << 14)
182
#define INSN_RS2(x) (x)
183
#define INSN_ASI(x) ((x) << 5)
184

    
185
#define INSN_IMM13(x) ((1 << 13) | ((x) & 0x1fff))
186
#define INSN_OFF22(x) (((x) >> 2) & 0x3fffff)
187

    
188
#define INSN_COND(x, a) (((x) << 25) | ((a) << 29))
189
#define COND_N     0x0
190
#define COND_E     0x1
191
#define COND_LE    0x2
192
#define COND_L     0x3
193
#define COND_LEU   0x4
194
#define COND_CS    0x5
195
#define COND_NEG   0x6
196
#define COND_VS    0x7
197
#define COND_A     0x8
198
#define COND_NE    0x9
199
#define COND_G     0xa
200
#define COND_GE    0xb
201
#define COND_GU    0xc
202
#define COND_CC    0xd
203
#define COND_POS   0xe
204
#define COND_VC    0xf
205
#define BA         (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2))
206

    
207
#define ARITH_ADD  (INSN_OP(2) | INSN_OP3(0x00))
208
#define ARITH_AND  (INSN_OP(2) | INSN_OP3(0x01))
209
#define ARITH_OR   (INSN_OP(2) | INSN_OP3(0x02))
210
#define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12))
211
#define ARITH_XOR  (INSN_OP(2) | INSN_OP3(0x03))
212
#define ARITH_SUB  (INSN_OP(2) | INSN_OP3(0x04))
213
#define ARITH_SUBCC (INSN_OP(2) | INSN_OP3(0x14))
214
#define ARITH_ADDX (INSN_OP(2) | INSN_OP3(0x10))
215
#define ARITH_SUBX (INSN_OP(2) | INSN_OP3(0x0c))
216
#define ARITH_UMUL (INSN_OP(2) | INSN_OP3(0x0a))
217
#define ARITH_UDIV (INSN_OP(2) | INSN_OP3(0x0e))
218
#define ARITH_SDIV (INSN_OP(2) | INSN_OP3(0x0f))
219
#define ARITH_MULX (INSN_OP(2) | INSN_OP3(0x09))
220
#define ARITH_UDIVX (INSN_OP(2) | INSN_OP3(0x0d))
221
#define ARITH_SDIVX (INSN_OP(2) | INSN_OP3(0x2d))
222

    
223
#define SHIFT_SLL  (INSN_OP(2) | INSN_OP3(0x25))
224
#define SHIFT_SRL  (INSN_OP(2) | INSN_OP3(0x26))
225
#define SHIFT_SRA  (INSN_OP(2) | INSN_OP3(0x27))
226

    
227
#define SHIFT_SLLX (INSN_OP(2) | INSN_OP3(0x25) | (1 << 12))
228
#define SHIFT_SRLX (INSN_OP(2) | INSN_OP3(0x26) | (1 << 12))
229
#define SHIFT_SRAX (INSN_OP(2) | INSN_OP3(0x27) | (1 << 12))
230

    
231
#define WRY        (INSN_OP(2) | INSN_OP3(0x30))
232
#define JMPL       (INSN_OP(2) | INSN_OP3(0x38))
233
#define SAVE       (INSN_OP(2) | INSN_OP3(0x3c))
234
#define RESTORE    (INSN_OP(2) | INSN_OP3(0x3d))
235
#define SETHI      (INSN_OP(0) | INSN_OP2(0x4))
236
#define CALL       INSN_OP(1)
237
#define LDUB       (INSN_OP(3) | INSN_OP3(0x01))
238
#define LDSB       (INSN_OP(3) | INSN_OP3(0x09))
239
#define LDUH       (INSN_OP(3) | INSN_OP3(0x02))
240
#define LDSH       (INSN_OP(3) | INSN_OP3(0x0a))
241
#define LDUW       (INSN_OP(3) | INSN_OP3(0x00))
242
#define LDSW       (INSN_OP(3) | INSN_OP3(0x08))
243
#define LDX        (INSN_OP(3) | INSN_OP3(0x0b))
244
#define STB        (INSN_OP(3) | INSN_OP3(0x05))
245
#define STH        (INSN_OP(3) | INSN_OP3(0x06))
246
#define STW        (INSN_OP(3) | INSN_OP3(0x04))
247
#define STX        (INSN_OP(3) | INSN_OP3(0x0e))
248
#define LDUBA      (INSN_OP(3) | INSN_OP3(0x11))
249
#define LDSBA      (INSN_OP(3) | INSN_OP3(0x19))
250
#define LDUHA      (INSN_OP(3) | INSN_OP3(0x12))
251
#define LDSHA      (INSN_OP(3) | INSN_OP3(0x1a))
252
#define LDUWA      (INSN_OP(3) | INSN_OP3(0x10))
253
#define LDSWA      (INSN_OP(3) | INSN_OP3(0x18))
254
#define LDXA       (INSN_OP(3) | INSN_OP3(0x1b))
255
#define STBA       (INSN_OP(3) | INSN_OP3(0x15))
256
#define STHA       (INSN_OP(3) | INSN_OP3(0x16))
257
#define STWA       (INSN_OP(3) | INSN_OP3(0x14))
258
#define STXA       (INSN_OP(3) | INSN_OP3(0x1e))
259

    
260
#ifndef ASI_PRIMARY_LITTLE
261
#define ASI_PRIMARY_LITTLE 0x88
262
#endif
263

    
264
static inline void tcg_out_arith(TCGContext *s, int rd, int rs1, int rs2,
265
                                 int op)
266
{
267
    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
268
              INSN_RS2(rs2));
269
}
270

    
271
static inline void tcg_out_arithi(TCGContext *s, int rd, int rs1, int offset,
272
                                  int op)
273
{
274
    tcg_out32(s, op | INSN_RD(rd) | INSN_RS1(rs1) |
275
              INSN_IMM13(offset));
276
}
277

    
278
static inline void tcg_out_mov(TCGContext *s, int ret, int arg)
279
{
280
    tcg_out_arith(s, ret, arg, TCG_REG_G0, ARITH_OR);
281
}
282

    
283
static inline void tcg_out_sethi(TCGContext *s, int ret, uint32_t arg)
284
{
285
    tcg_out32(s, SETHI | INSN_RD(ret) | ((arg & 0xfffffc00) >> 10));
286
}
287

    
288
static inline void tcg_out_movi_imm13(TCGContext *s, int ret, uint32_t arg)
289
{
290
    tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR);
291
}
292

    
293
static inline void tcg_out_movi_imm32(TCGContext *s, int ret, uint32_t arg)
294
{
295
    if (check_fit_i32(arg, 12))
296
        tcg_out_movi_imm13(s, ret, arg);
297
    else {
298
        tcg_out_sethi(s, ret, arg);
299
        if (arg & 0x3ff)
300
            tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
301
    }
302
}
303

    
304
static inline void tcg_out_movi(TCGContext *s, TCGType type,
305
                                int ret, tcg_target_long arg)
306
{
307
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
308
    if (!check_fit_tl(arg, 32) && (arg & ~0xffffffffULL) != 0) {
309
        tcg_out_movi_imm32(s, TCG_REG_I4, arg >> 32);
310
        tcg_out_arithi(s, TCG_REG_I4, TCG_REG_I4, 32, SHIFT_SLLX);
311
        tcg_out_movi_imm32(s, ret, arg);
312
        tcg_out_arith(s, ret, ret, TCG_REG_I4, ARITH_OR);
313
    } else
314
#endif
315
        tcg_out_movi_imm32(s, ret, arg);
316
}
317

    
318
static inline void tcg_out_ld_raw(TCGContext *s, int ret,
319
                                  tcg_target_long arg)
320
{
321
    tcg_out_sethi(s, ret, arg);
322
    tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
323
              INSN_IMM13(arg & 0x3ff));
324
}
325

    
326
static inline void tcg_out_ld_ptr(TCGContext *s, int ret,
327
                                  tcg_target_long arg)
328
{
329
    if (!check_fit_tl(arg, 10))
330
        tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ffULL);
331
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
332
    tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) |
333
              INSN_IMM13(arg & 0x3ff));
334
#else
335
    tcg_out32(s, LDUW | INSN_RD(ret) | INSN_RS1(ret) |
336
              INSN_IMM13(arg & 0x3ff));
337
#endif
338
}
339

    
340
static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op)
341
{
342
    if (check_fit_tl(offset, 13))
343
        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) |
344
                  INSN_IMM13(offset));
345
    else {
346
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
347
        tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
348
                  INSN_RS2(addr));
349
    }
350
}
351

    
352
static inline void tcg_out_ldst_asi(TCGContext *s, int ret, int addr,
353
                                    int offset, int op, int asi)
354
{
355
    tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, offset);
356
    tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(TCG_REG_I5) |
357
              INSN_ASI(asi) | INSN_RS2(addr));
358
}
359

    
360
static inline void tcg_out_ld(TCGContext *s, TCGType type, int ret,
361
                              int arg1, tcg_target_long arg2)
362
{
363
    if (type == TCG_TYPE_I32)
364
        tcg_out_ldst(s, ret, arg1, arg2, LDUW);
365
    else
366
        tcg_out_ldst(s, ret, arg1, arg2, LDX);
367
}
368

    
369
static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
370
                              int arg1, tcg_target_long arg2)
371
{
372
    if (type == TCG_TYPE_I32)
373
        tcg_out_ldst(s, arg, arg1, arg2, STW);
374
    else
375
        tcg_out_ldst(s, arg, arg1, arg2, STX);
376
}
377

    
378
static inline void tcg_out_sety(TCGContext *s, tcg_target_long val)
379
{
380
    if (val == 0 || val == -1)
381
        tcg_out32(s, WRY | INSN_IMM13(val));
382
    else
383
        fprintf(stderr, "unimplemented sety %ld\n", (long)val);
384
}
385

    
386
static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
387
{
388
    if (val != 0) {
389
        if (check_fit_tl(val, 13))
390
            tcg_out_arithi(s, reg, reg, val, ARITH_ADD);
391
        else {
392
            tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, val);
393
            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_ADD);
394
        }
395
    }
396
}
397

    
398
static inline void tcg_out_andi(TCGContext *s, int reg, tcg_target_long val)
399
{
400
    if (val != 0) {
401
        if (check_fit_tl(val, 13))
402
            tcg_out_arithi(s, reg, reg, val, ARITH_AND);
403
        else {
404
            tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_I5, val);
405
            tcg_out_arith(s, reg, reg, TCG_REG_I5, ARITH_AND);
406
        }
407
    }
408
}
409

    
410
static inline void tcg_out_nop(TCGContext *s)
411
{
412
    tcg_out_sethi(s, TCG_REG_G0, 0);
413
}
414

    
415
static void tcg_out_branch(TCGContext *s, int opc, int label_index)
416
{
417
    int32_t val;
418
    TCGLabel *l = &s->labels[label_index];
419

    
420
    if (l->has_value) {
421
        val = l->u.value - (tcg_target_long)s->code_ptr;
422
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2)
423
                      | INSN_OFF22(l->u.value - (unsigned long)s->code_ptr)));
424
    } else {
425
        tcg_out_reloc(s, s->code_ptr, R_SPARC_WDISP22, label_index, 0);
426
        tcg_out32(s, (INSN_OP(0) | INSN_COND(opc, 0) | INSN_OP2(0x2) | 0));
427
    }
428
}
429

    
430
static const uint8_t tcg_cond_to_bcond[10] = {
431
    [TCG_COND_EQ] = COND_E,
432
    [TCG_COND_NE] = COND_NE,
433
    [TCG_COND_LT] = COND_L,
434
    [TCG_COND_GE] = COND_GE,
435
    [TCG_COND_LE] = COND_LE,
436
    [TCG_COND_GT] = COND_G,
437
    [TCG_COND_LTU] = COND_CS,
438
    [TCG_COND_GEU] = COND_CC,
439
    [TCG_COND_LEU] = COND_LEU,
440
    [TCG_COND_GTU] = COND_GU,
441
};
442

    
443
static void tcg_out_brcond(TCGContext *s, int cond,
444
                           TCGArg arg1, TCGArg arg2, int const_arg2,
445
                           int label_index)
446
{
447
    if (const_arg2 && arg2 == 0)
448
        /* orcc %g0, r, %g0 */
449
        tcg_out_arith(s, TCG_REG_G0, TCG_REG_G0, arg1, ARITH_ORCC);
450
    else
451
        /* subcc r1, r2, %g0 */
452
        tcg_out_arith(s, TCG_REG_G0, arg1, arg2, ARITH_SUBCC);
453
    tcg_out_branch(s, tcg_cond_to_bcond[cond], label_index);
454
    tcg_out_nop(s);
455
}
456

    
457
/* Generate global QEMU prologue and epilogue code */
458
void tcg_target_qemu_prologue(TCGContext *s)
459
{
460
    tcg_out32(s, SAVE | INSN_RD(TCG_REG_O6) | INSN_RS1(TCG_REG_O6) |
461
              INSN_IMM13(-TCG_TARGET_STACK_MINFRAME));
462
    tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I0) |
463
              INSN_RS2(TCG_REG_G0));
464
    tcg_out_nop(s);
465
}
466

    
467
#if defined(CONFIG_SOFTMMU)
468
extern void __ldb_mmu(void);
469
extern void __ldw_mmu(void);
470
extern void __ldl_mmu(void);
471
extern void __ldq_mmu(void);
472

    
473
extern void __stb_mmu(void);
474
extern void __stw_mmu(void);
475
extern void __stl_mmu(void);
476
extern void __stq_mmu(void);
477

    
478

    
479
static const void * const qemu_ld_helpers[4] = {
480
    __ldb_mmu,
481
    __ldw_mmu,
482
    __ldl_mmu,
483
    __ldq_mmu,
484
};
485

    
486
static const void * const qemu_st_helpers[4] = {
487
    __stb_mmu,
488
    __stw_mmu,
489
    __stl_mmu,
490
    __stq_mmu,
491
};
492
#endif
493

    
494
#if TARGET_LONG_BITS == 32
495
#define TARGET_LD_OP LDUW
496
#else
497
#define TARGET_LD_OP LDX
498
#endif
499

    
500
#ifdef __arch64__
501
#define HOST_LD_OP LDX
502
#define HOST_ST_OP STX
503
#define HOST_SLL_OP SHIFT_SLLX
504
#define HOST_SRA_OP SHIFT_SRAX
505
#else
506
#define HOST_LD_OP LDUW
507
#define HOST_ST_OP STW
508
#define HOST_SLL_OP SHIFT_SLL
509
#define HOST_SRA_OP SHIFT_SRA
510
#endif
511

    
512
static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
513
                            int opc)
514
{
515
    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
516
#if defined(CONFIG_SOFTMMU)
517
    uint32_t *label1_ptr, *label2_ptr;
518
#endif
519

    
520
    data_reg = *args++;
521
    addr_reg = *args++;
522
    mem_index = *args;
523
    s_bits = opc & 3;
524

    
525
    arg0 = TCG_REG_O0;
526
    arg1 = TCG_REG_O1;
527
    arg2 = TCG_REG_O2;
528

    
529
#if defined(CONFIG_SOFTMMU)
530
    /* srl addr_reg, x, arg1 */
531
    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
532
                   SHIFT_SRL);
533
    /* and addr_reg, x, arg0 */
534
    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
535
                   ARITH_AND);
536

    
537
    /* and arg1, x, arg1 */
538
    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
539

    
540
    /* add arg1, x, arg1 */
541
    tcg_out_addi(s, arg1, offsetof(CPUState,
542
                                   tlb_table[mem_index][0].addr_read));
543

    
544
    /* add env, arg1, arg1 */
545
    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
546

    
547
    /* ld [arg1], arg2 */
548
    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
549
              INSN_RS2(TCG_REG_G0));
550

    
551
    /* subcc arg0, arg2, %g0 */
552
    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
553

    
554
    /* will become:
555
       be label1 */
556
    label1_ptr = (uint32_t *)s->code_ptr;
557
    tcg_out32(s, 0);
558

    
559
    /* mov (delay slot) */
560
    tcg_out_mov(s, arg0, addr_reg);
561

    
562
    /* mov */
563
    tcg_out_movi(s, TCG_TYPE_I32, arg1, mem_index);
564

    
565
    /* XXX: move that code at the end of the TB */
566
    /* qemu_ld_helper[s_bits](arg0, arg1) */
567
    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_ld_helpers[s_bits]
568
                           - (tcg_target_ulong)s->code_ptr) >> 2)
569
                         & 0x3fffffff));
570
    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
571
       global registers */
572
    // delay slot
573
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
574
                 TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_ST_OP);
575
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
576
                 TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_LD_OP);
577

    
578
    /* data_reg = sign_extend(arg0) */
579
    switch(opc) {
580
    case 0 | 4:
581
        /* sll arg0, 24/56, data_reg */
582
        tcg_out_arithi(s, data_reg, arg0, (int)sizeof(tcg_target_long) * 8 - 8,
583
                       HOST_SLL_OP);
584
        /* sra data_reg, 24/56, data_reg */
585
        tcg_out_arithi(s, data_reg, data_reg,
586
                       (int)sizeof(tcg_target_long) * 8 - 8, HOST_SRA_OP);
587
        break;
588
    case 1 | 4:
589
        /* sll arg0, 16/48, data_reg */
590
        tcg_out_arithi(s, data_reg, arg0,
591
                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SLL_OP);
592
        /* sra data_reg, 16/48, data_reg */
593
        tcg_out_arithi(s, data_reg, data_reg,
594
                       (int)sizeof(tcg_target_long) * 8 - 16, HOST_SRA_OP);
595
        break;
596
    case 2 | 4:
597
        /* sll arg0, 32, data_reg */
598
        tcg_out_arithi(s, data_reg, arg0, 32, HOST_SLL_OP);
599
        /* sra data_reg, 32, data_reg */
600
        tcg_out_arithi(s, data_reg, data_reg, 32, HOST_SRA_OP);
601
        break;
602
    case 0:
603
    case 1:
604
    case 2:
605
    case 3:
606
    default:
607
        /* mov */
608
        tcg_out_mov(s, data_reg, arg0);
609
        break;
610
    }
611

    
612
    /* will become:
613
       ba label2 */
614
    label2_ptr = (uint32_t *)s->code_ptr;
615
    tcg_out32(s, 0);
616

    
617
    /* nop (delay slot */
618
    tcg_out_nop(s);
619

    
620
    /* label1: */
621
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
622
                   INSN_OFF22((unsigned long)s->code_ptr -
623
                              (unsigned long)label1_ptr));
624

    
625
    /* ld [arg1 + x], arg1 */
626
    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
627
                 offsetof(CPUTLBEntry, addr_read), HOST_LD_OP);
628
    /* add addr_reg, arg1, arg0 */
629
    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
630
#else
631
    arg0 = addr_reg;
632
#endif
633

    
634
    switch(opc) {
635
    case 0:
636
        /* ldub [arg0], data_reg */
637
        tcg_out_ldst(s, data_reg, arg0, 0, LDUB);
638
        break;
639
    case 0 | 4:
640
        /* ldsb [arg0], data_reg */
641
        tcg_out_ldst(s, data_reg, arg0, 0, LDSB);
642
        break;
643
    case 1:
644
#ifdef TARGET_WORDS_BIGENDIAN
645
        /* lduh [arg0], data_reg */
646
        tcg_out_ldst(s, data_reg, arg0, 0, LDUH);
647
#else
648
        /* lduha [arg0] ASI_PRIMARY_LITTLE, data_reg */
649
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUHA, ASI_PRIMARY_LITTLE);
650
#endif
651
        break;
652
    case 1 | 4:
653
#ifdef TARGET_WORDS_BIGENDIAN
654
        /* ldsh [arg0], data_reg */
655
        tcg_out_ldst(s, data_reg, arg0, 0, LDSH);
656
#else
657
        /* ldsha [arg0] ASI_PRIMARY_LITTLE, data_reg */
658
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSHA, ASI_PRIMARY_LITTLE);
659
#endif
660
        break;
661
    case 2:
662
#ifdef TARGET_WORDS_BIGENDIAN
663
        /* lduw [arg0], data_reg */
664
        tcg_out_ldst(s, data_reg, arg0, 0, LDUW);
665
#else
666
        /* lduwa [arg0] ASI_PRIMARY_LITTLE, data_reg */
667
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDUWA, ASI_PRIMARY_LITTLE);
668
#endif
669
        break;
670
    case 2 | 4:
671
#ifdef TARGET_WORDS_BIGENDIAN
672
        /* ldsw [arg0], data_reg */
673
        tcg_out_ldst(s, data_reg, arg0, 0, LDSW);
674
#else
675
        /* ldswa [arg0] ASI_PRIMARY_LITTLE, data_reg */
676
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDSWA, ASI_PRIMARY_LITTLE);
677
#endif
678
        break;
679
    case 3:
680
#ifdef TARGET_WORDS_BIGENDIAN
681
        /* ldx [arg0], data_reg */
682
        tcg_out_ldst(s, data_reg, arg0, 0, LDX);
683
#else
684
        /* ldxa [arg0] ASI_PRIMARY_LITTLE, data_reg */
685
        tcg_out_ldst_asi(s, data_reg, arg0, 0, LDXA, ASI_PRIMARY_LITTLE);
686
#endif
687
        break;
688
    default:
689
        tcg_abort();
690
    }
691

    
692
#if defined(CONFIG_SOFTMMU)
693
    /* label2: */
694
    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
695
                   INSN_OFF22((unsigned long)s->code_ptr -
696
                              (unsigned long)label2_ptr));
697
#endif
698
}
699

    
700
static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
701
                            int opc)
702
{
703
    int addr_reg, data_reg, arg0, arg1, arg2, mem_index, s_bits;
704
#if defined(CONFIG_SOFTMMU)
705
    uint32_t *label1_ptr, *label2_ptr;
706
#endif
707

    
708
    data_reg = *args++;
709
    addr_reg = *args++;
710
    mem_index = *args;
711

    
712
    s_bits = opc;
713

    
714
    arg0 = TCG_REG_O0;
715
    arg1 = TCG_REG_O1;
716
    arg2 = TCG_REG_O2;
717

    
718
#if defined(CONFIG_SOFTMMU)
719
    /* srl addr_reg, x, arg1 */
720
    tcg_out_arithi(s, arg1, addr_reg, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS,
721
                   SHIFT_SRL);
722

    
723
    /* and addr_reg, x, arg0 */
724
    tcg_out_arithi(s, arg0, addr_reg, TARGET_PAGE_MASK | ((1 << s_bits) - 1),
725
                   ARITH_AND);
726

    
727
    /* and arg1, x, arg1 */
728
    tcg_out_andi(s, arg1, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
729

    
730
    /* add arg1, x, arg1 */
731
    tcg_out_addi(s, arg1, offsetof(CPUState,
732
                                   tlb_table[mem_index][0].addr_write));
733

    
734
    /* add env, arg1, arg1 */
735
    tcg_out_arith(s, arg1, TCG_AREG0, arg1, ARITH_ADD);
736

    
737
    /* ld [arg1], arg2 */
738
    tcg_out32(s, TARGET_LD_OP | INSN_RD(arg2) | INSN_RS1(arg1) |
739
              INSN_RS2(TCG_REG_G0));
740

    
741
    /* subcc arg0, arg2, %g0 */
742
    tcg_out_arith(s, TCG_REG_G0, arg0, arg2, ARITH_SUBCC);
743

    
744
    /* will become:
745
       be label1 */
746
    label1_ptr = (uint32_t *)s->code_ptr;
747
    tcg_out32(s, 0);
748

    
749
    /* mov (delay slot) */
750
    tcg_out_mov(s, arg0, addr_reg);
751

    
752
    /* mov */
753
    tcg_out_mov(s, arg1, data_reg);
754

    
755
    /* mov */
756
    tcg_out_movi(s, TCG_TYPE_I32, arg2, mem_index);
757

    
758
    /* XXX: move that code at the end of the TB */
759
    /* qemu_st_helper[s_bits](arg0, arg1, arg2) */
760
    tcg_out32(s, CALL | ((((tcg_target_ulong)qemu_st_helpers[s_bits]
761
                           - (tcg_target_ulong)s->code_ptr) >> 2)
762
                         & 0x3fffffff));
763
    /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
764
       global registers */
765
    // delay slot
766
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
767
                 TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_ST_OP);
768
    tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
769
                 TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_LD_OP);
770

    
771
    /* will become:
772
       ba label2 */
773
    label2_ptr = (uint32_t *)s->code_ptr;
774
    tcg_out32(s, 0);
775

    
776
    /* nop (delay slot) */
777
    tcg_out_nop(s);
778

    
779
    /* label1: */
780
    *label1_ptr = (INSN_OP(0) | INSN_COND(COND_E, 0) | INSN_OP2(0x2) |
781
                   INSN_OFF22((unsigned long)s->code_ptr -
782
                              (unsigned long)label1_ptr));
783

    
784
    /* ld [arg1 + x], arg1 */
785
    tcg_out_ldst(s, arg1, arg1, offsetof(CPUTLBEntry, addend) -
786
                 offsetof(CPUTLBEntry, addr_write), HOST_LD_OP);
787

    
788
    /* add addr_reg, arg1, arg0 */
789
    tcg_out_arith(s, arg0, addr_reg, arg1, ARITH_ADD);
790
#else
791
    arg0 = addr_reg;
792
#endif
793

    
794
    switch(opc) {
795
    case 0:
796
        /* stb data_reg, [arg0] */
797
        tcg_out_ldst(s, data_reg, arg0, 0, STB);
798
        break;
799
    case 1:
800
#ifdef TARGET_WORDS_BIGENDIAN
801
        /* sth data_reg, [arg0] */
802
        tcg_out_ldst(s, data_reg, arg0, 0, STH);
803
#else
804
        /* stha data_reg, [arg0] ASI_PRIMARY_LITTLE */
805
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STHA, ASI_PRIMARY_LITTLE);
806
#endif
807
        break;
808
    case 2:
809
#ifdef TARGET_WORDS_BIGENDIAN
810
        /* stw data_reg, [arg0] */
811
        tcg_out_ldst(s, data_reg, arg0, 0, STW);
812
#else
813
        /* stwa data_reg, [arg0] ASI_PRIMARY_LITTLE */
814
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STWA, ASI_PRIMARY_LITTLE);
815
#endif
816
        break;
817
    case 3:
818
#ifdef TARGET_WORDS_BIGENDIAN
819
        /* stx data_reg, [arg0] */
820
        tcg_out_ldst(s, data_reg, arg0, 0, STX);
821
#else
822
        /* stxa data_reg, [arg0] ASI_PRIMARY_LITTLE */
823
        tcg_out_ldst_asi(s, data_reg, arg0, 0, STXA, ASI_PRIMARY_LITTLE);
824
#endif
825
        break;
826
    default:
827
        tcg_abort();
828
    }
829

    
830
#if defined(CONFIG_SOFTMMU)
831
    /* label2: */
832
    *label2_ptr = (INSN_OP(0) | INSN_COND(COND_A, 0) | INSN_OP2(0x2) |
833
                   INSN_OFF22((unsigned long)s->code_ptr -
834
                              (unsigned long)label2_ptr));
835
#endif
836
}
837

    
838
static inline void tcg_out_op(TCGContext *s, int opc, const TCGArg *args,
839
                              const int *const_args)
840
{
841
    int c;
842

    
843
    switch (opc) {
844
    case INDEX_op_exit_tb:
845
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, args[0]);
846
        tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I7) |
847
                  INSN_IMM13(8));
848
        tcg_out32(s, RESTORE | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_G0) |
849
                      INSN_RS2(TCG_REG_G0));
850
        break;
851
    case INDEX_op_goto_tb:
852
        if (s->tb_jmp_offset) {
853
            /* direct jump method */
854
            tcg_out_sethi(s, TCG_REG_I5, args[0] & 0xffffe000);
855
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
856
                      INSN_IMM13((args[0] & 0x1fff)));
857
            s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf;
858
        } else {
859
            /* indirect jump method */
860
            tcg_out_ld_ptr(s, TCG_REG_I5, (tcg_target_long)(s->tb_next + args[0]));
861
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) |
862
                      INSN_RS2(TCG_REG_G0));
863
        }
864
        tcg_out_nop(s);
865
        s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
866
        break;
867
    case INDEX_op_call:
868
        if (const_args[0])
869
            tcg_out32(s, CALL | ((((tcg_target_ulong)args[0]
870
                                   - (tcg_target_ulong)s->code_ptr) >> 2)
871
                                 & 0x3fffffff));
872
        else {
873
            tcg_out_ld_ptr(s, TCG_REG_I5,
874
                           (tcg_target_long)(s->tb_next + args[0]));
875
            tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_I5) |
876
                      INSN_RS2(TCG_REG_G0));
877
        }
878
        /* Store AREG0 in stack to avoid ugly glibc bugs that mangle
879
           global registers */
880
        // delay slot
881
        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
882
                     TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_ST_OP);
883
        tcg_out_ldst(s, TCG_AREG0, TCG_REG_CALL_STACK,
884
                     TCG_TARGET_CALL_STACK_OFFSET - sizeof(long), HOST_LD_OP);
885
        break;
886
    case INDEX_op_jmp:
887
    case INDEX_op_br:
888
        tcg_out_branch(s, COND_A, args[0]);
889
        tcg_out_nop(s);
890
        break;
891
    case INDEX_op_movi_i32:
892
        tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]);
893
        break;
894

    
895
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
896
#define OP_32_64(x)                             \
897
        glue(glue(case INDEX_op_, x), _i32:)    \
898
        glue(glue(case INDEX_op_, x), _i64:)
899
#else
900
#define OP_32_64(x)                             \
901
        glue(glue(case INDEX_op_, x), _i32:)
902
#endif
903
        OP_32_64(ld8u);
904
        tcg_out_ldst(s, args[0], args[1], args[2], LDUB);
905
        break;
906
        OP_32_64(ld8s);
907
        tcg_out_ldst(s, args[0], args[1], args[2], LDSB);
908
        break;
909
        OP_32_64(ld16u);
910
        tcg_out_ldst(s, args[0], args[1], args[2], LDUH);
911
        break;
912
        OP_32_64(ld16s);
913
        tcg_out_ldst(s, args[0], args[1], args[2], LDSH);
914
        break;
915
    case INDEX_op_ld_i32:
916
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
917
    case INDEX_op_ld32u_i64:
918
#endif
919
        tcg_out_ldst(s, args[0], args[1], args[2], LDUW);
920
        break;
921
        OP_32_64(st8);
922
        tcg_out_ldst(s, args[0], args[1], args[2], STB);
923
        break;
924
        OP_32_64(st16);
925
        tcg_out_ldst(s, args[0], args[1], args[2], STH);
926
        break;
927
    case INDEX_op_st_i32:
928
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
929
    case INDEX_op_st32_i64:
930
#endif
931
        tcg_out_ldst(s, args[0], args[1], args[2], STW);
932
        break;
933
        OP_32_64(add);
934
        c = ARITH_ADD;
935
        goto gen_arith32;
936
        OP_32_64(sub);
937
        c = ARITH_SUB;
938
        goto gen_arith32;
939
        OP_32_64(and);
940
        c = ARITH_AND;
941
        goto gen_arith32;
942
        OP_32_64(or);
943
        c = ARITH_OR;
944
        goto gen_arith32;
945
        OP_32_64(xor);
946
        c = ARITH_XOR;
947
        goto gen_arith32;
948
    case INDEX_op_shl_i32:
949
        c = SHIFT_SLL;
950
        goto gen_arith32;
951
    case INDEX_op_shr_i32:
952
        c = SHIFT_SRL;
953
        goto gen_arith32;
954
    case INDEX_op_sar_i32:
955
        c = SHIFT_SRA;
956
        goto gen_arith32;
957
    case INDEX_op_mul_i32:
958
        c = ARITH_UMUL;
959
        goto gen_arith32;
960
    case INDEX_op_div2_i32:
961
#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
962
        c = ARITH_SDIVX;
963
        goto gen_arith32;
964
#else
965
        tcg_out_sety(s, 0);
966
        c = ARITH_SDIV;
967
        goto gen_arith32;
968
#endif
969
    case INDEX_op_divu2_i32:
970
#if defined(__sparc_v9__) || defined(__sparc_v8plus__)
971
        c = ARITH_UDIVX;
972
        goto gen_arith32;
973
#else
974
        tcg_out_sety(s, 0);
975
        c = ARITH_UDIV;
976
        goto gen_arith32;
977
#endif
978

    
979
    case INDEX_op_brcond_i32:
980
        tcg_out_brcond(s, args[2], args[0], args[1], const_args[1],
981
                       args[3]);
982
        break;
983

    
984
    case INDEX_op_qemu_ld8u:
985
        tcg_out_qemu_ld(s, args, 0);
986
        break;
987
    case INDEX_op_qemu_ld8s:
988
        tcg_out_qemu_ld(s, args, 0 | 4);
989
        break;
990
    case INDEX_op_qemu_ld16u:
991
        tcg_out_qemu_ld(s, args, 1);
992
        break;
993
    case INDEX_op_qemu_ld16s:
994
        tcg_out_qemu_ld(s, args, 1 | 4);
995
        break;
996
    case INDEX_op_qemu_ld32u:
997
        tcg_out_qemu_ld(s, args, 2);
998
        break;
999
    case INDEX_op_qemu_ld32s:
1000
        tcg_out_qemu_ld(s, args, 2 | 4);
1001
        break;
1002
    case INDEX_op_qemu_st8:
1003
        tcg_out_qemu_st(s, args, 0);
1004
        break;
1005
    case INDEX_op_qemu_st16:
1006
        tcg_out_qemu_st(s, args, 1);
1007
        break;
1008
    case INDEX_op_qemu_st32:
1009
        tcg_out_qemu_st(s, args, 2);
1010
        break;
1011

    
1012
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
1013
    case INDEX_op_movi_i64:
1014
        tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]);
1015
        break;
1016
    case INDEX_op_ld32s_i64:
1017
        tcg_out_ldst(s, args[0], args[1], args[2], LDSW);
1018
        break;
1019
    case INDEX_op_ld_i64:
1020
        tcg_out_ldst(s, args[0], args[1], args[2], LDX);
1021
        break;
1022
    case INDEX_op_st_i64:
1023
        tcg_out_ldst(s, args[0], args[1], args[2], STX);
1024
        break;
1025
    case INDEX_op_shl_i64:
1026
        c = SHIFT_SLLX;
1027
        goto gen_arith32;
1028
    case INDEX_op_shr_i64:
1029
        c = SHIFT_SRLX;
1030
        goto gen_arith32;
1031
    case INDEX_op_sar_i64:
1032
        c = SHIFT_SRAX;
1033
        goto gen_arith32;
1034
    case INDEX_op_mul_i64:
1035
        c = ARITH_MULX;
1036
        goto gen_arith32;
1037
    case INDEX_op_div2_i64:
1038
        c = ARITH_SDIVX;
1039
        goto gen_arith32;
1040
    case INDEX_op_divu2_i64:
1041
        c = ARITH_UDIVX;
1042
        goto gen_arith32;
1043

    
1044
    case INDEX_op_brcond_i64:
1045
        tcg_out_brcond(s, args[2], args[0], args[1], const_args[1],
1046
                       args[3]);
1047
        break;
1048
    case INDEX_op_qemu_ld64:
1049
        tcg_out_qemu_ld(s, args, 3);
1050
        break;
1051
    case INDEX_op_qemu_st64:
1052
        tcg_out_qemu_st(s, args, 3);
1053
        break;
1054

    
1055
#endif
1056
    gen_arith32:
1057
        if (const_args[2]) {
1058
            tcg_out_arithi(s, args[0], args[1], args[2], c);
1059
        } else {
1060
            tcg_out_arith(s, args[0], args[1], args[2], c);
1061
        }
1062
        break;
1063

    
1064
    default:
1065
        fprintf(stderr, "unknown opcode 0x%x\n", opc);
1066
        tcg_abort();
1067
    }
1068
}
1069

    
1070
static const TCGTargetOpDef sparc_op_defs[] = {
1071
    { INDEX_op_exit_tb, { } },
1072
    { INDEX_op_goto_tb, { } },
1073
    { INDEX_op_call, { "ri" } },
1074
    { INDEX_op_jmp, { "ri" } },
1075
    { INDEX_op_br, { } },
1076

    
1077
    { INDEX_op_mov_i32, { "r", "r" } },
1078
    { INDEX_op_movi_i32, { "r" } },
1079
    { INDEX_op_ld8u_i32, { "r", "r" } },
1080
    { INDEX_op_ld8s_i32, { "r", "r" } },
1081
    { INDEX_op_ld16u_i32, { "r", "r" } },
1082
    { INDEX_op_ld16s_i32, { "r", "r" } },
1083
    { INDEX_op_ld_i32, { "r", "r" } },
1084
    { INDEX_op_st8_i32, { "r", "r" } },
1085
    { INDEX_op_st16_i32, { "r", "r" } },
1086
    { INDEX_op_st_i32, { "r", "r" } },
1087

    
1088
    { INDEX_op_add_i32, { "r", "r", "rJ" } },
1089
    { INDEX_op_mul_i32, { "r", "r", "rJ" } },
1090
    { INDEX_op_div2_i32, { "r", "r", "0", "1", "r" } },
1091
    { INDEX_op_divu2_i32, { "r", "r", "0", "1", "r" } },
1092
    { INDEX_op_sub_i32, { "r", "r", "rJ" } },
1093
    { INDEX_op_and_i32, { "r", "r", "rJ" } },
1094
    { INDEX_op_or_i32, { "r", "r", "rJ" } },
1095
    { INDEX_op_xor_i32, { "r", "r", "rJ" } },
1096

    
1097
    { INDEX_op_shl_i32, { "r", "r", "rJ" } },
1098
    { INDEX_op_shr_i32, { "r", "r", "rJ" } },
1099
    { INDEX_op_sar_i32, { "r", "r", "rJ" } },
1100

    
1101
    { INDEX_op_brcond_i32, { "r", "ri" } },
1102

    
1103
    { INDEX_op_qemu_ld8u, { "r", "L" } },
1104
    { INDEX_op_qemu_ld8s, { "r", "L" } },
1105
    { INDEX_op_qemu_ld16u, { "r", "L" } },
1106
    { INDEX_op_qemu_ld16s, { "r", "L" } },
1107
    { INDEX_op_qemu_ld32u, { "r", "L" } },
1108
    { INDEX_op_qemu_ld32s, { "r", "L" } },
1109

    
1110
    { INDEX_op_qemu_st8, { "L", "L" } },
1111
    { INDEX_op_qemu_st16, { "L", "L" } },
1112
    { INDEX_op_qemu_st32, { "L", "L" } },
1113

    
1114
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
1115
    { INDEX_op_mov_i64, { "r", "r" } },
1116
    { INDEX_op_movi_i64, { "r" } },
1117
    { INDEX_op_ld8u_i64, { "r", "r" } },
1118
    { INDEX_op_ld8s_i64, { "r", "r" } },
1119
    { INDEX_op_ld16u_i64, { "r", "r" } },
1120
    { INDEX_op_ld16s_i64, { "r", "r" } },
1121
    { INDEX_op_ld32u_i64, { "r", "r" } },
1122
    { INDEX_op_ld32s_i64, { "r", "r" } },
1123
    { INDEX_op_ld_i64, { "r", "r" } },
1124
    { INDEX_op_st8_i64, { "r", "r" } },
1125
    { INDEX_op_st16_i64, { "r", "r" } },
1126
    { INDEX_op_st32_i64, { "r", "r" } },
1127
    { INDEX_op_st_i64, { "r", "r" } },
1128
    { INDEX_op_qemu_ld64, { "L", "L" } },
1129
    { INDEX_op_qemu_st64, { "L", "L" } },
1130

    
1131
    { INDEX_op_add_i64, { "r", "r", "rJ" } },
1132
    { INDEX_op_mul_i64, { "r", "r", "rJ" } },
1133
    { INDEX_op_div2_i64, { "r", "r", "0", "1", "r" } },
1134
    { INDEX_op_divu2_i64, { "r", "r", "0", "1", "r" } },
1135
    { INDEX_op_sub_i64, { "r", "r", "rJ" } },
1136
    { INDEX_op_and_i64, { "r", "r", "rJ" } },
1137
    { INDEX_op_or_i64, { "r", "r", "rJ" } },
1138
    { INDEX_op_xor_i64, { "r", "r", "rJ" } },
1139

    
1140
    { INDEX_op_shl_i64, { "r", "r", "rJ" } },
1141
    { INDEX_op_shr_i64, { "r", "r", "rJ" } },
1142
    { INDEX_op_sar_i64, { "r", "r", "rJ" } },
1143

    
1144
    { INDEX_op_brcond_i64, { "r", "ri" } },
1145
#endif
1146
    { -1 },
1147
};
1148

    
1149
void tcg_target_init(TCGContext *s)
1150
{
1151
    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
1152
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
1153
    tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
1154
#endif
1155
    tcg_regset_set32(tcg_target_call_clobber_regs, 0,
1156
                     (1 << TCG_REG_G1) |
1157
                     (1 << TCG_REG_G2) |
1158
                     (1 << TCG_REG_G3) |
1159
                     (1 << TCG_REG_G4) |
1160
                     (1 << TCG_REG_G5) |
1161
                     (1 << TCG_REG_G6) |
1162
                     (1 << TCG_REG_G7) |
1163
                     (1 << TCG_REG_O0) |
1164
                     (1 << TCG_REG_O1) |
1165
                     (1 << TCG_REG_O2) |
1166
                     (1 << TCG_REG_O3) |
1167
                     (1 << TCG_REG_O4) |
1168
                     (1 << TCG_REG_O5) |
1169
                     (1 << TCG_REG_O7));
1170

    
1171
    tcg_regset_clear(s->reserved_regs);
1172
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_G0);
1173
#if defined(__sparc_v9__) && !defined(__sparc_v8plus__)
1174
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I4); // for internal use
1175
#endif
1176
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I5); // for internal use
1177
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I6);
1178
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_I7);
1179
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O6);
1180
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_O7);
1181
    tcg_add_target_add_op_defs(sparc_op_defs);
1182
}