VirtualBox

source: vbox/trunk/src/recompiler_new/translate-all.c@ 13368

最後變更 在這個檔案從13368是 13358,由 vboxsync 提交於 16 年 前

fixed couple cosmetical issues

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.0 KB
 
1/*
2 * Host code generation
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
23 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
24 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
25 * a choice of LGPL license versions is made available with the language indicating
26 * that LGPLv2 or any later version may be used, or where a choice of which version
27 * of the LGPL is applied is otherwise unspecified.
28 */
29#include <stdarg.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33#include <inttypes.h>
34
35#include "config.h"
36
37#define NO_CPU_IO_DEFS
38#include "cpu.h"
39#include "exec-all.h"
40#include "disas.h"
41#include "tcg.h"
42
43/* code generation context */
44TCGContext tcg_ctx;
45
46uint16_t gen_opc_buf[OPC_BUF_SIZE];
47TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE];
48
49target_ulong gen_opc_pc[OPC_BUF_SIZE];
50uint16_t gen_opc_icount[OPC_BUF_SIZE];
51uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
52#if defined(TARGET_I386)
53uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
54#elif defined(TARGET_SPARC)
55target_ulong gen_opc_npc[OPC_BUF_SIZE];
56target_ulong gen_opc_jump_pc[2];
57#elif defined(TARGET_MIPS)
58uint32_t gen_opc_hflags[OPC_BUF_SIZE];
59#endif
60
61/* XXX: suppress that */
62unsigned long code_gen_max_block_size(void)
63{
64#ifdef VBOX
65 /* Just to suppress a lot of dummy warnings */
66 static long max;
67#else
68 static unsigned long max;
69#endif
70
71 if (max == 0) {
72 max = TCG_MAX_OP_SIZE;
73#define DEF(s, n, copy_size) max = (copy_size > max) ? copy_size : max;
74#include "tcg-opc.h"
75#undef DEF
76 max *= OPC_MAX_SIZE;
77 }
78
79 return max;
80}
81
82void cpu_gen_init()
83{
84 tcg_context_init(&tcg_ctx);
85 tcg_set_frame(&tcg_ctx, TCG_AREG0, offsetof(CPUState, temp_buf),
86 CPU_TEMP_BUF_NLONGS * sizeof(long));
87}
88
89/* return non zero if the very first instruction is invalid so that
90 the virtual CPU can trigger an exception.
91
92 '*gen_code_size_ptr' contains the size of the generated code (host
93 code).
94*/
95int cpu_gen_code(CPUState *env, TranslationBlock *tb,
96 int *gen_code_size_ptr)
97{
98 TCGContext *s = &tcg_ctx;
99 uint8_t *gen_code_buf;
100 int gen_code_size;
101#ifdef CONFIG_PROFILER
102 int64_t ti;
103#endif
104
105#ifdef CONFIG_PROFILER
106 s->tb_count1++; /* includes aborted translations because of
107 exceptions */
108 ti = profile_getclock();
109#endif
110
111#ifdef VBOX
112 RAWEx_ProfileStart(env, STATS_QEMU_COMPILATION);
113 tcg_func_start(s);
114
115 gen_intermediate_code(env, tb);
116#else /* !VBOX */
117 tcg_func_start(s);
118
119 gen_intermediate_code(env, tb);
120#endif /* !VBOX */
121
122 /* generate machine code */
123 gen_code_buf = tb->tc_ptr;
124 tb->tb_next_offset[0] = 0xffff;
125 tb->tb_next_offset[1] = 0xffff;
126 s->tb_next_offset = tb->tb_next_offset;
127#ifdef USE_DIRECT_JUMP
128 s->tb_jmp_offset = tb->tb_jmp_offset;
129 s->tb_next = NULL;
130 /* the following two entries are optional (only used for string ops) */
131 tb->tb_jmp_offset[2] = 0xffff;
132 tb->tb_jmp_offset[3] = 0xffff;
133#else
134 s->tb_jmp_offset = NULL;
135 s->tb_next = tb->tb_next;
136#endif
137
138#ifdef CONFIG_PROFILER
139 s->tb_count++;
140 s->interm_time += profile_getclock() - ti;
141 s->code_time -= profile_getclock();
142#endif
143
144 gen_code_size = dyngen_code(s, gen_code_buf);
145 *gen_code_size_ptr = gen_code_size;
146#ifdef CONFIG_PROFILER
147 s->code_time += profile_getclock();
148 s->code_in_len += tb->size;
149 s->code_out_len += gen_code_size;
150#endif
151
152#ifdef VBOX
153 RAWEx_ProfileStop(env, STATS_QEMU_COMPILATION);
154#endif
155
156#ifdef DEBUG_DISAS
157 if (loglevel & CPU_LOG_TB_OUT_ASM) {
158 fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr);
159 disas(logfile, tb->tc_ptr, *gen_code_size_ptr);
160 fprintf(logfile, "\n");
161 fflush(logfile);
162 }
163#endif
164 return 0;
165}
166
167/* The cpu state corresponding to 'searched_pc' is restored.
168 */
169int cpu_restore_state(TranslationBlock *tb,
170 CPUState *env, unsigned long searched_pc,
171 void *puc)
172{
173 TCGContext *s = &tcg_ctx;
174 int j;
175 unsigned long tc_ptr;
176#ifdef CONFIG_PROFILER
177 int64_t ti;
178#endif
179
180#ifdef CONFIG_PROFILER
181 ti = profile_getclock();
182#endif
183 tcg_func_start(s);
184
185#ifdef VBOX
186 gen_intermediate_code_pc(env, tb);
187#else
188 gen_intermediate_code_pc(env, tb);
189#endif
190
191 if (use_icount) {
192 /* Reset the cycle counter to the start of the block. */
193 env->icount_decr.u16.low += tb->icount;
194 /* Clear the IO flag. */
195 env->can_do_io = 0;
196 }
197
198 /* find opc index corresponding to search_pc */
199 tc_ptr = (unsigned long)tb->tc_ptr;
200 if (searched_pc < tc_ptr)
201 return -1;
202
203 s->tb_next_offset = tb->tb_next_offset;
204#ifdef USE_DIRECT_JUMP
205 s->tb_jmp_offset = tb->tb_jmp_offset;
206 s->tb_next = NULL;
207#else
208 s->tb_jmp_offset = NULL;
209 s->tb_next = tb->tb_next;
210#endif
211 j = dyngen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
212 if (j < 0)
213 return -1;
214 /* now find start of instruction before */
215 while (gen_opc_instr_start[j] == 0)
216 j--;
217 env->icount_decr.u16.low -= gen_opc_icount[j];
218
219 gen_pc_load(env, tb, searched_pc, j, puc);
220
221#ifdef CONFIG_PROFILER
222 s->restore_time += profile_getclock() - ti;
223 s->restore_count++;
224#endif
225 return 0;
226}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette