4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
28 #define NO_CPU_IO_DEFS
34 #define DEF(s, n, copy_size) INDEX_op_ ## s,
43 uint16_t gen_opc_buf[OPC_BUF_SIZE];
44 uint32_t gen_opparam_buf[OPPARAM_BUF_SIZE];
45 uint32_t gen_opc_pc[OPC_BUF_SIZE];
46 uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
47 #if defined(TARGET_I386)
48 uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
52 static const char *op_str[] = {
53 #define DEF(s, n, copy_size) #s,
58 static uint8_t op_nb_args[] = {
59 #define DEF(s, n, copy_size) n,
64 void dump_ops(const uint16_t *opc_buf, const uint32_t *opparam_buf)
66 const uint16_t *opc_ptr;
67 const uint32_t *opparam_ptr;
71 opparam_ptr = opparam_buf;
75 fprintf(logfile, "0x%04x: %s",
76 (int)(opc_ptr - opc_buf - 1), op_str[c]);
77 for(i = 0; i < n; i++) {
78 fprintf(logfile, " 0x%x", opparam_ptr[i]);
80 fprintf(logfile, "\n");
81 if (c == INDEX_op_end)
89 /* return non zero if the very first instruction is invalid so that
90 the virtual CPU can trigger an exception.
92 '*gen_code_size_ptr' contains the size of the generated code (host
95 int cpu_gen_code(CPUState *env, TranslationBlock *tb,
96 int max_code_size, int *gen_code_size_ptr)
98 uint8_t *gen_code_buf;
101 if (gen_intermediate_code(env, tb) < 0)
104 /* generate machine code */
105 tb->tb_next_offset[0] = 0xffff;
106 tb->tb_next_offset[1] = 0xffff;
107 gen_code_buf = tb->tc_ptr;
108 #ifdef USE_DIRECT_JUMP
109 /* the following two entries are optional (only used for string ops) */
110 tb->tb_jmp_offset[2] = 0xffff;
111 tb->tb_jmp_offset[3] = 0xffff;
113 gen_code_size = dyngen_code(gen_code_buf, tb->tb_next_offset,
114 #ifdef USE_DIRECT_JUMP
119 gen_opc_buf, gen_opparam_buf);
120 *gen_code_size_ptr = gen_code_size;
123 fprintf(logfile, "OUT: [size=%d]\n", *gen_code_size_ptr);
124 disas(logfile, gen_code_buf, *gen_code_size_ptr, 1, 0);
125 fprintf(logfile, "\n");
132 static const unsigned short opc_copy_size[] = {
133 #define DEF(s, n, copy_size) copy_size,
138 /* The cpu state corresponding to 'searched_pc' is restored.
140 int cpu_restore_state(TranslationBlock *tb,
141 CPUState *env, unsigned long searched_pc)
144 unsigned long tc_ptr;
147 if (gen_intermediate_code_pc(env, tb) < 0)
150 /* find opc index corresponding to search_pc */
151 tc_ptr = (unsigned long)tb->tc_ptr;
152 if (searched_pc < tc_ptr)
155 opc_ptr = gen_opc_buf;
158 if (c == INDEX_op_end)
160 tc_ptr += opc_copy_size[c];
161 if (searched_pc < tc_ptr)
165 j = opc_ptr - gen_opc_buf;
166 /* now find start of instruction before */
167 while (gen_opc_instr_start[j] == 0)
169 #if defined(TARGET_I386)
175 fprintf(logfile, "RESTORE:\n");
177 if (gen_opc_instr_start[i]) {
178 fprintf(logfile, "0x%04x: 0x%08x\n", i, gen_opc_pc[i]);
181 fprintf(logfile, "spc=0x%08lx j=0x%x eip=0x%lx cs_base=%lx\n",
182 searched_pc, j, gen_opc_pc[j] - tb->cs_base, tb->cs_base);
185 env->eip = gen_opc_pc[j] - tb->cs_base;
186 cc_op = gen_opc_cc_op[j];
187 if (cc_op != CC_OP_DYNAMIC)
190 #elif defined(TARGET_ARM)
191 env->regs[15] = gen_opc_pc[j];
192 #elif defined(TARGET_SPARC)
193 env->pc = gen_opc_pc[j];
194 #elif defined(TARGET_PPC)
197 /* for PPC, we need to look at the micro operation to get the
199 env->nip = gen_opc_pc[j];
201 #if defined(CONFIG_USER_ONLY)
203 case INDEX_op_ ## op ## _raw
206 case INDEX_op_ ## op ## _raw:\
207 case INDEX_op_ ## op ## _user:\
208 case INDEX_op_ ## op ## _kernel
228 env->access_type = type;