Statistics
| Branch: | Revision:

root / tcg / ia64 / tcg-target.c @ 6781d08d

History | View | Annotate | Download (83.2 kB)

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

    
26
/*
27
 * Register definitions
28
 */
29

    
30
#ifndef NDEBUG
31
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
32
     "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
33
     "r8",  "r9", "r10", "r11", "r12", "r13", "r14", "r15",
34
    "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
35
    "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
36
    "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
37
    "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
38
    "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
39
    "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
40
};
41
#endif
42

    
43
#ifdef CONFIG_USE_GUEST_BASE
44
#define TCG_GUEST_BASE_REG TCG_REG_R55
45
#else
46
#define TCG_GUEST_BASE_REG TCG_REG_R0
47
#endif
48

    
49
/* Branch registers */
50
enum {
51
    TCG_REG_B0 = 0,
52
    TCG_REG_B1,
53
    TCG_REG_B2,
54
    TCG_REG_B3,
55
    TCG_REG_B4,
56
    TCG_REG_B5,
57
    TCG_REG_B6,
58
    TCG_REG_B7,
59
};
60

    
61
/* Floating point registers */
62
enum {
63
    TCG_REG_F0 = 0,
64
    TCG_REG_F1,
65
    TCG_REG_F2,
66
    TCG_REG_F3,
67
    TCG_REG_F4,
68
    TCG_REG_F5,
69
    TCG_REG_F6,
70
    TCG_REG_F7,
71
    TCG_REG_F8,
72
    TCG_REG_F9,
73
    TCG_REG_F10,
74
    TCG_REG_F11,
75
    TCG_REG_F12,
76
    TCG_REG_F13,
77
    TCG_REG_F14,
78
    TCG_REG_F15,
79
};
80

    
81
/* Predicate registers */
82
enum {
83
    TCG_REG_P0 = 0,
84
    TCG_REG_P1,
85
    TCG_REG_P2,
86
    TCG_REG_P3,
87
    TCG_REG_P4,
88
    TCG_REG_P5,
89
    TCG_REG_P6,
90
    TCG_REG_P7,
91
    TCG_REG_P8,
92
    TCG_REG_P9,
93
    TCG_REG_P10,
94
    TCG_REG_P11,
95
    TCG_REG_P12,
96
    TCG_REG_P13,
97
    TCG_REG_P14,
98
    TCG_REG_P15,
99
};
100

    
101
/* Application registers */
102
enum {
103
    TCG_REG_PFS = 64,
104
};
105

    
106
static const int tcg_target_reg_alloc_order[] = {
107
    TCG_REG_R34,
108
    TCG_REG_R35,
109
    TCG_REG_R36,
110
    TCG_REG_R37,
111
    TCG_REG_R38,
112
    TCG_REG_R39,
113
    TCG_REG_R40,
114
    TCG_REG_R41,
115
    TCG_REG_R42,
116
    TCG_REG_R43,
117
    TCG_REG_R44,
118
    TCG_REG_R45,
119
    TCG_REG_R46,
120
    TCG_REG_R47,
121
    TCG_REG_R48,
122
    TCG_REG_R49,
123
    TCG_REG_R50,
124
    TCG_REG_R51,
125
    TCG_REG_R52,
126
    TCG_REG_R53,
127
    TCG_REG_R54,
128
    TCG_REG_R55,
129
    TCG_REG_R14,
130
    TCG_REG_R15,
131
    TCG_REG_R16,
132
    TCG_REG_R17,
133
    TCG_REG_R18,
134
    TCG_REG_R19,
135
    TCG_REG_R20,
136
    TCG_REG_R21,
137
    TCG_REG_R22,
138
    TCG_REG_R23,
139
    TCG_REG_R24,
140
    TCG_REG_R25,
141
    TCG_REG_R26,
142
    TCG_REG_R27,
143
    TCG_REG_R28,
144
    TCG_REG_R29,
145
    TCG_REG_R30,
146
    TCG_REG_R31,
147
    TCG_REG_R56,
148
    TCG_REG_R57,
149
    TCG_REG_R58,
150
    TCG_REG_R59,
151
    TCG_REG_R60,
152
    TCG_REG_R61,
153
    TCG_REG_R62,
154
    TCG_REG_R63,
155
    TCG_REG_R8,
156
    TCG_REG_R9,
157
    TCG_REG_R10,
158
    TCG_REG_R11
159
};
160

    
161
static const int tcg_target_call_iarg_regs[8] = {
162
    TCG_REG_R56,
163
    TCG_REG_R57,
164
    TCG_REG_R58,
165
    TCG_REG_R59,
166
    TCG_REG_R60,
167
    TCG_REG_R61,
168
    TCG_REG_R62,
169
    TCG_REG_R63,
170
};
171

    
172
static const int tcg_target_call_oarg_regs[2] = {
173
    TCG_REG_R8,
174
    TCG_REG_R9
175
};
176

    
177
/* maximum number of register used for input function arguments */
178
static inline int tcg_target_get_call_iarg_regs_count(int flags)
179
{
180
    return 8;
181
}
182

    
183
/*
184
 * opcode formation
185
 */
186

    
187
/* bundle templates: stops (double bar in the IA64 manual) are marked with
188
   an uppercase letter. */
189
enum {
190
    mii = 0x00,
191
    miI = 0x01,
192
    mIi = 0x02,
193
    mII = 0x03,
194
    mlx = 0x04,
195
    mLX = 0x05,
196
    mmi = 0x08,
197
    mmI = 0x09,
198
    Mmi = 0x0a,
199
    MmI = 0x0b,
200
    mfi = 0x0c,
201
    mfI = 0x0d,
202
    mmf = 0x0e,
203
    mmF = 0x0f,
204
    mib = 0x10,
205
    miB = 0x11,
206
    mbb = 0x12,
207
    mbB = 0x13,
208
    bbb = 0x16,
209
    bbB = 0x17,
210
    mmb = 0x18,
211
    mmB = 0x19,
212
    mfb = 0x1c,
213
    mfB = 0x1d,
214
};
215

    
216
enum {
217
    OPC_ADD_A1                = 0x10000000000ull,
218
    OPC_AND_A1                = 0x10060000000ull,
219
    OPC_AND_A3                = 0x10160000000ull,
220
    OPC_ANDCM_A1              = 0x10068000000ull,
221
    OPC_ANDCM_A3              = 0x10168000000ull,
222
    OPC_ADDS_A4               = 0x10800000000ull,
223
    OPC_ADDL_A5               = 0x12000000000ull,
224
    OPC_ALLOC_M34             = 0x02c00000000ull,
225
    OPC_BR_DPTK_FEW_B1        = 0x08400000000ull,
226
    OPC_BR_SPTK_MANY_B1       = 0x08000001000ull,
227
    OPC_BR_SPTK_MANY_B4       = 0x00100001000ull,
228
    OPC_BR_CALL_SPTK_MANY_B5  = 0x02100001000ull,
229
    OPC_BR_RET_SPTK_MANY_B4   = 0x00108001100ull,
230
    OPC_BRL_SPTK_MANY_X3      = 0x18000001000ull,
231
    OPC_CMP_LT_A6             = 0x18000000000ull,
232
    OPC_CMP_LTU_A6            = 0x1a000000000ull,
233
    OPC_CMP_EQ_A6             = 0x1c000000000ull,
234
    OPC_CMP4_LT_A6            = 0x18400000000ull,
235
    OPC_CMP4_LTU_A6           = 0x1a400000000ull,
236
    OPC_CMP4_EQ_A6            = 0x1c400000000ull,
237
    OPC_DEP_Z_I12             = 0x0a600000000ull,
238
    OPC_EXTR_I11              = 0x0a400002000ull,
239
    OPC_EXTR_U_I11            = 0x0a400000000ull,
240
    OPC_FCVT_FX_TRUNC_S1_F10  = 0x004d0000000ull,
241
    OPC_FCVT_FXU_TRUNC_S1_F10 = 0x004d8000000ull,
242
    OPC_FCVT_XF_F11           = 0x000e0000000ull,
243
    OPC_FMA_S1_F1             = 0x10400000000ull,
244
    OPC_FNMA_S1_F1            = 0x18400000000ull,
245
    OPC_FRCPA_S1_F6           = 0x00600000000ull,
246
    OPC_GETF_SIG_M19          = 0x08708000000ull,
247
    OPC_LD1_M1                = 0x08000000000ull,
248
    OPC_LD1_M3                = 0x0a000000000ull,
249
    OPC_LD2_M1                = 0x08040000000ull,
250
    OPC_LD2_M3                = 0x0a040000000ull,
251
    OPC_LD4_M1                = 0x08080000000ull,
252
    OPC_LD4_M3                = 0x0a080000000ull,
253
    OPC_LD8_M1                = 0x080c0000000ull,
254
    OPC_LD8_M3                = 0x0a0c0000000ull,
255
    OPC_MUX1_I3               = 0x0eca0000000ull,
256
    OPC_NOP_B9                = 0x04008000000ull,
257
    OPC_NOP_F16               = 0x00008000000ull,
258
    OPC_NOP_I18               = 0x00008000000ull,
259
    OPC_NOP_M48               = 0x00008000000ull,
260
    OPC_MOV_I21               = 0x00e00100000ull,
261
    OPC_MOV_RET_I21           = 0x00e00500000ull,
262
    OPC_MOV_I22               = 0x00188000000ull,
263
    OPC_MOV_I_I26             = 0x00150000000ull,
264
    OPC_MOVL_X2               = 0x0c000000000ull,
265
    OPC_OR_A1                 = 0x10070000000ull,
266
    OPC_SETF_EXP_M18          = 0x0c748000000ull,
267
    OPC_SETF_SIG_M18          = 0x0c708000000ull,
268
    OPC_SHL_I7                = 0x0f240000000ull,
269
    OPC_SHR_I5                = 0x0f220000000ull,
270
    OPC_SHR_U_I5              = 0x0f200000000ull,
271
    OPC_SHRP_I10              = 0x0ac00000000ull,
272
    OPC_SXT1_I29              = 0x000a0000000ull,
273
    OPC_SXT2_I29              = 0x000a8000000ull,
274
    OPC_SXT4_I29              = 0x000b0000000ull,
275
    OPC_ST1_M4                = 0x08c00000000ull,
276
    OPC_ST2_M4                = 0x08c40000000ull,
277
    OPC_ST4_M4                = 0x08c80000000ull,
278
    OPC_ST8_M4                = 0x08cc0000000ull,
279
    OPC_SUB_A1                = 0x10028000000ull,
280
    OPC_SUB_A3                = 0x10128000000ull,
281
    OPC_UNPACK4_L_I2          = 0x0f860000000ull,
282
    OPC_XMA_L_F2              = 0x1d000000000ull,
283
    OPC_XOR_A1                = 0x10078000000ull,
284
    OPC_ZXT1_I29              = 0x00080000000ull,
285
    OPC_ZXT2_I29              = 0x00088000000ull,
286
    OPC_ZXT4_I29              = 0x00090000000ull,
287
};
288

    
289
static inline uint64_t tcg_opc_a1(int qp, uint64_t opc, int r1,
290
                                  int r2, int r3)
291
{
292
    return opc
293
           | ((r3 & 0x7f) << 20)
294
           | ((r2 & 0x7f) << 13)
295
           | ((r1 & 0x7f) << 6)
296
           | (qp & 0x3f);
297
}
298

    
299
static inline uint64_t tcg_opc_a3(int qp, uint64_t opc, int r1,
300
                                  uint64_t imm, int r3)
301
{
302
    return opc
303
           | ((imm & 0x80) << 29) /* s */
304
           | ((imm & 0x7f) << 13) /* imm7b */
305
           | ((r3 & 0x7f) << 20)
306
           | ((r1 & 0x7f) << 6)
307
           | (qp & 0x3f);
308
}
309

    
310
static inline uint64_t tcg_opc_a4(int qp, uint64_t opc, int r1,
311
                                  uint64_t imm, int r3)
312
{
313
    return opc
314
           | ((imm & 0x2000) << 23) /* s */
315
           | ((imm & 0x1f80) << 20) /* imm6d */
316
           | ((imm & 0x007f) << 13) /* imm7b */
317
           | ((r3 & 0x7f) << 20)
318
           | ((r1 & 0x7f) << 6)
319
           | (qp & 0x3f);
320
}
321

    
322
static inline uint64_t tcg_opc_a5(int qp, uint64_t opc, int r1,
323
                                  uint64_t imm, int r3)
