]>
Commit | Line | Data |
---|---|---|
c896fe29 FB |
1 | /* |
2 | * Tiny Code Generator for QEMU | |
3 | * | |
4 | * Copyright (c) 2008 Fabrice Bellard | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
f8393946 | 24 | #include "qemu-common.h" |
c896fe29 | 25 | #include "tcg-target.h" |
96e132e2 | 26 | #include "tcg-runtime.h" |
c896fe29 FB |
27 | |
28 | #if TCG_TARGET_REG_BITS == 32 | |
29 | typedef int32_t tcg_target_long; | |
30 | typedef uint32_t tcg_target_ulong; | |
31 | #define TCG_PRIlx PRIx32 | |
32 | #define TCG_PRIld PRId32 | |
33 | #elif TCG_TARGET_REG_BITS == 64 | |
34 | typedef int64_t tcg_target_long; | |
35 | typedef uint64_t tcg_target_ulong; | |
36 | #define TCG_PRIlx PRIx64 | |
37 | #define TCG_PRIld PRId64 | |
38 | #else | |
39 | #error unsupported | |
40 | #endif | |
41 | ||
42 | #if TCG_TARGET_NB_REGS <= 32 | |
43 | typedef uint32_t TCGRegSet; | |
44 | #elif TCG_TARGET_NB_REGS <= 64 | |
45 | typedef uint64_t TCGRegSet; | |
46 | #else | |
47 | #error unsupported | |
48 | #endif | |
49 | ||
25c4d9cc RH |
50 | /* Turn some undef macros into false macros. */ |
51 | #if TCG_TARGET_REG_BITS == 32 | |
52 | #define TCG_TARGET_HAS_div_i64 0 | |
53 | #define TCG_TARGET_HAS_div2_i64 0 | |
54 | #define TCG_TARGET_HAS_rot_i64 0 | |
55 | #define TCG_TARGET_HAS_ext8s_i64 0 | |
56 | #define TCG_TARGET_HAS_ext16s_i64 0 | |
57 | #define TCG_TARGET_HAS_ext32s_i64 0 | |
58 | #define TCG_TARGET_HAS_ext8u_i64 0 | |
59 | #define TCG_TARGET_HAS_ext16u_i64 0 | |
60 | #define TCG_TARGET_HAS_ext32u_i64 0 | |
61 | #define TCG_TARGET_HAS_bswap16_i64 0 | |
62 | #define TCG_TARGET_HAS_bswap32_i64 0 | |
63 | #define TCG_TARGET_HAS_bswap64_i64 0 | |
64 | #define TCG_TARGET_HAS_neg_i64 0 | |
65 | #define TCG_TARGET_HAS_not_i64 0 | |
66 | #define TCG_TARGET_HAS_andc_i64 0 | |
67 | #define TCG_TARGET_HAS_orc_i64 0 | |
68 | #define TCG_TARGET_HAS_eqv_i64 0 | |
69 | #define TCG_TARGET_HAS_nand_i64 0 | |
70 | #define TCG_TARGET_HAS_nor_i64 0 | |
71 | #define TCG_TARGET_HAS_deposit_i64 0 | |
72 | #endif | |
73 | ||
74 | /* Only one of DIV or DIV2 should be defined. */ | |
75 | #if defined(TCG_TARGET_HAS_div_i32) | |
76 | #define TCG_TARGET_HAS_div2_i32 0 | |
77 | #elif defined(TCG_TARGET_HAS_div2_i32) | |
78 | #define TCG_TARGET_HAS_div_i32 0 | |
79 | #endif | |
80 | #if defined(TCG_TARGET_HAS_div_i64) | |
81 | #define TCG_TARGET_HAS_div2_i64 0 | |
82 | #elif defined(TCG_TARGET_HAS_div2_i64) | |
83 | #define TCG_TARGET_HAS_div_i64 0 | |
84 | #endif | |
85 | ||
a9751609 | 86 | typedef enum TCGOpcode { |
c61aaf7a | 87 | #define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name, |
c896fe29 FB |
88 | #include "tcg-opc.h" |
89 | #undef DEF | |
90 | NB_OPS, | |
a9751609 | 91 | } TCGOpcode; |
c896fe29 FB |
92 | |
93 | #define tcg_regset_clear(d) (d) = 0 | |
94 | #define tcg_regset_set(d, s) (d) = (s) | |
95 | #define tcg_regset_set32(d, reg, val32) (d) |= (val32) << (reg) | |
7d301752 AJ |
96 | #define tcg_regset_set_reg(d, r) (d) |= 1L << (r) |
97 | #define tcg_regset_reset_reg(d, r) (d) &= ~(1L << (r)) | |
c896fe29 FB |
98 | #define tcg_regset_test_reg(d, r) (((d) >> (r)) & 1) |
99 | #define tcg_regset_or(d, a, b) (d) = (a) | (b) | |
100 | #define tcg_regset_and(d, a, b) (d) = (a) & (b) | |
101 | #define tcg_regset_andnot(d, a, b) (d) = (a) & ~(b) | |
102 | #define tcg_regset_not(d, a) (d) = ~(a) | |
103 | ||
104 | typedef struct TCGRelocation { | |
105 | struct TCGRelocation *next; | |
106 | int type; | |
107 | uint8_t *ptr; | |
108 | tcg_target_long addend; | |
109 | } TCGRelocation; | |
110 | ||
111 | typedef struct TCGLabel { | |
c44f945a | 112 | int has_value; |
c896fe29 FB |
113 | union { |
114 | tcg_target_ulong value; | |
115 | TCGRelocation *first_reloc; | |
116 | } u; | |
117 | } TCGLabel; | |
118 | ||
119 | typedef struct TCGPool { | |
120 | struct TCGPool *next; | |
c44f945a BS |
121 | int size; |
122 | uint8_t data[0] __attribute__ ((aligned)); | |
c896fe29 FB |
123 | } TCGPool; |
124 | ||
125 | #define TCG_POOL_CHUNK_SIZE 32768 | |
126 | ||
127 | #define TCG_MAX_LABELS 512 | |
128 | ||
c4071c90 | 129 | #define TCG_MAX_TEMPS 512 |
c896fe29 | 130 | |
b03cce8e FB |
131 | /* when the size of the arguments of a called function is smaller than |
132 | this value, they are statically allocated in the TB stack frame */ | |
133 | #define TCG_STATIC_CALL_ARGS_SIZE 128 | |
134 | ||
c02244a5 RH |
135 | typedef enum TCGType { |
136 | TCG_TYPE_I32, | |
137 | TCG_TYPE_I64, | |
138 | TCG_TYPE_COUNT, /* number of different types */ | |
c896fe29 | 139 | |
3b6dac34 | 140 | /* An alias for the size of the host register. */ |
c896fe29 | 141 | #if TCG_TARGET_REG_BITS == 32 |
3b6dac34 | 142 | TCG_TYPE_REG = TCG_TYPE_I32, |
c02244a5 | 143 | #else |
3b6dac34 | 144 | TCG_TYPE_REG = TCG_TYPE_I64, |
c02244a5 | 145 | #endif |
3b6dac34 RH |
146 | |
147 | /* An alias for the size of the native pointer. We don't currently | |
148 | support any hosts with 64-bit registers and 32-bit pointers. */ | |
149 | TCG_TYPE_PTR = TCG_TYPE_REG, | |
150 | ||
151 | /* An alias for the size of the target "long", aka register. */ | |
c02244a5 RH |
152 | #if TARGET_LONG_BITS == 64 |
153 | TCG_TYPE_TL = TCG_TYPE_I64, | |
c896fe29 | 154 | #else |
c02244a5 | 155 | TCG_TYPE_TL = TCG_TYPE_I32, |
c896fe29 | 156 | #endif |
c02244a5 | 157 | } TCGType; |
c896fe29 FB |
158 | |
159 | typedef tcg_target_ulong TCGArg; | |
160 | ||
ac56dd48 PB |
161 | /* Define a type and accessor macros for varables. Using a struct is |
162 | nice because it gives some level of type safely. Ideally the compiler | |
163 | be able to see through all this. However in practice this is not true, | |
164 | expecially on targets with braindamaged ABIs (e.g. i386). | |
165 | We use plain int by default to avoid this runtime overhead. | |
166 | Users of tcg_gen_* don't need to know about any of this, and should | |
a7812ae4 | 167 | treat TCGv as an opaque type. |
06ea77bc | 168 | In addition we do typechecking for different types of variables. TCGv_i32 |
a7812ae4 PB |
169 | and TCGv_i64 are 32/64-bit variables respectively. TCGv and TCGv_ptr |
170 | are aliases for target_ulong and host pointer sized values respectively. | |
171 | */ | |
ac56dd48 | 172 | |
092c73ee | 173 | #ifdef CONFIG_DEBUG_TCG |
f8393946 AJ |
174 | #define DEBUG_TCGV 1 |
175 | #endif | |
ac56dd48 PB |
176 | |
177 | #ifdef DEBUG_TCGV | |
178 | ||
179 | typedef struct | |
180 | { | |
a810a2de | 181 | int i32; |
a7812ae4 | 182 | } TCGv_i32; |
ac56dd48 | 183 | |
a7812ae4 PB |
184 | typedef struct |
185 | { | |
a810a2de | 186 | int i64; |
a7812ae4 PB |
187 | } TCGv_i64; |
188 | ||
ebecf363 PM |
189 | typedef struct { |
190 | int iptr; | |
191 | } TCGv_ptr; | |
192 | ||
a7812ae4 PB |
193 | #define MAKE_TCGV_I32(i) __extension__ \ |
194 | ({ TCGv_i32 make_tcgv_tmp = {i}; make_tcgv_tmp;}) | |
195 | #define MAKE_TCGV_I64(i) __extension__ \ | |
196 | ({ TCGv_i64 make_tcgv_tmp = {i}; make_tcgv_tmp;}) | |
ebecf363 PM |
197 | #define MAKE_TCGV_PTR(i) __extension__ \ |
198 | ({ TCGv_ptr make_tcgv_tmp = {i}; make_tcgv_tmp; }) | |
a810a2de BS |
199 | #define GET_TCGV_I32(t) ((t).i32) |
200 | #define GET_TCGV_I64(t) ((t).i64) | |
ebecf363 | 201 | #define GET_TCGV_PTR(t) ((t).iptr) |
ac56dd48 | 202 | #if TCG_TARGET_REG_BITS == 32 |
a7812ae4 PB |
203 | #define TCGV_LOW(t) MAKE_TCGV_I32(GET_TCGV_I64(t)) |
204 | #define TCGV_HIGH(t) MAKE_TCGV_I32(GET_TCGV_I64(t) + 1) | |
ac56dd48 PB |
205 | #endif |
206 | ||
207 | #else /* !DEBUG_TCGV */ | |
208 | ||
a7812ae4 PB |
209 | typedef int TCGv_i32; |
210 | typedef int TCGv_i64; | |
ebecf363 PM |
211 | #if TCG_TARGET_REG_BITS == 32 |
212 | #define TCGv_ptr TCGv_i32 | |
213 | #else | |
214 | #define TCGv_ptr TCGv_i64 | |
215 | #endif | |
a7812ae4 PB |
216 | #define MAKE_TCGV_I32(x) (x) |
217 | #define MAKE_TCGV_I64(x) (x) | |
ebecf363 | 218 | #define MAKE_TCGV_PTR(x) (x) |
a7812ae4 PB |
219 | #define GET_TCGV_I32(t) (t) |
220 | #define GET_TCGV_I64(t) (t) | |
ebecf363 | 221 | #define GET_TCGV_PTR(t) (t) |
44e6acb0 | 222 | |
ac56dd48 | 223 | #if TCG_TARGET_REG_BITS == 32 |
a7812ae4 | 224 | #define TCGV_LOW(t) (t) |
ac56dd48 PB |
225 | #define TCGV_HIGH(t) ((t) + 1) |
226 | #endif | |
227 | ||
228 | #endif /* DEBUG_TCGV */ | |
229 | ||
43e860ef AJ |
230 | #define TCGV_EQUAL_I32(a, b) (GET_TCGV_I32(a) == GET_TCGV_I32(b)) |
231 | #define TCGV_EQUAL_I64(a, b) (GET_TCGV_I64(a) == GET_TCGV_I64(b)) | |
232 | ||
a50f5b91 | 233 | /* Dummy definition to avoid compiler warnings. */ |
a7812ae4 PB |
234 | #define TCGV_UNUSED_I32(x) x = MAKE_TCGV_I32(-1) |
235 | #define TCGV_UNUSED_I64(x) x = MAKE_TCGV_I64(-1) | |
a50f5b91 | 236 | |
c896fe29 FB |
237 | /* call flags */ |
238 | #define TCG_CALL_TYPE_MASK 0x000f | |
239 | #define TCG_CALL_TYPE_STD 0x0000 /* standard C call */ | |
240 | #define TCG_CALL_TYPE_REGPARM_1 0x0001 /* i386 style regparm call (1 reg) */ | |
241 | #define TCG_CALL_TYPE_REGPARM_2 0x0002 /* i386 style regparm call (2 regs) */ | |
242 | #define TCG_CALL_TYPE_REGPARM 0x0003 /* i386 style regparm call (3 regs) */ | |
3e00b3f5 | 243 | /* A pure function only reads its arguments and TCG global variables |
34d5a9ff | 244 | and cannot raise exceptions. Hence a call to a pure function can be |
c6e113f5 FB |
245 | safely suppressed if the return value is not used. */ |
246 | #define TCG_CALL_PURE 0x0010 | |
b9c18f56 | 247 | /* A const function only reads its arguments and does not use TCG |
3e00b3f5 AJ |
248 | global variables. Hence a call to such a function does not |
249 | save TCG global variables back to their canonical location. */ | |
b9c18f56 | 250 | #define TCG_CALL_CONST 0x0020 |
c896fe29 | 251 | |
39cf05d3 | 252 | /* used to align parameters */ |
a7812ae4 | 253 | #define TCG_CALL_DUMMY_TCGV MAKE_TCGV_I32(-1) |
39cf05d3 FB |
254 | #define TCG_CALL_DUMMY_ARG ((TCGArg)(-1)) |
255 | ||
c896fe29 FB |
256 | typedef enum { |
257 | TCG_COND_EQ, | |
258 | TCG_COND_NE, | |
259 | TCG_COND_LT, | |
260 | TCG_COND_GE, | |
261 | TCG_COND_LE, | |
262 | TCG_COND_GT, | |
263 | /* unsigned */ | |
264 | TCG_COND_LTU, | |
265 | TCG_COND_GEU, | |
266 | TCG_COND_LEU, | |
267 | TCG_COND_GTU, | |
268 | } TCGCond; | |
269 | ||
1c086220 | 270 | /* Invert the sense of the comparison. */ |
401d466d RH |
271 | static inline TCGCond tcg_invert_cond(TCGCond c) |
272 | { | |
273 | return (TCGCond)(c ^ 1); | |
274 | } | |
275 | ||
1c086220 RH |
276 | /* Swap the operands in a comparison. */ |
277 | static inline TCGCond tcg_swap_cond(TCGCond c) | |
278 | { | |
279 | int mask = (c < TCG_COND_LT ? 0 : c < TCG_COND_LTU ? 7 : 15); | |
280 | return (TCGCond)(c ^ mask); | |
281 | } | |
282 | ||
ff44c2f3 RH |
283 | static inline TCGCond tcg_unsigned_cond(TCGCond c) |
284 | { | |
285 | return (c >= TCG_COND_LT && c <= TCG_COND_GT ? c + 4 : c); | |
286 | } | |
287 | ||
c896fe29 FB |
288 | #define TEMP_VAL_DEAD 0 |
289 | #define TEMP_VAL_REG 1 | |
290 | #define TEMP_VAL_MEM 2 | |
291 | #define TEMP_VAL_CONST 3 | |
292 | ||
293 | /* XXX: optimize memory layout */ | |
294 | typedef struct TCGTemp { | |
295 | TCGType base_type; | |
296 | TCGType type; | |
297 | int val_type; | |
298 | int reg; | |
299 | tcg_target_long val; | |
300 | int mem_reg; | |
301 | tcg_target_long mem_offset; | |
302 | unsigned int fixed_reg:1; | |
303 | unsigned int mem_coherent:1; | |
304 | unsigned int mem_allocated:1; | |
5225d669 | 305 | unsigned int temp_local:1; /* If true, the temp is saved across |
641d5fbe | 306 | basic blocks. Otherwise, it is not |
5225d669 | 307 | preserved across basic blocks. */ |
e8996ee0 FB |
308 | unsigned int temp_allocated:1; /* never used for code gen */ |
309 | /* index of next free temp of same base type, -1 if end */ | |
310 | int next_free_temp; | |
c896fe29 FB |
311 | const char *name; |
312 | } TCGTemp; | |
313 | ||
314 | typedef struct TCGHelperInfo { | |
4dc81f28 | 315 | tcg_target_ulong func; |
c896fe29 FB |
316 | const char *name; |
317 | } TCGHelperInfo; | |
318 | ||
319 | typedef struct TCGContext TCGContext; | |
320 | ||
c896fe29 FB |
321 | struct TCGContext { |
322 | uint8_t *pool_cur, *pool_end; | |
323 | TCGPool *pool_first, *pool_current; | |
324 | TCGLabel *labels; | |
325 | int nb_labels; | |
326 | TCGTemp *temps; /* globals first, temps after */ | |
327 | int nb_globals; | |
328 | int nb_temps; | |
641d5fbe FB |
329 | /* index of free temps, -1 if none */ |
330 | int first_free_temp[TCG_TYPE_COUNT * 2]; | |
c896fe29 FB |
331 | |
332 | /* goto_tb support */ | |
333 | uint8_t *code_buf; | |
334 | unsigned long *tb_next; | |
335 | uint16_t *tb_next_offset; | |
336 | uint16_t *tb_jmp_offset; /* != NULL if USE_DIRECT_JUMP */ | |
337 | ||
641d5fbe | 338 | /* liveness analysis */ |
866cb6cb AJ |
339 | uint16_t *op_dead_args; /* for each operation, each bit tells if the |
340 | corresponding argument is dead */ | |
641d5fbe | 341 | |
c896fe29 FB |
342 | /* tells in which temporary a given register is. It does not take |
343 | into account fixed registers */ | |
344 | int reg_to_temp[TCG_TARGET_NB_REGS]; | |
345 | TCGRegSet reserved_regs; | |
346 | tcg_target_long current_frame_offset; | |
347 | tcg_target_long frame_start; | |
348 | tcg_target_long frame_end; | |
349 | int frame_reg; | |
350 | ||
351 | uint8_t *code_ptr; | |
352 | TCGTemp static_temps[TCG_MAX_TEMPS]; | |
353 | ||
c896fe29 FB |
354 | TCGHelperInfo *helpers; |
355 | int nb_helpers; | |
356 | int allocated_helpers; | |
e8996ee0 | 357 | int helpers_sorted; |
a23a9ec6 FB |
358 | |
359 | #ifdef CONFIG_PROFILER | |
360 | /* profiling info */ | |
361 | int64_t tb_count1; | |
362 | int64_t tb_count; | |
363 | int64_t op_count; /* total insn count */ | |
364 | int op_count_max; /* max insn per TB */ | |
365 | int64_t temp_count; | |
366 | int temp_count_max; | |
a23a9ec6 FB |
367 | int64_t del_op_count; |
368 | int64_t code_in_len; | |
369 | int64_t code_out_len; | |
370 | int64_t interm_time; | |
371 | int64_t code_time; | |
372 | int64_t la_time; | |
373 | int64_t restore_count; | |
374 | int64_t restore_time; | |
375 | #endif | |
27bfd83c PM |
376 | |
377 | #ifdef CONFIG_DEBUG_TCG | |
378 | int temps_in_use; | |
379 | #endif | |
c896fe29 FB |
380 | }; |
381 | ||
382 | extern TCGContext tcg_ctx; | |
383 | extern uint16_t *gen_opc_ptr; | |
384 | extern TCGArg *gen_opparam_ptr; | |
385 | extern uint16_t gen_opc_buf[]; | |
386 | extern TCGArg gen_opparam_buf[]; | |
387 | ||
388 | /* pool based memory allocation */ | |
389 | ||
390 | void *tcg_malloc_internal(TCGContext *s, int size); | |
391 | void tcg_pool_reset(TCGContext *s); | |
392 | void tcg_pool_delete(TCGContext *s); | |
393 | ||
394 | static inline void *tcg_malloc(int size) | |
395 | { | |
396 | TCGContext *s = &tcg_ctx; | |
397 | uint8_t *ptr, *ptr_end; | |
398 | size = (size + sizeof(long) - 1) & ~(sizeof(long) - 1); | |
399 | ptr = s->pool_cur; | |
400 | ptr_end = ptr + size; | |
401 | if (unlikely(ptr_end > s->pool_end)) { | |
402 | return tcg_malloc_internal(&tcg_ctx, size); | |
403 | } else { | |
404 | s->pool_cur = ptr_end; | |
405 | return ptr; | |
406 | } | |
407 | } | |
408 | ||
409 | void tcg_context_init(TCGContext *s); | |
9002ec79 | 410 | void tcg_prologue_init(TCGContext *s); |
c896fe29 FB |
411 | void tcg_func_start(TCGContext *s); |
412 | ||
54604f74 AJ |
413 | int tcg_gen_code(TCGContext *s, uint8_t *gen_code_buf); |
414 | int tcg_gen_code_search_pc(TCGContext *s, uint8_t *gen_code_buf, long offset); | |
c896fe29 FB |
415 | |
416 | void tcg_set_frame(TCGContext *s, int reg, | |
417 | tcg_target_long start, tcg_target_long size); | |
a7812ae4 PB |
418 | |
419 | TCGv_i32 tcg_global_reg_new_i32(int reg, const char *name); | |
420 | TCGv_i32 tcg_global_mem_new_i32(int reg, tcg_target_long offset, | |
421 | const char *name); | |
422 | TCGv_i32 tcg_temp_new_internal_i32(int temp_local); | |
423 | static inline TCGv_i32 tcg_temp_new_i32(void) | |
424 | { | |
425 | return tcg_temp_new_internal_i32(0); | |
426 | } | |
427 | static inline TCGv_i32 tcg_temp_local_new_i32(void) | |
428 | { | |
429 | return tcg_temp_new_internal_i32(1); | |
430 | } | |
431 | void tcg_temp_free_i32(TCGv_i32 arg); | |
432 | char *tcg_get_arg_str_i32(TCGContext *s, char *buf, int buf_size, TCGv_i32 arg); | |
433 | ||
434 | TCGv_i64 tcg_global_reg_new_i64(int reg, const char *name); | |
435 | TCGv_i64 tcg_global_mem_new_i64(int reg, tcg_target_long offset, | |
436 | const char *name); | |
437 | TCGv_i64 tcg_temp_new_internal_i64(int temp_local); | |
438 | static inline TCGv_i64 tcg_temp_new_i64(void) | |
641d5fbe | 439 | { |
a7812ae4 | 440 | return tcg_temp_new_internal_i64(0); |
641d5fbe | 441 | } |
a7812ae4 | 442 | static inline TCGv_i64 tcg_temp_local_new_i64(void) |
641d5fbe | 443 | { |
a7812ae4 | 444 | return tcg_temp_new_internal_i64(1); |
641d5fbe | 445 | } |
a7812ae4 PB |
446 | void tcg_temp_free_i64(TCGv_i64 arg); |
447 | char *tcg_get_arg_str_i64(TCGContext *s, char *buf, int buf_size, TCGv_i64 arg); | |
448 | ||
e31b0a7c BS |
449 | static inline bool tcg_arg_is_local(TCGContext *s, TCGArg arg) |
450 | { | |
451 | return s->temps[arg].temp_local; | |
452 | } | |
453 | ||
27bfd83c PM |
454 | #if defined(CONFIG_DEBUG_TCG) |
455 | /* If you call tcg_clear_temp_count() at the start of a section of | |
456 | * code which is not supposed to leak any TCG temporaries, then | |
457 | * calling tcg_check_temp_count() at the end of the section will | |
458 | * return 1 if the section did in fact leak a temporary. | |
459 | */ | |
460 | void tcg_clear_temp_count(void); | |
461 | int tcg_check_temp_count(void); | |
462 | #else | |
463 | #define tcg_clear_temp_count() do { } while (0) | |
464 | #define tcg_check_temp_count() 0 | |
465 | #endif | |
466 | ||
405cf9ff | 467 | void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf); |
c896fe29 FB |
468 | |
469 | #define TCG_CT_ALIAS 0x80 | |
470 | #define TCG_CT_IALIAS 0x40 | |
471 | #define TCG_CT_REG 0x01 | |
472 | #define TCG_CT_CONST 0x02 /* any constant of register size */ | |
473 | ||
474 | typedef struct TCGArgConstraint { | |
5ff9d6a4 FB |
475 | uint16_t ct; |
476 | uint8_t alias_index; | |
c896fe29 FB |
477 | union { |
478 | TCGRegSet regs; | |
479 | } u; | |
480 | } TCGArgConstraint; | |
481 | ||
482 | #define TCG_MAX_OP_ARGS 16 | |
483 | ||
8399ad59 RH |
484 | /* Bits for TCGOpDef->flags, 8 bits available. */ |
485 | enum { | |
486 | /* Instruction defines the end of a basic block. */ | |
487 | TCG_OPF_BB_END = 0x01, | |
488 | /* Instruction clobbers call registers and potentially update globals. */ | |
489 | TCG_OPF_CALL_CLOBBER = 0x02, | |
490 | /* Instruction has side effects: it cannot be removed | |
491 | if its outputs are not used. */ | |
492 | TCG_OPF_SIDE_EFFECTS = 0x04, | |
493 | /* Instruction operands are 64-bits (otherwise 32-bits). */ | |
494 | TCG_OPF_64BIT = 0x08, | |
25c4d9cc RH |
495 | /* Instruction is optional and not implemented by the host. */ |
496 | TCG_OPF_NOT_PRESENT = 0x10, | |
8399ad59 | 497 | }; |
c896fe29 FB |
498 | |
499 | typedef struct TCGOpDef { | |
500 | const char *name; | |
501 | uint8_t nb_oargs, nb_iargs, nb_cargs, nb_args; | |
502 | uint8_t flags; | |
c896fe29 FB |
503 | TCGArgConstraint *args_ct; |
504 | int *sorted_args; | |
c68aaa18 SW |
505 | #if defined(CONFIG_DEBUG_TCG) |
506 | int used; | |
507 | #endif | |
c896fe29 | 508 | } TCGOpDef; |
8399ad59 RH |
509 | |
510 | extern TCGOpDef tcg_op_defs[]; | |
c896fe29 FB |
511 | |
512 | typedef struct TCGTargetOpDef { | |
a9751609 | 513 | TCGOpcode op; |
c896fe29 FB |
514 | const char *args_ct_str[TCG_MAX_OP_ARGS]; |
515 | } TCGTargetOpDef; | |
516 | ||
c896fe29 FB |
517 | #define tcg_abort() \ |
518 | do {\ | |
519 | fprintf(stderr, "%s:%d: tcg fatal error\n", __FILE__, __LINE__);\ | |
520 | abort();\ | |
521 | } while (0) | |
522 | ||
523 | void tcg_add_target_add_op_defs(const TCGTargetOpDef *tdefs); | |
524 | ||
c896fe29 | 525 | #if TCG_TARGET_REG_BITS == 32 |
ebecf363 PM |
526 | #define TCGV_NAT_TO_PTR(n) MAKE_TCGV_PTR(GET_TCGV_I32(n)) |
527 | #define TCGV_PTR_TO_NAT(n) MAKE_TCGV_I32(GET_TCGV_PTR(n)) | |
528 | ||
529 | #define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i32(V)) | |
530 | #define tcg_global_reg_new_ptr(R, N) \ | |
531 | TCGV_NAT_TO_PTR(tcg_global_reg_new_i32((R), (N))) | |
532 | #define tcg_global_mem_new_ptr(R, O, N) \ | |
533 | TCGV_NAT_TO_PTR(tcg_global_mem_new_i32((R), (O), (N))) | |
534 | #define tcg_temp_new_ptr() TCGV_NAT_TO_PTR(tcg_temp_new_i32()) | |
535 | #define tcg_temp_free_ptr(T) tcg_temp_free_i32(TCGV_PTR_TO_NAT(T)) | |
c896fe29 | 536 | #else |
ebecf363 PM |
537 | #define TCGV_NAT_TO_PTR(n) MAKE_TCGV_PTR(GET_TCGV_I64(n)) |
538 | #define TCGV_PTR_TO_NAT(n) MAKE_TCGV_I64(GET_TCGV_PTR(n)) | |
539 | ||
540 | #define tcg_const_ptr(V) TCGV_NAT_TO_PTR(tcg_const_i64(V)) | |
541 | #define tcg_global_reg_new_ptr(R, N) \ | |
542 | TCGV_NAT_TO_PTR(tcg_global_reg_new_i64((R), (N))) | |
543 | #define tcg_global_mem_new_ptr(R, O, N) \ | |
544 | TCGV_NAT_TO_PTR(tcg_global_mem_new_i64((R), (O), (N))) | |
545 | #define tcg_temp_new_ptr() TCGV_NAT_TO_PTR(tcg_temp_new_i64()) | |
546 | #define tcg_temp_free_ptr(T) tcg_temp_free_i64(TCGV_PTR_TO_NAT(T)) | |
c896fe29 FB |
547 | #endif |
548 | ||
a7812ae4 PB |
549 | void tcg_gen_callN(TCGContext *s, TCGv_ptr func, unsigned int flags, |
550 | int sizemask, TCGArg ret, int nargs, TCGArg *args); | |
551 | ||
552 | void tcg_gen_shifti_i64(TCGv_i64 ret, TCGv_i64 arg1, | |
553 | int c, int right, int arith); | |
554 | ||
8f2e8c07 KB |
555 | TCGArg *tcg_optimize(TCGContext *s, uint16_t *tcg_opc_ptr, TCGArg *args, |
556 | TCGOpDef *tcg_op_def); | |
557 | ||
a7812ae4 PB |
558 | /* only used for debugging purposes */ |
559 | void tcg_register_helper(void *func, const char *name); | |
560 | const char *tcg_helper_get_name(TCGContext *s, void *func); | |
561 | void tcg_dump_ops(TCGContext *s, FILE *outfile); | |
562 | ||
563 | void dump_ops(const uint16_t *opc_buf, const TCGArg *opparam_buf); | |
564 | TCGv_i32 tcg_const_i32(int32_t val); | |
565 | TCGv_i64 tcg_const_i64(int64_t val); | |
566 | TCGv_i32 tcg_const_local_i32(int32_t val); | |
567 | TCGv_i64 tcg_const_local_i64(int64_t val); | |
568 | ||
b03cce8e | 569 | extern uint8_t code_gen_prologue[]; |
e58ffeb3 | 570 | #if defined(_ARCH_PPC) && !defined(_ARCH_PPC64) |
cea5f9a2 BS |
571 | #define tcg_qemu_tb_exec(env, tb_ptr) \ |
572 | ((long REGPARM __attribute__ ((longcall)) (*)(void *, void *))code_gen_prologue)(env, tb_ptr) | |
932a6909 | 573 | #else |
cea5f9a2 BS |
574 | #define tcg_qemu_tb_exec(env, tb_ptr) \ |
575 | ((long REGPARM (*)(void *, void *))code_gen_prologue)(env, tb_ptr) | |
932a6909 | 576 | #endif |