sclp: Fix uninitialized var in handle_write_event_buf().
[qemu.git] / translate-all.c
blobd9c2e57861d877694ef9a191a8db2f4d6df6972e
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, see <http://www.gnu.org/licenses/>.
19 #include <stdarg.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <inttypes.h>
25 #include "config.h"
27 #define NO_CPU_IO_DEFS
28 #include "cpu.h"
29 #include "disas.h"
30 #include "tcg.h"
31 #include "qemu-timer.h"
33 /* code generation context */
34 TCGContext tcg_ctx;
36 target_ulong gen_opc_pc[OPC_BUF_SIZE];
37 uint16_t gen_opc_icount[OPC_BUF_SIZE];
38 uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
40 void cpu_gen_init(void)
42 tcg_context_init(&tcg_ctx);
45 /* return non zero if the very first instruction is invalid so that
46 the virtual CPU can trigger an exception.
48 '*gen_code_size_ptr' contains the size of the generated code (host
49 code).
51 int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr)
53 TCGContext *s = &tcg_ctx;
54 uint8_t *gen_code_buf;
55 int gen_code_size;
56 #ifdef CONFIG_PROFILER
57 int64_t ti;
58 #endif
60 #ifdef CONFIG_PROFILER
61 s->tb_count1++; /* includes aborted translations because of
62 exceptions */
63 ti = profile_getclock();
64 #endif
65 tcg_func_start(s);
67 gen_intermediate_code(env, tb);
69 /* generate machine code */
70 gen_code_buf = tb->tc_ptr;
71 tb->tb_next_offset[0] = 0xffff;
72 tb->tb_next_offset[1] = 0xffff;
73 s->tb_next_offset = tb->tb_next_offset;
74 #ifdef USE_DIRECT_JUMP
75 s->tb_jmp_offset = tb->tb_jmp_offset;
76 s->tb_next = NULL;
77 #else
78 s->tb_jmp_offset = NULL;
79 s->tb_next = tb->tb_next;
80 #endif
82 #ifdef CONFIG_PROFILER
83 s->tb_count++;
84 s->interm_time += profile_getclock() - ti;
85 s->code_time -= profile_getclock();
86 #endif
87 gen_code_size = tcg_gen_code(s, gen_code_buf);
88 *gen_code_size_ptr = gen_code_size;
89 #ifdef CONFIG_PROFILER
90 s->code_time += profile_getclock();
91 s->code_in_len += tb->size;
92 s->code_out_len += gen_code_size;
93 #endif
95 #ifdef DEBUG_DISAS
96 if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
97 qemu_log("OUT: [size=%d]\n", *gen_code_size_ptr);
98 log_disas(tb->tc_ptr, *gen_code_size_ptr);
99 qemu_log("\n");
100 qemu_log_flush();
102 #endif
103 return 0;
106 /* The cpu state corresponding to 'searched_pc' is restored.
108 int cpu_restore_state(TranslationBlock *tb,
109 CPUArchState *env, uintptr_t searched_pc)
111 TCGContext *s = &tcg_ctx;
112 int j;
113 uintptr_t tc_ptr;
114 #ifdef CONFIG_PROFILER
115 int64_t ti;
116 #endif
118 #ifdef CONFIG_PROFILER
119 ti = profile_getclock();
120 #endif
121 tcg_func_start(s);
123 gen_intermediate_code_pc(env, tb);
125 if (use_icount) {
126 /* Reset the cycle counter to the start of the block. */
127 env->icount_decr.u16.low += tb->icount;
128 /* Clear the IO flag. */
129 env->can_do_io = 0;
132 /* find opc index corresponding to search_pc */
133 tc_ptr = (uintptr_t)tb->tc_ptr;
134 if (searched_pc < tc_ptr)
135 return -1;
137 s->tb_next_offset = tb->tb_next_offset;
138 #ifdef USE_DIRECT_JUMP
139 s->tb_jmp_offset = tb->tb_jmp_offset;
140 s->tb_next = NULL;
141 #else
142 s->tb_jmp_offset = NULL;
143 s->tb_next = tb->tb_next;
144 #endif
145 j = tcg_gen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
146 if (j < 0)
147 return -1;
148 /* now find start of instruction before */
149 while (gen_opc_instr_start[j] == 0)
150 j--;
151 env->icount_decr.u16.low -= gen_opc_icount[j];
153 restore_state_to_opc(env, tb, j);
155 #ifdef CONFIG_PROFILER
156 s->restore_time += profile_getclock() - ti;
157 s->restore_count++;
158 #endif
159 return 0;