324
{
325
    return opc
326
           | ((imm & 0x200000) << 15) /* s */
327
           | ((imm & 0x1f0000) <<  6) /* imm5c */
328
           | ((imm & 0x00ff80) << 20) /* imm9d */
329
           | ((imm & 0x00007f) << 13) /* imm7b */
330
           | ((r3 & 0x03) << 20)
331
           | ((r1 & 0x7f) << 6)
332
           | (qp & 0x3f);
333
}
334

    
335
static inline uint64_t tcg_opc_a6(int qp, uint64_t opc, int p1,
336
                                  int p2, int r2, int r3)
337
{
338
    return opc
339
           | ((p2 & 0x3f) << 27)
340
           | ((r3 & 0x7f) << 20)
341
           | ((r2 & 0x7f) << 13)
342
           | ((p1 & 0x3f) << 6)
343
           | (qp & 0x3f);
344
}
345

    
346
static inline uint64_t tcg_opc_b1(int qp, uint64_t opc, uint64_t imm)
347
{
348
    return opc
349
           | ((imm & 0x100000) << 16) /* s */
350
           | ((imm & 0x0fffff) << 13) /* imm20b */
351
           | (qp & 0x3f);
352
}
353

    
354
static inline uint64_t tcg_opc_b4(int qp, uint64_t opc, int b2)
355
{
356
    return opc
357
           | ((b2 & 0x7) << 13)
358
           | (qp & 0x3f);
359
}
360

    
361
static inline uint64_t tcg_opc_b5(int qp, uint64_t opc, int b1, int b2)
362
{
363
    return opc
364
           | ((b2 & 0x7) << 13)
365
           | ((b1 & 0x7) << 6)
366
           | (qp & 0x3f);
367
}
368

    
369

    
370
static inline uint64_t tcg_opc_b9(int qp, uint64_t opc, uint64_t imm)
371
{
372
    return opc
373
           | ((imm & 0x100000) << 16) /* i */
374
           | ((imm & 0x0fffff) << 6)  /* imm20a */
375
           | (qp & 0x3f);
376
}
377

    
378
static inline uint64_t tcg_opc_f1(int qp, uint64_t opc, int f1,
379
                                  int f3, int f4, int f2)
380
{
381
    return opc
382
           | ((f4 & 0x7f) << 27)
383
           | ((f3 & 0x7f) << 20)
384
           | ((f2 & 0x7f) << 13)
385
           | ((f1 & 0x7f) << 6)
386
           | (qp & 0x3f);
387
}
388

    
389
static inline uint64_t tcg_opc_f2(int qp, uint64_t opc, int f1,
390
                                  int f3, int f4, int f2)
391
{
392
    return opc
393
           | ((f4 & 0x7f) << 27)
394
           | ((f3 & 0x7f) << 20)
395
           | ((f2 & 0x7f) << 13)
396
           | ((f1 & 0x7f) << 6)
397
           | (qp & 0x3f);
398
}
399

    
400
static inline uint64_t tcg_opc_f6(int qp, uint64_t opc, int f1,
401
                                  int p2, int f2, int f3)
402
{
403
    return opc
404
           | ((p2 & 0x3f) << 27)
405
           | ((f3 & 0x7f) << 20)
406
           | ((f2 & 0x7f) << 13)
407
           | ((f1 & 0x7f) << 6)
408
           | (qp & 0x3f);
409
}
410

    
411
static inline uint64_t tcg_opc_f10(int qp, uint64_t opc, int f1, int f2)
412
{
413
    return opc
414
           | ((f2 & 0x7f) << 13)
415
           | ((f1 & 0x7f) << 6)
416
           | (qp & 0x3f);
417
}
418

    
419
static inline uint64_t tcg_opc_f11(int qp, uint64_t opc, int f1, int f2)
420
{
421
    return opc
422
           | ((f2 & 0x7f) << 13)
423
           | ((f1 & 0x7f) << 6)
424
           | (qp & 0x3f);
425
}
426

    
427
static inline uint64_t tcg_opc_f16(int qp, uint64_t opc, uint64_t imm)
428
{
429
    return opc
430
           | ((imm & 0x100000) << 16) /* i */
431
           | ((imm & 0x0fffff) << 6)  /* imm20a */
432
           | (qp & 0x3f);
433
}
434

    
435
static inline uint64_t tcg_opc_i2(int qp, uint64_t opc, int r1,
436
                                  int r2, int r3)
437
{
438
    return opc
439
           | ((r3 & 0x7f) << 20)
440
           | ((r2 & 0x7f) << 13)
441
           | ((r1 & 0x7f) << 6)
442
           | (qp & 0x3f);
443
}
444

    
445
static inline uint64_t tcg_opc_i3(int qp, uint64_t opc, int r1,
446
                                  int r2, int mbtype)
447
{
448
    return opc
449
           | ((mbtype & 0x0f) << 20)
450
           | ((r2 & 0x7f) << 13)
451
           | ((r1 & 0x7f) << 6)
452
           | (qp & 0x3f);
453
}
454

    
455
static inline uint64_t tcg_opc_i5(int qp, uint64_t opc, int r1,
456
                                  int r3, int r2)
457
{
458
    return opc
459
           | ((r3 & 0x7f) << 20)
460
           | ((r2 & 0x7f) << 13)
461
           | ((r1 & 0x7f) << 6)
462
           | (qp & 0x3f);
463
}
464

    
465
static inline uint64_t tcg_opc_i7(int qp, uint64_t opc, int r1,
466
                                  int r2, int r3)
467
{
468
    return opc
469
           | ((r3 & 0x7f) << 20)
470
           | ((r2 & 0x7f) << 13)
471
           | ((r1 & 0x7f) << 6)
472
           | (qp & 0x3f);
473
}
474

    
475
static inline uint64_t tcg_opc_i10(int qp, uint64_t opc, int r1,
476
                                   int r2, int r3, uint64_t count)
477
{
478
    return opc
479
           | ((count & 0x3f) << 27)
480
           | ((r3 & 0x7f) << 20)
481
           | ((r2 & 0x7f) << 13)
482
           | ((r1 & 0x7f) << 6)
483
           | (qp & 0x3f);
484
}
485

    
486
static inline uint64_t tcg_opc_i11(int qp, uint64_t opc, int r1,
487
                                   int r3, uint64_t pos, uint64_t len)
488
{
489
    return opc
490
           | ((len & 0x3f) << 27)
491
           | ((r3 & 0x7f) << 20)
492
           | ((pos & 0x3f) << 14)
493
           | ((r1 & 0x7f) << 6)
494
           | (qp & 0x3f);
495
}
496

    
497
static inline uint64_t tcg_opc_i12(int qp, uint64_t opc, int r1,
498
                                   int r2, uint64_t pos, uint64_t len)
499
{
500
    return opc
501
           | ((len & 0x3f) << 27)
502
           | ((pos & 0x3f) << 20)
503
           | ((r2 & 0x7f) << 13)
504
           | ((r1 & 0x7f) << 6)
505
           | (qp & 0x3f);
506
}
507

    
508
static inline uint64_t tcg_opc_i18(int qp, uint64_t opc, uint64_t imm)
509
{
510
    return opc
511
           | ((imm & 0x100000) << 16) /* i */
512
           | ((imm & 0x0fffff) << 6)  /* imm20a */
513
           | (qp & 0x3f);
514
}
515

    
516
static inline uint64_t tcg_opc_i21(int qp, uint64_t opc, int b1,
517
                                   int r2, uint64_t imm)
518
{
519
    return opc
520
           | ((imm & 0x1ff) << 24)
521
           | ((r2 & 0x7f) << 13)
522
           | ((b1 & 0x7) << 6)
523
           | (qp & 0x3f);
524
}
525

    
526
static inline uint64_t tcg_opc_i22(int qp, uint64_t opc, int r1, int b2)
527
{
528
    return opc
529
           | ((b2 & 0x7) << 13)
530
           | ((r1 & 0x7f) << 6)
531
           | (qp & 0x3f);
532
}
533

    
534
static inline uint64_t tcg_opc_i26(int qp, uint64_t opc, int ar3, int r2)
535
{
536
    return opc
537
           | ((ar3 & 0x7f) << 20)
538
           | ((r2 & 0x7f) << 13)
539
           | (qp & 0x3f);
540
}
541

    
542
static inline uint64_t tcg_opc_i29(int qp, uint64_t opc, int r1, int r3)
543
{
544
    return opc
545
           | ((r3 & 0x7f) << 20)
546
           | ((r1 & 0x7f) << 6)
547
           | (qp & 0x3f);
548
}
549

    
550
static inline uint64_t tcg_opc_l2(uint64_t imm)
551
{
552
    return (imm & 0x7fffffffffc00000ull) >> 22;
553
}
554

    
555
static inline uint64_t tcg_opc_l3(uint64_t imm)
556
{
557
    return (imm & 0x07fffffffff00000ull) >> 18;
558
}
559

    
560
static inline uint64_t tcg_opc_m1(int qp, uint64_t opc, int r1, int r3)
561
{
562
    return opc
563
           | ((r3 & 0x7f) << 20)
564
           | ((r1 & 0x7f) << 6)
565
           | (qp & 0x3f);
566
}
567

    
568
static inline uint64_t tcg_opc_m3(int qp, uint64_t opc, int r1,
569
                                  int r3, uint64_t imm)
570
{
571
    return opc
572
           | ((imm & 0x100) << 28) /* s */
573
           | ((imm & 0x080) << 20) /* i */
574
           | ((imm & 0x07f) << 13) /* imm7b */
575
           | ((r3 & 0x7f) << 20)
576
           | ((r1 & 0x7f) << 6)
577
           | (qp & 0x3f);
578
}
579

    
580
static inline uint64_t tcg_opc_m4(int qp, uint64_t opc, int r2, int r3)
581
{
582
    return opc
583
           | ((r3 & 0x7f) << 20)
584
           | ((r2 & 0x7f) << 13)
585
           | (qp & 0x3f);
586
}
587

    
588
static inline uint64_t tcg_opc_m18(int qp, uint64_t opc, int f1, int r2)
589
{
590
    return opc
591
           | ((r2 & 0x7f) << 13)
592
           | ((f1 & 0x7f) << 6)
593
           | (qp & 0x3f);
594
}
595

    
596
static inline uint64_t tcg_opc_m19(int qp, uint64_t opc, int r1, int f2)
597
{
598
    return opc
599
           | ((f2 & 0x7f) << 13)
600
           | ((r1 & 0x7f) << 6)
601
           | (qp & 0x3f);
602
}
603

    
604
static inline uint64_t tcg_opc_m34(int qp, uint64_t opc, int r1,
605
                                   int sof, int sol, int sor)
606
{
607
    return opc
608
           | ((sor & 0x0f) << 27)
609
           | ((sol & 0x7f) << 20)
610
           | ((sof & 0x7f) << 13)
611
           | ((r1 & 0x7f) << 6)
612
           | (qp & 0x3f);
613
}
614

    
615
static inline uint64_t tcg_opc_m48(int qp, uint64_t opc, uint64_t imm)
616
{
617
    return opc
618
           | ((imm & 0x100000) << 16) /* i */
619
           | ((imm & 0x0fffff) << 6)  /* imm20a */
620
           | (qp & 0x3f);
621
}
622

    
623
static inline uint64_t tcg_opc_x2(int qp, uint64_t opc,
624
                                  int r1, uint64_t imm)
625
{
626
    return opc
627
           | ((imm & 0x8000000000000000ull) >> 27) /* i */
628
           |  (imm & 0x0000000000200000ull)        /* ic */
629
           | ((imm & 0x00000000001f0000ull) << 6)  /* imm5c */
630
           | ((imm & 0x000000000000ff80ull) << 20) /* imm9d */
631
           | ((imm & 0x000000000000007full) << 13) /* imm7b */
632
           | ((r1 & 0x7f) << 6)
633
           | (qp & 0x3f);
634
}
635

    
636
static inline uint64_t tcg_opc_x3(int qp, uint64_t opc, uint64_t imm)
637
{
638
    return opc
639
           | ((imm & 0x0800000000000000ull) >> 23) /* i */
640
           | ((imm & 0x00000000000fffffull) << 13) /* imm20b */
641
           | (qp & 0x3f);
642
}
643

    
644

    
645
/*
646
 * Relocations
647
 */
648

    
649
static inline void reloc_pcrel21b (void *pc, tcg_target_long target)
650
{
651
    uint64_t imm;
652
    int64_t disp;
653
    int slot;
654

    
655
    slot = (tcg_target_long) pc & 3;
656
    pc = (void *)((tcg_target_long) pc & ~3);
657

    
658
    disp = target - (tcg_target_long) pc;
659
    imm = (uint64_t) disp >> 4;
660

    
661
    switch(slot) {
662
    case 0:
663
        *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 8) & 0xfffffdc00003ffffull)
