2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2009, 2011 Stefan Weil
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * - See TODO comments in code.
29 /* Marker for missing code. */
32 fprintf(stderr, "TODO %s:%u: %s()\n", \
33 __FILE__, __LINE__, __func__); \
38 #define BIT(n) (1 << (n))
40 /* Bitfield n...m (in 32 bit value). */
41 #define BITS(n, m) (((0xffffffffU << (31 - n)) >> (31 - n + m)) << m)
43 /* Used for function call generation. */
44 #define TCG_REG_CALL_STACK TCG_REG_R4
45 #define TCG_TARGET_STACK_ALIGN 16
46 #define TCG_TARGET_CALL_STACK_OFFSET 0
48 /* TODO: documentation. */
49 static uint8_t *tb_ret_addr
;
51 /* Macros used in tcg_target_op_defs. */
54 #if TCG_TARGET_REG_BITS == 32
59 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
67 /* TODO: documentation. */
68 static const TCGTargetOpDef tcg_target_op_defs
[] = {
69 { INDEX_op_exit_tb
, { NULL
} },
70 { INDEX_op_goto_tb
, { NULL
} },
71 { INDEX_op_call
, { RI
} },
72 { INDEX_op_br
, { NULL
} },
74 { INDEX_op_mov_i32
, { R
, R
} },
75 { INDEX_op_movi_i32
, { R
} },
77 { INDEX_op_ld8u_i32
, { R
, R
} },
78 { INDEX_op_ld8s_i32
, { R
, R
} },
79 { INDEX_op_ld16u_i32
, { R
, R
} },
80 { INDEX_op_ld16s_i32
, { R
, R
} },
81 { INDEX_op_ld_i32
, { R
, R
} },
82 { INDEX_op_st8_i32
, { R
, R
} },
83 { INDEX_op_st16_i32
, { R
, R
} },
84 { INDEX_op_st_i32
, { R
, R
} },
86 { INDEX_op_add_i32
, { R
, RI
, RI
} },
87 { INDEX_op_sub_i32
, { R
, RI
, RI
} },
88 { INDEX_op_mul_i32
, { R
, RI
, RI
} },
89 #if TCG_TARGET_HAS_div_i32
90 { INDEX_op_div_i32
, { R
, R
, R
} },
91 { INDEX_op_divu_i32
, { R
, R
, R
} },
92 { INDEX_op_rem_i32
, { R
, R
, R
} },
93 { INDEX_op_remu_i32
, { R
, R
, R
} },
94 #elif TCG_TARGET_HAS_div2_i32
95 { INDEX_op_div2_i32
, { R
, R
, "0", "1", R
} },
96 { INDEX_op_divu2_i32
, { R
, R
, "0", "1", R
} },
98 /* TODO: Does R, RI, RI result in faster code than R, R, RI?
99 If both operands are constants, we can optimize. */
100 { INDEX_op_and_i32
, { R
, RI
, RI
} },
101 #if TCG_TARGET_HAS_andc_i32
102 { INDEX_op_andc_i32
, { R
, RI
, RI
} },
104 #if TCG_TARGET_HAS_eqv_i32
105 { INDEX_op_eqv_i32
, { R
, RI
, RI
} },
107 #if TCG_TARGET_HAS_nand_i32
108 { INDEX_op_nand_i32
, { R
, RI
, RI
} },
110 #if TCG_TARGET_HAS_nor_i32
111 { INDEX_op_nor_i32
, { R
, RI
, RI
} },
113 { INDEX_op_or_i32
, { R
, RI
, RI
} },
114 #if TCG_TARGET_HAS_orc_i32
115 { INDEX_op_orc_i32
, { R
, RI
, RI
} },
117 { INDEX_op_xor_i32
, { R
, RI
, RI
} },
118 { INDEX_op_shl_i32
, { R
, RI
, RI
} },
119 { INDEX_op_shr_i32
, { R
, RI
, RI
} },
120 { INDEX_op_sar_i32
, { R
, RI
, RI
} },
121 #if TCG_TARGET_HAS_rot_i32
122 { INDEX_op_rotl_i32
, { R
, RI
, RI
} },
123 { INDEX_op_rotr_i32
, { R
, RI
, RI
} },
125 #if TCG_TARGET_HAS_deposit_i32
126 { INDEX_op_deposit_i32
, { R
, "0", R
} },
129 { INDEX_op_brcond_i32
, { R
, RI
} },
131 { INDEX_op_setcond_i32
, { R
, R
, RI
} },
132 #if TCG_TARGET_REG_BITS == 64
133 { INDEX_op_setcond_i64
, { R
, R
, RI
} },
134 #endif /* TCG_TARGET_REG_BITS == 64 */
136 #if TCG_TARGET_REG_BITS == 32
137 /* TODO: Support R, R, R, R, RI, RI? Will it be faster? */
138 { INDEX_op_add2_i32
, { R
, R
, R
, R
, R
, R
} },
139 { INDEX_op_sub2_i32
, { R
, R
, R
, R
, R
, R
} },
140 { INDEX_op_brcond2_i32
, { R
, R
, RI
, RI
} },
141 { INDEX_op_mulu2_i32
, { R
, R
, R
, R
} },
142 { INDEX_op_setcond2_i32
, { R
, R
, R
, RI
, RI
} },
145 #if TCG_TARGET_HAS_not_i32
146 { INDEX_op_not_i32
, { R
, R
} },
148 #if TCG_TARGET_HAS_neg_i32
149 { INDEX_op_neg_i32
, { R
, R
} },
152 #if TCG_TARGET_REG_BITS == 64
153 { INDEX_op_mov_i64
, { R
, R
} },
154 { INDEX_op_movi_i64
, { R
} },
156 { INDEX_op_ld8u_i64
, { R
, R
} },
157 { INDEX_op_ld8s_i64
, { R
, R
} },
158 { INDEX_op_ld16u_i64
, { R
, R
} },
159 { INDEX_op_ld16s_i64
, { R
, R
} },
160 { INDEX_op_ld32u_i64
, { R
, R
} },
161 { INDEX_op_ld32s_i64
, { R
, R
} },
162 { INDEX_op_ld_i64
, { R
, R
} },
164 { INDEX_op_st8_i64
, { R
, R
} },
165 { INDEX_op_st16_i64
, { R
, R
} },
166 { INDEX_op_st32_i64
, { R
, R
} },
167 { INDEX_op_st_i64
, { R
, R
} },
169 { INDEX_op_add_i64
, { R
, RI
, RI
} },
170 { INDEX_op_sub_i64
, { R
, RI
, RI
} },
171 { INDEX_op_mul_i64
, { R
, RI
, RI
} },
172 #if TCG_TARGET_HAS_div_i64
173 { INDEX_op_div_i64
, { R
, R
, R
} },
174 { INDEX_op_divu_i64
, { R
, R
, R
} },
175 { INDEX_op_rem_i64
, { R
, R
, R
} },
176 { INDEX_op_remu_i64
, { R
, R
, R
} },
177 #elif TCG_TARGET_HAS_div2_i64
178 { INDEX_op_div2_i64
, { R
, R
, "0", "1", R
} },
179 { INDEX_op_divu2_i64
, { R
, R
, "0", "1", R
} },
181 { INDEX_op_and_i64
, { R
, RI
, RI
} },
182 #if TCG_TARGET_HAS_andc_i64
183 { INDEX_op_andc_i64
, { R
, RI
, RI
} },
185 #if TCG_TARGET_HAS_eqv_i64
186 { INDEX_op_eqv_i64
, { R
, RI
, RI
} },
188 #if TCG_TARGET_HAS_nand_i64
189 { INDEX_op_nand_i64
, { R
, RI
, RI
} },
191 #if TCG_TARGET_HAS_nor_i64
192 { INDEX_op_nor_i64
, { R
, RI
, RI
} },
194 { INDEX_op_or_i64
, { R
, RI
, RI
} },
195 #if TCG_TARGET_HAS_orc_i64
196 { INDEX_op_orc_i64
, { R
, RI
, RI
} },
198 { INDEX_op_xor_i64
, { R
, RI
, RI
} },
199 { INDEX_op_shl_i64
, { R
, RI
, RI
} },
200 { INDEX_op_shr_i64
, { R
, RI
, RI
} },
201 { INDEX_op_sar_i64
, { R
, RI
, RI
} },
202 #if TCG_TARGET_HAS_rot_i64
203 { INDEX_op_rotl_i64
, { R
, RI
, RI
} },
204 { INDEX_op_rotr_i64
, { R
, RI
, RI
} },
206 #if TCG_TARGET_HAS_deposit_i64
207 { INDEX_op_deposit_i64
, { R
, "0", R
} },
209 { INDEX_op_brcond_i64
, { R
, RI
} },
211 #if TCG_TARGET_HAS_ext8s_i64
212 { INDEX_op_ext8s_i64
, { R
, R
} },
214 #if TCG_TARGET_HAS_ext16s_i64
215 { INDEX_op_ext16s_i64
, { R
, R
} },
217 #if TCG_TARGET_HAS_ext32s_i64
218 { INDEX_op_ext32s_i64
, { R
, R
} },
220 #if TCG_TARGET_HAS_ext8u_i64
221 { INDEX_op_ext8u_i64
, { R
, R
} },
223 #if TCG_TARGET_HAS_ext16u_i64
224 { INDEX_op_ext16u_i64
, { R
, R
} },
226 #if TCG_TARGET_HAS_ext32u_i64
227 { INDEX_op_ext32u_i64
, { R
, R
} },
229 #if TCG_TARGET_HAS_bswap16_i64
230 { INDEX_op_bswap16_i64
, { R
, R
} },
232 #if TCG_TARGET_HAS_bswap32_i64
233 { INDEX_op_bswap32_i64
, { R
, R
} },
235 #if TCG_TARGET_HAS_bswap64_i64
236 { INDEX_op_bswap64_i64
, { R
, R
} },
238 #if TCG_TARGET_HAS_not_i64
239 { INDEX_op_not_i64
, { R
, R
} },
241 #if TCG_TARGET_HAS_neg_i64
242 { INDEX_op_neg_i64
, { R
, R
} },
244 #endif /* TCG_TARGET_REG_BITS == 64 */
246 { INDEX_op_qemu_ld8u
, { R
, L
} },
247 { INDEX_op_qemu_ld8s
, { R
, L
} },
248 { INDEX_op_qemu_ld16u
, { R
, L
} },
249 { INDEX_op_qemu_ld16s
, { R
, L
} },
250 { INDEX_op_qemu_ld32
, { R
, L
} },
251 #if TCG_TARGET_REG_BITS == 64
252 { INDEX_op_qemu_ld32u
, { R
, L
} },
253 { INDEX_op_qemu_ld32s
, { R
, L
} },
255 { INDEX_op_qemu_ld64
, { R64
, L
} },
257 { INDEX_op_qemu_st8
, { R
, S
} },
258 { INDEX_op_qemu_st16
, { R
, S
} },
259 { INDEX_op_qemu_st32
, { R
, S
} },
260 { INDEX_op_qemu_st64
, { R64
, S
} },
262 #if TCG_TARGET_HAS_ext8s_i32
263 { INDEX_op_ext8s_i32
, { R
, R
} },
265 #if TCG_TARGET_HAS_ext16s_i32
266 { INDEX_op_ext16s_i32
, { R
, R
} },
268 #if TCG_TARGET_HAS_ext8u_i32
269 { INDEX_op_ext8u_i32
, { R
, R
} },
271 #if TCG_TARGET_HAS_ext16u_i32
272 { INDEX_op_ext16u_i32
, { R
, R
} },
275 #if TCG_TARGET_HAS_bswap16_i32
276 { INDEX_op_bswap16_i32
, { R
, R
} },
278 #if TCG_TARGET_HAS_bswap32_i32
279 { INDEX_op_bswap32_i32
, { R
, R
} },
285 static const int tcg_target_reg_alloc_order
[] = {
290 #if 0 /* used for TCG_REG_CALL_STACK */
296 #if TCG_TARGET_NB_REGS >= 16
308 #if MAX_OPC_PARAM_IARGS != 5
309 # error Fix needed, number of supported input arguments changed!
312 static const int tcg_target_call_iarg_regs
[] = {
317 #if 0 /* used for TCG_REG_CALL_STACK */
321 #if TCG_TARGET_REG_BITS == 32
322 /* 32 bit hosts need 2 * MAX_OPC_PARAM_IARGS registers. */
325 #if TCG_TARGET_NB_REGS >= 16
330 # error Too few input registers available
335 static const int tcg_target_call_oarg_regs
[] = {
337 #if TCG_TARGET_REG_BITS == 32
343 static const char *const tcg_target_reg_names
[TCG_TARGET_NB_REGS
] = {
352 #if TCG_TARGET_NB_REGS >= 16
361 #if TCG_TARGET_NB_REGS >= 32
383 static void patch_reloc(uint8_t *code_ptr
, int type
,
384 tcg_target_long value
, tcg_target_long addend
)
386 /* tcg_out_reloc always uses the same type, addend. */
387 assert(type
== sizeof(tcg_target_long
));
390 *(tcg_target_long
*)code_ptr
= value
;
393 /* Parse target specific constraints. */
394 static int target_parse_constraint(TCGArgConstraint
*ct
, const char **pct_str
)
396 const char *ct_str
= *pct_str
;
399 case 'L': /* qemu_ld constraint */
400 case 'S': /* qemu_st constraint */
401 ct
->ct
|= TCG_CT_REG
;
402 tcg_regset_set32(ct
->u
.regs
, 0, BIT(TCG_TARGET_NB_REGS
) - 1);
412 #if defined(CONFIG_DEBUG_TCG_INTERPRETER)
413 /* Show current bytecode. Used by tcg interpreter. */
414 void tci_disas(uint8_t opc
)
416 const TCGOpDef
*def
= &tcg_op_defs
[opc
];
417 fprintf(stderr
, "TCG %s %u, %u, %u\n",
418 def
->name
, def
->nb_oargs
, def
->nb_iargs
, def
->nb_cargs
);
422 /* Write value (native size). */
423 static void tcg_out_i(TCGContext
*s
, tcg_target_ulong v
)
425 *(tcg_target_ulong
*)s
->code_ptr
= v
;
426 s
->code_ptr
+= sizeof(tcg_target_ulong
);
429 /* Write 64 bit value. */
430 static void tcg_out64(TCGContext
*s
, uint64_t v
)
432 *(uint64_t *)s
->code_ptr
= v
;
433 s
->code_ptr
+= sizeof(v
);
437 static void tcg_out_op_t(TCGContext
*s
, TCGOpcode op
)
443 /* Write register. */
444 static void tcg_out_r(TCGContext
*s
, TCGArg t0
)
446 assert(t0
< TCG_TARGET_NB_REGS
);
450 /* Write register or constant (native size). */
451 static void tcg_out_ri(TCGContext
*s
, int const_arg
, TCGArg arg
)
454 assert(const_arg
== 1);
455 tcg_out8(s
, TCG_CONST
);
462 /* Write register or constant (32 bit). */
463 static void tcg_out_ri32(TCGContext
*s
, int const_arg
, TCGArg arg
)
466 assert(const_arg
== 1);
467 tcg_out8(s
, TCG_CONST
);
474 #if TCG_TARGET_REG_BITS == 64
475 /* Write register or constant (64 bit). */
476 static void tcg_out_ri64(TCGContext
*s
, int const_arg
, TCGArg arg
)
479 assert(const_arg
== 1);
480 tcg_out8(s
, TCG_CONST
);
489 static void tci_out_label(TCGContext
*s
, TCGArg arg
)
491 TCGLabel
*label
= &s
->labels
[arg
];
492 if (label
->has_value
) {
493 tcg_out_i(s
, label
->u
.value
);
494 assert(label
->u
.value
);
496 tcg_out_reloc(s
, s
->code_ptr
, sizeof(tcg_target_ulong
), arg
, 0);
497 s
->code_ptr
+= sizeof(tcg_target_ulong
);
501 static void tcg_out_ld(TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg1
,
502 tcg_target_long arg2
)
504 uint8_t *old_code_ptr
= s
->code_ptr
;
505 if (type
== TCG_TYPE_I32
) {
506 tcg_out_op_t(s
, INDEX_op_ld_i32
);
511 assert(type
== TCG_TYPE_I64
);
512 #if TCG_TARGET_REG_BITS == 64
513 tcg_out_op_t(s
, INDEX_op_ld_i64
);
516 assert(arg2
== (uint32_t)arg2
);
522 old_code_ptr
[1] = s
->code_ptr
- old_code_ptr
;
525 static void tcg_out_mov(TCGContext
*s
, TCGType type
, TCGReg ret
, TCGReg arg
)
527 uint8_t *old_code_ptr
= s
->code_ptr
;
529 #if TCG_TARGET_REG_BITS == 32
530 tcg_out_op_t(s
, INDEX_op_mov_i32
);
532 tcg_out_op_t(s
, INDEX_op_mov_i64
);
536 old_code_ptr
[1] = s
->code_ptr
- old_code_ptr
;
539 static void tcg_out_movi(TCGContext
*s
, TCGType type
,
540 TCGReg t0
, tcg_target_long arg
)
542 uint8_t *old_code_ptr
= s
->code_ptr
;
543 uint32_t arg32
= arg
;
544 if (type
== TCG_TYPE_I32
|| arg
== arg32
) {
545 tcg_out_op_t(s
, INDEX_op_movi_i32
);
549 assert(type
== TCG_TYPE_I64
);
550 #if TCG_TARGET_REG_BITS == 64
551 tcg_out_op_t(s
, INDEX_op_movi_i64
);
558 old_code_ptr
[1] = s
->code_ptr
- old_code_ptr
;
561 static void tcg_out_op(TCGContext
*s
, TCGOpcode opc
, const TCGArg
*args
,
562 const int *const_args
)
564 uint8_t *old_code_ptr
= s
->code_ptr
;
566 tcg_out_op_t(s
, opc
);
569 case INDEX_op_exit_tb
:
570 tcg_out64(s
, args
[0]);
572 case INDEX_op_goto_tb
:
573 if (s
->tb_jmp_offset
) {
574 /* Direct jump method. */
575 assert(args
[0] < ARRAY_SIZE(s
->tb_jmp_offset
));
576 s
->tb_jmp_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
579 /* Indirect jump method. */
582 assert(args
[0] < ARRAY_SIZE(s
->tb_next_offset
));
583 s
->tb_next_offset
[args
[0]] = s
->code_ptr
- s
->code_buf
;
586 tci_out_label(s
, args
[0]);
589 tcg_out_ri(s
, const_args
[0], args
[0]);
591 case INDEX_op_setcond_i32
:
592 tcg_out_r(s
, args
[0]);
593 tcg_out_r(s
, args
[1]);
594 tcg_out_ri32(s
, const_args
[2], args
[2]);
595 tcg_out8(s
, args
[3]); /* condition */
597 #if TCG_TARGET_REG_BITS == 32
598 case INDEX_op_setcond2_i32
:
599 /* setcond2_i32 cond, t0, t1_low, t1_high, t2_low, t2_high */
600 tcg_out_r(s
, args
[0]);
601 tcg_out_r(s
, args
[1]);
602 tcg_out_r(s
, args
[2]);
603 tcg_out_ri32(s
, const_args
[3], args
[3]);
604 tcg_out_ri32(s
, const_args
[4], args
[4]);
605 tcg_out8(s
, args
[5]); /* condition */
607 #elif TCG_TARGET_REG_BITS == 64
608 case INDEX_op_setcond_i64
:
609 tcg_out_r(s
, args
[0]);
610 tcg_out_r(s
, args
[1]);
611 tcg_out_ri64(s
, const_args
[2], args
[2]);
612 tcg_out8(s
, args
[3]); /* condition */
615 case INDEX_op_movi_i32
:
616 TODO(); /* Handled by tcg_out_movi? */
618 case INDEX_op_ld8u_i32
:
619 case INDEX_op_ld8s_i32
:
620 case INDEX_op_ld16u_i32
:
621 case INDEX_op_ld16s_i32
:
622 case INDEX_op_ld_i32
:
623 case INDEX_op_st8_i32
:
624 case INDEX_op_st16_i32
:
625 case INDEX_op_st_i32
:
626 case INDEX_op_ld8u_i64
:
627 case INDEX_op_ld8s_i64
:
628 case INDEX_op_ld16u_i64
:
629 case INDEX_op_ld16s_i64
:
630 case INDEX_op_ld32u_i64
:
631 case INDEX_op_ld32s_i64
:
632 case INDEX_op_ld_i64
:
633 case INDEX_op_st8_i64
:
634 case INDEX_op_st16_i64
:
635 case INDEX_op_st32_i64
:
636 case INDEX_op_st_i64
:
637 tcg_out_r(s
, args
[0]);
638 tcg_out_r(s
, args
[1]);
639 assert(args
[2] == (uint32_t)args
[2]);
640 tcg_out32(s
, args
[2]);
642 case INDEX_op_add_i32
:
643 case INDEX_op_sub_i32
:
644 case INDEX_op_mul_i32
:
645 case INDEX_op_and_i32
:
646 case INDEX_op_andc_i32
: /* Optional (TCG_TARGET_HAS_andc_i32). */
647 case INDEX_op_eqv_i32
: /* Optional (TCG_TARGET_HAS_eqv_i32). */
648 case INDEX_op_nand_i32
: /* Optional (TCG_TARGET_HAS_nand_i32). */
649 case INDEX_op_nor_i32
: /* Optional (TCG_TARGET_HAS_nor_i32). */
650 case INDEX_op_or_i32
:
651 case INDEX_op_orc_i32
: /* Optional (TCG_TARGET_HAS_orc_i32). */
652 case INDEX_op_xor_i32
:
653 case INDEX_op_shl_i32
:
654 case INDEX_op_shr_i32
:
655 case INDEX_op_sar_i32
:
656 case INDEX_op_rotl_i32
: /* Optional (TCG_TARGET_HAS_rot_i32). */
657 case INDEX_op_rotr_i32
: /* Optional (TCG_TARGET_HAS_rot_i32). */
658 tcg_out_r(s
, args
[0]);
659 tcg_out_ri32(s
, const_args
[1], args
[1]);
660 tcg_out_ri32(s
, const_args
[2], args
[2]);
662 case INDEX_op_deposit_i32
: /* Optional (TCG_TARGET_HAS_deposit_i32). */
663 tcg_out_r(s
, args
[0]);
664 tcg_out_r(s
, args
[1]);
665 tcg_out_r(s
, args
[2]);
666 assert(args
[3] <= UINT8_MAX
);
667 tcg_out8(s
, args
[3]);
668 assert(args
[4] <= UINT8_MAX
);
669 tcg_out8(s
, args
[4]);
672 #if TCG_TARGET_REG_BITS == 64
673 case INDEX_op_mov_i64
:
674 case INDEX_op_movi_i64
:
677 case INDEX_op_add_i64
:
678 case INDEX_op_sub_i64
:
679 case INDEX_op_mul_i64
:
680 case INDEX_op_and_i64
:
681 case INDEX_op_andc_i64
: /* Optional (TCG_TARGET_HAS_andc_i64). */
682 case INDEX_op_eqv_i64
: /* Optional (TCG_TARGET_HAS_eqv_i64). */
683 case INDEX_op_nand_i64
: /* Optional (TCG_TARGET_HAS_nand_i64). */
684 case INDEX_op_nor_i64
: /* Optional (TCG_TARGET_HAS_nor_i64). */
685 case INDEX_op_or_i64
:
686 case INDEX_op_orc_i64
: /* Optional (TCG_TARGET_HAS_orc_i64). */
687 case INDEX_op_xor_i64
:
688 case INDEX_op_shl_i64
:
689 case INDEX_op_shr_i64
:
690 case INDEX_op_sar_i64
:
691 /* TODO: Implementation of rotl_i64, rotr_i64 missing in tci.c. */
692 case INDEX_op_rotl_i64
: /* Optional (TCG_TARGET_HAS_rot_i64). */
693 case INDEX_op_rotr_i64
: /* Optional (TCG_TARGET_HAS_rot_i64). */
694 tcg_out_r(s
, args
[0]);
695 tcg_out_ri64(s
, const_args
[1], args
[1]);
696 tcg_out_ri64(s
, const_args
[2], args
[2]);
698 case INDEX_op_deposit_i64
: /* Optional (TCG_TARGET_HAS_deposit_i64). */
699 tcg_out_r(s
, args
[0]);
700 tcg_out_r(s
, args
[1]);
701 tcg_out_r(s
, args
[2]);
702 assert(args
[3] <= UINT8_MAX
);
703 tcg_out8(s
, args
[3]);
704 assert(args
[4] <= UINT8_MAX
);
705 tcg_out8(s
, args
[4]);
707 case INDEX_op_div_i64
: /* Optional (TCG_TARGET_HAS_div_i64). */
708 case INDEX_op_divu_i64
: /* Optional (TCG_TARGET_HAS_div_i64). */
709 case INDEX_op_rem_i64
: /* Optional (TCG_TARGET_HAS_div_i64). */
710 case INDEX_op_remu_i64
: /* Optional (TCG_TARGET_HAS_div_i64). */
713 case INDEX_op_div2_i64
: /* Optional (TCG_TARGET_HAS_div2_i64). */
714 case INDEX_op_divu2_i64
: /* Optional (TCG_TARGET_HAS_div2_i64). */
717 case INDEX_op_brcond_i64
:
718 tcg_out_r(s
, args
[0]);
719 tcg_out_ri64(s
, const_args
[1], args
[1]);
720 tcg_out8(s
, args
[2]); /* condition */
721 tci_out_label(s
, args
[3]);
723 case INDEX_op_bswap16_i64
: /* Optional (TCG_TARGET_HAS_bswap16_i64). */
724 case INDEX_op_bswap32_i64
: /* Optional (TCG_TARGET_HAS_bswap32_i64). */
725 case INDEX_op_bswap64_i64
: /* Optional (TCG_TARGET_HAS_bswap64_i64). */
726 case INDEX_op_not_i64
: /* Optional (TCG_TARGET_HAS_not_i64). */
727 case INDEX_op_neg_i64
: /* Optional (TCG_TARGET_HAS_neg_i64). */
728 case INDEX_op_ext8s_i64
: /* Optional (TCG_TARGET_HAS_ext8s_i64). */
729 case INDEX_op_ext8u_i64
: /* Optional (TCG_TARGET_HAS_ext8u_i64). */
730 case INDEX_op_ext16s_i64
: /* Optional (TCG_TARGET_HAS_ext16s_i64). */
731 case INDEX_op_ext16u_i64
: /* Optional (TCG_TARGET_HAS_ext16u_i64). */
732 case INDEX_op_ext32s_i64
: /* Optional (TCG_TARGET_HAS_ext32s_i64). */
733 case INDEX_op_ext32u_i64
: /* Optional (TCG_TARGET_HAS_ext32u_i64). */
734 #endif /* TCG_TARGET_REG_BITS == 64 */
735 case INDEX_op_neg_i32
: /* Optional (TCG_TARGET_HAS_neg_i32). */
736 case INDEX_op_not_i32
: /* Optional (TCG_TARGET_HAS_not_i32). */
737 case INDEX_op_ext8s_i32
: /* Optional (TCG_TARGET_HAS_ext8s_i32). */
738 case INDEX_op_ext16s_i32
: /* Optional (TCG_TARGET_HAS_ext16s_i32). */
739 case INDEX_op_ext8u_i32
: /* Optional (TCG_TARGET_HAS_ext8u_i32). */
740 case INDEX_op_ext16u_i32
: /* Optional (TCG_TARGET_HAS_ext16u_i32). */
741 case INDEX_op_bswap16_i32
: /* Optional (TCG_TARGET_HAS_bswap16_i32). */
742 case INDEX_op_bswap32_i32
: /* Optional (TCG_TARGET_HAS_bswap32_i32). */
743 tcg_out_r(s
, args
[0]);
744 tcg_out_r(s
, args
[1]);
746 case INDEX_op_div_i32
: /* Optional (TCG_TARGET_HAS_div_i32). */
747 case INDEX_op_divu_i32
: /* Optional (TCG_TARGET_HAS_div_i32). */
748 case INDEX_op_rem_i32
: /* Optional (TCG_TARGET_HAS_div_i32). */
749 case INDEX_op_remu_i32
: /* Optional (TCG_TARGET_HAS_div_i32). */
750 tcg_out_r(s
, args
[0]);
751 tcg_out_ri32(s
, const_args
[1], args
[1]);
752 tcg_out_ri32(s
, const_args
[2], args
[2]);
754 case INDEX_op_div2_i32
: /* Optional (TCG_TARGET_HAS_div2_i32). */
755 case INDEX_op_divu2_i32
: /* Optional (TCG_TARGET_HAS_div2_i32). */
758 #if TCG_TARGET_REG_BITS == 32
759 case INDEX_op_add2_i32
:
760 case INDEX_op_sub2_i32
:
761 tcg_out_r(s
, args
[0]);
762 tcg_out_r(s
, args
[1]);
763 tcg_out_r(s
, args
[2]);
764 tcg_out_r(s
, args
[3]);
765 tcg_out_r(s
, args
[4]);
766 tcg_out_r(s
, args
[5]);
768 case INDEX_op_brcond2_i32
:
769 tcg_out_r(s
, args
[0]);
770 tcg_out_r(s
, args
[1]);
771 tcg_out_ri32(s
, const_args
[2], args
[2]);
772 tcg_out_ri32(s
, const_args
[3], args
[3]);
773 tcg_out8(s
, args
[4]); /* condition */
774 tci_out_label(s
, args
[5]);
776 case INDEX_op_mulu2_i32
:
777 tcg_out_r(s
, args
[0]);
778 tcg_out_r(s
, args
[1]);
779 tcg_out_r(s
, args
[2]);
780 tcg_out_r(s
, args
[3]);
783 case INDEX_op_brcond_i32
:
784 tcg_out_r(s
, args
[0]);
785 tcg_out_ri32(s
, const_args
[1], args
[1]);
786 tcg_out8(s
, args
[2]); /* condition */
787 tci_out_label(s
, args
[3]);
789 case INDEX_op_qemu_ld8u
:
790 case INDEX_op_qemu_ld8s
:
791 case INDEX_op_qemu_ld16u
:
792 case INDEX_op_qemu_ld16s
:
793 case INDEX_op_qemu_ld32
:
794 #if TCG_TARGET_REG_BITS == 64
795 case INDEX_op_qemu_ld32s
:
796 case INDEX_op_qemu_ld32u
:
798 tcg_out_r(s
, *args
++);
799 tcg_out_r(s
, *args
++);
800 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
801 tcg_out_r(s
, *args
++);
803 #ifdef CONFIG_SOFTMMU
807 case INDEX_op_qemu_ld64
:
808 tcg_out_r(s
, *args
++);
809 #if TCG_TARGET_REG_BITS == 32
810 tcg_out_r(s
, *args
++);
812 tcg_out_r(s
, *args
++);
813 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
814 tcg_out_r(s
, *args
++);
816 #ifdef CONFIG_SOFTMMU
820 case INDEX_op_qemu_st8
:
821 case INDEX_op_qemu_st16
:
822 case INDEX_op_qemu_st32
:
823 tcg_out_r(s
, *args
++);
824 tcg_out_r(s
, *args
++);
825 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
826 tcg_out_r(s
, *args
++);
828 #ifdef CONFIG_SOFTMMU
832 case INDEX_op_qemu_st64
:
833 tcg_out_r(s
, *args
++);
834 #if TCG_TARGET_REG_BITS == 32
835 tcg_out_r(s
, *args
++);
837 tcg_out_r(s
, *args
++);
838 #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS
839 tcg_out_r(s
, *args
++);
841 #ifdef CONFIG_SOFTMMU
849 fprintf(stderr
, "Missing: %s\n", tcg_op_defs
[opc
].name
);
852 old_code_ptr
[1] = s
->code_ptr
- old_code_ptr
;
855 static void tcg_out_st(TCGContext
*s
, TCGType type
, TCGReg arg
, TCGReg arg1
,
856 tcg_target_long arg2
)
858 uint8_t *old_code_ptr
= s
->code_ptr
;
859 if (type
== TCG_TYPE_I32
) {
860 tcg_out_op_t(s
, INDEX_op_st_i32
);
865 assert(type
== TCG_TYPE_I64
);
866 #if TCG_TARGET_REG_BITS == 64
867 tcg_out_op_t(s
, INDEX_op_st_i64
);
875 old_code_ptr
[1] = s
->code_ptr
- old_code_ptr
;
878 /* Test if a constant matches the constraint. */
879 static int tcg_target_const_match(tcg_target_long val
,
880 const TCGArgConstraint
*arg_ct
)
882 /* No need to return 0 or 1, 0 or != 0 is good enough. */
883 return arg_ct
->ct
& TCG_CT_CONST
;
886 static void tcg_target_init(TCGContext
*s
)
888 #if defined(CONFIG_DEBUG_TCG_INTERPRETER)
889 const char *envval
= getenv("DEBUG_TCG");
891 cpu_set_log(strtol(envval
, NULL
, 0));
895 /* The current code uses uint8_t for tcg operations. */
896 assert(ARRAY_SIZE(tcg_op_defs
) <= UINT8_MAX
);
898 /* Registers available for 32 bit operations. */
899 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I32
], 0,
900 BIT(TCG_TARGET_NB_REGS
) - 1);
901 /* Registers available for 64 bit operations. */
902 tcg_regset_set32(tcg_target_available_regs
[TCG_TYPE_I64
], 0,
903 BIT(TCG_TARGET_NB_REGS
) - 1);
904 /* TODO: Which registers should be set here? */
905 tcg_regset_set32(tcg_target_call_clobber_regs
, 0,
906 BIT(TCG_TARGET_NB_REGS
) - 1);
907 tcg_regset_clear(s
->reserved_regs
);
908 tcg_regset_set_reg(s
->reserved_regs
, TCG_REG_CALL_STACK
);
909 tcg_add_target_add_op_defs(tcg_target_op_defs
);
910 tcg_set_frame(s
, TCG_AREG0
, offsetof(CPUArchState
, temp_buf
),
911 CPU_TEMP_BUF_NLONGS
* sizeof(long));
914 /* Generate global QEMU prologue and epilogue code. */
915 static void tcg_target_qemu_prologue(TCGContext
*s
)
917 tb_ret_addr
= s
->code_ptr
;