VirtualBox

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

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

more recompiler work

  • 屬性 svn:eol-style 設為 native
檔案大小: 5.9 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 static unsigned long max;
65
66 if (max == 0) {
67 max = TCG_MAX_OP_SIZE;
68#define DEF(s, n, copy_size) max = copy_size > max? copy_size : max;
69#include "tcg-opc.h"
70#undef DEF
71 max *= OPC_MAX_SIZE;
72 }
73
74 return max;
75}
76
77void cpu_gen_init()
78{
79 tcg_context_init(&tcg_ctx);
80 tcg_set_frame(&tcg_ctx, TCG_AREG0, offsetof(CPUState, temp_buf),
81 CPU_TEMP_BUF_NLONGS * sizeof(long));
82}
83
84/* return non zero if the very first instruction is invalid so that
85 the virtual CPU can trigger an exception.
86
87 '*gen_code_size_ptr' contains the size of the generated code (host
88 code).
89*/
90int cpu_gen_code(CPUState *env, TranslationBlock *tb,
91 int *gen_code_size_ptr)
92{
93 TCGContext *s = &tcg_ctx;
94 uint8_t *gen_code_buf;
95 int gen_code_size;
96#ifdef CONFIG_PROFILER
97 int64_t ti;
98#endif
99
100#ifdef CONFIG_PROFILER
101 s->tb_count1++; /* includes aborted translations because of
102 exceptions */
103 ti = profile_getclock();
104#endif
105
106#ifdef VBOX
107 RAWEx_ProfileStart(env, STATS_QEMU_COMPILATION);
108 tcg_func_start(s);
109
110 gen_intermediate_code(env, tb);
111#else /* !VBOX */
112 tcg_func_start(s);
113
114 gen_intermediate_code(env, tb);
115#endif /* !VBOX */
116
117 /* generate machine code */
118 gen_code_buf = tb->tc_ptr;
119 tb->tb_next_offset[0] = 0xffff;
120 tb->tb_next_offset[1] = 0xffff;
121 s->tb_next_offset = tb->tb_next_offset;
122#ifdef USE_DIRECT_JUMP
123 s->tb_jmp_offset = tb->tb_jmp_offset;
124 s->tb_next = NULL;
125 /* the following two entries are optional (only used for string ops) */
126 tb->tb_jmp_offset[2] = 0xffff;
127 tb->tb_jmp_offset[3] = 0xffff;
128#else
129 s->tb_jmp_offset = NULL;
130 s->tb_next = tb->tb_next;
131#endif
132
133#ifdef CONFIG_PROFILER
134 s->tb_count++;
135 s->interm_time += profile_getclock() - ti;
136 s->code_time -= profile_getclock();
137#endif
138
139 gen_code_size = dyngen_code(s, gen_code_buf);
140 *gen_code_size_ptr = gen_code_size;
141#ifdef CONFIG_PROFILER
142 s->code_time += profile_getclock();
143 s->code_in_len += tb->size;
144 s->code_out_len += gen_code_size;
145#endif
146
147#ifdef VBOX
148 RAWEx_ProfileStop(env, STATS_QEMU_COMPILATION);
149#endif
150
151#ifdef DEBUG_DISAS
152 if (loglevel & CPU_LOG_TB_OUT_ASM) {
153 fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr);
154 disas(logfile, tb->tc_ptr, *gen_code_size_ptr);
155 fprintf(logfile, "\n");
156 fflush(logfile);
157 }
158#endif
159 return 0;
160}
161
162/* The cpu state corresponding to 'searched_pc' is restored.
163 */
164int cpu_restore_state(TranslationBlock *tb,
165 CPUState *env, unsigned long searched_pc,
166 void *puc)
167{
168 TCGContext *s = &tcg_ctx;
169 int j;
170 unsigned long tc_ptr;
171#ifdef CONFIG_PROFILER
172 int64_t ti;
173#endif
174
175#ifdef CONFIG_PROFILER
176 ti = profile_getclock();
177#endif
178 tcg_func_start(s);
179
180#ifdef VBOX
181 gen_intermediate_code_pc(env, tb);
182#else
183 gen_intermediate_code_pc(env, tb);
184#endif
185
186 if (use_icount) {
187 /* Reset the cycle counter to the start of the block. */
188 env->icount_decr.u16.low += tb->icount;
189 /* Clear the IO flag. */
190 env->can_do_io = 0;
191 }
192
193 /* find opc index corresponding to search_pc */
194 tc_ptr = (unsigned long)tb->tc_ptr;
195 if (searched_pc < tc_ptr)
196 return -1;
197
198 s->tb_next_offset = tb->tb_next_offset;
199#ifdef USE_DIRECT_JUMP
200 s->tb_jmp_offset = tb->tb_jmp_offset;
201 s->tb_next = NULL;
202#else
203 s->tb_jmp_offset = NULL;
204 s->tb_next = tb->tb_next;
205#endif
206 j = dyngen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
207 if (j < 0)
208 return -1;
209 /* now find start of instruction before */
210 while (gen_opc_instr_start[j] == 0)
211 j--;
212 env->icount_decr.u16.low -= gen_opc_icount[j];
213
214 gen_pc_load(env, tb, searched_pc, j, puc);
215
216#ifdef CONFIG_PROFILER
217 s->restore_time += profile_getclock() - ti;
218 s->restore_count++;
219#endif
220 return 0;
221}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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