664
                                | ((imm & 0x100000) << 21)  /* s */
665
                                | ((imm & 0x0fffff) << 18); /* imm20b */
666
        break;
667
    case 1:
668
        *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xfffffffffffb8000ull)
669
                                | ((imm & 0x100000) >> 2)   /* s */
670
                                | ((imm & 0x0fffe0) >> 5);  /* imm20b */
671
        *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 0) & 0x07ffffffffffffffull)
672
                                | ((imm & 0x00001f) << 59); /* imm20b */
673
        break;
674
    case 2:
675
        *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xf700000fffffffffull)
676
                                | ((imm & 0x100000) << 39)  /* s */
677
                                | ((imm & 0x0fffff) << 36); /* imm20b */
678
        break;
679
    }
680
}
681

    
682
static inline uint64_t get_reloc_pcrel21b (void *pc)
683
{
684
    int64_t low, high;
685
    int slot;
686

    
687
    slot = (tcg_target_long) pc & 3;
688
    pc = (void *)((tcg_target_long) pc & ~3);
689

    
690
    low  = (*(uint64_t *)(pc + 0));
691
    high = (*(uint64_t *)(pc + 8));
692

    
693
    switch(slot) {
694
    case 0:
695
        return ((low >> 21) & 0x100000) + /* s */
696
               ((low >> 18) & 0x0fffff);  /* imm20b */
697
    case 1:
698
        return ((high << 2) & 0x100000) + /* s */
699
               ((high << 5) & 0x0fffe0) + /* imm20b */
700
               ((low >> 59) & 0x00001f);  /* imm20b */
701
    case 2:
702
        return ((high >> 39) & 0x100000) + /* s */
703
               ((high >> 36) & 0x0fffff);  /* imm20b */
704
    default:
705
        tcg_abort();
706
    }
707
}
708

    
709
static inline void reloc_pcrel60b (void *pc, tcg_target_long target)
710
{
711
    int64_t disp;
712
    uint64_t imm;
713

    
714
    disp = target - (tcg_target_long) pc;
715
    imm = (uint64_t) disp >> 4;
716

    
717
    *(uint64_t *)(pc + 8) = (*(uint64_t *)(pc + 8) & 0xf700000fff800000ull)
718
                             |  (imm & 0x0800000000000000ull)         /* s */
719
                             | ((imm & 0x07fffff000000000ull) >> 36)  /* imm39 */
720
                             | ((imm & 0x00000000000fffffull) << 36); /* imm20b */
721
    *(uint64_t *)(pc + 0) = (*(uint64_t *)(pc + 0) & 0x00003fffffffffffull)
722
                             | ((imm & 0x0000000ffff00000ull) << 28); /* imm39 */
723
}
724

    
725
static inline uint64_t get_reloc_pcrel60b (void *pc)
726
{
727
    int64_t low, high;
728

    
729
    low  = (*(uint64_t *)(pc + 0));
730
    high = (*(uint64_t *)(pc + 8));
731

    
732
    return ((high)       & 0x0800000000000000ull) + /* s */
733
           ((high >> 36) & 0x00000000000fffffull) + /* imm20b */
734
           ((high << 36) & 0x07fffff000000000ull) + /* imm39 */
735
           ((low >> 28)  & 0x0000000ffff00000ull);  /* imm39 */
736
}
737

    
738

    
739
static void patch_reloc(uint8_t *code_ptr, int type,
740
                        tcg_target_long value, tcg_target_long addend)
741
{
742
    value += addend;
743
    switch (type) {
744
    case R_IA64_PCREL21B:
745
        reloc_pcrel21b(code_ptr, value);
746
        break;
747
    case R_IA64_PCREL60B:
748
        reloc_pcrel60b(code_ptr, value);
749
    default:
750
        tcg_abort();
751
    }
752
}
753

    
754
/*
755
 * Constraints
756
 */
757

    
758
/* parse target specific constraints */
759
static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
760
{
761
    const char *ct_str;
762

    
763
    ct_str = *pct_str;
764
    switch(ct_str[0]) {
765
    case 'r':
766
        ct->ct |= TCG_CT_REG;
767
        tcg_regset_set(ct->u.regs, 0xffffffffffffffffull);
768
        break;
769
    case 'I':
770
        ct->ct |= TCG_CT_CONST_S22;
771
        break;
772
    case 'S':
773
        ct->ct |= TCG_CT_REG;
774
        tcg_regset_set(ct->u.regs, 0xffffffffffffffffull);
775
#if defined(CONFIG_SOFTMMU)
776
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_R56);
777
        tcg_regset_reset_reg(ct->u.regs, TCG_REG_R57);
778
#endif
779
        break;
780
    case 'Z':
781
        /* We are cheating a bit here, using the fact that the register
782
           r0 is also the register number 0. Hence there is no need
783
           to check for const_args in each instruction. */
784
        ct->ct |= TCG_CT_CONST_ZERO;
785
        break;
786
    default:
787
        return -1;
788
    }
789
    ct_str++;
790
    *pct_str = ct_str;
791
    return 0;
792
}
793

    
794
/* test if a constant matches the constraint */
795
static inline int tcg_target_const_match(tcg_target_long val,
796
                                         const TCGArgConstraint *arg_ct)
797
{
798
    int ct;
799
    ct = arg_ct->ct;
800
    if (ct & TCG_CT_CONST)
801
        return 1;
802
    else if ((ct & TCG_CT_CONST_ZERO) && val == 0)
803
        return 1;
804
    else if ((ct & TCG_CT_CONST_S22) && val == ((int32_t)val << 10) >> 10)
805
        return 1;
806
    else
807
        return 0;
808
}
809

    
810
/*
811
 * Code generation
812
 */
813

    
814
static uint8_t *tb_ret_addr;
815

    
816
static inline void tcg_out_bundle(TCGContext *s, int template,
817
                                  uint64_t slot0, uint64_t slot1,
818
                                  uint64_t slot2)
819
{
820
    template &= 0x1f;          /* 5 bits */
821
    slot0 &= 0x1ffffffffffull; /* 41 bits */
822
    slot1 &= 0x1ffffffffffull; /* 41 bits */
823
    slot2 &= 0x1ffffffffffull; /* 41 bits */
824

    
825
    *(uint64_t *)(s->code_ptr + 0) = (slot1 << 46) | (slot0 << 5) | template;
826
    *(uint64_t *)(s->code_ptr + 8) = (slot2 << 23) | (slot1 >> 18);
827
    s->code_ptr += 16;
828
}
829

    
830
static inline void tcg_out_mov(TCGContext *s, TCGArg ret, TCGArg arg)
831
{
832
    tcg_out_bundle(s, mmI,
833
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
834
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
835
                   tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, ret, 0, arg));
836
}
837

    
838
static inline void tcg_out_movi(TCGContext *s, TCGType type,
839
                                TCGArg reg, tcg_target_long arg)
840
{
841
    tcg_out_bundle(s, mLX,
842
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
843
                   tcg_opc_l2 (arg),
844
                   tcg_opc_x2 (TCG_REG_P0, OPC_MOVL_X2, reg, arg));
845
}
846

    
847
static inline void tcg_out_addi(TCGContext *s, TCGArg reg, tcg_target_long val)
848
{
849
    if (val == ((int32_t)val << 10) >> 10) {
850
        tcg_out_bundle(s, MmI,
851
                       tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5,
852
                                  TCG_REG_R2, val, TCG_REG_R0),
853
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
854
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, reg,
855
                                   reg, TCG_REG_R2));
856
    } else {
857
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, val);
858
        tcg_out_bundle(s, mmI,
859
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
860
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
861
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, reg,
862
                                   reg, TCG_REG_R2));
863
    }
864
}
865

    
866
static void tcg_out_br(TCGContext *s, int label_index)
867
{
868
    TCGLabel *l = &s->labels[label_index];
869

    
870
    tcg_out_bundle(s, mmB,
871
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
872
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
873
                   tcg_opc_b1 (TCG_REG_P0, OPC_BR_SPTK_MANY_B1,
874
                               get_reloc_pcrel21b(s->code_ptr + 2)));
875

    
876
    if (l->has_value) {
877
        reloc_pcrel21b((s->code_ptr - 16) + 2, l->u.value);
878
    } else {
879
        tcg_out_reloc(s, (s->code_ptr - 16) + 2,
880
                      R_IA64_PCREL21B, label_index, 0);
881
    }
882
}
883

    
884
static inline void tcg_out_call(TCGContext *s, TCGArg addr)
885
{
886
    tcg_out_bundle(s, MmI,
887
                   tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1, TCG_REG_R2, addr),
888
                   tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4, TCG_REG_R3, 8, addr),
889
                   tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21,
890
                               TCG_REG_B6, TCG_REG_R2, 0));
891
    tcg_out_bundle(s, mmB,
892
                   tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R3),
893
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
894
                   tcg_opc_b5 (TCG_REG_P0, OPC_BR_CALL_SPTK_MANY_B5,
895
                               TCG_REG_B0, TCG_REG_B6));
896
}
897

    
898
static void tcg_out_exit_tb(TCGContext *s, tcg_target_long arg)
899
{
900
    int64_t disp;
901
    uint64_t imm;
902

    
903
    tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R8, arg);
904

    
905
    disp = tb_ret_addr - s->code_ptr;
906
    imm = (uint64_t)disp >> 4;
907

    
908
    tcg_out_bundle(s, mLX,
909
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
910
                   tcg_opc_l3 (imm),
911
                   tcg_opc_x3 (TCG_REG_P0, OPC_BRL_SPTK_MANY_X3, imm));
912
}
913

    
914
static inline void tcg_out_goto_tb(TCGContext *s, TCGArg arg)
915
{
916
    if (s->tb_jmp_offset) {
917
        /* direct jump method */
918
        tcg_abort();
919
    } else {
920
        /* indirect jump method */
921
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2,
922
                     (tcg_target_long)(s->tb_next + arg));
923
        tcg_out_bundle(s, MmI,
924
                       tcg_opc_m1 (TCG_REG_P0, OPC_LD8_M1,
925
                                   TCG_REG_R2, TCG_REG_R2),
926
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
927
                       tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, TCG_REG_B6,
928
                                   TCG_REG_R2, 0));
929
        tcg_out_bundle(s, mmB,
930
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
931
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
932
                       tcg_opc_b4 (TCG_REG_P0, OPC_BR_SPTK_MANY_B4,
933
                                   TCG_REG_B6));
934
    }
935
    s->tb_next_offset[arg] = s->code_ptr - s->code_buf;
936
}
937

    
938
static inline void tcg_out_jmp(TCGContext *s, TCGArg addr)
939
{
940
    tcg_out_bundle(s, mmI,
941
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
942
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
943
                   tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21, TCG_REG_B6, addr, 0));
944
    tcg_out_bundle(s, mmB,
945
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
946
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
947
                   tcg_opc_b4(TCG_REG_P0, OPC_BR_SPTK_MANY_B4, TCG_REG_B6));
948
}
949

    
950
static inline void tcg_out_ld_rel(TCGContext *s, uint64_t opc_m4, TCGArg arg,
951
                                  TCGArg arg1, tcg_target_long arg2)
952
{
953
    if (arg2 == ((int16_t)arg2 >> 2) << 2) {
954
        tcg_out_bundle(s, MmI,
955
                       tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4,
956
                                  TCG_REG_R2, arg2, arg1),
957
                       tcg_opc_m1 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2),
958
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
959
    } else {
960
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, arg2);
961
        tcg_out_bundle(s, MmI,
962
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1,
963
                                   TCG_REG_R2, TCG_REG_R2, arg1),
964
                       tcg_opc_m1 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2),
965
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
966
    }
967
}
968

    
969
static inline void tcg_out_st_rel(TCGContext *s, uint64_t opc_m4, TCGArg arg,
970
                                  TCGArg arg1, tcg_target_long arg2)
971
{
972
    if (arg2 == ((int16_t)arg2 >> 2) << 2) {
973
        tcg_out_bundle(s, MmI,
974
                       tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4,
975
                                  TCG_REG_R2, arg2, arg1),
976
                       tcg_opc_m4 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2),
977
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
978
    } else {
979
        tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R2, arg2);
980
        tcg_out_bundle(s, MmI,
981
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1,
982
                                   TCG_REG_R2, TCG_REG_R2, arg1),
983
                       tcg_opc_m4 (TCG_REG_P0, opc_m4, arg, TCG_REG_R2),
984
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
985
    }
986
}
987

    
988
static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGArg arg,
989
                              TCGArg arg1, tcg_target_long arg2)
