]> git.proxmox.com Git - mirror_qemu.git/blame - translate-all.c
Fix shell quoting.
[mirror_qemu.git] / translate-all.c
CommitLineData
d19893da
FB
1/*
2 * Host code generation
5fafdf24 3 *
d19893da
FB
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#include <stdarg.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <inttypes.h>
25
26#include "config.h"
2054396a 27
af5ad107 28#define NO_CPU_IO_DEFS
d3eead2e
FB
29#include "cpu.h"
30#include "exec-all.h"
d19893da 31#include "disas.h"
57fec1fe 32#include "tcg.h"
d19893da 33
57fec1fe
FB
34/* code generation context */
35TCGContext tcg_ctx;
d19893da 36
d19893da 37uint16_t gen_opc_buf[OPC_BUF_SIZE];
57fec1fe 38TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE];
c4687878
FB
39
40target_ulong gen_opc_pc[OPC_BUF_SIZE];
d19893da 41uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
f76af4b3
FB
42#if defined(TARGET_I386)
43uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
e95c8d51 44#elif defined(TARGET_SPARC)
c4687878 45target_ulong gen_opc_npc[OPC_BUF_SIZE];
c3278b7b 46target_ulong gen_opc_jump_pc[2];
823029f9 47#elif defined(TARGET_MIPS) || defined(TARGET_SH4)
30d6cb84 48uint32_t gen_opc_hflags[OPC_BUF_SIZE];
f76af4b3 49#endif
d19893da 50
57fec1fe 51/* XXX: suppress that */
d07bde88
BS
52unsigned long code_gen_max_block_size(void)
53{
54 static unsigned long max;
55
56 if (max == 0) {
a208e54a 57 max = TCG_MAX_OP_SIZE;
d07bde88 58#define DEF(s, n, copy_size) max = copy_size > max? copy_size : max;
57fec1fe 59#include "tcg-opc.h"
d07bde88
BS
60#undef DEF
61 max *= OPC_MAX_SIZE;
62 }
63
64 return max;
65}
66
57fec1fe
FB
67void cpu_gen_init(void)
68{
69 tcg_context_init(&tcg_ctx);
70 tcg_set_frame(&tcg_ctx, TCG_AREG0, offsetof(CPUState, temp_buf),
a20e31dc 71 CPU_TEMP_BUF_NLONGS * sizeof(long));
57fec1fe
FB
72}
73
d19893da 74/* return non zero if the very first instruction is invalid so that
5fafdf24 75 the virtual CPU can trigger an exception.
d19893da
FB
76
77 '*gen_code_size_ptr' contains the size of the generated code (host
78 code).
79*/
d07bde88 80int cpu_gen_code(CPUState *env, TranslationBlock *tb, int *gen_code_size_ptr)
d19893da 81{
57fec1fe 82 TCGContext *s = &tcg_ctx;
d19893da
FB
83 uint8_t *gen_code_buf;
84 int gen_code_size;
57fec1fe
FB
85#ifdef CONFIG_PROFILER
86 int64_t ti;
87#endif
88
89#ifdef CONFIG_PROFILER
b67d9a52
FB
90 s->tb_count1++; /* includes aborted translations because of
91 exceptions */
57fec1fe
FB
92 ti = profile_getclock();
93#endif
94 tcg_func_start(s);
d19893da 95
ec6338ba
FB
96 if (gen_intermediate_code(env, tb) < 0)
97 return -1;
98
99 /* generate machine code */
57fec1fe 100 gen_code_buf = tb->tc_ptr;
ec6338ba
FB
101 tb->tb_next_offset[0] = 0xffff;
102 tb->tb_next_offset[1] = 0xffff;
57fec1fe 103 s->tb_next_offset = tb->tb_next_offset;
4cbb86e1 104#ifdef USE_DIRECT_JUMP
57fec1fe
FB
105 s->tb_jmp_offset = tb->tb_jmp_offset;
106 s->tb_next = NULL;
ec6338ba 107 /* the following two entries are optional (only used for string ops) */
57fec1fe 108 /* XXX: not used ? */
ec6338ba
FB
109 tb->tb_jmp_offset[2] = 0xffff;
110 tb->tb_jmp_offset[3] = 0xffff;
d19893da 111#else
57fec1fe
FB
112 s->tb_jmp_offset = NULL;
113 s->tb_next = tb->tb_next;
d19893da 114#endif
57fec1fe
FB
115
116#ifdef CONFIG_PROFILER
b67d9a52
FB
117 s->tb_count++;
118 s->interm_time += profile_getclock() - ti;
119 s->code_time -= profile_getclock();
57fec1fe
FB
120#endif
121 gen_code_size = dyngen_code(s, gen_code_buf);
d19893da 122 *gen_code_size_ptr = gen_code_size;
57fec1fe 123#ifdef CONFIG_PROFILER
b67d9a52
FB
124 s->code_time += profile_getclock();
125 s->code_in_len += tb->size;
126 s->code_out_len += gen_code_size;
57fec1fe
FB
127#endif
128
d19893da 129#ifdef DEBUG_DISAS
f193c797 130 if (loglevel & CPU_LOG_TB_OUT_ASM) {
d19893da 131 fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr);
c4687878 132 disas(logfile, tb->tc_ptr, *gen_code_size_ptr);
d19893da
FB
133 fprintf(logfile, "\n");
134 fflush(logfile);
135 }
136#endif
137 return 0;
138}
139
5fafdf24 140/* The cpu state corresponding to 'searched_pc' is restored.
d19893da 141 */
5fafdf24 142int cpu_restore_state(TranslationBlock *tb,
58fe2f10
FB
143 CPUState *env, unsigned long searched_pc,
144 void *puc)
d19893da 145{
57fec1fe
FB
146 TCGContext *s = &tcg_ctx;
147 int j;
d19893da 148 unsigned long tc_ptr;
57fec1fe
FB
149#ifdef CONFIG_PROFILER
150 int64_t ti;
151#endif
152
153#ifdef CONFIG_PROFILER
154 ti = profile_getclock();
155#endif
156 tcg_func_start(s);
d19893da 157
4c3a88a2 158 if (gen_intermediate_code_pc(env, tb) < 0)
d19893da 159 return -1;
3b46e624 160
d19893da
FB
161 /* find opc index corresponding to search_pc */
162 tc_ptr = (unsigned long)tb->tc_ptr;
163 if (searched_pc < tc_ptr)
164 return -1;
57fec1fe
FB
165
166 s->tb_next_offset = tb->tb_next_offset;
167#ifdef USE_DIRECT_JUMP
168 s->tb_jmp_offset = tb->tb_jmp_offset;
169 s->tb_next = NULL;
170#else
171 s->tb_jmp_offset = NULL;
172 s->tb_next = tb->tb_next;
173#endif
623e265c 174 j = dyngen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
57fec1fe
FB
175 if (j < 0)
176 return -1;
d19893da
FB
177 /* now find start of instruction before */
178 while (gen_opc_instr_start[j] == 0)
179 j--;
3b46e624 180
d2856f1a 181 gen_pc_load(env, tb, searched_pc, j, puc);
57fec1fe
FB
182
183#ifdef CONFIG_PROFILER
b67d9a52
FB
184 s->restore_time += profile_getclock() - ti;
185 s->restore_count++;
57fec1fe 186#endif
d19893da
FB
187 return 0;
188}