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