990
{
991
    if (type == TCG_TYPE_I32) {
992
        tcg_out_ld_rel(s, OPC_LD4_M1, arg, arg1, arg2);
993
    } else {
994
        tcg_out_ld_rel(s, OPC_LD8_M1, arg, arg1, arg2);
995
    }
996
}
997

    
998
static inline void tcg_out_st(TCGContext *s, TCGType type, TCGArg arg,
999
                              TCGArg arg1, tcg_target_long arg2)
1000
{
1001
    if (type == TCG_TYPE_I32) {
1002
        tcg_out_st_rel(s, OPC_ST4_M4, arg, arg1, arg2);
1003
    } else {
1004
        tcg_out_st_rel(s, OPC_ST8_M4, arg, arg1, arg2);
1005
    }
1006
}
1007

    
1008
static inline void tcg_out_alu(TCGContext *s, uint64_t opc_a1, TCGArg ret,
1009
                               TCGArg arg1, int const_arg1,
1010
                               TCGArg arg2, int const_arg2)
1011
{
1012
    uint64_t opc1, opc2;
1013

    
1014
    if (const_arg1 && arg1 != 0) {
1015
        opc1 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5,
1016
                          TCG_REG_R2, arg1, TCG_REG_R0);
1017
        arg1 = TCG_REG_R2;
1018
    } else {
1019
        opc1 = tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0);
1020
    }
1021

    
1022
    if (const_arg2 && arg2 != 0) {
1023
        opc2 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5,
1024
                          TCG_REG_R3, arg2, TCG_REG_R0);
1025
        arg2 = TCG_REG_R3;
1026
    } else {
1027
        opc2 = tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0);
1028
    }
1029

    
1030
    tcg_out_bundle(s, mII,
1031
                   opc1,
1032
                   opc2,
1033
                   tcg_opc_a1(TCG_REG_P0, opc_a1, ret, arg1, arg2));
1034
}
1035

    
1036
static inline void tcg_out_eqv(TCGContext *s, TCGArg ret,
1037
                               TCGArg arg1, int const_arg1,
1038
                               TCGArg arg2, int const_arg2)
1039
{
1040
    tcg_out_bundle(s, mII,
1041
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1042
                   tcg_opc_a1 (TCG_REG_P0, OPC_XOR_A1, ret, arg1, arg2),
1043
                   tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret));
1044
}
1045

    
1046
static inline void tcg_out_nand(TCGContext *s, TCGArg ret,
1047
                                TCGArg arg1, int const_arg1,
1048
                                TCGArg arg2, int const_arg2)
1049
{
1050
    tcg_out_bundle(s, mII,
1051
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1052
                   tcg_opc_a1 (TCG_REG_P0, OPC_AND_A1, ret, arg1, arg2),
1053
                   tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret));
1054
}
1055

    
1056
static inline void tcg_out_nor(TCGContext *s, TCGArg ret,
1057
                               TCGArg arg1, int const_arg1,
1058
                               TCGArg arg2, int const_arg2)
1059
{
1060
    tcg_out_bundle(s, mII,
1061
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1062
                   tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, arg1, arg2),
1063
                   tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, ret, -1, ret));
1064
}
1065

    
1066
static inline void tcg_out_orc(TCGContext *s, TCGArg ret,
1067
                               TCGArg arg1, int const_arg1,
1068
                               TCGArg arg2, int const_arg2)
1069
{
1070
    tcg_out_bundle(s, mII,
1071
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1072
                   tcg_opc_a3 (TCG_REG_P0, OPC_ANDCM_A3, TCG_REG_R2, -1, arg2),
1073
                   tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret, arg1, TCG_REG_R2));
1074
}
1075

    
1076
static inline void tcg_out_mul(TCGContext *s, TCGArg ret,
1077
                               TCGArg arg1, TCGArg arg2)
1078
{
1079
    tcg_out_bundle(s, mmI,
1080
                   tcg_opc_m18(TCG_REG_P0, OPC_SETF_SIG_M18, TCG_REG_F6, arg1),
1081
                   tcg_opc_m18(TCG_REG_P0, OPC_SETF_SIG_M18, TCG_REG_F7, arg2),
1082
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1083
    tcg_out_bundle(s, mmF,
1084
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1085
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1086
                   tcg_opc_f2 (TCG_REG_P0, OPC_XMA_L_F2, TCG_REG_F6, TCG_REG_F6,
1087
                               TCG_REG_F7, TCG_REG_F0));
1088
    tcg_out_bundle(s, miI,
1089
                   tcg_opc_m19(TCG_REG_P0, OPC_GETF_SIG_M19, ret, TCG_REG_F6),
1090
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1091
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1092
}
1093

    
1094
static inline void tcg_out_sar_i32(TCGContext *s, TCGArg ret, TCGArg arg1,
1095
                                   TCGArg arg2, int const_arg2)
1096
{
1097
    if (const_arg2) {
1098
        tcg_out_bundle(s, miI,
1099
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1100
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1101
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_I11,
1102
                                   ret, arg1, arg2, 31 - arg2));
1103
    } else {
1104
        tcg_out_bundle(s, mII,
1105
                       tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3,
1106
                                   TCG_REG_R3, 0x1f, arg2),
1107
                       tcg_opc_i29(TCG_REG_P0, OPC_SXT4_I29, TCG_REG_R2, arg1),
1108
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_I5, ret,
1109
                                   TCG_REG_R2, TCG_REG_R3));
1110
    }
1111
}
1112

    
1113
static inline void tcg_out_sar_i64(TCGContext *s, TCGArg ret, TCGArg arg1,
1114
                                   TCGArg arg2, int const_arg2)
1115
{
1116
    if (const_arg2) {
1117
        tcg_out_bundle(s, miI,
1118
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1119
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1120
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_I11,
1121
                                   ret, arg1, arg2, 63 - arg2));
1122
    } else {
1123
        tcg_out_bundle(s, miI,
1124
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1125
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1126
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_I5, ret, arg1, arg2));
1127
    }
1128
}
1129

    
1130
static inline void tcg_out_shl_i32(TCGContext *s, TCGArg ret, TCGArg arg1,
1131
                                   TCGArg arg2, int const_arg2)
1132
{
1133
    if (const_arg2) {
1134
        tcg_out_bundle(s, miI,
1135
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1136
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1137
                       tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret,
1138
                                   arg1, 63 - arg2, 31 - arg2));
1139
    } else {
1140
        tcg_out_bundle(s, mII,
1141
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1142
                       tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R2,
1143
                                   0x1f, arg2),
1144
                       tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, ret,
1145
                                   arg1, TCG_REG_R2));
1146
    }
1147
}
1148

    
1149
static inline void tcg_out_shl_i64(TCGContext *s, TCGArg ret, TCGArg arg1,
1150
                                   TCGArg arg2, int const_arg2)
1151
{
1152
    if (const_arg2) {
1153
        tcg_out_bundle(s, miI,
1154
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1155
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1156
                       tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret,
1157
                                   arg1, 63 - arg2, 63 - arg2));
1158
    } else {
1159
        tcg_out_bundle(s, miI,
1160
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1161
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1162
                       tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, ret,
1163
                                   arg1, arg2));
1164
    }
1165
}
1166

    
1167
static inline void tcg_out_shr_i32(TCGContext *s, TCGArg ret, TCGArg arg1,
1168
                                   TCGArg arg2, int const_arg2)
1169
{
1170
    if (const_arg2) {
1171
        tcg_out_bundle(s, miI,
1172
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1173
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1174
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret,
1175
                                   arg1, arg2, 31 - arg2));
1176
    } else {
1177
        tcg_out_bundle(s, mII,
1178
                       tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3,
1179
                                   0x1f, arg2),
1180
                       tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, TCG_REG_R2, arg1),
1181
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret,
1182
                                   TCG_REG_R2, TCG_REG_R3));
1183
    }
1184
}
1185

    
1186
static inline void tcg_out_shr_i64(TCGContext *s, TCGArg ret, TCGArg arg1,
1187
                                   TCGArg arg2, int const_arg2)
1188
{
1189
    if (const_arg2) {
1190
        tcg_out_bundle(s, miI,
1191
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1192
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1193
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret,
1194
                                   arg1, arg2, 63 - arg2));
1195
    } else {
1196
        tcg_out_bundle(s, miI,
1197
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1198
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1199
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret,
1200
                                   arg1, arg2));
1201
    }
1202
}
1203

    
1204
static inline void tcg_out_rotl_i32(TCGContext *s, TCGArg ret, TCGArg arg1,
1205
                                    TCGArg arg2, int const_arg2)
1206
{
1207
    if (const_arg2) {
1208
        tcg_out_bundle(s, mII,
1209
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1210
                       tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2,
1211
                                   TCG_REG_R2, arg1, arg1),
1212
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret,
1213
                                   TCG_REG_R2, 32 - arg2, 31));
1214
    } else {
1215
        tcg_out_bundle(s, miI,
1216
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1217
                       tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2,
1218
                                   TCG_REG_R2, arg1, arg1),
1219
                       tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3,
1220
                                   0x1f, arg2));
1221
        tcg_out_bundle(s, mII,
1222
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1223
                       tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R3,
1224
                                   0x20, TCG_REG_R3),
1225
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret,
1226
                                   TCG_REG_R2, TCG_REG_R3));
1227
    }
1228
}
1229

    
1230
static inline void tcg_out_rotl_i64(TCGContext *s, TCGArg ret, TCGArg arg1,
1231
                                    TCGArg arg2, int const_arg2)
1232
{
1233
    if (const_arg2) {
1234
        tcg_out_bundle(s, miI,
1235
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1236
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1237
                       tcg_opc_i10(TCG_REG_P0, OPC_SHRP_I10, ret, arg1,
1238
                                   arg1, 0x40 - arg2));
1239
    } else {
1240
        tcg_out_bundle(s, mII,
1241
                       tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R2,
1242
                                   0x40, arg2),
1243
                       tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, TCG_REG_R3,
1244
                                   arg1, arg2),
1245
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, TCG_REG_R2,
1246
                                   arg1, TCG_REG_R2));
1247
        tcg_out_bundle(s, miI,
1248
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1249
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1250
                       tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret,
1251
                                   TCG_REG_R2, TCG_REG_R3));
1252
    }
1253
}
1254

    
1255
static inline void tcg_out_rotr_i32(TCGContext *s, TCGArg ret, TCGArg arg1,
1256
                                    TCGArg arg2, int const_arg2)
1257
{
1258
    if (const_arg2) {
1259
        tcg_out_bundle(s, mII,
1260
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1261
                       tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2,
1262
                                   TCG_REG_R2, arg1, arg1),
1263
                       tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, ret,
1264
                                   TCG_REG_R2, arg2, 31));
1265
    } else {
1266
        tcg_out_bundle(s, mII,
1267
                       tcg_opc_a3 (TCG_REG_P0, OPC_AND_A3, TCG_REG_R3,
1268
                                   0x1f, arg2),
1269
                       tcg_opc_i2 (TCG_REG_P0, OPC_UNPACK4_L_I2,
1270
                                   TCG_REG_R2, arg1, arg1),
1271
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, ret,
1272
                                   TCG_REG_R2, TCG_REG_R3));
1273
    }
1274
}
1275

    
1276
static inline void tcg_out_rotr_i64(TCGContext *s, TCGArg ret, TCGArg arg1,
1277
                                    TCGArg arg2, int const_arg2)
1278
{
1279
    if (const_arg2) {
1280
        tcg_out_bundle(s, miI,
1281
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1282
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1283
                       tcg_opc_i10(TCG_REG_P0, OPC_SHRP_I10, ret, arg1,
1284
                                   arg1, arg2));
1285
    } else {
1286
        tcg_out_bundle(s, mII,
1287
                       tcg_opc_a3 (TCG_REG_P0, OPC_SUB_A3, TCG_REG_R2,
1288
                                   0x40, arg2),
1289
                       tcg_opc_i5 (TCG_REG_P0, OPC_SHR_U_I5, TCG_REG_R3,
1290
                                   arg1, arg2),
1291
                       tcg_opc_i7 (TCG_REG_P0, OPC_SHL_I7, TCG_REG_R2,
1292
                                   arg1, TCG_REG_R2));
1293
        tcg_out_bundle(s, miI,
1294
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1295
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1296
                       tcg_opc_a1 (TCG_REG_P0, OPC_OR_A1, ret,
1297
                                   TCG_REG_R2, TCG_REG_R3));
1298
    }
1299
}
1300

    
1301
static inline void tcg_out_ext(TCGContext *s, uint64_t opc_i29,
1302
                               TCGArg ret, TCGArg arg)
