]> Git Repo - qemu.git/blob - tcg/mips/tcg-target.c
tcg/mips: use stack for TCG temps
[qemu.git] / tcg / mips / tcg-target.c
1 /*
2  * Tiny Code Generator for QEMU
3  *
4  * Copyright (c) 2008-2009 Arnaud Patard <[email protected]>
5  * Copyright (c) 2009 Aurelien Jarno <[email protected]>
6  * Based on i386/tcg-target.c - Copyright (c) 2008 Fabrice Bellard
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26
27 #if defined(TCG_TARGET_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
28 # define TCG_NEED_BSWAP 0
29 #else
30 # define TCG_NEED_BSWAP 1
31 #endif
32
33 #ifndef NDEBUG
34 static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
35     "zero",
36     "at",
37     "v0",
38     "v1",
39     "a0",
40     "a1",
41     "a2",
42     "a3",
43     "t0",
44     "t1",
45     "t2",
46     "t3",
47     "t4",
48     "t5",
49     "t6",
50     "t7",
51     "s0",
52     "s1",
53     "s2",
54     "s3",
55     "s4",
56     "s5",
57     "s6",
58     "s7",
59     "t8",
60     "t9",
61     "k0",
62     "k1",
63     "gp",
64     "sp",
65     "fp",
66     "ra",
67 };
68 #endif
69
70 /* check if we really need so many registers :P */
71 static const TCGReg tcg_target_reg_alloc_order[] = {
72     TCG_REG_S0,
73     TCG_REG_S1,
74     TCG_REG_S2,
75     TCG_REG_S3,
76     TCG_REG_S4,
77     TCG_REG_S5,
78     TCG_REG_S6,
79     TCG_REG_S7,
80     TCG_REG_T1,
81     TCG_REG_T2,
82     TCG_REG_T3,
83     TCG_REG_T4,
84     TCG_REG_T5,
85     TCG_REG_T6,
86     TCG_REG_T7,
87     TCG_REG_T8,
88     TCG_REG_T9,
89     TCG_REG_A0,
90     TCG_REG_A1,
91     TCG_REG_A2,
92     TCG_REG_A3,
93     TCG_REG_V0,
94     TCG_REG_V1
95 };
96
97 static const TCGReg tcg_target_call_iarg_regs[4] = {
98     TCG_REG_A0,
99     TCG_REG_A1,
100     TCG_REG_A2,
101     TCG_REG_A3
102 };
103
104 static const TCGReg tcg_target_call_oarg_regs[2] = {
105     TCG_REG_V0,
106     TCG_REG_V1
107 };
108
109 static uint8_t *tb_ret_addr;
110
111 static inline uint32_t reloc_lo16_val (void *pc, tcg_target_long target)
112 {
113     return target & 0xffff;
114 }
115
116 static inline void reloc_lo16 (void *pc, tcg_target_long target)
117 {
118     *(uint32_t *) pc = (*(uint32_t *) pc & ~0xffff)
119                        | reloc_lo16_val(pc, target);
120 }
121
122 static inline uint32_t reloc_hi16_val (void *pc, tcg_target_long target)
123 {
124     return (target >> 16) & 0xffff;
125 }
126
127 static inline void reloc_hi16 (void *pc, tcg_target_long target)
128 {
129     *(uint32_t *) pc = (*(uint32_t *) pc & ~0xffff)
130                        | reloc_hi16_val(pc, target);
131 }
132
133 static inline uint32_t reloc_pc16_val (void *pc, tcg_target_long target)
134 {
135     int32_t disp;
136
137     disp = target - (tcg_target_long) pc - 4;
138     if (disp != (disp << 14) >> 14) {
139         tcg_abort ();
140     }
141
142     return (disp >> 2) & 0xffff;
143 }
144
145 static inline void reloc_pc16 (void *pc, tcg_target_long target)
146 {
147     *(uint32_t *) pc = (*(uint32_t *) pc & ~0xffff)
148                        | reloc_pc16_val(pc, target);
149 }
150
151 static inline uint32_t reloc_26_val (void *pc, tcg_target_long target)
152 {
153     if ((((tcg_target_long)pc + 4) & 0xf0000000) != (target & 0xf0000000)) {
154         tcg_abort ();
155     }
156
157     return (target >> 2) & 0x3ffffff;
158 }
159
160 static inline void reloc_pc26 (void *pc, tcg_target_long target)
161 {
162     *(uint32_t *) pc = (*(uint32_t *) pc & ~0x3ffffff)
163                        | reloc_26_val(pc, target);
164 }
165
166 static void patch_reloc(uint8_t *code_ptr, int type,
167                         tcg_target_long value, tcg_target_long addend)
168 {
169     value += addend;
170     switch(type) {
171     case R_MIPS_LO16:
172         reloc_lo16(code_ptr, value);
173         break;
174     case R_MIPS_HI16:
175         reloc_hi16(code_ptr, value);
176         break;
177     case R_MIPS_PC16:
178         reloc_pc16(code_ptr, value);
179         break;
180     case R_MIPS_26:
181         reloc_pc26(code_ptr, value);
182         break;
183     default:
184         tcg_abort();
185     }
186 }
187
188 /* maximum number of register used for input function arguments */
189 static inline int tcg_target_get_call_iarg_regs_count(int flags)
190 {
191     return 4;
192 }
193
194 /* parse target specific constraints */
195 static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str)
196 {
197     const char *ct_str;
198
199     ct_str = *pct_str;
200     switch(ct_str[0]) {
201     case 'r':
202         ct->ct |= TCG_CT_REG;
203         tcg_regset_set(ct->u.regs, 0xffffffff);
204         break;
205     case 'C':
206         ct->ct |= TCG_CT_REG;
207         tcg_regset_clear(ct->u.regs);
208         tcg_regset_set_reg(ct->u.regs, TCG_REG_T9);
209         break;
210     case 'L': /* qemu_ld output arg constraint */
211         ct->ct |= TCG_CT_REG;
212         tcg_regset_set(ct->u.regs, 0xffffffff);
213         tcg_regset_reset_reg(ct->u.regs, TCG_REG_V0);
214         break;
215     case 'l': /* qemu_ld input arg constraint */
216         ct->ct |= TCG_CT_REG;
217         tcg_regset_set(ct->u.regs, 0xffffffff);
218 #if defined(CONFIG_SOFTMMU)
219         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A0);
220 # if (TARGET_LONG_BITS == 64)
221         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A2);
222 # endif
223 #endif
224         break;
225     case 'S': /* qemu_st constraint */
226         ct->ct |= TCG_CT_REG;
227         tcg_regset_set(ct->u.regs, 0xffffffff);
228         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A0);
229 #if defined(CONFIG_SOFTMMU)
230 # if (TARGET_LONG_BITS == 32)
231         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A1);
232 # endif
233         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A2);
234 # if TARGET_LONG_BITS == 64
235         tcg_regset_reset_reg(ct->u.regs, TCG_REG_A3);
236 # endif
237 #endif
238         break;
239     case 'I':
240         ct->ct |= TCG_CT_CONST_U16;
241         break;
242     case 'J':
243         ct->ct |= TCG_CT_CONST_S16;
244         break;
245     case 'Z':
246         /* We are cheating a bit here, using the fact that the register
247            ZERO is also the register number 0. Hence there is no need
248            to check for const_args in each instruction. */
249         ct->ct |= TCG_CT_CONST_ZERO;
250         break;
251     default:
252         return -1;
253     }
254     ct_str++;
255     *pct_str = ct_str;
256     return 0;
257 }
258
259 /* test if a constant matches the constraint */
260 static inline int tcg_target_const_match(tcg_target_long val,
261                                          const TCGArgConstraint *arg_ct)
262 {
263     int ct;
264     ct = arg_ct->ct;
265     if (ct & TCG_CT_CONST)
266         return 1;
267     else if ((ct & TCG_CT_CONST_ZERO) && val == 0)
268         return 1;
269     else if ((ct & TCG_CT_CONST_U16) && val == (uint16_t)val)
270         return 1;
271     else if ((ct & TCG_CT_CONST_S16) && val == (int16_t)val)
272         return 1;
273     else
274         return 0;
275 }
276
277 /* instruction opcodes */
278 enum {
279     OPC_BEQ      = 0x04 << 26,
280     OPC_BNE      = 0x05 << 26,
281     OPC_ADDIU    = 0x09 << 26,
282     OPC_SLTI     = 0x0A << 26,
283     OPC_SLTIU    = 0x0B << 26,
284     OPC_ANDI     = 0x0C << 26,
285     OPC_ORI      = 0x0D << 26,
286     OPC_XORI     = 0x0E << 26,
287     OPC_LUI      = 0x0F << 26,
288     OPC_LB       = 0x20 << 26,
289     OPC_LH       = 0x21 << 26,
290     OPC_LW       = 0x23 << 26,
291     OPC_LBU      = 0x24 << 26,
292     OPC_LHU      = 0x25 << 26,
293     OPC_LWU      = 0x27 << 26,
294     OPC_SB       = 0x28 << 26,
295     OPC_SH       = 0x29 << 26,
296     OPC_SW       = 0x2B << 26,
297
298     OPC_SPECIAL  = 0x00 << 26,
299     OPC_SLL      = OPC_SPECIAL | 0x00,
300     OPC_SRL      = OPC_SPECIAL | 0x02,
301     OPC_SRA      = OPC_SPECIAL | 0x03,
302     OPC_SLLV     = OPC_SPECIAL | 0x04,
303     OPC_SRLV     = OPC_SPECIAL | 0x06,
304     OPC_SRAV     = OPC_SPECIAL | 0x07,
305     OPC_JR       = OPC_SPECIAL | 0x08,
306     OPC_JALR     = OPC_SPECIAL | 0x09,
307     OPC_MFHI     = OPC_SPECIAL | 0x10,
308     OPC_MFLO     = OPC_SPECIAL | 0x12,
309     OPC_MULT     = OPC_SPECIAL | 0x18,
310     OPC_MULTU    = OPC_SPECIAL | 0x19,
311     OPC_DIV      = OPC_SPECIAL | 0x1A,
312     OPC_DIVU     = OPC_SPECIAL | 0x1B,
313     OPC_ADDU     = OPC_SPECIAL | 0x21,
314     OPC_SUBU     = OPC_SPECIAL | 0x23,
315     OPC_AND      = OPC_SPECIAL | 0x24,
316     OPC_OR       = OPC_SPECIAL | 0x25,
317     OPC_XOR      = OPC_SPECIAL | 0x26,
318     OPC_NOR      = OPC_SPECIAL | 0x27,
319     OPC_SLT      = OPC_SPECIAL | 0x2A,
320     OPC_SLTU     = OPC_SPECIAL | 0x2B,
321
322     OPC_SPECIAL3 = 0x1f << 26,
323     OPC_SEB      = OPC_SPECIAL3 | 0x420,
324     OPC_SEH      = OPC_SPECIAL3 | 0x620,
325 };
326
327 /*
328  * Type reg
329  */
330 static inline void tcg_out_opc_reg(TCGContext *s, int opc,
331                                    TCGReg rd, TCGReg rs, TCGReg rt)
332 {
333     int32_t inst;
334
335     inst = opc;
336     inst |= (rs & 0x1F) << 21;
337     inst |= (rt & 0x1F) << 16;
338     inst |= (rd & 0x1F) << 11;
339     tcg_out32(s, inst);
340 }
341
342 /*
343  * Type immediate
344  */
345 static inline void tcg_out_opc_imm(TCGContext *s, int opc,
346                                    TCGReg rt, TCGReg rs, TCGArg imm)
347 {
348     int32_t inst;
349
350     inst = opc;
351     inst |= (rs & 0x1F) << 21;
352     inst |= (rt & 0x1F) << 16;
353     inst |= (imm & 0xffff);
354     tcg_out32(s, inst);
355 }
356
357 /*
358  * Type branch
359  */
360 static inline void tcg_out_opc_br(TCGContext *s, int opc,
361                                   TCGReg rt, TCGReg rs)
362 {
363     /* We pay attention here to not modify the branch target by reading
364        the existing value and using it again. This ensure that caches and
365        memory are kept coherent during retranslation. */
366     uint16_t offset = (uint16_t)(*(uint32_t *) s->code_ptr);
367
368     tcg_out_opc_imm(s, opc, rt, rs, offset);
369 }
370
371 /*
372  * Type sa
373  */
374 static inline void tcg_out_opc_sa(TCGContext *s, int opc,
375                                   TCGReg rd, TCGReg rt, TCGArg sa)
376 {
377     int32_t inst;
378
379     inst = opc;
380     inst |= (rt & 0x1F) << 16;
381     inst |= (rd & 0x1F) << 11;
382     inst |= (sa & 0x1F) <<  6;
383     tcg_out32(s, inst);
384
385 }
386
387 static inline void tcg_out_nop(TCGContext *s)
388 {
389     tcg_out32(s, 0);
390 }
391
392 static inline void tcg_out_mov(TCGContext *s, TCGType type,
393                                TCGReg ret, TCGReg arg)
394 {
395     /* Simple reg-reg move, optimising out the 'do nothing' case */
396     if (ret != arg) {
397         tcg_out_opc_reg(s, OPC_ADDU, ret, arg, TCG_REG_ZERO);
398     }
399 }
400
401 static inline void tcg_out_movi(TCGContext *s, TCGType type,
402                                 TCGReg reg, tcg_target_long arg)
403 {
404     if (arg == (int16_t)arg) {
405         tcg_out_opc_imm(s, OPC_ADDIU, reg, TCG_REG_ZERO, arg);
406     } else if (arg == (uint16_t)arg) {
407         tcg_out_opc_imm(s, OPC_ORI, reg, TCG_REG_ZERO, arg);
408     } else {
409         tcg_out_opc_imm(s, OPC_LUI, reg, 0, arg >> 16);
410         tcg_out_opc_imm(s, OPC_ORI, reg, reg, arg & 0xffff);
411     }
412 }
413
414 static inline void tcg_out_bswap16(TCGContext *s, TCGReg ret, TCGReg arg)
415 {
416     /* ret and arg can't be register at */
417     if (ret == TCG_REG_AT || arg == TCG_REG_AT) {
418         tcg_abort();
419     }
420
421     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_AT, arg, 8);
422     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_AT, TCG_REG_AT, 0x00ff);
423
424     tcg_out_opc_sa(s, OPC_SLL, ret, arg, 8);
425     tcg_out_opc_imm(s, OPC_ANDI, ret, ret, 0xff00);
426     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
427 }
428
429 static inline void tcg_out_bswap16s(TCGContext *s, TCGReg ret, TCGReg arg)
430 {
431     /* ret and arg can't be register at */
432     if (ret == TCG_REG_AT || arg == TCG_REG_AT) {
433         tcg_abort();
434     }
435
436     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_AT, arg, 8);
437     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_AT, TCG_REG_AT, 0xff);
438
439     tcg_out_opc_sa(s, OPC_SLL, ret, arg, 24);
440     tcg_out_opc_sa(s, OPC_SRA, ret, ret, 16);
441     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
442 }
443
444 static inline void tcg_out_bswap32(TCGContext *s, TCGReg ret, TCGReg arg)
445 {
446     /* ret and arg must be different and can't be register at */
447     if (ret == arg || ret == TCG_REG_AT || arg == TCG_REG_AT) {
448         tcg_abort();
449     }
450
451     tcg_out_opc_sa(s, OPC_SLL, ret, arg, 24);
452
453     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_AT, arg, 24);
454     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
455
456     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_AT, arg, 0xff00);
457     tcg_out_opc_sa(s, OPC_SLL, TCG_REG_AT, TCG_REG_AT, 8);
458     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
459
460     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_AT, arg, 8);
461     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_AT, TCG_REG_AT, 0xff00);
462     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
463 }
464
465 static inline void tcg_out_ext8s(TCGContext *s, TCGReg ret, TCGReg arg)
466 {
467 #ifdef _MIPS_ARCH_MIPS32R2
468     tcg_out_opc_reg(s, OPC_SEB, ret, 0, arg);
469 #else
470     tcg_out_opc_sa(s, OPC_SLL, ret, arg, 24);
471     tcg_out_opc_sa(s, OPC_SRA, ret, ret, 24);
472 #endif
473 }
474
475 static inline void tcg_out_ext16s(TCGContext *s, TCGReg ret, TCGReg arg)
476 {
477 #ifdef _MIPS_ARCH_MIPS32R2
478     tcg_out_opc_reg(s, OPC_SEH, ret, 0, arg);
479 #else
480     tcg_out_opc_sa(s, OPC_SLL, ret, arg, 16);
481     tcg_out_opc_sa(s, OPC_SRA, ret, ret, 16);
482 #endif
483 }
484
485 static inline void tcg_out_ldst(TCGContext *s, int opc, TCGArg arg,
486                                 TCGReg arg1, TCGArg arg2)
487 {
488     if (arg2 == (int16_t) arg2) {
489         tcg_out_opc_imm(s, opc, arg, arg1, arg2);
490     } else {
491         tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_AT, arg2);
492         tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_AT, TCG_REG_AT, arg1);
493         tcg_out_opc_imm(s, opc, arg, TCG_REG_AT, 0);
494     }
495 }
496
497 static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg,
498                               TCGReg arg1, tcg_target_long arg2)
499 {
500     tcg_out_ldst(s, OPC_LW, arg, arg1, arg2);
501 }
502
503 static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg,
504                               TCGReg arg1, tcg_target_long arg2)
505 {
506     tcg_out_ldst(s, OPC_SW, arg, arg1, arg2);
507 }
508
509 static inline void tcg_out_addi(TCGContext *s, TCGReg reg, TCGArg val)
510 {
511     if (val == (int16_t)val) {
512         tcg_out_opc_imm(s, OPC_ADDIU, reg, reg, val);
513     } else {
514         tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_AT, val);
515         tcg_out_opc_reg(s, OPC_ADDU, reg, reg, TCG_REG_AT);
516     }
517 }
518
519 /* Helper routines for marshalling helper function arguments into
520  * the correct registers and stack.
521  * arg_num is where we want to put this argument, and is updated to be ready
522  * for the next call. arg is the argument itself. Note that arg_num 0..3 is
523  * real registers, 4+ on stack.
524  *
525  * We provide routines for arguments which are: immediate, 32 bit
526  * value in register, 16 and 8 bit values in register (which must be zero
527  * extended before use) and 64 bit value in a lo:hi register pair.
528  */
529 #define DEFINE_TCG_OUT_CALL_IARG(NAME, ARGPARAM)                               \
530     static inline void NAME(TCGContext *s, int *arg_num, ARGPARAM)             \
531     {                                                                          \
532     if (*arg_num < 4) {                                                        \
533         DEFINE_TCG_OUT_CALL_IARG_GET_ARG(tcg_target_call_iarg_regs[*arg_num]); \
534     } else {                                                                   \
535         DEFINE_TCG_OUT_CALL_IARG_GET_ARG(TCG_REG_AT);                          \
536         tcg_out_st(s, TCG_TYPE_I32, TCG_REG_AT, TCG_REG_SP, 4 * (*arg_num));   \
537     }                                                                          \
538     (*arg_num)++;                                                              \
539 }
540 #define DEFINE_TCG_OUT_CALL_IARG_GET_ARG(A) \
541     tcg_out_opc_imm(s, OPC_ANDI, A, arg, 0xff);
542 DEFINE_TCG_OUT_CALL_IARG(tcg_out_call_iarg_reg8, TCGReg arg)
543 #undef DEFINE_TCG_OUT_CALL_IARG_GET_ARG
544 #define DEFINE_TCG_OUT_CALL_IARG_GET_ARG(A) \
545     tcg_out_opc_imm(s, OPC_ANDI, A, arg, 0xffff);
546 DEFINE_TCG_OUT_CALL_IARG(tcg_out_call_iarg_reg16, TCGReg arg)
547 #undef DEFINE_TCG_OUT_CALL_IARG_GET_ARG
548 #define DEFINE_TCG_OUT_CALL_IARG_GET_ARG(A) \
549     tcg_out_movi(s, TCG_TYPE_I32, A, arg);
550 DEFINE_TCG_OUT_CALL_IARG(tcg_out_call_iarg_imm32, TCGArg arg)
551 #undef DEFINE_TCG_OUT_CALL_IARG_GET_ARG
552
553 /* We don't use the macro for this one to avoid an unnecessary reg-reg
554    move when storing to the stack. */
555 static inline void tcg_out_call_iarg_reg32(TCGContext *s, int *arg_num,
556                                            TCGReg arg)
557 {
558     if (*arg_num < 4) {
559         tcg_out_mov(s, TCG_TYPE_I32, tcg_target_call_iarg_regs[*arg_num], arg);
560     } else {
561         tcg_out_st(s, TCG_TYPE_I32, arg, TCG_REG_SP, 4 * (*arg_num));
562     }
563     (*arg_num)++;
564 }
565
566 static inline void tcg_out_call_iarg_reg64(TCGContext *s, int *arg_num,
567                                            TCGReg arg_low, TCGReg arg_high)
568 {
569     (*arg_num) = (*arg_num + 1) & ~1;
570
571 #if defined(TCG_TARGET_WORDS_BIGENDIAN)
572     tcg_out_call_iarg_reg32(s, arg_num, arg_high);
573     tcg_out_call_iarg_reg32(s, arg_num, arg_low);
574 #else
575     tcg_out_call_iarg_reg32(s, arg_num, arg_low);
576     tcg_out_call_iarg_reg32(s, arg_num, arg_high);
577 #endif
578 }
579
580 static void tcg_out_brcond(TCGContext *s, TCGCond cond, TCGArg arg1,
581                            TCGArg arg2, int label_index)
582 {
583     TCGLabel *l = &s->labels[label_index];
584
585     switch (cond) {
586     case TCG_COND_EQ:
587         tcg_out_opc_br(s, OPC_BEQ, arg1, arg2);
588         break;
589     case TCG_COND_NE:
590         tcg_out_opc_br(s, OPC_BNE, arg1, arg2);
591         break;
592     case TCG_COND_LT:
593         tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
594         tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
595         break;
596     case TCG_COND_LTU:
597         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg1, arg2);
598         tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
599         break;
600     case TCG_COND_GE:
601         tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg1, arg2);
602         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
603         break;
604     case TCG_COND_GEU:
605         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg1, arg2);
606         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
607         break;
608     case TCG_COND_LE:
609         tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
610         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
611         break;
612     case TCG_COND_LEU:
613         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg2, arg1);
614         tcg_out_opc_br(s, OPC_BEQ, TCG_REG_AT, TCG_REG_ZERO);
615         break;
616     case TCG_COND_GT:
617         tcg_out_opc_reg(s, OPC_SLT, TCG_REG_AT, arg2, arg1);
618         tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
619         break;
620     case TCG_COND_GTU:
621         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_AT, arg2, arg1);
622         tcg_out_opc_br(s, OPC_BNE, TCG_REG_AT, TCG_REG_ZERO);
623         break;
624     default:
625         tcg_abort();
626         break;
627     }
628     if (l->has_value) {
629         reloc_pc16(s->code_ptr - 4, l->u.value);
630     } else {
631         tcg_out_reloc(s, s->code_ptr - 4, R_MIPS_PC16, label_index, 0);
632     }
633     tcg_out_nop(s);
634 }
635
636 /* XXX: we implement it at the target level to avoid having to
637    handle cross basic blocks temporaries */
638 static void tcg_out_brcond2(TCGContext *s, TCGCond cond, TCGArg arg1,
639                             TCGArg arg2, TCGArg arg3, TCGArg arg4,
640                             int label_index)
641 {
642     void *label_ptr;
643
644     switch(cond) {
645     case TCG_COND_NE:
646         tcg_out_brcond(s, TCG_COND_NE, arg2, arg4, label_index);
647         tcg_out_brcond(s, TCG_COND_NE, arg1, arg3, label_index);
648         return;
649     case TCG_COND_EQ:
650         break;
651     case TCG_COND_LT:
652     case TCG_COND_LE:
653         tcg_out_brcond(s, TCG_COND_LT, arg2, arg4, label_index);
654         break;
655     case TCG_COND_GT:
656     case TCG_COND_GE:
657         tcg_out_brcond(s, TCG_COND_GT, arg2, arg4, label_index);
658         break;
659     case TCG_COND_LTU:
660     case TCG_COND_LEU:
661         tcg_out_brcond(s, TCG_COND_LTU, arg2, arg4, label_index);
662         break;
663     case TCG_COND_GTU:
664     case TCG_COND_GEU:
665         tcg_out_brcond(s, TCG_COND_GTU, arg2, arg4, label_index);
666         break;
667     default:
668         tcg_abort();
669     }
670
671     label_ptr = s->code_ptr;
672     tcg_out_opc_br(s, OPC_BNE, arg2, arg4);
673     tcg_out_nop(s);
674
675     switch(cond) {
676     case TCG_COND_EQ:
677         tcg_out_brcond(s, TCG_COND_EQ, arg1, arg3, label_index);
678         break;
679     case TCG_COND_LT:
680     case TCG_COND_LTU:
681         tcg_out_brcond(s, TCG_COND_LTU, arg1, arg3, label_index);
682         break;
683     case TCG_COND_LE:
684     case TCG_COND_LEU:
685         tcg_out_brcond(s, TCG_COND_LEU, arg1, arg3, label_index);
686         break;
687     case TCG_COND_GT:
688     case TCG_COND_GTU:
689         tcg_out_brcond(s, TCG_COND_GTU, arg1, arg3, label_index);
690         break;
691     case TCG_COND_GE:
692     case TCG_COND_GEU:
693         tcg_out_brcond(s, TCG_COND_GEU, arg1, arg3, label_index);
694         break;
695     default:
696         tcg_abort();
697     }
698
699     reloc_pc16(label_ptr, (tcg_target_long) s->code_ptr);
700 }
701
702 static void tcg_out_setcond(TCGContext *s, TCGCond cond, TCGReg ret,
703                             TCGArg arg1, TCGArg arg2)
704 {
705     switch (cond) {
706     case TCG_COND_EQ:
707         if (arg1 == 0) {
708             tcg_out_opc_imm(s, OPC_SLTIU, ret, arg2, 1);
709         } else if (arg2 == 0) {
710             tcg_out_opc_imm(s, OPC_SLTIU, ret, arg1, 1);
711         } else {
712             tcg_out_opc_reg(s, OPC_XOR, ret, arg1, arg2);
713             tcg_out_opc_imm(s, OPC_SLTIU, ret, ret, 1);
714         }
715         break;
716     case TCG_COND_NE:
717         if (arg1 == 0) {
718             tcg_out_opc_reg(s, OPC_SLTU, ret, TCG_REG_ZERO, arg2);
719         } else if (arg2 == 0) {
720             tcg_out_opc_reg(s, OPC_SLTU, ret, TCG_REG_ZERO, arg1);
721         } else {
722             tcg_out_opc_reg(s, OPC_XOR, ret, arg1, arg2);
723             tcg_out_opc_reg(s, OPC_SLTU, ret, TCG_REG_ZERO, ret);
724         }
725         break;
726     case TCG_COND_LT:
727         tcg_out_opc_reg(s, OPC_SLT, ret, arg1, arg2);
728         break;
729     case TCG_COND_LTU:
730         tcg_out_opc_reg(s, OPC_SLTU, ret, arg1, arg2);
731         break;
732     case TCG_COND_GE:
733         tcg_out_opc_reg(s, OPC_SLT, ret, arg1, arg2);
734         tcg_out_opc_imm(s, OPC_XORI, ret, ret, 1);
735         break;
736     case TCG_COND_GEU:
737         tcg_out_opc_reg(s, OPC_SLTU, ret, arg1, arg2);
738         tcg_out_opc_imm(s, OPC_XORI, ret, ret, 1);
739         break;
740     case TCG_COND_LE:
741         tcg_out_opc_reg(s, OPC_SLT, ret, arg2, arg1);
742         tcg_out_opc_imm(s, OPC_XORI, ret, ret, 1);
743         break;
744     case TCG_COND_LEU:
745         tcg_out_opc_reg(s, OPC_SLTU, ret, arg2, arg1);
746         tcg_out_opc_imm(s, OPC_XORI, ret, ret, 1);
747         break;
748     case TCG_COND_GT:
749         tcg_out_opc_reg(s, OPC_SLT, ret, arg2, arg1);
750         break;
751     case TCG_COND_GTU:
752         tcg_out_opc_reg(s, OPC_SLTU, ret, arg2, arg1);
753         break;
754     default:
755         tcg_abort();
756         break;
757     }
758 }
759
760 /* XXX: we implement it at the target level to avoid having to
761    handle cross basic blocks temporaries */
762 static void tcg_out_setcond2(TCGContext *s, TCGCond cond, TCGReg ret,
763                              TCGArg arg1, TCGArg arg2, TCGArg arg3, TCGArg arg4)
764 {
765     switch (cond) {
766     case TCG_COND_EQ:
767         tcg_out_setcond(s, TCG_COND_EQ, TCG_REG_AT, arg2, arg4);
768         tcg_out_setcond(s, TCG_COND_EQ, TCG_REG_T0, arg1, arg3);
769         tcg_out_opc_reg(s, OPC_AND, ret, TCG_REG_AT, TCG_REG_T0);
770         return;
771     case TCG_COND_NE:
772         tcg_out_setcond(s, TCG_COND_NE, TCG_REG_AT, arg2, arg4);
773         tcg_out_setcond(s, TCG_COND_NE, TCG_REG_T0, arg1, arg3);
774         tcg_out_opc_reg(s, OPC_OR, ret, TCG_REG_AT, TCG_REG_T0);
775         return;
776     case TCG_COND_LT:
777     case TCG_COND_LE:
778         tcg_out_setcond(s, TCG_COND_LT, TCG_REG_AT, arg2, arg4);
779         break;
780     case TCG_COND_GT:
781     case TCG_COND_GE:
782         tcg_out_setcond(s, TCG_COND_GT, TCG_REG_AT, arg2, arg4);
783         break;
784     case TCG_COND_LTU:
785     case TCG_COND_LEU:
786         tcg_out_setcond(s, TCG_COND_LTU, TCG_REG_AT, arg2, arg4);
787         break;
788     case TCG_COND_GTU:
789     case TCG_COND_GEU:
790         tcg_out_setcond(s, TCG_COND_GTU, TCG_REG_AT, arg2, arg4);
791         break;
792     default:
793         tcg_abort();
794         break;
795     }
796
797     tcg_out_setcond(s, TCG_COND_EQ, TCG_REG_T0, arg2, arg4);
798
799     switch(cond) {
800     case TCG_COND_LT:
801     case TCG_COND_LTU:
802         tcg_out_setcond(s, TCG_COND_LTU, ret, arg1, arg3);
803         break;
804     case TCG_COND_LE:
805     case TCG_COND_LEU:
806         tcg_out_setcond(s, TCG_COND_LEU, ret, arg1, arg3);
807         break;
808     case TCG_COND_GT:
809     case TCG_COND_GTU:
810         tcg_out_setcond(s, TCG_COND_GTU, ret, arg1, arg3);
811         break;
812     case TCG_COND_GE:
813     case TCG_COND_GEU:
814         tcg_out_setcond(s, TCG_COND_GEU, ret, arg1, arg3);
815         break;
816     default:
817         tcg_abort();
818     }
819
820     tcg_out_opc_reg(s, OPC_AND, ret, ret, TCG_REG_T0);
821     tcg_out_opc_reg(s, OPC_OR, ret, ret, TCG_REG_AT);
822 }
823
824 #if defined(CONFIG_SOFTMMU)
825
826 #include "../../softmmu_defs.h"
827
828 /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
829    int mmu_idx) */
830 static const void * const qemu_ld_helpers[4] = {
831     helper_ldb_mmu,
832     helper_ldw_mmu,
833     helper_ldl_mmu,
834     helper_ldq_mmu,
835 };
836
837 /* helper signature: helper_st_mmu(CPUState *env, target_ulong addr,
838    uintxx_t val, int mmu_idx) */
839 static const void * const qemu_st_helpers[4] = {
840     helper_stb_mmu,
841     helper_stw_mmu,
842     helper_stl_mmu,
843     helper_stq_mmu,
844 };
845 #endif
846
847 static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args,
848                             int opc)
849 {
850     TCGReg addr_regl, data_regl, data_regh, data_reg1, data_reg2;
851 #if defined(CONFIG_SOFTMMU)
852     void *label1_ptr, *label2_ptr;
853     int arg_num;
854     int mem_index, s_bits;
855     int addr_meml;
856 # if TARGET_LONG_BITS == 64
857     uint8_t *label3_ptr;
858     TCGReg addr_regh;
859     int addr_memh;
860 # endif
861 #endif
862     data_regl = *args++;
863     if (opc == 3)
864         data_regh = *args++;
865     else
866         data_regh = 0;
867     addr_regl = *args++;
868 #if defined(CONFIG_SOFTMMU)
869 # if TARGET_LONG_BITS == 64
870     addr_regh = *args++;
871 #  if defined(TCG_TARGET_WORDS_BIGENDIAN)
872     addr_memh = 0;
873     addr_meml = 4;
874 #  else
875     addr_memh = 4;
876     addr_meml = 0;
877 #  endif
878 # else
879     addr_meml = 0;
880 # endif
881     mem_index = *args;
882     s_bits = opc & 3;
883 #endif
884
885     if (opc == 3) {
886 #if defined(TCG_TARGET_WORDS_BIGENDIAN)
887         data_reg1 = data_regh;
888         data_reg2 = data_regl;
889 #else
890         data_reg1 = data_regl;
891         data_reg2 = data_regh;
892 #endif
893     } else {
894         data_reg1 = data_regl;
895         data_reg2 = 0;
896     }
897 #if defined(CONFIG_SOFTMMU)
898     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_A0, addr_regl, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS);
899     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_A0, TCG_REG_A0, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
900     tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, TCG_AREG0);
901     tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
902                     offsetof(CPUArchState, tlb_table[mem_index][0].addr_read) + addr_meml);
903     tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T0, TARGET_PAGE_MASK | ((1 << s_bits) - 1));
904     tcg_out_opc_reg(s, OPC_AND, TCG_REG_T0, TCG_REG_T0, addr_regl);
905
906 # if TARGET_LONG_BITS == 64
907     label3_ptr = s->code_ptr;
908     tcg_out_opc_br(s, OPC_BNE, TCG_REG_T0, TCG_REG_AT);
909     tcg_out_nop(s);
910
911     tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
912                     offsetof(CPUArchState, tlb_table[mem_index][0].addr_read) + addr_memh);
913
914     label1_ptr = s->code_ptr;
915     tcg_out_opc_br(s, OPC_BEQ, addr_regh, TCG_REG_AT);
916     tcg_out_nop(s);
917
918     reloc_pc16(label3_ptr, (tcg_target_long) s->code_ptr);
919 # else
920     label1_ptr = s->code_ptr;
921     tcg_out_opc_br(s, OPC_BEQ, TCG_REG_T0, TCG_REG_AT);
922     tcg_out_nop(s);
923 # endif
924
925     /* slow path */
926     arg_num = 0;
927     tcg_out_call_iarg_reg32(s, &arg_num, TCG_AREG0);
928 # if TARGET_LONG_BITS == 64
929     tcg_out_call_iarg_reg64(s, &arg_num, addr_regl, addr_regh);
930 # else
931     tcg_out_call_iarg_reg32(s, &arg_num, addr_regl);
932 # endif
933     tcg_out_call_iarg_imm32(s, &arg_num, mem_index);
934     tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T9, (tcg_target_long)qemu_ld_helpers[s_bits]);
935     tcg_out_opc_reg(s, OPC_JALR, TCG_REG_RA, TCG_REG_T9, 0);
936     tcg_out_nop(s);
937
938     switch(opc) {
939     case 0:
940         tcg_out_opc_imm(s, OPC_ANDI, data_reg1, TCG_REG_V0, 0xff);
941         break;
942     case 0 | 4:
943         tcg_out_ext8s(s, data_reg1, TCG_REG_V0);
944         break;
945     case 1:
946         tcg_out_opc_imm(s, OPC_ANDI, data_reg1, TCG_REG_V0, 0xffff);
947         break;
948     case 1 | 4:
949         tcg_out_ext16s(s, data_reg1, TCG_REG_V0);
950         break;
951     case 2:
952         tcg_out_mov(s, TCG_TYPE_I32, data_reg1, TCG_REG_V0);
953         break;
954     case 3:
955         tcg_out_mov(s, TCG_TYPE_I32, data_reg2, TCG_REG_V1);
956         tcg_out_mov(s, TCG_TYPE_I32, data_reg1, TCG_REG_V0);
957         break;
958     default:
959         tcg_abort();
960     }
961
962     label2_ptr = s->code_ptr;
963     tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO);
964     tcg_out_nop(s);
965
966     /* label1: fast path */
967     reloc_pc16(label1_ptr, (tcg_target_long) s->code_ptr);
968
969     tcg_out_opc_imm(s, OPC_LW, TCG_REG_A0, TCG_REG_A0,
970                     offsetof(CPUArchState, tlb_table[mem_index][0].addend));
971     tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_V0, TCG_REG_A0, addr_regl);
972 #else
973     if (GUEST_BASE == (int16_t)GUEST_BASE) {
974         tcg_out_opc_imm(s, OPC_ADDIU, TCG_REG_V0, addr_regl, GUEST_BASE);
975     } else {
976         tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_V0, GUEST_BASE);
977         tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_V0, TCG_REG_V0, addr_regl);
978     }
979 #endif
980
981     switch(opc) {
982     case 0:
983         tcg_out_opc_imm(s, OPC_LBU, data_reg1, TCG_REG_V0, 0);
984         break;
985     case 0 | 4:
986         tcg_out_opc_imm(s, OPC_LB, data_reg1, TCG_REG_V0, 0);
987         break;
988     case 1:
989         if (TCG_NEED_BSWAP) {
990             tcg_out_opc_imm(s, OPC_LHU, TCG_REG_T0, TCG_REG_V0, 0);
991             tcg_out_bswap16(s, data_reg1, TCG_REG_T0);
992         } else {
993             tcg_out_opc_imm(s, OPC_LHU, data_reg1, TCG_REG_V0, 0);
994         }
995         break;
996     case 1 | 4:
997         if (TCG_NEED_BSWAP) {
998             tcg_out_opc_imm(s, OPC_LHU, TCG_REG_T0, TCG_REG_V0, 0);
999             tcg_out_bswap16s(s, data_reg1, TCG_REG_T0);
1000         } else {
1001             tcg_out_opc_imm(s, OPC_LH, data_reg1, TCG_REG_V0, 0);
1002         }
1003         break;
1004     case 2:
1005         if (TCG_NEED_BSWAP) {
1006             tcg_out_opc_imm(s, OPC_LW, TCG_REG_T0, TCG_REG_V0, 0);
1007             tcg_out_bswap32(s, data_reg1, TCG_REG_T0);
1008         } else {
1009             tcg_out_opc_imm(s, OPC_LW, data_reg1, TCG_REG_V0, 0);
1010         }
1011         break;
1012     case 3:
1013         if (TCG_NEED_BSWAP) {
1014             tcg_out_opc_imm(s, OPC_LW, TCG_REG_T0, TCG_REG_V0, 4);
1015             tcg_out_bswap32(s, data_reg1, TCG_REG_T0);
1016             tcg_out_opc_imm(s, OPC_LW, TCG_REG_T0, TCG_REG_V0, 0);
1017             tcg_out_bswap32(s, data_reg2, TCG_REG_T0);
1018         } else {
1019             tcg_out_opc_imm(s, OPC_LW, data_reg1, TCG_REG_V0, 0);
1020             tcg_out_opc_imm(s, OPC_LW, data_reg2, TCG_REG_V0, 4);
1021         }
1022         break;
1023     default:
1024         tcg_abort();
1025     }
1026
1027 #if defined(CONFIG_SOFTMMU)
1028     reloc_pc16(label2_ptr, (tcg_target_long) s->code_ptr);
1029 #endif
1030 }
1031
1032 static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args,
1033                             int opc)
1034 {
1035     TCGReg addr_regl, data_regl, data_regh, data_reg1, data_reg2;
1036 #if defined(CONFIG_SOFTMMU)
1037     uint8_t *label1_ptr, *label2_ptr;
1038     int arg_num;
1039     int mem_index, s_bits;
1040     int addr_meml;
1041 #endif
1042 #if TARGET_LONG_BITS == 64
1043 # if defined(CONFIG_SOFTMMU)
1044     uint8_t *label3_ptr;
1045     TCGReg addr_regh;
1046     int addr_memh;
1047 # endif
1048 #endif
1049     data_regl = *args++;
1050     if (opc == 3) {
1051         data_regh = *args++;
1052     } else {
1053         data_regh = 0;
1054     }
1055     addr_regl = *args++;
1056 #if defined(CONFIG_SOFTMMU)
1057 # if TARGET_LONG_BITS == 64
1058     addr_regh = *args++;
1059 #  if defined(TCG_TARGET_WORDS_BIGENDIAN)
1060     addr_memh = 0;
1061     addr_meml = 4;
1062 #  else
1063     addr_memh = 4;
1064     addr_meml = 0;
1065 #  endif
1066 # else
1067     addr_meml = 0;
1068 # endif
1069     mem_index = *args;
1070     s_bits = opc;
1071 #endif
1072
1073     if (opc == 3) {
1074 #if defined(TCG_TARGET_WORDS_BIGENDIAN)
1075         data_reg1 = data_regh;
1076         data_reg2 = data_regl;
1077 #else
1078         data_reg1 = data_regl;
1079         data_reg2 = data_regh;
1080 #endif
1081     } else {
1082         data_reg1 = data_regl;
1083         data_reg2 = 0;
1084     }
1085
1086 #if defined(CONFIG_SOFTMMU)
1087     tcg_out_opc_sa(s, OPC_SRL, TCG_REG_A0, addr_regl, TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS);
1088     tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_A0, TCG_REG_A0, (CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS);
1089     tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, TCG_AREG0);
1090     tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
1091                     offsetof(CPUArchState, tlb_table[mem_index][0].addr_write) + addr_meml);
1092     tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T0, TARGET_PAGE_MASK | ((1 << s_bits) - 1));
1093     tcg_out_opc_reg(s, OPC_AND, TCG_REG_T0, TCG_REG_T0, addr_regl);
1094
1095 # if TARGET_LONG_BITS == 64
1096     label3_ptr = s->code_ptr;
1097     tcg_out_opc_br(s, OPC_BNE, TCG_REG_T0, TCG_REG_AT);
1098     tcg_out_nop(s);
1099
1100     tcg_out_opc_imm(s, OPC_LW, TCG_REG_AT, TCG_REG_A0,
1101                     offsetof(CPUArchState, tlb_table[mem_index][0].addr_write) + addr_memh);
1102
1103     label1_ptr = s->code_ptr;
1104     tcg_out_opc_br(s, OPC_BEQ, addr_regh, TCG_REG_AT);
1105     tcg_out_nop(s);
1106
1107     reloc_pc16(label3_ptr, (tcg_target_long) s->code_ptr);
1108 # else
1109     label1_ptr = s->code_ptr;
1110     tcg_out_opc_br(s, OPC_BEQ, TCG_REG_T0, TCG_REG_AT);
1111     tcg_out_nop(s);
1112 # endif
1113
1114     /* slow path */
1115     arg_num = 0;
1116     tcg_out_call_iarg_reg32(s, &arg_num, TCG_AREG0);
1117 # if TARGET_LONG_BITS == 64
1118     tcg_out_call_iarg_reg64(s, &arg_num, addr_regl, addr_regh);
1119 # else
1120     tcg_out_call_iarg_reg32(s, &arg_num, addr_regl);
1121 # endif
1122     switch(opc) {
1123     case 0:
1124         tcg_out_call_iarg_reg8(s, &arg_num, data_regl);
1125         break;
1126     case 1:
1127         tcg_out_call_iarg_reg16(s, &arg_num, data_regl);
1128         break;
1129     case 2:
1130         tcg_out_call_iarg_reg32(s, &arg_num, data_regl);
1131         break;
1132     case 3:
1133         tcg_out_call_iarg_reg64(s, &arg_num, data_regl, data_regh);
1134         break;
1135     default:
1136         tcg_abort();
1137     }
1138     tcg_out_call_iarg_imm32(s, &arg_num, mem_index);
1139     tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T9, (tcg_target_long)qemu_st_helpers[s_bits]);
1140     tcg_out_opc_reg(s, OPC_JALR, TCG_REG_RA, TCG_REG_T9, 0);
1141     tcg_out_nop(s);
1142
1143     label2_ptr = s->code_ptr;
1144     tcg_out_opc_br(s, OPC_BEQ, TCG_REG_ZERO, TCG_REG_ZERO);
1145     tcg_out_nop(s);
1146
1147     /* label1: fast path */
1148     reloc_pc16(label1_ptr, (tcg_target_long) s->code_ptr);
1149
1150     tcg_out_opc_imm(s, OPC_LW, TCG_REG_A0, TCG_REG_A0,
1151                     offsetof(CPUArchState, tlb_table[mem_index][0].addend));
1152     tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, addr_regl);
1153 #else
1154     if (GUEST_BASE == (int16_t)GUEST_BASE) {
1155         tcg_out_opc_imm(s, OPC_ADDIU, TCG_REG_A0, addr_regl, GUEST_BASE);
1156     } else {
1157         tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_A0, GUEST_BASE);
1158         tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_A0, TCG_REG_A0, addr_regl);
1159     }
1160
1161 #endif
1162
1163     switch(opc) {
1164     case 0:
1165         tcg_out_opc_imm(s, OPC_SB, data_reg1, TCG_REG_A0, 0);
1166         break;
1167     case 1:
1168         if (TCG_NEED_BSWAP) {
1169             tcg_out_bswap16(s, TCG_REG_T0, data_reg1);
1170             tcg_out_opc_imm(s, OPC_SH, TCG_REG_T0, TCG_REG_A0, 0);
1171         } else {
1172             tcg_out_opc_imm(s, OPC_SH, data_reg1, TCG_REG_A0, 0);
1173         }
1174         break;
1175     case 2:
1176         if (TCG_NEED_BSWAP) {
1177             tcg_out_bswap32(s, TCG_REG_T0, data_reg1);
1178             tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 0);
1179         } else {
1180             tcg_out_opc_imm(s, OPC_SW, data_reg1, TCG_REG_A0, 0);
1181         }
1182         break;
1183     case 3:
1184         if (TCG_NEED_BSWAP) {
1185             tcg_out_bswap32(s, TCG_REG_T0, data_reg2);
1186             tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 0);
1187             tcg_out_bswap32(s, TCG_REG_T0, data_reg1);
1188             tcg_out_opc_imm(s, OPC_SW, TCG_REG_T0, TCG_REG_A0, 4);
1189         } else {
1190             tcg_out_opc_imm(s, OPC_SW, data_reg1, TCG_REG_A0, 0);
1191             tcg_out_opc_imm(s, OPC_SW, data_reg2, TCG_REG_A0, 4);
1192         }
1193         break;
1194     default:
1195         tcg_abort();
1196     }
1197
1198 #if defined(CONFIG_SOFTMMU)
1199     reloc_pc16(label2_ptr, (tcg_target_long) s->code_ptr);
1200 #endif
1201 }
1202
1203 static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
1204                               const TCGArg *args, const int *const_args)
1205 {
1206     switch(opc) {
1207     case INDEX_op_exit_tb:
1208         tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_V0, args[0]);
1209         tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_AT, (tcg_target_long)tb_ret_addr);
1210         tcg_out_opc_reg(s, OPC_JR, 0, TCG_REG_AT, 0);
1211         tcg_out_nop(s);
1212         break;
1213     case INDEX_op_goto_tb:
1214         if (s->tb_jmp_offset) {
1215             /* direct jump method */
1216             tcg_abort();
1217         } else {
1218             /* indirect jump method */
1219             tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_AT, (tcg_target_long)(s->tb_next + args[0]));
1220             tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_AT, TCG_REG_AT, 0);
1221             tcg_out_opc_reg(s, OPC_JR, 0, TCG_REG_AT, 0);
1222         }
1223         tcg_out_nop(s);
1224         s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf;
1225         break;
1226     case INDEX_op_call:
1227         tcg_out_opc_reg(s, OPC_JALR, TCG_REG_RA, args[0], 0);
1228         tcg_out_nop(s);
1229         break;
1230     case INDEX_op_jmp:
1231         tcg_out_opc_reg(s, OPC_JR, 0, args[0], 0);
1232         tcg_out_nop(s);
1233         break;
1234     case INDEX_op_br:
1235         tcg_out_brcond(s, TCG_COND_EQ, TCG_REG_ZERO, TCG_REG_ZERO, args[0]);
1236         break;
1237
1238     case INDEX_op_mov_i32:
1239         tcg_out_mov(s, TCG_TYPE_I32, args[0], args[1]);
1240         break;
1241     case INDEX_op_movi_i32:
1242         tcg_out_movi(s, TCG_TYPE_I32, args[0], args[1]);
1243         break;
1244
1245     case INDEX_op_ld8u_i32:
1246         tcg_out_ldst(s, OPC_LBU, args[0], args[1], args[2]);
1247         break;
1248     case INDEX_op_ld8s_i32:
1249         tcg_out_ldst(s, OPC_LB, args[0], args[1], args[2]);
1250         break;
1251     case INDEX_op_ld16u_i32:
1252         tcg_out_ldst(s, OPC_LHU, args[0], args[1], args[2]);
1253         break;
1254     case INDEX_op_ld16s_i32:
1255         tcg_out_ldst(s, OPC_LH, args[0], args[1], args[2]);
1256         break;
1257     case INDEX_op_ld_i32:
1258         tcg_out_ldst(s, OPC_LW, args[0], args[1], args[2]);
1259         break;
1260     case INDEX_op_st8_i32:
1261         tcg_out_ldst(s, OPC_SB, args[0], args[1], args[2]);
1262         break;
1263     case INDEX_op_st16_i32:
1264         tcg_out_ldst(s, OPC_SH, args[0], args[1], args[2]);
1265         break;
1266     case INDEX_op_st_i32:
1267         tcg_out_ldst(s, OPC_SW, args[0], args[1], args[2]);
1268         break;
1269
1270     case INDEX_op_add_i32:
1271         if (const_args[2]) {
1272             tcg_out_opc_imm(s, OPC_ADDIU, args[0], args[1], args[2]);
1273         } else {
1274             tcg_out_opc_reg(s, OPC_ADDU, args[0], args[1], args[2]);
1275         }
1276         break;
1277     case INDEX_op_add2_i32:
1278         if (const_args[4]) {
1279             tcg_out_opc_imm(s, OPC_ADDIU, TCG_REG_AT, args[2], args[4]);
1280         } else {
1281             tcg_out_opc_reg(s, OPC_ADDU, TCG_REG_AT, args[2], args[4]);
1282         }
1283         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_T0, TCG_REG_AT, args[2]);
1284         if (const_args[5]) {
1285             tcg_out_opc_imm(s, OPC_ADDIU, args[1], args[3], args[5]);
1286         } else {
1287              tcg_out_opc_reg(s, OPC_ADDU, args[1], args[3], args[5]);
1288         }
1289         tcg_out_opc_reg(s, OPC_ADDU, args[1], args[1], TCG_REG_T0);
1290         tcg_out_mov(s, TCG_TYPE_I32, args[0], TCG_REG_AT);
1291         break;
1292     case INDEX_op_sub_i32:
1293         if (const_args[2]) {
1294             tcg_out_opc_imm(s, OPC_ADDIU, args[0], args[1], -args[2]);
1295         } else {
1296             tcg_out_opc_reg(s, OPC_SUBU, args[0], args[1], args[2]);
1297         }
1298         break;
1299     case INDEX_op_sub2_i32:
1300         if (const_args[4]) {
1301             tcg_out_opc_imm(s, OPC_ADDIU, TCG_REG_AT, args[2], -args[4]);
1302         } else {
1303             tcg_out_opc_reg(s, OPC_SUBU, TCG_REG_AT, args[2], args[4]);
1304         }
1305         tcg_out_opc_reg(s, OPC_SLTU, TCG_REG_T0, args[2], TCG_REG_AT);
1306         if (const_args[5]) {
1307             tcg_out_opc_imm(s, OPC_ADDIU, args[1], args[3], -args[5]);
1308         } else {
1309              tcg_out_opc_reg(s, OPC_SUBU, args[1], args[3], args[5]);
1310         }
1311         tcg_out_opc_reg(s, OPC_SUBU, args[1], args[1], TCG_REG_T0);
1312         tcg_out_mov(s, TCG_TYPE_I32, args[0], TCG_REG_AT);
1313         break;
1314     case INDEX_op_mul_i32:
1315         tcg_out_opc_reg(s, OPC_MULT, 0, args[1], args[2]);
1316         tcg_out_opc_reg(s, OPC_MFLO, args[0], 0, 0);
1317         break;
1318     case INDEX_op_mulu2_i32:
1319         tcg_out_opc_reg(s, OPC_MULTU, 0, args[2], args[3]);
1320         tcg_out_opc_reg(s, OPC_MFLO, args[0], 0, 0);
1321         tcg_out_opc_reg(s, OPC_MFHI, args[1], 0, 0);
1322         break;
1323     case INDEX_op_div_i32:
1324         tcg_out_opc_reg(s, OPC_DIV, 0, args[1], args[2]);
1325         tcg_out_opc_reg(s, OPC_MFLO, args[0], 0, 0);
1326         break;
1327     case INDEX_op_divu_i32:
1328         tcg_out_opc_reg(s, OPC_DIVU, 0, args[1], args[2]);
1329         tcg_out_opc_reg(s, OPC_MFLO, args[0], 0, 0);
1330         break;
1331     case INDEX_op_rem_i32:
1332         tcg_out_opc_reg(s, OPC_DIV, 0, args[1], args[2]);
1333         tcg_out_opc_reg(s, OPC_MFHI, args[0], 0, 0);
1334         break;
1335     case INDEX_op_remu_i32:
1336         tcg_out_opc_reg(s, OPC_DIVU, 0, args[1], args[2]);
1337         tcg_out_opc_reg(s, OPC_MFHI, args[0], 0, 0);
1338         break;
1339
1340     case INDEX_op_and_i32:
1341         if (const_args[2]) {
1342             tcg_out_opc_imm(s, OPC_ANDI, args[0], args[1], args[2]);
1343         } else {
1344             tcg_out_opc_reg(s, OPC_AND, args[0], args[1], args[2]);
1345         }
1346         break;
1347     case INDEX_op_or_i32:
1348         if (const_args[2]) {
1349             tcg_out_opc_imm(s, OPC_ORI, args[0], args[1], args[2]);
1350         } else {
1351             tcg_out_opc_reg(s, OPC_OR, args[0], args[1], args[2]);
1352         }
1353         break;
1354     case INDEX_op_nor_i32:
1355         tcg_out_opc_reg(s, OPC_NOR, args[0], args[1], args[2]);
1356         break;
1357     case INDEX_op_not_i32:
1358         tcg_out_opc_reg(s, OPC_NOR, args[0], TCG_REG_ZERO, args[1]);
1359         break;
1360     case INDEX_op_xor_i32:
1361         if (const_args[2]) {
1362             tcg_out_opc_imm(s, OPC_XORI, args[0], args[1], args[2]);
1363         } else {
1364             tcg_out_opc_reg(s, OPC_XOR, args[0], args[1], args[2]);
1365         }
1366         break;
1367
1368     case INDEX_op_sar_i32:
1369         if (const_args[2]) {
1370             tcg_out_opc_sa(s, OPC_SRA, args[0], args[1], args[2]);
1371         } else {
1372             tcg_out_opc_reg(s, OPC_SRAV, args[0], args[2], args[1]);
1373         }
1374         break;
1375     case INDEX_op_shl_i32:
1376         if (const_args[2]) {
1377             tcg_out_opc_sa(s, OPC_SLL, args[0], args[1], args[2]);
1378         } else {
1379             tcg_out_opc_reg(s, OPC_SLLV, args[0], args[2], args[1]);
1380         }
1381         break;
1382     case INDEX_op_shr_i32:
1383         if (const_args[2]) {
1384             tcg_out_opc_sa(s, OPC_SRL, args[0], args[1], args[2]);
1385         } else {
1386             tcg_out_opc_reg(s, OPC_SRLV, args[0], args[2], args[1]);
1387         }
1388         break;
1389
1390     case INDEX_op_ext8s_i32:
1391         tcg_out_ext8s(s, args[0], args[1]);
1392         break;
1393     case INDEX_op_ext16s_i32:
1394         tcg_out_ext16s(s, args[0], args[1]);
1395         break;
1396
1397     case INDEX_op_brcond_i32:
1398         tcg_out_brcond(s, args[2], args[0], args[1], args[3]);
1399         break;
1400     case INDEX_op_brcond2_i32:
1401         tcg_out_brcond2(s, args[4], args[0], args[1], args[2], args[3], args[5]);
1402         break;
1403
1404     case INDEX_op_setcond_i32:
1405         tcg_out_setcond(s, args[3], args[0], args[1], args[2]);
1406         break;
1407     case INDEX_op_setcond2_i32:
1408         tcg_out_setcond2(s, args[5], args[0], args[1], args[2], args[3], args[4]);
1409         break;
1410
1411     case INDEX_op_qemu_ld8u:
1412         tcg_out_qemu_ld(s, args, 0);
1413         break;
1414     case INDEX_op_qemu_ld8s:
1415         tcg_out_qemu_ld(s, args, 0 | 4);
1416         break;
1417     case INDEX_op_qemu_ld16u:
1418         tcg_out_qemu_ld(s, args, 1);
1419         break;
1420     case INDEX_op_qemu_ld16s:
1421         tcg_out_qemu_ld(s, args, 1 | 4);
1422         break;
1423     case INDEX_op_qemu_ld32:
1424         tcg_out_qemu_ld(s, args, 2);
1425         break;
1426     case INDEX_op_qemu_ld64:
1427         tcg_out_qemu_ld(s, args, 3);
1428         break;
1429     case INDEX_op_qemu_st8:
1430         tcg_out_qemu_st(s, args, 0);
1431         break;
1432     case INDEX_op_qemu_st16:
1433         tcg_out_qemu_st(s, args, 1);
1434         break;
1435     case INDEX_op_qemu_st32:
1436         tcg_out_qemu_st(s, args, 2);
1437         break;
1438     case INDEX_op_qemu_st64:
1439         tcg_out_qemu_st(s, args, 3);
1440         break;
1441
1442     default:
1443         tcg_abort();
1444     }
1445 }
1446
1447 static const TCGTargetOpDef mips_op_defs[] = {
1448     { INDEX_op_exit_tb, { } },
1449     { INDEX_op_goto_tb, { } },
1450     { INDEX_op_call, { "C" } },
1451     { INDEX_op_jmp, { "r" } },
1452     { INDEX_op_br, { } },
1453
1454     { INDEX_op_mov_i32, { "r", "r" } },
1455     { INDEX_op_movi_i32, { "r" } },
1456     { INDEX_op_ld8u_i32, { "r", "r" } },
1457     { INDEX_op_ld8s_i32, { "r", "r" } },
1458     { INDEX_op_ld16u_i32, { "r", "r" } },
1459     { INDEX_op_ld16s_i32, { "r", "r" } },
1460     { INDEX_op_ld_i32, { "r", "r" } },
1461     { INDEX_op_st8_i32, { "rZ", "r" } },
1462     { INDEX_op_st16_i32, { "rZ", "r" } },
1463     { INDEX_op_st_i32, { "rZ", "r" } },
1464
1465     { INDEX_op_add_i32, { "r", "rZ", "rJ" } },
1466     { INDEX_op_mul_i32, { "r", "rZ", "rZ" } },
1467     { INDEX_op_mulu2_i32, { "r", "r", "rZ", "rZ" } },
1468     { INDEX_op_div_i32, { "r", "rZ", "rZ" } },
1469     { INDEX_op_divu_i32, { "r", "rZ", "rZ" } },
1470     { INDEX_op_rem_i32, { "r", "rZ", "rZ" } },
1471     { INDEX_op_remu_i32, { "r", "rZ", "rZ" } },
1472     { INDEX_op_sub_i32, { "r", "rZ", "rJ" } },
1473
1474     { INDEX_op_and_i32, { "r", "rZ", "rI" } },
1475     { INDEX_op_nor_i32, { "r", "rZ", "rZ" } },
1476     { INDEX_op_not_i32, { "r", "rZ" } },
1477     { INDEX_op_or_i32, { "r", "rZ", "rIZ" } },
1478     { INDEX_op_xor_i32, { "r", "rZ", "rIZ" } },
1479
1480     { INDEX_op_shl_i32, { "r", "rZ", "ri" } },
1481     { INDEX_op_shr_i32, { "r", "rZ", "ri" } },
1482     { INDEX_op_sar_i32, { "r", "rZ", "ri" } },
1483
1484     { INDEX_op_ext8s_i32, { "r", "rZ" } },
1485     { INDEX_op_ext16s_i32, { "r", "rZ" } },
1486
1487     { INDEX_op_brcond_i32, { "rZ", "rZ" } },
1488     { INDEX_op_setcond_i32, { "r", "rZ", "rZ" } },
1489     { INDEX_op_setcond2_i32, { "r", "rZ", "rZ", "rZ", "rZ" } },
1490
1491     { INDEX_op_add2_i32, { "r", "r", "rZ", "rZ", "rJ", "rJ" } },
1492     { INDEX_op_sub2_i32, { "r", "r", "rZ", "rZ", "rJ", "rJ" } },
1493     { INDEX_op_brcond2_i32, { "rZ", "rZ", "rZ", "rZ" } },
1494
1495 #if TARGET_LONG_BITS == 32
1496     { INDEX_op_qemu_ld8u, { "L", "lZ" } },
1497     { INDEX_op_qemu_ld8s, { "L", "lZ" } },
1498     { INDEX_op_qemu_ld16u, { "L", "lZ" } },
1499     { INDEX_op_qemu_ld16s, { "L", "lZ" } },
1500     { INDEX_op_qemu_ld32, { "L", "lZ" } },
1501     { INDEX_op_qemu_ld64, { "L", "L", "lZ" } },
1502
1503     { INDEX_op_qemu_st8, { "SZ", "SZ" } },
1504     { INDEX_op_qemu_st16, { "SZ", "SZ" } },
1505     { INDEX_op_qemu_st32, { "SZ", "SZ" } },
1506     { INDEX_op_qemu_st64, { "SZ", "SZ", "SZ" } },
1507 #else
1508     { INDEX_op_qemu_ld8u, { "L", "lZ", "lZ" } },
1509     { INDEX_op_qemu_ld8s, { "L", "lZ", "lZ" } },
1510     { INDEX_op_qemu_ld16u, { "L", "lZ", "lZ" } },
1511     { INDEX_op_qemu_ld16s, { "L", "lZ", "lZ" } },
1512     { INDEX_op_qemu_ld32, { "L", "lZ", "lZ" } },
1513     { INDEX_op_qemu_ld64, { "L", "L", "lZ", "lZ" } },
1514
1515     { INDEX_op_qemu_st8, { "SZ", "SZ", "SZ" } },
1516     { INDEX_op_qemu_st16, { "SZ", "SZ", "SZ" } },
1517     { INDEX_op_qemu_st32, { "SZ", "SZ", "SZ" } },
1518     { INDEX_op_qemu_st64, { "SZ", "SZ", "SZ", "SZ" } },
1519 #endif
1520     { -1 },
1521 };
1522
1523 static int tcg_target_callee_save_regs[] = {
1524     TCG_REG_S0,       /* used for the global env (TCG_AREG0) */
1525     TCG_REG_S1,
1526     TCG_REG_S2,
1527     TCG_REG_S3,
1528     TCG_REG_S4,
1529     TCG_REG_S5,
1530     TCG_REG_S6,
1531     TCG_REG_S7,
1532     TCG_REG_FP,
1533     TCG_REG_RA,       /* should be last for ABI compliance */
1534 };
1535
1536 /* Generate global QEMU prologue and epilogue code */
1537 static void tcg_target_qemu_prologue(TCGContext *s)
1538 {
1539     int i, frame_size;
1540
1541     /* reserve some stack space, also for TCG temps. */
1542     frame_size = ARRAY_SIZE(tcg_target_callee_save_regs) * 4
1543                  + TCG_STATIC_CALL_ARGS_SIZE
1544                  + CPU_TEMP_BUF_NLONGS * sizeof(long);
1545     frame_size = (frame_size + TCG_TARGET_STACK_ALIGN - 1) &
1546                  ~(TCG_TARGET_STACK_ALIGN - 1);
1547     tcg_set_frame(s, TCG_REG_SP, ARRAY_SIZE(tcg_target_callee_save_regs) * 4
1548                   + TCG_STATIC_CALL_ARGS_SIZE,
1549                   CPU_TEMP_BUF_NLONGS * sizeof(long));
1550
1551     /* TB prologue */
1552     tcg_out_addi(s, TCG_REG_SP, -frame_size);
1553     for(i = 0 ; i < ARRAY_SIZE(tcg_target_callee_save_regs) ; i++) {
1554         tcg_out_st(s, TCG_TYPE_I32, tcg_target_callee_save_regs[i],
1555                    TCG_REG_SP, TCG_STATIC_CALL_ARGS_SIZE + i * 4);
1556     }
1557
1558     /* Call generated code */
1559     tcg_out_opc_reg(s, OPC_JR, 0, tcg_target_call_iarg_regs[1], 0);
1560     tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
1561     tb_ret_addr = s->code_ptr;
1562
1563     /* TB epilogue */
1564     for(i = 0 ; i < ARRAY_SIZE(tcg_target_callee_save_regs) ; i++) {
1565         tcg_out_ld(s, TCG_TYPE_I32, tcg_target_callee_save_regs[i],
1566                    TCG_REG_SP, TCG_STATIC_CALL_ARGS_SIZE + i * 4);
1567     }
1568
1569     tcg_out_opc_reg(s, OPC_JR, 0, TCG_REG_RA, 0);
1570     tcg_out_addi(s, TCG_REG_SP, frame_size);
1571 }
1572
1573 static void tcg_target_init(TCGContext *s)
1574 {
1575     tcg_regset_set(tcg_target_available_regs[TCG_TYPE_I32], 0xffffffff);
1576     tcg_regset_set(tcg_target_call_clobber_regs,
1577                    (1 << TCG_REG_V0) |
1578                    (1 << TCG_REG_V1) |
1579                    (1 << TCG_REG_A0) |
1580                    (1 << TCG_REG_A1) |
1581                    (1 << TCG_REG_A2) |
1582                    (1 << TCG_REG_A3) |
1583                    (1 << TCG_REG_T1) |
1584                    (1 << TCG_REG_T2) |
1585                    (1 << TCG_REG_T3) |
1586                    (1 << TCG_REG_T4) |
1587                    (1 << TCG_REG_T5) |
1588                    (1 << TCG_REG_T6) |
1589                    (1 << TCG_REG_T7) |
1590                    (1 << TCG_REG_T8) |
1591                    (1 << TCG_REG_T9));
1592
1593     tcg_regset_clear(s->reserved_regs);
1594     tcg_regset_set_reg(s->reserved_regs, TCG_REG_ZERO); /* zero register */
1595     tcg_regset_set_reg(s->reserved_regs, TCG_REG_K0);   /* kernel use only */
1596     tcg_regset_set_reg(s->reserved_regs, TCG_REG_K1);   /* kernel use only */
1597     tcg_regset_set_reg(s->reserved_regs, TCG_REG_AT);   /* internal use */
1598     tcg_regset_set_reg(s->reserved_regs, TCG_REG_T0);   /* internal use */
1599     tcg_regset_set_reg(s->reserved_regs, TCG_REG_RA);   /* return address */
1600     tcg_regset_set_reg(s->reserved_regs, TCG_REG_SP);   /* stack pointer */
1601     tcg_regset_set_reg(s->reserved_regs, TCG_REG_GP);   /* global pointer */
1602
1603     tcg_add_target_add_op_defs(mips_op_defs);
1604 }
This page took 0.110197 seconds and 4 git commands to generate.