Log CPU reset events
[qemu/hppa.git] / translate-all.c
blobb32052a97ac91a4f5984e49760214ce4bdf1bb7d
1 /*
2 * Host code generation
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
20 #include <stdarg.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <inttypes.h>
26 #include "config.h"
28 #define NO_CPU_IO_DEFS
29 #include "cpu.h"
30 #include "exec-all.h"
31 #include "disas.h"
32 #include "tcg.h"
34 /* code generation context */
35 TCGContext tcg_ctx;
37 uint16_t gen_opc_buf[OPC_BUF_SIZE];
38 TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE];
40 target_ulong gen_opc_pc[OPC_BUF_SIZE];
41 uint16_t gen_opc_icount[OPC_BUF_SIZE];
42 uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
43 #if defined(TARGET_I386)
44 uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
45 #elif defined(TARGET_SPARC)
46 target_ulong gen_opc_npc[OPC_BUF_SIZE];
47 target_ulong gen_opc_jump_pc[2];
48 #elif defined(TARGET_HPPA)
49 target_ulong gen_opc_npc[OPC_BUF_SIZE];
50 #elif defined(TARGET_MIPS) || defined(TARGET_SH4)
51 uint32_t gen_opc_hflags[OPC_BUF_SIZE];
52 #endif
54 /* XXX: suppress that */
55 unsigned long code_gen_max_block_size(void)
57 static unsigned long max;
59 if (max == 0) {
60 max = TCG_MAX_OP_SIZE;
61 #define DEF(s, n, copy_size) max = copy_size > max? copy_size : max;
62 #include "tcg-opc.h"
63 #undef DEF
64 max *= OPC_MAX_SIZE;
67 return max;
70 void cpu_gen_init(void)
72 tcg_context_init(&tcg_ctx);
73 tcg_set_frame(&tcg_ctx, TCG_AREG0, offsetof(CPUState, temp_buf),
74 CPU_TEMP_BUF_NLONGS * sizeof(long));
77 /* return non zero if the very first instruction is invalid so that
78 the virtual CPU can trigger an exception.
80 '*gen_code_size_ptr' contains the size of the generated code (host
81 code).
83 int cpu_gen_code(CPUState *env, TranslationBlock *tb, int *gen_code_size_ptr)
85 TCGContext *s = &tcg_ctx;
86 uint8_t *gen_code_buf;
87 int gen_code_size;
88 #ifdef CONFIG_PROFILER
89 int64_t ti;
90 #endif
92 #ifdef CONFIG_PROFILER
93 s->tb_count1++; /* includes aborted translations because of
94 exceptions */
95 ti = profile_getclock();
96 #endif
97 tcg_func_start(s);
99 gen_intermediate_code(env, tb);
101 /* generate machine code */
102 gen_code_buf = tb->tc_ptr;
103 tb->tb_next_offset[0] = 0xffff;
104 tb->tb_next_offset[1] = 0xffff;
105 s->tb_next_offset = tb->tb_next_offset;
106 #ifdef USE_DIRECT_JUMP
107 s->tb_jmp_offset = tb->tb_jmp_offset;
108 s->tb_next = NULL;
109 /* the following two entries are optional (only used for string ops) */
110 /* XXX: not used ? */
111 tb->tb_jmp_offset[2] = 0xffff;
112 tb->tb_jmp_offset[3] = 0xffff;
113 #else
114 s->tb_jmp_offset = NULL;
115 s->tb_next = tb->tb_next;
116 #endif
118 #ifdef CONFIG_PROFILER
119 s->tb_count++;
120 s->interm_time += profile_getclock() - ti;
121 s->code_time -= profile_getclock();
122 #endif
123 gen_code_size = tcg_gen_code(s, gen_code_buf);
124 *gen_code_size_ptr = gen_code_size;
125 #ifdef CONFIG_PROFILER
126 s->code_time += profile_getclock();
127 s->code_in_len += tb->size;
128 s->code_out_len += gen_code_size;
129 #endif
131 #ifdef DEBUG_DISAS
132 if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
133 qemu_log("OUT: [size=%d]\n", *gen_code_size_ptr);
134 log_disas(tb->tc_ptr, *gen_code_size_ptr);
135 qemu_log("\n");
136 qemu_log_flush();
138 #endif
139 return 0;
142 /* The cpu state corresponding to 'searched_pc' is restored.
144 int cpu_restore_state(TranslationBlock *tb,
145 CPUState *env, unsigned long searched_pc,
146 void *puc)
148 TCGContext *s = &tcg_ctx;
149 int j;
150 unsigned long tc_ptr;
151 #ifdef CONFIG_PROFILER
152 int64_t ti;
153 #endif
155 #ifdef CONFIG_PROFILER
156 ti = profile_getclock();
157 #endif
158 tcg_func_start(s);
160 gen_intermediate_code_pc(env, tb);
162 if (use_icount) {
163 /* Reset the cycle counter to the start of the block. */
164 env->icount_decr.u16.low += tb->icount;
165 /* Clear the IO flag. */
166 env->can_do_io = 0;
169 /* find opc index corresponding to search_pc */
170 tc_ptr = (unsigned long)tb->tc_ptr;
171 if (searched_pc < tc_ptr)
172 return -1;
174 s->tb_next_offset = tb->tb_next_offset;
175 #ifdef USE_DIRECT_JUMP
176 s->tb_jmp_offset = tb->tb_jmp_offset;
177 s->tb_next = NULL;
178 #else
179 s->tb_jmp_offset = NULL;
180 s->tb_next = tb->tb_next;
181 #endif
182 j = tcg_gen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
183 if (j < 0)
184 return -1;
185 /* now find start of instruction before */
186 while (gen_opc_instr_start[j] == 0)
187 j--;
188 env->icount_decr.u16.low -= gen_opc_icount[j];
190 gen_pc_load(env, tb, searched_pc, j, puc);
192 #ifdef CONFIG_PROFILER
193 s->restore_time += profile_getclock() - ti;
194 s->restore_count++;
195 #endif
196 return 0;