1303
{
1304
    tcg_out_bundle(s, miI,
1305
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1306
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1307
                   tcg_opc_i29(TCG_REG_P0, opc_i29, ret, arg));
1308
}
1309

    
1310
static inline void tcg_out_bswap16(TCGContext *s, TCGArg ret, TCGArg arg)
1311
{
1312
    tcg_out_bundle(s, mII,
1313
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1314
                   tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, arg, 15, 15),
1315
                   tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, ret, 0xb));
1316
}
1317

    
1318
static inline void tcg_out_bswap32(TCGContext *s, TCGArg ret, TCGArg arg)
1319
{
1320
    tcg_out_bundle(s, mII,
1321
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1322
                   tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, ret, arg, 31, 31),
1323
                   tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, ret, 0xb));
1324
}
1325

    
1326
static inline void tcg_out_bswap64(TCGContext *s, TCGArg ret, TCGArg arg)
1327
{
1328
    tcg_out_bundle(s, mII,
1329
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1330
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1331
                   tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3, ret, arg, 0xb));
1332
}
1333

    
1334
static inline uint64_t tcg_opc_cmp_a(int qp, TCGCond cond, TCGArg arg1,
1335
                                     TCGArg arg2, int cmp4)
1336
{
1337
    uint64_t opc_eq_a6, opc_lt_a6, opc_ltu_a6;
1338

    
1339
    if (cmp4) {
1340
        opc_eq_a6 = OPC_CMP4_EQ_A6;
1341
        opc_lt_a6 = OPC_CMP4_LT_A6;
1342
        opc_ltu_a6 = OPC_CMP4_LTU_A6;
1343
    } else {
1344
        opc_eq_a6 = OPC_CMP_EQ_A6;
1345
        opc_lt_a6 = OPC_CMP_LT_A6;
1346
        opc_ltu_a6 = OPC_CMP_LTU_A6;
1347
    }
1348

    
1349
    switch (cond) {
1350
    case TCG_COND_EQ:
1351
        return tcg_opc_a6 (qp, opc_eq_a6,  TCG_REG_P6, TCG_REG_P7, arg1, arg2);
1352
    case TCG_COND_NE:
1353
        return tcg_opc_a6 (qp, opc_eq_a6,  TCG_REG_P7, TCG_REG_P6, arg1, arg2);
1354
    case TCG_COND_LT:
1355
        return tcg_opc_a6 (qp, opc_lt_a6,  TCG_REG_P6, TCG_REG_P7, arg1, arg2);
1356
    case TCG_COND_LTU:
1357
        return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P6, TCG_REG_P7, arg1, arg2);
1358
    case TCG_COND_GE:
1359
        return tcg_opc_a6 (qp, opc_lt_a6,  TCG_REG_P7, TCG_REG_P6, arg1, arg2);
1360
    case TCG_COND_GEU:
1361
        return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P7, TCG_REG_P6, arg1, arg2);
1362
    case TCG_COND_LE:
1363
        return tcg_opc_a6 (qp, opc_lt_a6,  TCG_REG_P7, TCG_REG_P6, arg2, arg1);
1364
    case TCG_COND_LEU:
1365
        return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P7, TCG_REG_P6, arg2, arg1);
1366
    case TCG_COND_GT:
1367
        return tcg_opc_a6 (qp, opc_lt_a6,  TCG_REG_P6, TCG_REG_P7, arg2, arg1);
1368
    case TCG_COND_GTU:
1369
        return tcg_opc_a6 (qp, opc_ltu_a6, TCG_REG_P6, TCG_REG_P7, arg2, arg1);
1370
    default:
1371
        tcg_abort();
1372
        break;
1373
    }
1374
}
1375

    
1376
static inline void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1,
1377
                                  int const_arg1, TCGArg arg2, int const_arg2,
1378
                                  int label_index, int cmp4)
1379
{
1380
    TCGLabel *l = &s->labels[label_index];
1381
    uint64_t opc1, opc2;
1382

    
1383
    if (const_arg1 && arg1 != 0) {
1384
        opc1 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R2,
1385
                          arg1, TCG_REG_R0);
1386
        arg1 = TCG_REG_R2;
1387
    } else {
1388
        opc1 = tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0);
1389
    }
1390

    
1391
    if (const_arg2 && arg2 != 0) {
1392
        opc2 = tcg_opc_a5(TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R3,
1393
                          arg2, TCG_REG_R0);
1394
        arg2 = TCG_REG_R3;
1395
    } else {
1396
        opc2 = tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0);
1397
    }
1398

    
1399
    tcg_out_bundle(s, mII,
1400
                   opc1,
1401
                   opc2,
1402
                   tcg_opc_cmp_a(TCG_REG_P0, cond, arg1, arg2, cmp4));
1403
    tcg_out_bundle(s, mmB,
1404
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1405
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1406
                   tcg_opc_b1 (TCG_REG_P6, OPC_BR_DPTK_FEW_B1,
1407
                               get_reloc_pcrel21b(s->code_ptr + 2)));
1408

    
1409
    if (l->has_value) {
1410
        reloc_pcrel21b((s->code_ptr - 16) + 2, l->u.value);
1411
    } else {
1412
        tcg_out_reloc(s, (s->code_ptr - 16) + 2,
1413
                      R_IA64_PCREL21B, label_index, 0);
1414
    }
1415
}
1416

    
1417
static inline void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGArg ret,
1418
                                   TCGArg arg1, TCGArg arg2, int cmp4)
1419
{
1420
    tcg_out_bundle(s, MmI,
1421
                   tcg_opc_cmp_a(TCG_REG_P0, cond, arg1, arg2, cmp4),
1422
                   tcg_opc_a5(TCG_REG_P6, OPC_ADDL_A5, ret, 1, TCG_REG_R0),
1423
                   tcg_opc_a5(TCG_REG_P7, OPC_ADDL_A5, ret, 0, TCG_REG_R0));
1424
}
1425

    
1426
#if defined(CONFIG_SOFTMMU)
1427

    
1428
#include "../../softmmu_defs.h"
1429

    
1430
/* Load and compare a TLB entry, and return the result in (p6, p7).
1431
   R2 is loaded with the address of the addend TLB entry.
1432
   R56 is loaded with the address, zero extented on 32-bit targets. */
1433
static inline void tcg_out_qemu_tlb(TCGContext *s, TCGArg addr_reg,
1434
                                    int s_bits, uint64_t offset_rw,
1435
                                    uint64_t offset_addend)
1436
{
1437
    tcg_out_bundle(s, mII,
1438
                   tcg_opc_a5 (TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R3,
1439
                               TARGET_PAGE_MASK | ((1 << s_bits) - 1),
1440
                               TCG_REG_R0),
1441
                   tcg_opc_i11(TCG_REG_P0, OPC_EXTR_U_I11, TCG_REG_R2,
1442
                               addr_reg, TARGET_PAGE_BITS, CPU_TLB_BITS - 1),
1443
                   tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12, TCG_REG_R2,
1444
                               TCG_REG_R2, 63 - CPU_TLB_ENTRY_BITS,
1445
                               63 - CPU_TLB_ENTRY_BITS));
1446
    tcg_out_bundle(s, mII,
1447
                   tcg_opc_a5 (TCG_REG_P0, OPC_ADDL_A5, TCG_REG_R2,
1448
                               offset_rw, TCG_REG_R2),
1449
#if TARGET_LONG_BITS == 32
1450
                   tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29, TCG_REG_R56, addr_reg),
1451
#else
1452
                   tcg_opc_a4(TCG_REG_P0, OPC_ADDS_A4, TCG_REG_R56,
1453
                              0, addr_reg),
1454
#endif
1455
                   tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2,
1456
                               TCG_REG_R2, TCG_AREG0));
1457
    tcg_out_bundle(s, mII,
1458
                   tcg_opc_m3 (TCG_REG_P0, OPC_LD8_M3, TCG_REG_R57,
1459
                               TCG_REG_R2, offset_addend - offset_rw),
1460
                   tcg_opc_a1 (TCG_REG_P0, OPC_AND_A1, TCG_REG_R3,
1461
                               TCG_REG_R3, TCG_REG_R56),
1462
                   tcg_opc_a6 (TCG_REG_P0, OPC_CMP_EQ_A6, TCG_REG_P6,
1463
                               TCG_REG_P7, TCG_REG_R3, TCG_REG_R57));
1464
}
1465

    
1466
static void *qemu_ld_helpers[4] = {
1467
    __ldb_mmu,
1468
    __ldw_mmu,
1469
    __ldl_mmu,
1470
    __ldq_mmu,
1471
};
1472

    
1473
static inline void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int opc)
1474
{
1475
    int addr_reg, data_reg, mem_index, s_bits, bswap;
1476
    uint64_t opc_ld_m1[4] = { OPC_LD1_M1, OPC_LD2_M1, OPC_LD4_M1, OPC_LD8_M1 };
1477
    uint64_t opc_ext_i29[8] = { OPC_ZXT1_I29, OPC_ZXT2_I29, OPC_ZXT4_I29, 0,
1478
                                OPC_SXT1_I29, OPC_SXT2_I29, OPC_SXT4_I29, 0 };
1479

    
1480
    data_reg = *args++;
1481
    addr_reg = *args++;
1482
    mem_index = *args;
1483
    s_bits = opc & 3;
1484

    
1485
#ifdef TARGET_WORDS_BIGENDIAN
1486
    bswap = 1;
1487
#else
1488
    bswap = 0;
1489
#endif
1490

    
1491
    /* Read the TLB entry */
1492
    tcg_out_qemu_tlb(s, addr_reg, s_bits,
1493
                     offsetof(CPUState, tlb_table[mem_index][0].addr_read),
1494
                     offsetof(CPUState, tlb_table[mem_index][0].addend));
1495

    
1496
    /* P6 is the fast path, and P7 the slow path */
1497
    tcg_out_bundle(s, mLX,
1498
                   tcg_opc_a5 (TCG_REG_P7, OPC_ADDL_A5, TCG_REG_R57,
1499
                               mem_index, TCG_REG_R0),
1500
                   tcg_opc_l2 ((tcg_target_long) qemu_ld_helpers[s_bits]),
1501
                   tcg_opc_x2 (TCG_REG_P7, OPC_MOVL_X2, TCG_REG_R2,
1502
                               (tcg_target_long) qemu_ld_helpers[s_bits]));
1503
    tcg_out_bundle(s, MmI,
1504
                   tcg_opc_m3 (TCG_REG_P0, OPC_LD8_M3, TCG_REG_R3,
1505
                               TCG_REG_R2, 8),
1506
                   tcg_opc_a1 (TCG_REG_P6, OPC_ADD_A1, TCG_REG_R3,
1507
                               TCG_REG_R3, TCG_REG_R56),
1508
                   tcg_opc_i21(TCG_REG_P7, OPC_MOV_I21, TCG_REG_B6,
1509
                               TCG_REG_R3, 0));
1510
    if (bswap && s_bits == 1) {
1511
        tcg_out_bundle(s, MmI,
1512
                       tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits],
1513
                                   TCG_REG_R8, TCG_REG_R3),
1514
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2),
1515
                       tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12,
1516
                                   TCG_REG_R8, TCG_REG_R8, 15, 15));
1517
    } else if (bswap && s_bits == 2) {
1518
        tcg_out_bundle(s, MmI,
1519
                       tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits],
1520
                                   TCG_REG_R8, TCG_REG_R3),
1521
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2),
1522
                       tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12,
1523
                                   TCG_REG_R8, TCG_REG_R8, 31, 31));
1524
    } else {
1525
        tcg_out_bundle(s, mmI,
1526
                       tcg_opc_m1 (TCG_REG_P6, opc_ld_m1[s_bits],
1527
                                   TCG_REG_R8, TCG_REG_R3),
1528
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1, TCG_REG_R1, TCG_REG_R2),
1529
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1530
    }
1531
    if (!bswap || s_bits == 0) {
1532
        tcg_out_bundle(s, miB,
1533
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1534
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1535
                       tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5,
1536
                                   TCG_REG_B0, TCG_REG_B6));
1537
    } else {
1538
        tcg_out_bundle(s, miB,
1539
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1540
                       tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3,
1541
                                   TCG_REG_R8, TCG_REG_R8, 0xb),
1542
                       tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5,
1543
                                   TCG_REG_B0, TCG_REG_B6));
1544
    }
1545

    
1546
    if (opc == 3) {
1547
        tcg_out_bundle(s, miI,
1548
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1549
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1550
                       tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4,
1551
                                   data_reg, 0, TCG_REG_R8));
