pci: rename pci_internals.h pci_bus.h
[qemu/ar7.git] / translate-all.c
blobf22e3eedd2c7362f3006bd191b64a9c203080df7
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 void cpu_gen_init(void)
38 tcg_context_init(&tcg_ctx);
41 /* return non zero if the very first instruction is invalid so that
42 the virtual CPU can trigger an exception.
44 '*gen_code_size_ptr' contains the size of the generated code (host
45 code).
47 int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr)
49 TCGContext *s = &tcg_ctx;
50 uint8_t *gen_code_buf;
51 int gen_code_size;
52 #ifdef CONFIG_PROFILER
53 int64_t ti;
54 #endif
56 #ifdef CONFIG_PROFILER
57 s->tb_count1++; /* includes aborted translations because of
58 exceptions */
59 ti = profile_getclock();
60 #endif
61 tcg_func_start(s);
63 gen_intermediate_code(env, tb);
65 /* generate machine code */
66 gen_code_buf = tb->tc_ptr;
67 tb->tb_next_offset[0] = 0xffff;
68 tb->tb_next_offset[1] = 0xffff;
69 s->tb_next_offset = tb->tb_next_offset;
70 #ifdef USE_DIRECT_JUMP
71 s->tb_jmp_offset = tb->tb_jmp_offset;
72 s->tb_next = NULL;
73 #else
74 s->tb_jmp_offset = NULL;
75 s->tb_next = tb->tb_next;
76 #endif
78 #ifdef CONFIG_PROFILER
79 s->tb_count++;
80 s->interm_time += profile_getclock() - ti;
81 s->code_time -= profile_getclock();
82 #endif
83 gen_code_size = tcg_gen_code(s, gen_code_buf);
84 *gen_code_size_ptr = gen_code_size;
85 #ifdef CONFIG_PROFILER
86 s->code_time += profile_getclock();
87 s->code_in_len += tb->size;
88 s->code_out_len += gen_code_size;
89 #endif
91 #ifdef DEBUG_DISAS
92 if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
93 qemu_log("OUT: [size=%d]\n", *gen_code_size_ptr);
94 log_disas(tb->tc_ptr, *gen_code_size_ptr);
95 qemu_log("\n");
96 qemu_log_flush();
98 #endif
99 return 0;
102 /* The cpu state corresponding to 'searched_pc' is restored.
104 int cpu_restore_state(TranslationBlock *tb,
105 CPUArchState *env, uintptr_t searched_pc)
107 TCGContext *s = &tcg_ctx;
108 int j;
109 uintptr_t tc_ptr;
110 #ifdef CONFIG_PROFILER
111 int64_t ti;
112 #endif
114 #ifdef CONFIG_PROFILER
115 ti = profile_getclock();
116 #endif
117 tcg_func_start(s);
119 gen_intermediate_code_pc(env, tb);
121 if (use_icount) {
122 /* Reset the cycle counter to the start of the block. */
123 env->icount_decr.u16.low += tb->icount;
124 /* Clear the IO flag. */
125 env->can_do_io = 0;
128 /* find opc index corresponding to search_pc */
129 tc_ptr = (uintptr_t)tb->tc_ptr;
130 if (searched_pc < tc_ptr)
131 return -1;
133 s->tb_next_offset = tb->tb_next_offset;
134 #ifdef USE_DIRECT_JUMP
135 s->tb_jmp_offset = tb->tb_jmp_offset;
136 s->tb_next = NULL;
137 #else
138 s->tb_jmp_offset = NULL;
139 s->tb_next = tb->tb_next;
140 #endif
141 j = tcg_gen_code_search_pc(s, (uint8_t *)tc_ptr, searched_pc - tc_ptr);
142 if (j < 0)
143 return -1;
144 /* now find start of instruction before */
145 while (s->gen_opc_instr_start[j] == 0) {
146 j--;
148 env->icount_decr.u16.low -= s->gen_opc_icount[j];
150 restore_state_to_opc(env, tb, j);
152 #ifdef CONFIG_PROFILER
153 s->restore_time += profile_getclock() - ti;
154 s->restore_count++;
155 #endif
156 return 0;