1552
    } else {
1553
        tcg_out_bundle(s, miI,
1554
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1555
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1556
                       tcg_opc_i29(TCG_REG_P0, opc_ext_i29[opc],
1557
                                   data_reg, TCG_REG_R8));
1558
    }
1559
}
1560

    
1561
static void *qemu_st_helpers[4] = {
1562
    __stb_mmu,
1563
    __stw_mmu,
1564
    __stl_mmu,
1565
    __stq_mmu,
1566
};
1567

    
1568
static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int opc)
1569
{
1570
    int addr_reg, data_reg, mem_index, bswap;
1571
    uint64_t opc_st_m4[4] = { OPC_ST1_M4, OPC_ST2_M4, OPC_ST4_M4, OPC_ST8_M4 };
1572

    
1573
    data_reg = *args++;
1574
    addr_reg = *args++;
1575
    mem_index = *args;
1576

    
1577
#ifdef TARGET_WORDS_BIGENDIAN
1578
    bswap = 1;
1579
#else
1580
    bswap = 0;
1581
#endif
1582

    
1583
    tcg_out_qemu_tlb(s, addr_reg, opc,
1584
                     offsetof(CPUState, tlb_table[mem_index][0].addr_write),
1585
                     offsetof(CPUState, tlb_table[mem_index][0].addend));
1586

    
1587
    /* P6 is the fast path, and P7 the slow path */
1588
    tcg_out_bundle(s, mLX,
1589
                   tcg_opc_a4(TCG_REG_P7, OPC_ADDS_A4, TCG_REG_R57,
1590
                              0, data_reg),
1591
                   tcg_opc_l2 ((tcg_target_long) qemu_st_helpers[opc]),
1592
                   tcg_opc_x2 (TCG_REG_P7, OPC_MOVL_X2, TCG_REG_R2,
1593
                               (tcg_target_long) qemu_st_helpers[opc]));
1594
    tcg_out_bundle(s, MmI,
1595
                   tcg_opc_m3 (TCG_REG_P0, OPC_LD8_M3, TCG_REG_R3,
1596
                               TCG_REG_R2, 8),
1597
                   tcg_opc_a1 (TCG_REG_P6, OPC_ADD_A1, TCG_REG_R3,
1598
                               TCG_REG_R3, TCG_REG_R56),
1599
                   tcg_opc_i21(TCG_REG_P7, OPC_MOV_I21, TCG_REG_B6,
1600
                               TCG_REG_R3, 0));
1601

    
1602
    if (!bswap || opc == 0) {
1603
        tcg_out_bundle(s, mII,
1604
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1,
1605
                                   TCG_REG_R1, TCG_REG_R2),
1606
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1607
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1608
    } else if (opc == 1) {
1609
        tcg_out_bundle(s, mII,
1610
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1,
1611
                                   TCG_REG_R1, TCG_REG_R2),
1612
                       tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12,
1613
                                   TCG_REG_R2, data_reg, 15, 15),
1614
                       tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3,
1615
                                   TCG_REG_R2, TCG_REG_R2, 0xb));
1616
        data_reg = TCG_REG_R2;
1617
    } else if (opc == 2) {
1618
        tcg_out_bundle(s, mII,
1619
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1,
1620
                                   TCG_REG_R1, TCG_REG_R2),
1621
                       tcg_opc_i12(TCG_REG_P6, OPC_DEP_Z_I12,
1622
                                   TCG_REG_R2, data_reg, 31, 31),
1623
                       tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3,
1624
                                   TCG_REG_R2, TCG_REG_R2, 0xb));
1625
        data_reg = TCG_REG_R2;
1626
    } else if (opc == 3) {
1627
        tcg_out_bundle(s, miI,
1628
                       tcg_opc_m1 (TCG_REG_P7, OPC_LD8_M1,
1629
                                   TCG_REG_R1, TCG_REG_R2),
1630
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1631
                       tcg_opc_i3 (TCG_REG_P6, OPC_MUX1_I3,
1632
                                   TCG_REG_R2, data_reg, 0xb));
1633
        data_reg = TCG_REG_R2;
1634
    }
1635

    
1636
    tcg_out_bundle(s, miB,
1637
                   tcg_opc_m4 (TCG_REG_P6, opc_st_m4[opc],
1638
                               data_reg, TCG_REG_R3),
1639
                   tcg_opc_a5 (TCG_REG_P7, OPC_ADDL_A5, TCG_REG_R58,
1640
                               mem_index, TCG_REG_R0),
1641
                   tcg_opc_b5 (TCG_REG_P7, OPC_BR_CALL_SPTK_MANY_B5,
1642
                               TCG_REG_B0, TCG_REG_B6));
1643
}
1644

    
1645
#else /* !CONFIG_SOFTMMU */
1646

    
1647
static inline void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int opc)
1648
{
1649
    static uint64_t const opc_ld_m1[4] = {
1650
        OPC_LD1_M1, OPC_LD2_M1, OPC_LD4_M1, OPC_LD8_M1
1651
    };
1652
    static uint64_t const opc_sxt_i29[4] = {
1653
        OPC_SXT1_I29, OPC_SXT2_I29, OPC_SXT4_I29, 0
1654
    };
1655
    int addr_reg, data_reg, mem_index, s_bits, bswap;
1656

    
1657
    data_reg = *args++;
1658
    addr_reg = *args++;
1659
    mem_index = *args;
1660
    s_bits = opc & 3;
1661

    
1662
#ifdef TARGET_WORDS_BIGENDIAN
1663
    bswap = 1;
1664
#else
1665
    bswap = 0;
1666
#endif
1667

    
1668
#if TARGET_LONG_BITS == 32
1669
    if (GUEST_BASE != 0) {
1670
        tcg_out_bundle(s, mII,
1671
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1672
                       tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29,
1673
                                   TCG_REG_R3, addr_reg),
1674
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2,
1675
                                   TCG_GUEST_BASE_REG, TCG_REG_R3));
1676
    } else {
1677
        tcg_out_bundle(s, miI,
1678
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1679
                       tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29,
1680
                                   TCG_REG_R2, addr_reg),
1681
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1682
    }
1683

    
1684
    if (!bswap || s_bits == 0) {
1685
        if (s_bits == opc) {
1686
            tcg_out_bundle(s, miI,
1687
                           tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1688
                                       data_reg, TCG_REG_R2),
1689
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1690
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1691
        } else {
1692
            tcg_out_bundle(s, mII,
1693
                           tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1694
                                       data_reg, TCG_REG_R2),
1695
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1696
                           tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits],
1697
                                       data_reg, data_reg));
1698
        }
1699
    } else if (s_bits == 3) {
1700
            tcg_out_bundle(s, mII,
1701
                           tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1702
                                       data_reg, TCG_REG_R2),
1703
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1704
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1705
                                       data_reg, data_reg, 0xb));
1706
    } else {
1707
        if (s_bits == 1) {
1708
            tcg_out_bundle(s, mII,
1709
                           tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1710
                                       data_reg, TCG_REG_R2),
1711
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1712
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1713
                                      data_reg, data_reg, 15, 15));
1714
        } else {
1715
            tcg_out_bundle(s, mII,
1716
                           tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1717
                                       data_reg, TCG_REG_R2),
1718
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1719
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1720
                                      data_reg, data_reg, 31, 31));
1721
        }
1722
        if (opc == s_bits) {
1723
            tcg_out_bundle(s, miI,
1724
                           tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1725
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1726
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1727
                                       data_reg, data_reg, 0xb));
1728
        } else {
1729
            tcg_out_bundle(s, mII,
1730
                           tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1731
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1732
                                       data_reg, data_reg, 0xb),
1733
                           tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits],
1734
                                       data_reg, data_reg));
1735
        }
1736
    }
1737
#else
1738
    if (GUEST_BASE != 0) {
1739
        tcg_out_bundle(s, MmI,
1740
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2,
1741
                                   TCG_GUEST_BASE_REG, addr_reg),
1742
                       tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1743
                                   data_reg, TCG_REG_R2),
1744
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1745
    } else {
1746
        tcg_out_bundle(s, mmI,
1747
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1748
                       tcg_opc_m1 (TCG_REG_P0, opc_ld_m1[s_bits],
1749
                                   data_reg, addr_reg),
1750
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1751
    }
1752

    
1753
    if (bswap && s_bits == 1) {
1754
        tcg_out_bundle(s, mII,
1755
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1756
                       tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1757
                                   data_reg, data_reg, 15, 15),
1758
                       tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1759
                                   data_reg, data_reg, 0xb));
1760
    } else if (bswap && s_bits == 2) {
1761
        tcg_out_bundle(s, mII,
1762
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1763
                       tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1764
                                   data_reg, data_reg, 31, 31),
1765
                       tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1766
                                   data_reg, data_reg, 0xb));
1767
    } else if (bswap && s_bits == 3) {
1768
        tcg_out_bundle(s, miI,
1769
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1770
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1771
                       tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1772
                                   data_reg, data_reg, 0xb));
1773
    }
1774
    if (s_bits != opc) {
1775
        tcg_out_bundle(s, miI,
1776
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1777
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1778
                       tcg_opc_i29(TCG_REG_P0, opc_sxt_i29[s_bits],
1779
                                   data_reg, data_reg));
1780
    }
1781
#endif
1782
}
1783

    
1784
static inline void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int opc)
1785
{
1786
    static uint64_t const opc_st_m4[4] = {
1787
        OPC_ST1_M4, OPC_ST2_M4, OPC_ST4_M4, OPC_ST8_M4
1788
    };
1789
    int addr_reg, data_reg, bswap;
1790
#if TARGET_LONG_BITS == 64
1791
    uint64_t add_guest_base;
1792
#endif
1793

    
1794
    data_reg = *args++;
1795
    addr_reg = *args++;
1796

    
1797
#ifdef TARGET_WORDS_BIGENDIAN
1798
    bswap = 1;
1799
#else
1800
    bswap = 0;
1801
#endif
1802

    
1803
#if TARGET_LONG_BITS == 32
1804
    if (GUEST_BASE != 0) {
1805
        tcg_out_bundle(s, mII,
1806
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1807
                       tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29,
1808
                                   TCG_REG_R3, addr_reg),
1809
                       tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2,
1810
                                   TCG_GUEST_BASE_REG, TCG_REG_R3));
1811
    } else {
1812
        tcg_out_bundle(s, miI,
1813
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1814
                       tcg_opc_i29(TCG_REG_P0, OPC_ZXT4_I29,
1815
                                   TCG_REG_R3, addr_reg),
1816
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1817
    }
1818

    
1819
    if (bswap) {
1820
        if (opc == 1) {
1821
            tcg_out_bundle(s, mII,
1822
                           tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1823
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1824
                                       TCG_REG_R3, data_reg, 15, 15),
1825
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1826
                                       TCG_REG_R3, TCG_REG_R3, 0xb));
1827
            data_reg = TCG_REG_R3;
1828
        } else if (opc == 2) {
1829
            tcg_out_bundle(s, mII,
1830
                           tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1831
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1832
                                       TCG_REG_R3, data_reg, 31, 31),
1833
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1834
                                       TCG_REG_R3, TCG_REG_R3, 0xb));
1835
            data_reg = TCG_REG_R3;
1836
        } else if (opc == 3) {
1837
            tcg_out_bundle(s, miI,
1838
                           tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1839
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1840
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1841
                                       TCG_REG_R3, data_reg, 0xb));
1842
            data_reg = TCG_REG_R3;
1843
        }
1844
    }
1845
    tcg_out_bundle(s, mmI,
1846
                   tcg_opc_m4 (TCG_REG_P0, opc_st_m4[opc],
1847
                               data_reg, TCG_REG_R2),
1848
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
1849
                   tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1850
#else
1851
    if (GUEST_BASE != 0) {
1852
        add_guest_base = tcg_opc_a1 (TCG_REG_P0, OPC_ADD_A1, TCG_REG_R2,
1853
                                     TCG_GUEST_BASE_REG, addr_reg);
1854
        addr_reg = TCG_REG_R2;
1855
    } else {
1856
        add_guest_base = tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0);
1857
    }
1858

    
1859
    if (!bswap || opc == 0) {
1860
        tcg_out_bundle(s, (GUEST_BASE ? MmI : mmI),
1861
                       add_guest_base,
1862
                       tcg_opc_m4 (TCG_REG_P0, opc_st_m4[opc],
1863
                                   data_reg, addr_reg),
1864
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1865
    } else {
1866
        if (opc == 1) {
1867
            tcg_out_bundle(s, mII,
1868
                           add_guest_base,
1869
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1870
                                       TCG_REG_R3, data_reg, 15, 15),
1871
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1872
                                       TCG_REG_R3, TCG_REG_R3, 0xb));
1873
            data_reg = TCG_REG_R3;
1874
        } else if (opc == 2) {
1875
            tcg_out_bundle(s, mII,
1876
                           add_guest_base,
1877
                           tcg_opc_i12(TCG_REG_P0, OPC_DEP_Z_I12,
1878
                                       TCG_REG_R3, data_reg, 31, 31),
1879
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1880
                                       TCG_REG_R3, TCG_REG_R3, 0xb));
1881
            data_reg = TCG_REG_R3;
1882
        } else if (opc == 3) {
1883
            tcg_out_bundle(s, miI,
1884
                           add_guest_base,
1885
                           tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1886
                           tcg_opc_i3 (TCG_REG_P0, OPC_MUX1_I3,
1887
                                       TCG_REG_R3, data_reg, 0xb));
1888
            data_reg = TCG_REG_R3;
1889
        }
1890
        tcg_out_bundle(s, miI,
1891
                       tcg_opc_m4 (TCG_REG_P0, opc_st_m4[opc],
1892
                                   data_reg, addr_reg),
1893
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0),
1894
                       tcg_opc_i18(TCG_REG_P0, OPC_NOP_I18, 0));
1895
    }
1896
#endif
1897
}
1898

    
1899
#endif
1900

    
1901
static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
1902
                              const TCGArg *args, const int *const_args)
1903
{
1904
    switch(opc) {
1905
    case INDEX_op_exit_tb:
1906
        tcg_out_exit_tb(s, args[0]);
1907
        break;
1908
    case INDEX_op_br:
1909
        tcg_out_br(s, args[0]);
1910
        break;
1911
    case INDEX_op_call:
1912
        tcg_out_call(s, args[0]);
1913
        break;
1914
    case INDEX_op_goto_tb:
1915
        tcg_out_goto_tb(s, args[0]);
1916
        break;
1917
    case INDEX_op_jmp:
1918
        tcg_out_jmp(s, args[0]);
1919
        break;
1920

    
1921
    case INDEX_op_movi_i32:
1922
        tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]);
1923
        break;
1924
    case INDEX_op_movi_i64:
1925
        tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]);
1926
        break;
1927

    
1928
    case INDEX_op_ld8u_i32:
1929
    case INDEX_op_ld8u_i64:
1930
        tcg_out_ld_rel(s, OPC_LD1_M1, args[0], args[1], args[2]);
1931
        break;
1932
    case INDEX_op_ld8s_i32:
1933
    case INDEX_op_ld8s_i64:
1934
        tcg_out_ld_rel(s, OPC_LD1_M1, args[0], args[1], args[2]);
1935
        tcg_out_ext(s, OPC_SXT1_I29, args[0], args[0]);
1936
        break;
1937
    case INDEX_op_ld16u_i32:
1938
    case INDEX_op_ld16u_i64:
1939
        tcg_out_ld_rel(s, OPC_LD2_M1, args[0], args[1], args[2]);
1940
        break;
1941
    case INDEX_op_ld16s_i32:
1942
    case INDEX_op_ld16s_i64:
1943
        tcg_out_ld_rel(s, OPC_LD2_M1, args[0], args[1], args[2]);
1944
        tcg_out_ext(s, OPC_SXT2_I29, args[0], args[0]);
1945
        break;
1946
    case INDEX_op_ld_i32:
1947
    case INDEX_op_ld32u_i64:
1948
        tcg_out_ld_rel(s, OPC_LD4_M1, args[0], args[1], args[2]);
1949
        break;
1950
    case INDEX_op_ld32s_i64:
1951
        tcg_out_ld_rel(s, OPC_LD4_M1, args[0], args[1], args[2]);
1952
        tcg_out_ext(s, OPC_SXT4_I29, args[0], args[0]);
1953
        break;
1954
    case INDEX_op_ld_i64:
1955
        tcg_out_ld_rel(s, OPC_LD8_M1, args[0], args[1], args[2]);
1956
        break;
1957
    case INDEX_op_st8_i32:
1958
    case INDEX_op_st8_i64:
1959
        tcg_out_st_rel(s, OPC_ST1_M4, args[0], args[1], args[2]);
1960
        break;
1961
    case INDEX_op_st16_i32:
1962
    case INDEX_op_st16_i64:
1963
        tcg_out_st_rel(s, OPC_ST2_M4, args[0], args[1], args[2]);
1964
        break;
1965
    case INDEX_op_st_i32:
1966
    case INDEX_op_st32_i64:
1967
        tcg_out_st_rel(s, OPC_ST4_M4, args[0], args[1], args[2]);
1968
        break;
1969
    case INDEX_op_st_i64:
1970
        tcg_out_st_rel(s, OPC_ST8_M4, args[0], args[1], args[2]);
1971
        break;
1972

    
1973
    case INDEX_op_add_i32:
1974
    case INDEX_op_add_i64:
1975
        tcg_out_alu(s, OPC_ADD_A1, args[0], args[1], const_args[1],
1976
                    args[2], const_args[2]);
1977
        break;
1978
    case INDEX_op_sub_i32:
1979
    case INDEX_op_sub_i64:
1980
        tcg_out_alu(s, OPC_SUB_A1, args[0], args[1], const_args[1],
1981
                    args[2], const_args[2]);
1982
        break;
1983

    
1984
    case INDEX_op_and_i32:
1985
    case INDEX_op_and_i64:
1986
        tcg_out_alu(s, OPC_AND_A1, args[0], args[1], const_args[1],
1987
                    args[2], const_args[2]);
1988
        break;
1989
    case INDEX_op_andc_i32:
1990
    case INDEX_op_andc_i64:
1991
        tcg_out_alu(s, OPC_ANDCM_A1, args[0], args[1], const_args[1],
1992
                    args[2], const_args[2]);
1993
        break;
1994
    case INDEX_op_eqv_i32:
1995
    case INDEX_op_eqv_i64:
1996
        tcg_out_eqv(s, args[0], args[1], const_args[1],
1997
                    args[2], const_args[2]);
1998
        break;
1999
    case INDEX_op_nand_i32:
2000
    case INDEX_op_nand_i64:
2001
        tcg_out_nand(s, args[0], args[1], const_args[1],
2002
                     args[2], const_args[2]);
2003
        break;
2004
    case INDEX_op_nor_i32:
2005
    case INDEX_op_nor_i64:
2006
        tcg_out_nor(s, args[0], args[1], const_args[1],
2007
                    args[2], const_args[2]);
2008
        break;
2009
    case INDEX_op_or_i32:
2010
    case INDEX_op_or_i64:
2011
        tcg_out_alu(s, OPC_OR_A1, args[0], args[1], const_args[1],
2012
                    args[2], const_args[2]);
2013
        break;
2014
    case INDEX_op_orc_i32:
2015
    case INDEX_op_orc_i64:
2016
        tcg_out_orc(s, args[0], args[1], const_args[1],
2017
                    args[2], const_args[2]);
2018
        break;
2019
    case INDEX_op_xor_i32:
2020
    case INDEX_op_xor_i64:
2021
        tcg_out_alu(s, OPC_XOR_A1, args[0], args[1], const_args[1],
2022
                    args[2], const_args[2]);
2023
        break;
2024

    
2025
    case INDEX_op_mul_i32:
2026
    case INDEX_op_mul_i64:
2027
        tcg_out_mul(s, args[0], args[1], args[2]);
2028
        break;
2029

    
2030
    case INDEX_op_sar_i32:
2031
        tcg_out_sar_i32(s, args[0], args[1], args[2], const_args[2]);
2032
        break;
2033
    case INDEX_op_sar_i64:
2034
        tcg_out_sar_i64(s, args[0], args[1], args[2], const_args[2]);
2035
        break;
2036
    case INDEX_op_shl_i32:
2037
        tcg_out_shl_i32(s, args[0], args[1], args[2], const_args[2]);
2038
        break;
2039
    case INDEX_op_shl_i64:
2040
        tcg_out_shl_i64(s, args[0], args[1], args[2], const_args[2]);
2041
        break;
2042
    case INDEX_op_shr_i32:
2043
        tcg_out_shr_i32(s, args[0], args[1], args[2], const_args[2]);
2044
        break;
2045
    case INDEX_op_shr_i64:
2046
        tcg_out_shr_i64(s, args[0], args[1], args[2], const_args[2]);
2047
        break;
2048
    case INDEX_op_rotl_i32:
2049
        tcg_out_rotl_i32(s, args[0], args[1], args[2], const_args[2]);
2050
        break;
2051
    case INDEX_op_rotl_i64:
2052
        tcg_out_rotl_i64(s, args[0], args[1], args[2], const_args[2]);
2053
        break;
2054
    case INDEX_op_rotr_i32:
2055
        tcg_out_rotr_i32(s, args[0], args[1], args[2], const_args[2]);
2056
        break;
2057
    case INDEX_op_rotr_i64:
2058
        tcg_out_rotr_i64(s, args[0], args[1], args[2], const_args[2]);
2059
        break;
2060

    
2061
    case INDEX_op_ext8s_i32:
2062
    case INDEX_op_ext8s_i64:
2063
        tcg_out_ext(s, OPC_SXT1_I29, args[0], args[1]);
2064
        break;
2065
    case INDEX_op_ext8u_i32:
2066
    case INDEX_op_ext8u_i64:
2067
        tcg_out_ext(s, OPC_ZXT1_I29, args[0], args[1]);
2068
        break;
2069
    case INDEX_op_ext16s_i32:
2070
    case INDEX_op_ext16s_i64:
2071
        tcg_out_ext(s, OPC_SXT2_I29, args[0], args[1]);
2072
        break;
2073
    case INDEX_op_ext16u_i32:
2074
    case INDEX_op_ext16u_i64:
2075
        tcg_out_ext(s, OPC_ZXT2_I29, args[0], args[1]);
2076
        break;
2077
    case INDEX_op_ext32s_i64:
2078
        tcg_out_ext(s, OPC_SXT4_I29, args[0], args[1]);
2079
        break;
2080
    case INDEX_op_ext32u_i64:
2081
        tcg_out_ext(s, OPC_ZXT4_I29, args[0], args[1]);
2082
        break;
2083

    
2084
    case INDEX_op_bswap16_i32:
2085
    case INDEX_op_bswap16_i64:
2086
        tcg_out_bswap16(s, args[0], args[1]);
2087
        break;
2088
    case INDEX_op_bswap32_i32:
2089
    case INDEX_op_bswap32_i64:
2090
        tcg_out_bswap32(s, args[0], args[1]);
2091
        break;
2092
    case INDEX_op_bswap64_i64:
2093
        tcg_out_bswap64(s, args[0], args[1]);
2094
        break;
2095

    
2096
    case INDEX_op_brcond_i32:
2097
        tcg_out_brcond(s, args[2], args[0], const_args[0],
2098
                       args[1], const_args[1], args[3], 1);
2099
        break;
2100
    case INDEX_op_brcond_i64:
2101
        tcg_out_brcond(s, args[2], args[0], const_args[0],
2102
                       args[1], const_args[1], args[3], 0);
2103
        break;
2104
    case INDEX_op_setcond_i32:
2105
        tcg_out_setcond(s, args[3], args[0], args[1], args[2], 1);
2106
        break;
2107
    case INDEX_op_setcond_i64:
2108
        tcg_out_setcond(s, args[3], args[0], args[1], args[2], 0);
2109
        break;
2110

    
2111
    case INDEX_op_qemu_ld8u:
2112
        tcg_out_qemu_ld(s, args, 0);
2113
        break;
2114
    case INDEX_op_qemu_ld8s:
2115
        tcg_out_qemu_ld(s, args, 0 | 4);
2116
        break;
2117
    case INDEX_op_qemu_ld16u:
2118
        tcg_out_qemu_ld(s, args, 1);
2119
        break;
2120
    case INDEX_op_qemu_ld16s:
2121
        tcg_out_qemu_ld(s, args, 1 | 4);
2122
        break;
2123
    case INDEX_op_qemu_ld32u:
2124
        tcg_out_qemu_ld(s, args, 2);
2125
        break;
2126
    case INDEX_op_qemu_ld32s:
2127
        tcg_out_qemu_ld(s, args, 2 | 4);
2128
        break;
2129
    case INDEX_op_qemu_ld64:
2130
        tcg_out_qemu_ld(s, args, 3);
2131
        break;
2132

    
2133
    case INDEX_op_qemu_st8:
2134
        tcg_out_qemu_st(s, args, 0);
2135
        break;
2136
    case INDEX_op_qemu_st16:
2137
        tcg_out_qemu_st(s, args, 1);
2138
        break;
2139
    case INDEX_op_qemu_st32:
2140
        tcg_out_qemu_st(s, args, 2);
2141
        break;
2142
    case INDEX_op_qemu_st64:
2143
        tcg_out_qemu_st(s, args, 3);
2144
        break;
2145

    
2146
    default:
2147
        tcg_abort();
2148
    }
2149
}
2150

    
2151
static const TCGTargetOpDef ia64_op_defs[] = {
2152
    { INDEX_op_br, { } },
2153
    { INDEX_op_call, { "r" } },
2154
    { INDEX_op_exit_tb, { } },
2155
    { INDEX_op_goto_tb, { } },
2156
    { INDEX_op_jmp, { "r" } },
2157

    
2158
    { INDEX_op_mov_i32, { "r", "r" } },
2159
    { INDEX_op_movi_i32, { "r" } },
2160

    
2161
    { INDEX_op_ld8u_i32, { "r", "r" } },
2162
    { INDEX_op_ld8s_i32, { "r", "r" } },
2163
    { INDEX_op_ld16u_i32, { "r", "r" } },
2164
    { INDEX_op_ld16s_i32, { "r", "r" } },
2165
    { INDEX_op_ld_i32, { "r", "r" } },
2166
    { INDEX_op_st8_i32, { "rZ", "r" } },
2167
    { INDEX_op_st16_i32, { "rZ", "r" } },
2168
    { INDEX_op_st_i32, { "rZ", "r" } },
2169

    
2170
    { INDEX_op_add_i32, { "r", "rI", "rI" } },
2171
    { INDEX_op_sub_i32, { "r", "rI", "rI" } },
2172

    
2173
    { INDEX_op_and_i32, { "r", "rI", "rI" } },
2174
    { INDEX_op_andc_i32, { "r", "rI", "rI" } },
2175
    { INDEX_op_eqv_i32, { "r", "rZ", "rZ" } },
2176
    { INDEX_op_nand_i32, { "r", "rZ", "rZ" } },
2177
    { INDEX_op_nor_i32, { "r", "rZ", "rZ" } },
2178
    { INDEX_op_or_i32, { "r", "rI", "rI" } },
2179
    { INDEX_op_orc_i32, { "r", "rZ", "rZ" } },
2180
    { INDEX_op_xor_i32, { "r", "rI", "rI" } },
2181

    
2182
    { INDEX_op_mul_i32, { "r", "rZ", "rZ" } },
2183

    
2184
    { INDEX_op_sar_i32, { "r", "rZ", "ri" } },
2185
    { INDEX_op_shl_i32, { "r", "rZ", "ri" } },
2186
    { INDEX_op_shr_i32, { "r", "rZ", "ri" } },
2187
    { INDEX_op_rotl_i32, { "r", "rZ", "ri" } },
2188
    { INDEX_op_rotr_i32, { "r", "rZ", "ri" } },
2189

    
2190
    { INDEX_op_ext8s_i32, { "r", "rZ"} },
2191
    { INDEX_op_ext8u_i32, { "r", "rZ"} },
2192
    { INDEX_op_ext16s_i32, { "r", "rZ"} },
2193
    { INDEX_op_ext16u_i32, { "r", "rZ"} },
2194

    
2195
    { INDEX_op_bswap16_i32, { "r", "rZ" } },
2196
    { INDEX_op_bswap32_i32, { "r", "rZ" } },
2197

    
2198
    { INDEX_op_brcond_i32, { "rI", "rI" } },
2199
    { INDEX_op_setcond_i32, { "r", "rZ", "rZ" } },
2200

    
2201
    { INDEX_op_mov_i64, { "r", "r" } },
2202
    { INDEX_op_movi_i64, { "r" } },
2203

    
2204
    { INDEX_op_ld8u_i64, { "r", "r" } },
2205
    { INDEX_op_ld8s_i64, { "r", "r" } },
2206
    { INDEX_op_ld16u_i64, { "r", "r" } },
2207
    { INDEX_op_ld16s_i64, { "r", "r" } },
2208
    { INDEX_op_ld32u_i64, { "r", "r" } },
2209
    { INDEX_op_ld32s_i64, { "r", "r" } },
2210
    { INDEX_op_ld_i64, { "r", "r" } },
2211
    { INDEX_op_st8_i64, { "rZ", "r" } },
2212
    { INDEX_op_st16_i64, { "rZ", "r" } },
2213
    { INDEX_op_st32_i64, { "rZ", "r" } },
2214
    { INDEX_op_st_i64, { "rZ", "r" } },
2215

    
2216
    { INDEX_op_add_i64, { "r", "rI", "rI" } },
2217
    { INDEX_op_sub_i64, { "r", "rI", "rI" } },
2218

    
2219
    { INDEX_op_and_i64, { "r", "rI", "rI" } },
2220
    { INDEX_op_andc_i64, { "r", "rI", "rI" } },
2221
    { INDEX_op_eqv_i64, { "r", "rZ", "rZ" } },
2222
    { INDEX_op_nand_i64, { "r", "rZ", "rZ" } },
2223
    { INDEX_op_nor_i64, { "r", "rZ", "rZ" } },
2224
    { INDEX_op_or_i64, { "r", "rI", "rI" } },
2225
    { INDEX_op_orc_i64, { "r", "rZ", "rZ" } },
2226
    { INDEX_op_xor_i64, { "r", "rI", "rI" } },
2227

    
2228
    { INDEX_op_mul_i64, { "r", "rZ", "rZ" } },
2229

    
2230
    { INDEX_op_sar_i64, { "r", "rZ", "ri" } },
2231
    { INDEX_op_shl_i64, { "r", "rZ", "ri" } },
2232
    { INDEX_op_shr_i64, { "r", "rZ", "ri" } },
2233
    { INDEX_op_rotl_i64, { "r", "rZ", "ri" } },
2234
    { INDEX_op_rotr_i64, { "r", "rZ", "ri" } },
2235

    
2236
    { INDEX_op_ext8s_i64, { "r", "rZ"} },
2237
    { INDEX_op_ext8u_i64, { "r", "rZ"} },
2238
    { INDEX_op_ext16s_i64, { "r", "rZ"} },
2239
    { INDEX_op_ext16u_i64, { "r", "rZ"} },
2240
    { INDEX_op_ext32s_i64, { "r", "rZ"} },
2241
    { INDEX_op_ext32u_i64, { "r", "rZ"} },
2242

    
2243
    { INDEX_op_bswap16_i64, { "r", "rZ" } },
2244
    { INDEX_op_bswap32_i64, { "r", "rZ" } },
2245
    { INDEX_op_bswap64_i64, { "r", "rZ" } },
2246

    
2247
    { INDEX_op_brcond_i64, { "rI", "rI" } },
2248
    { INDEX_op_setcond_i64, { "r", "rZ", "rZ" } },
2249

    
2250
    { INDEX_op_qemu_ld8u, { "r", "r" } },
2251
    { INDEX_op_qemu_ld8s, { "r", "r" } },
2252
    { INDEX_op_qemu_ld16u, { "r", "r" } },
2253
    { INDEX_op_qemu_ld16s, { "r", "r" } },
2254
    { INDEX_op_qemu_ld32, { "r", "r" } },
2255
    { INDEX_op_qemu_ld32u, { "r", "r" } },
2256
    { INDEX_op_qemu_ld32s, { "r", "r" } },
2257
    { INDEX_op_qemu_ld64, { "r", "r" } },
2258

    
2259
    { INDEX_op_qemu_st8, { "SZ", "r" } },
2260
    { INDEX_op_qemu_st16, { "SZ", "r" } },
2261
    { INDEX_op_qemu_st32, { "SZ", "r" } },
2262
    { INDEX_op_qemu_st64, { "SZ", "r" } },
2263

    
2264
    { -1 },
2265
};
2266

    
2267
/* Generate global QEMU prologue and epilogue code */
2268
void tcg_target_qemu_prologue(TCGContext *s)
2269
{
2270
    int frame_size;
2271

    
2272
    /* reserve some stack space */
2273
    frame_size = TCG_STATIC_CALL_ARGS_SIZE;
2274
    frame_size = (frame_size + TCG_TARGET_STACK_ALIGN - 1) &
2275
                 ~(TCG_TARGET_STACK_ALIGN - 1);
2276

    
2277
    /* First emit adhoc function descriptor */
2278
    *(uint64_t *)(s->code_ptr) = (uint64_t)s->code_ptr + 16; /* entry point */
2279
    s->code_ptr += 16; /* skip GP */
2280

    
2281
    /* prologue */
2282
    tcg_out_bundle(s, mII,
2283
                   tcg_opc_m34(TCG_REG_P0, OPC_ALLOC_M34,
2284
                               TCG_REG_R33, 32, 24, 0),
2285
                   tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21,
2286
                               TCG_REG_B6, TCG_REG_R32, 0),
2287
                   tcg_opc_i22(TCG_REG_P0, OPC_MOV_I22,
2288
                               TCG_REG_R32, TCG_REG_B0));
2289

    
2290
    /* ??? If GUEST_BASE < 0x200000, we could load the register via
2291
       an ADDL in the M slot of the next bundle.  */
2292
    if (GUEST_BASE != 0) {
2293
        tcg_out_bundle(s, mlx,
2294
                       tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
2295
                       tcg_opc_l2 (GUEST_BASE),
2296
                       tcg_opc_x2 (TCG_REG_P0, OPC_MOVL_X2,
2297
                                   TCG_GUEST_BASE_REG, GUEST_BASE));
2298
        tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
2299
    }
2300

    
2301
    tcg_out_bundle(s, miB,
2302
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
2303
                   tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4,
2304
                               TCG_REG_R12, -frame_size, TCG_REG_R12),
2305
                   tcg_opc_b4 (TCG_REG_P0, OPC_BR_SPTK_MANY_B4, TCG_REG_B6));
2306

    
2307
    /* epilogue */
2308
    tb_ret_addr = s->code_ptr;
2309
    tcg_out_bundle(s, miI,
2310
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
2311
                   tcg_opc_i21(TCG_REG_P0, OPC_MOV_I21,
2312
                               TCG_REG_B0, TCG_REG_R32, 0),
2313
                   tcg_opc_a4 (TCG_REG_P0, OPC_ADDS_A4,
2314
                               TCG_REG_R12, frame_size, TCG_REG_R12));
2315
    tcg_out_bundle(s, miB,
2316
                   tcg_opc_m48(TCG_REG_P0, OPC_NOP_M48, 0),
2317
                   tcg_opc_i26(TCG_REG_P0, OPC_MOV_I_I26,
2318
                               TCG_REG_PFS, TCG_REG_R33),
2319
                   tcg_opc_b4 (TCG_REG_P0, OPC_BR_RET_SPTK_MANY_B4,
2320
                               TCG_REG_B0));
2321
}
2322

    
2323
void tcg_target_init(TCGContext *s)
2324
{
2325
    tcg_regset_set(tcg_target_available_regs[TCG_TYPE_I32],
2326
                   0xffffffffffffffffull);
2327
    tcg_regset_set(tcg_target_available_regs[TCG_TYPE_I64],
2328
                   0xffffffffffffffffull);
2329

    
2330
    tcg_regset_clear(tcg_target_call_clobber_regs);
2331
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R8);
2332
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R9);
2333
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R10);
2334
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R11);
2335
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R14);
2336
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R15);
2337
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R16);
2338
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R17);
2339
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R18);
2340
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R19);
2341
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R20);
2342
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R21);
2343
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R22);
2344
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R23);
2345
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R24);
2346
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R25);
2347
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R26);
2348
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R27);
2349
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R28);
2350
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R29);
2351
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R30);
2352
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R31);
2353
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R56);
2354
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R57);
2355
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R58);
2356
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R59);
2357
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R60);
2358
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R61);
2359
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R62);
2360
    tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R63);
2361

    
2362
    tcg_regset_clear(s->reserved_regs);
2363
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0);   /* zero register */
2364
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R1);   /* global pointer */
2365
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R2);   /* internal use */
2366
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R3);   /* internal use */
2367
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R12);  /* stack pointer */
2368
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R13);  /* thread pointer */
2369
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R32);  /* return address */
2370
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R33);  /* PFS */
2371

    
2372
    /* The following 3 are not in use, are call-saved, but *not* saved
2373
       by the prologue.  Therefore we cannot use them without modifying
2374
       the prologue.  There doesn't seem to be any good reason to use
2375
       these as opposed to the windowed registers.  */
2376
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R4);
2377
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R5);
2378
    tcg_regset_set_reg(s->reserved_regs, TCG_REG_R6);
2379

    
2380
    tcg_add_target_add_op_defs(ia64_op_defs);
2381
}