root / exec-all.h @ a8c490cd
History | View | Annotate | Download (16.4 kB)
1 | d4e8164f | bellard | /*
|
---|---|---|---|
2 | d4e8164f | bellard | * internal execution defines for qemu
|
3 | d4e8164f | bellard | *
|
4 | d4e8164f | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | d4e8164f | bellard | *
|
6 | d4e8164f | bellard | * This library is free software; you can redistribute it and/or
|
7 | d4e8164f | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | d4e8164f | bellard | * License as published by the Free Software Foundation; either
|
9 | d4e8164f | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | d4e8164f | bellard | *
|
11 | d4e8164f | bellard | * This library is distributed in the hope that it will be useful,
|
12 | d4e8164f | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | d4e8164f | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | d4e8164f | bellard | * Lesser General Public License for more details.
|
15 | d4e8164f | bellard | *
|
16 | d4e8164f | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | d4e8164f | bellard | * License along with this library; if not, write to the Free Software
|
18 | d4e8164f | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | d4e8164f | bellard | */
|
20 | d4e8164f | bellard | |
21 | b346ff46 | bellard | /* allow to see translation results - the slowdown should be negligible, so we leave it */
|
22 | b346ff46 | bellard | #define DEBUG_DISAS
|
23 | b346ff46 | bellard | |
24 | 33417e70 | bellard | #ifndef glue
|
25 | 33417e70 | bellard | #define xglue(x, y) x ## y |
26 | 33417e70 | bellard | #define glue(x, y) xglue(x, y)
|
27 | 33417e70 | bellard | #define stringify(s) tostring(s)
|
28 | 33417e70 | bellard | #define tostring(s) #s |
29 | 33417e70 | bellard | #endif
|
30 | 33417e70 | bellard | |
31 | 33417e70 | bellard | #if GCC_MAJOR < 3 |
32 | 33417e70 | bellard | #define __builtin_expect(x, n) (x)
|
33 | 33417e70 | bellard | #endif
|
34 | 33417e70 | bellard | |
35 | e2222c39 | bellard | #ifdef __i386__
|
36 | e2222c39 | bellard | #define REGPARM(n) __attribute((regparm(n)))
|
37 | e2222c39 | bellard | #else
|
38 | e2222c39 | bellard | #define REGPARM(n)
|
39 | e2222c39 | bellard | #endif
|
40 | e2222c39 | bellard | |
41 | b346ff46 | bellard | /* is_jmp field values */
|
42 | b346ff46 | bellard | #define DISAS_NEXT 0 /* next instruction can be analyzed */ |
43 | b346ff46 | bellard | #define DISAS_JUMP 1 /* only pc was modified dynamically */ |
44 | b346ff46 | bellard | #define DISAS_UPDATE 2 /* cpu state was modified dynamically */ |
45 | b346ff46 | bellard | #define DISAS_TB_JUMP 3 /* only pc was modified statically */ |
46 | b346ff46 | bellard | |
47 | b346ff46 | bellard | struct TranslationBlock;
|
48 | b346ff46 | bellard | |
49 | b346ff46 | bellard | /* XXX: make safe guess about sizes */
|
50 | b346ff46 | bellard | #define MAX_OP_PER_INSTR 32 |
51 | b346ff46 | bellard | #define OPC_BUF_SIZE 512 |
52 | b346ff46 | bellard | #define OPC_MAX_SIZE (OPC_BUF_SIZE - MAX_OP_PER_INSTR)
|
53 | b346ff46 | bellard | |
54 | b346ff46 | bellard | #define OPPARAM_BUF_SIZE (OPC_BUF_SIZE * 3) |
55 | b346ff46 | bellard | |
56 | b346ff46 | bellard | extern uint16_t gen_opc_buf[OPC_BUF_SIZE];
|
57 | b346ff46 | bellard | extern uint32_t gen_opparam_buf[OPPARAM_BUF_SIZE];
|
58 | b346ff46 | bellard | extern uint32_t gen_opc_pc[OPC_BUF_SIZE];
|
59 | 66e85a21 | bellard | extern uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
|
60 | b346ff46 | bellard | extern uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
|
61 | b346ff46 | bellard | |
62 | 9886cc16 | bellard | typedef void (GenOpFunc)(void); |
63 | 9886cc16 | bellard | typedef void (GenOpFunc1)(long); |
64 | 9886cc16 | bellard | typedef void (GenOpFunc2)(long, long); |
65 | 9886cc16 | bellard | typedef void (GenOpFunc3)(long, long, long); |
66 | 9886cc16 | bellard | |
67 | b346ff46 | bellard | #if defined(TARGET_I386)
|
68 | b346ff46 | bellard | |
69 | 33417e70 | bellard | void optimize_flags_init(void); |
70 | d4e8164f | bellard | |
71 | b346ff46 | bellard | #endif
|
72 | b346ff46 | bellard | |
73 | b346ff46 | bellard | extern FILE *logfile;
|
74 | b346ff46 | bellard | extern int loglevel; |
75 | b346ff46 | bellard | |
76 | 4c3a88a2 | bellard | int gen_intermediate_code(CPUState *env, struct TranslationBlock *tb); |
77 | 4c3a88a2 | bellard | int gen_intermediate_code_pc(CPUState *env, struct TranslationBlock *tb); |
78 | b346ff46 | bellard | void dump_ops(const uint16_t *opc_buf, const uint32_t *opparam_buf); |
79 | 4c3a88a2 | bellard | int cpu_gen_code(CPUState *env, struct TranslationBlock *tb, |
80 | b346ff46 | bellard | int max_code_size, int *gen_code_size_ptr); |
81 | 66e85a21 | bellard | int cpu_restore_state(struct TranslationBlock *tb, |
82 | 58fe2f10 | bellard | CPUState *env, unsigned long searched_pc, |
83 | 58fe2f10 | bellard | void *puc);
|
84 | 58fe2f10 | bellard | int cpu_gen_code_copy(CPUState *env, struct TranslationBlock *tb, |
85 | 58fe2f10 | bellard | int max_code_size, int *gen_code_size_ptr); |
86 | 58fe2f10 | bellard | int cpu_restore_state_copy(struct TranslationBlock *tb, |
87 | 58fe2f10 | bellard | CPUState *env, unsigned long searched_pc, |
88 | 58fe2f10 | bellard | void *puc);
|
89 | 2e12669a | bellard | void cpu_resume_from_signal(CPUState *env1, void *puc); |
90 | b346ff46 | bellard | void cpu_exec_init(void); |
91 | 2e12669a | bellard | int page_unprotect(unsigned long address, unsigned long pc, void *puc); |
92 | 2e12669a | bellard | void tb_invalidate_phys_page_range(target_ulong start, target_ulong end,
|
93 | 2e12669a | bellard | int is_cpu_write_access);
|
94 | 4390df51 | bellard | void tb_invalidate_page_range(target_ulong start, target_ulong end);
|
95 | 2e12669a | bellard | void tlb_flush_page(CPUState *env, target_ulong addr);
|
96 | ee8b7021 | bellard | void tlb_flush(CPUState *env, int flush_global); |
97 | 2e12669a | bellard | int tlb_set_page(CPUState *env, target_ulong vaddr,
|
98 | 2e12669a | bellard | target_phys_addr_t paddr, int prot,
|
99 | 4390df51 | bellard | int is_user, int is_softmmu); |
100 | d4e8164f | bellard | |
101 | d4e8164f | bellard | #define CODE_GEN_MAX_SIZE 65536 |
102 | d4e8164f | bellard | #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ |
103 | d4e8164f | bellard | |
104 | d4e8164f | bellard | #define CODE_GEN_HASH_BITS 15 |
105 | d4e8164f | bellard | #define CODE_GEN_HASH_SIZE (1 << CODE_GEN_HASH_BITS) |
106 | d4e8164f | bellard | |
107 | 4390df51 | bellard | #define CODE_GEN_PHYS_HASH_BITS 15 |
108 | 4390df51 | bellard | #define CODE_GEN_PHYS_HASH_SIZE (1 << CODE_GEN_PHYS_HASH_BITS) |
109 | 4390df51 | bellard | |
110 | d4e8164f | bellard | /* maximum total translate dcode allocated */
|
111 | 4390df51 | bellard | |
112 | 4390df51 | bellard | /* NOTE: the translated code area cannot be too big because on some
|
113 | c4c7e3e6 | bellard | archs the range of "fast" function calls is limited. Here is a
|
114 | 4390df51 | bellard | summary of the ranges:
|
115 | 4390df51 | bellard | |
116 | 4390df51 | bellard | i386 : signed 32 bits
|
117 | 4390df51 | bellard | arm : signed 26 bits
|
118 | 4390df51 | bellard | ppc : signed 24 bits
|
119 | 4390df51 | bellard | sparc : signed 32 bits
|
120 | 4390df51 | bellard | alpha : signed 23 bits
|
121 | 4390df51 | bellard | */
|
122 | 4390df51 | bellard | |
123 | 4390df51 | bellard | #if defined(__alpha__)
|
124 | 4390df51 | bellard | #define CODE_GEN_BUFFER_SIZE (2 * 1024 * 1024) |
125 | 4390df51 | bellard | #elif defined(__powerpc__)
|
126 | c4c7e3e6 | bellard | #define CODE_GEN_BUFFER_SIZE (6 * 1024 * 1024) |
127 | 4390df51 | bellard | #else
|
128 | 4390df51 | bellard | #define CODE_GEN_BUFFER_SIZE (8 * 1024 * 1024) |
129 | 4390df51 | bellard | #endif
|
130 | 4390df51 | bellard | |
131 | d4e8164f | bellard | //#define CODE_GEN_BUFFER_SIZE (128 * 1024)
|
132 | d4e8164f | bellard | |
133 | 4390df51 | bellard | /* estimated block size for TB allocation */
|
134 | 4390df51 | bellard | /* XXX: use a per code average code fragment size and modulate it
|
135 | 4390df51 | bellard | according to the host CPU */
|
136 | 4390df51 | bellard | #if defined(CONFIG_SOFTMMU)
|
137 | 4390df51 | bellard | #define CODE_GEN_AVG_BLOCK_SIZE 128 |
138 | 4390df51 | bellard | #else
|
139 | 4390df51 | bellard | #define CODE_GEN_AVG_BLOCK_SIZE 64 |
140 | 4390df51 | bellard | #endif
|
141 | 4390df51 | bellard | |
142 | 4390df51 | bellard | #define CODE_GEN_MAX_BLOCKS (CODE_GEN_BUFFER_SIZE / CODE_GEN_AVG_BLOCK_SIZE)
|
143 | 4390df51 | bellard | |
144 | 4390df51 | bellard | #if defined(__powerpc__)
|
145 | 4390df51 | bellard | #define USE_DIRECT_JUMP
|
146 | 4390df51 | bellard | #endif
|
147 | 67b915a5 | bellard | #if defined(__i386__) && !defined(_WIN32)
|
148 | d4e8164f | bellard | #define USE_DIRECT_JUMP
|
149 | d4e8164f | bellard | #endif
|
150 | d4e8164f | bellard | |
151 | d4e8164f | bellard | typedef struct TranslationBlock { |
152 | 2e12669a | bellard | target_ulong pc; /* simulated PC corresponding to this block (EIP + CS base) */
|
153 | 2e12669a | bellard | target_ulong cs_base; /* CS base for this block */
|
154 | d4e8164f | bellard | unsigned int flags; /* flags defining in which context the code was generated */ |
155 | d4e8164f | bellard | uint16_t size; /* size of target code for this block (1 <=
|
156 | d4e8164f | bellard | size <= TARGET_PAGE_SIZE) */
|
157 | 58fe2f10 | bellard | uint16_t cflags; /* compile flags */
|
158 | bf088061 | bellard | #define CF_CODE_COPY 0x0001 /* block was generated in code copy mode */ |
159 | bf088061 | bellard | #define CF_TB_FP_USED 0x0002 /* fp ops are used in the TB */ |
160 | bf088061 | bellard | #define CF_FP_USED 0x0004 /* fp ops are used in the TB or in a chained TB */ |
161 | 2e12669a | bellard | #define CF_SINGLE_INSN 0x0008 /* compile only a single instruction */ |
162 | 58fe2f10 | bellard | |
163 | d4e8164f | bellard | uint8_t *tc_ptr; /* pointer to the translated code */
|
164 | 4390df51 | bellard | struct TranslationBlock *hash_next; /* next matching tb for virtual address */ |
165 | 4390df51 | bellard | /* next matching tb for physical address. */
|
166 | 4390df51 | bellard | struct TranslationBlock *phys_hash_next;
|
167 | 4390df51 | bellard | /* first and second physical page containing code. The lower bit
|
168 | 4390df51 | bellard | of the pointer tells the index in page_next[] */
|
169 | 4390df51 | bellard | struct TranslationBlock *page_next[2]; |
170 | 4390df51 | bellard | target_ulong page_addr[2];
|
171 | 4390df51 | bellard | |
172 | d4e8164f | bellard | /* the following data are used to directly call another TB from
|
173 | d4e8164f | bellard | the code of this one. */
|
174 | d4e8164f | bellard | uint16_t tb_next_offset[2]; /* offset of original jump target */ |
175 | d4e8164f | bellard | #ifdef USE_DIRECT_JUMP
|
176 | 4cbb86e1 | bellard | uint16_t tb_jmp_offset[4]; /* offset of jump instruction */ |
177 | d4e8164f | bellard | #else
|
178 | 95f7652d | bellard | uint32_t tb_next[2]; /* address of jump generated code */ |
179 | d4e8164f | bellard | #endif
|
180 | d4e8164f | bellard | /* list of TBs jumping to this one. This is a circular list using
|
181 | d4e8164f | bellard | the two least significant bits of the pointers to tell what is
|
182 | d4e8164f | bellard | the next pointer: 0 = jmp_next[0], 1 = jmp_next[1], 2 =
|
183 | d4e8164f | bellard | jmp_first */
|
184 | d4e8164f | bellard | struct TranslationBlock *jmp_next[2]; |
185 | d4e8164f | bellard | struct TranslationBlock *jmp_first;
|
186 | d4e8164f | bellard | } TranslationBlock; |
187 | d4e8164f | bellard | |
188 | d4e8164f | bellard | static inline unsigned int tb_hash_func(unsigned long pc) |
189 | d4e8164f | bellard | { |
190 | d4e8164f | bellard | return pc & (CODE_GEN_HASH_SIZE - 1); |
191 | d4e8164f | bellard | } |
192 | d4e8164f | bellard | |
193 | 4390df51 | bellard | static inline unsigned int tb_phys_hash_func(unsigned long pc) |
194 | 4390df51 | bellard | { |
195 | 4390df51 | bellard | return pc & (CODE_GEN_PHYS_HASH_SIZE - 1); |
196 | 4390df51 | bellard | } |
197 | 4390df51 | bellard | |
198 | d4e8164f | bellard | TranslationBlock *tb_alloc(unsigned long pc); |
199 | 0124311e | bellard | void tb_flush(CPUState *env);
|
200 | d4e8164f | bellard | void tb_link(TranslationBlock *tb);
|
201 | 4390df51 | bellard | void tb_link_phys(TranslationBlock *tb,
|
202 | 4390df51 | bellard | target_ulong phys_pc, target_ulong phys_page2); |
203 | d4e8164f | bellard | |
204 | d4e8164f | bellard | extern TranslationBlock *tb_hash[CODE_GEN_HASH_SIZE];
|
205 | 4390df51 | bellard | extern TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
|
206 | d4e8164f | bellard | |
207 | d4e8164f | bellard | extern uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE];
|
208 | d4e8164f | bellard | extern uint8_t *code_gen_ptr;
|
209 | d4e8164f | bellard | |
210 | d4e8164f | bellard | /* find a translation block in the translation cache. If not found,
|
211 | d4e8164f | bellard | return NULL and the pointer to the last element of the list in pptb */
|
212 | d4e8164f | bellard | static inline TranslationBlock *tb_find(TranslationBlock ***pptb, |
213 | 2e12669a | bellard | target_ulong pc, |
214 | 2e12669a | bellard | target_ulong cs_base, |
215 | d4e8164f | bellard | unsigned int flags) |
216 | d4e8164f | bellard | { |
217 | d4e8164f | bellard | TranslationBlock **ptb, *tb; |
218 | d4e8164f | bellard | unsigned int h; |
219 | d4e8164f | bellard | |
220 | d4e8164f | bellard | h = tb_hash_func(pc); |
221 | d4e8164f | bellard | ptb = &tb_hash[h]; |
222 | d4e8164f | bellard | for(;;) {
|
223 | d4e8164f | bellard | tb = *ptb; |
224 | d4e8164f | bellard | if (!tb)
|
225 | d4e8164f | bellard | break;
|
226 | d4e8164f | bellard | if (tb->pc == pc && tb->cs_base == cs_base && tb->flags == flags)
|
227 | d4e8164f | bellard | return tb;
|
228 | d4e8164f | bellard | ptb = &tb->hash_next; |
229 | d4e8164f | bellard | } |
230 | d4e8164f | bellard | *pptb = ptb; |
231 | d4e8164f | bellard | return NULL; |
232 | d4e8164f | bellard | } |
233 | d4e8164f | bellard | |
234 | d4e8164f | bellard | |
235 | 4390df51 | bellard | #if defined(USE_DIRECT_JUMP)
|
236 | 4390df51 | bellard | |
237 | 4390df51 | bellard | #if defined(__powerpc__)
|
238 | 4cbb86e1 | bellard | static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr) |
239 | d4e8164f | bellard | { |
240 | d4e8164f | bellard | uint32_t val, *ptr; |
241 | d4e8164f | bellard | |
242 | d4e8164f | bellard | /* patch the branch destination */
|
243 | 4cbb86e1 | bellard | ptr = (uint32_t *)jmp_addr; |
244 | d4e8164f | bellard | val = *ptr; |
245 | 4cbb86e1 | bellard | val = (val & ~0x03fffffc) | ((addr - jmp_addr) & 0x03fffffc); |
246 | d4e8164f | bellard | *ptr = val; |
247 | d4e8164f | bellard | /* flush icache */
|
248 | d4e8164f | bellard | asm volatile ("dcbst 0,%0" : : "r"(ptr) : "memory"); |
249 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
250 | d4e8164f | bellard | asm volatile ("icbi 0,%0" : : "r"(ptr) : "memory"); |
251 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
252 | d4e8164f | bellard | asm volatile ("isync" : : : "memory"); |
253 | d4e8164f | bellard | } |
254 | 4390df51 | bellard | #elif defined(__i386__)
|
255 | 4390df51 | bellard | static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr) |
256 | 4390df51 | bellard | { |
257 | 4390df51 | bellard | /* patch the branch destination */
|
258 | 4390df51 | bellard | *(uint32_t *)jmp_addr = addr - (jmp_addr + 4);
|
259 | 4390df51 | bellard | /* no need to flush icache explicitely */
|
260 | 4390df51 | bellard | } |
261 | 4390df51 | bellard | #endif
|
262 | d4e8164f | bellard | |
263 | 4cbb86e1 | bellard | static inline void tb_set_jmp_target(TranslationBlock *tb, |
264 | 4cbb86e1 | bellard | int n, unsigned long addr) |
265 | 4cbb86e1 | bellard | { |
266 | 4cbb86e1 | bellard | unsigned long offset; |
267 | 4cbb86e1 | bellard | |
268 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n]; |
269 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
270 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n + 2];
|
271 | 4cbb86e1 | bellard | if (offset != 0xffff) |
272 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
273 | 4cbb86e1 | bellard | } |
274 | 4cbb86e1 | bellard | |
275 | d4e8164f | bellard | #else
|
276 | d4e8164f | bellard | |
277 | d4e8164f | bellard | /* set the jump target */
|
278 | d4e8164f | bellard | static inline void tb_set_jmp_target(TranslationBlock *tb, |
279 | d4e8164f | bellard | int n, unsigned long addr) |
280 | d4e8164f | bellard | { |
281 | 95f7652d | bellard | tb->tb_next[n] = addr; |
282 | d4e8164f | bellard | } |
283 | d4e8164f | bellard | |
284 | d4e8164f | bellard | #endif
|
285 | d4e8164f | bellard | |
286 | d4e8164f | bellard | static inline void tb_add_jump(TranslationBlock *tb, int n, |
287 | d4e8164f | bellard | TranslationBlock *tb_next) |
288 | d4e8164f | bellard | { |
289 | cf25629d | bellard | /* NOTE: this test is only needed for thread safety */
|
290 | cf25629d | bellard | if (!tb->jmp_next[n]) {
|
291 | cf25629d | bellard | /* patch the native jump address */
|
292 | cf25629d | bellard | tb_set_jmp_target(tb, n, (unsigned long)tb_next->tc_ptr); |
293 | cf25629d | bellard | |
294 | cf25629d | bellard | /* add in TB jmp circular list */
|
295 | cf25629d | bellard | tb->jmp_next[n] = tb_next->jmp_first; |
296 | cf25629d | bellard | tb_next->jmp_first = (TranslationBlock *)((long)(tb) | (n));
|
297 | cf25629d | bellard | } |
298 | d4e8164f | bellard | } |
299 | d4e8164f | bellard | |
300 | a513fe19 | bellard | TranslationBlock *tb_find_pc(unsigned long pc_ptr); |
301 | a513fe19 | bellard | |
302 | d4e8164f | bellard | #ifndef offsetof
|
303 | d4e8164f | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
304 | d4e8164f | bellard | #endif
|
305 | d4e8164f | bellard | |
306 | b346ff46 | bellard | #if defined(__powerpc__)
|
307 | b346ff46 | bellard | |
308 | 4390df51 | bellard | /* we patch the jump instruction directly */
|
309 | 9257a9e4 | bellard | #define JUMP_TB(opname, tbparam, n, eip)\
|
310 | b346ff46 | bellard | do {\
|
311 | 9257a9e4 | bellard | asm volatile (".section \".data\"\n"\ |
312 | 9257a9e4 | bellard | "__op_label" #n "." stringify(opname) ":\n"\ |
313 | 9257a9e4 | bellard | ".long 1f\n"\
|
314 | 9257a9e4 | bellard | ".previous\n"\
|
315 | 9257a9e4 | bellard | "b __op_jmp" #n "\n"\ |
316 | 9257a9e4 | bellard | "1:\n");\
|
317 | b346ff46 | bellard | T0 = (long)(tbparam) + (n);\
|
318 | b346ff46 | bellard | EIP = eip;\ |
319 | 31e8f3c8 | bellard | EXIT_TB();\ |
320 | b346ff46 | bellard | } while (0) |
321 | b346ff46 | bellard | |
322 | 4cbb86e1 | bellard | #define JUMP_TB2(opname, tbparam, n)\
|
323 | 4cbb86e1 | bellard | do {\
|
324 | 4390df51 | bellard | asm volatile ("b __op_jmp" #n "\n");\ |
325 | 4390df51 | bellard | } while (0) |
326 | 4390df51 | bellard | |
327 | 4390df51 | bellard | #elif defined(__i386__) && defined(USE_DIRECT_JUMP)
|
328 | 4390df51 | bellard | |
329 | 67b915a5 | bellard | #ifdef _WIN32
|
330 | 67b915a5 | bellard | #define ASM_PREVIOUS_SECTION ".section .text\n" |
331 | 67b915a5 | bellard | #else
|
332 | 67b915a5 | bellard | #define ASM_PREVIOUS_SECTION ".previous\n" |
333 | 67b915a5 | bellard | #endif
|
334 | 67b915a5 | bellard | |
335 | 4390df51 | bellard | /* we patch the jump instruction directly */
|
336 | 4390df51 | bellard | #define JUMP_TB(opname, tbparam, n, eip)\
|
337 | 4390df51 | bellard | do {\
|
338 | 67b915a5 | bellard | asm volatile (".section .data\n"\ |
339 | 4390df51 | bellard | "__op_label" #n "." stringify(opname) ":\n"\ |
340 | 4390df51 | bellard | ".long 1f\n"\
|
341 | 67b915a5 | bellard | ASM_PREVIOUS_SECTION \ |
342 | 4390df51 | bellard | "jmp __op_jmp" #n "\n"\ |
343 | 4390df51 | bellard | "1:\n");\
|
344 | 4390df51 | bellard | T0 = (long)(tbparam) + (n);\
|
345 | 4390df51 | bellard | EIP = eip;\ |
346 | 4390df51 | bellard | EXIT_TB();\ |
347 | 4390df51 | bellard | } while (0) |
348 | 4390df51 | bellard | |
349 | 4390df51 | bellard | #define JUMP_TB2(opname, tbparam, n)\
|
350 | 4390df51 | bellard | do {\
|
351 | 4390df51 | bellard | asm volatile ("jmp __op_jmp" #n "\n");\ |
352 | 4cbb86e1 | bellard | } while (0) |
353 | 4cbb86e1 | bellard | |
354 | b346ff46 | bellard | #else
|
355 | b346ff46 | bellard | |
356 | b346ff46 | bellard | /* jump to next block operations (more portable code, does not need
|
357 | b346ff46 | bellard | cache flushing, but slower because of indirect jump) */
|
358 | 9257a9e4 | bellard | #define JUMP_TB(opname, tbparam, n, eip)\
|
359 | b346ff46 | bellard | do {\
|
360 | b346ff46 | bellard | static void __attribute__((unused)) *__op_label ## n = &&label ## n;\ |
361 | 2f62b397 | bellard | static void __attribute__((unused)) *dummy ## n = &&dummy_label ## n;\ |
362 | b346ff46 | bellard | goto *(void *)(((TranslationBlock *)tbparam)->tb_next[n]);\ |
363 | b346ff46 | bellard | label ## n:\ |
364 | b346ff46 | bellard | T0 = (long)(tbparam) + (n);\
|
365 | b346ff46 | bellard | EIP = eip;\ |
366 | 2f62b397 | bellard | dummy_label ## n:\ |
367 | 9621339d | bellard | EXIT_TB();\ |
368 | b346ff46 | bellard | } while (0) |
369 | b346ff46 | bellard | |
370 | 4cbb86e1 | bellard | /* second jump to same destination 'n' */
|
371 | 4cbb86e1 | bellard | #define JUMP_TB2(opname, tbparam, n)\
|
372 | 4cbb86e1 | bellard | do {\
|
373 | 4390df51 | bellard | goto *(void *)(((TranslationBlock *)tbparam)->tb_next[n - 2]);\ |
374 | 4cbb86e1 | bellard | } while (0) |
375 | 4cbb86e1 | bellard | |
376 | b346ff46 | bellard | #endif
|
377 | b346ff46 | bellard | |
378 | 33417e70 | bellard | extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; |
379 | 33417e70 | bellard | extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; |
380 | 33417e70 | bellard | |
381 | d4e8164f | bellard | #ifdef __powerpc__
|
382 | d4e8164f | bellard | static inline int testandset (int *p) |
383 | d4e8164f | bellard | { |
384 | d4e8164f | bellard | int ret;
|
385 | d4e8164f | bellard | __asm__ __volatile__ ( |
386 | d4e8164f | bellard | "0: lwarx %0,0,%1 ;"
|
387 | d4e8164f | bellard | " xor. %0,%3,%0;"
|
388 | d4e8164f | bellard | " bne 1f;"
|
389 | d4e8164f | bellard | " stwcx. %2,0,%1;"
|
390 | d4e8164f | bellard | " bne- 0b;"
|
391 | d4e8164f | bellard | "1: "
|
392 | d4e8164f | bellard | : "=&r" (ret)
|
393 | d4e8164f | bellard | : "r" (p), "r" (1), "r" (0) |
394 | d4e8164f | bellard | : "cr0", "memory"); |
395 | d4e8164f | bellard | return ret;
|
396 | d4e8164f | bellard | } |
397 | d4e8164f | bellard | #endif
|
398 | d4e8164f | bellard | |
399 | d4e8164f | bellard | #ifdef __i386__
|
400 | d4e8164f | bellard | static inline int testandset (int *p) |
401 | d4e8164f | bellard | { |
402 | d4e8164f | bellard | char ret;
|
403 | d4e8164f | bellard | long int readval; |
404 | d4e8164f | bellard | |
405 | d4e8164f | bellard | __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
|
406 | d4e8164f | bellard | : "=q" (ret), "=m" (*p), "=a" (readval) |
407 | d4e8164f | bellard | : "r" (1), "m" (*p), "a" (0) |
408 | d4e8164f | bellard | : "memory");
|
409 | d4e8164f | bellard | return ret;
|
410 | d4e8164f | bellard | } |
411 | d4e8164f | bellard | #endif
|
412 | d4e8164f | bellard | |
413 | bc51c5c9 | bellard | #ifdef __x86_64__
|
414 | bc51c5c9 | bellard | static inline int testandset (int *p) |
415 | bc51c5c9 | bellard | { |
416 | bc51c5c9 | bellard | char ret;
|
417 | bc51c5c9 | bellard | int readval;
|
418 | bc51c5c9 | bellard | |
419 | bc51c5c9 | bellard | __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
|
420 | bc51c5c9 | bellard | : "=q" (ret), "=m" (*p), "=a" (readval) |
421 | bc51c5c9 | bellard | : "r" (1), "m" (*p), "a" (0) |
422 | bc51c5c9 | bellard | : "memory");
|
423 | bc51c5c9 | bellard | return ret;
|
424 | bc51c5c9 | bellard | } |
425 | bc51c5c9 | bellard | #endif
|
426 | bc51c5c9 | bellard | |
427 | d4e8164f | bellard | #ifdef __s390__
|
428 | d4e8164f | bellard | static inline int testandset (int *p) |
429 | d4e8164f | bellard | { |
430 | d4e8164f | bellard | int ret;
|
431 | d4e8164f | bellard | |
432 | d4e8164f | bellard | __asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
|
433 | d4e8164f | bellard | " jl 0b"
|
434 | d4e8164f | bellard | : "=&d" (ret)
|
435 | d4e8164f | bellard | : "r" (1), "a" (p), "0" (*p) |
436 | d4e8164f | bellard | : "cc", "memory" ); |
437 | d4e8164f | bellard | return ret;
|
438 | d4e8164f | bellard | } |
439 | d4e8164f | bellard | #endif
|
440 | d4e8164f | bellard | |
441 | d4e8164f | bellard | #ifdef __alpha__
|
442 | 2f87c607 | bellard | static inline int testandset (int *p) |
443 | d4e8164f | bellard | { |
444 | d4e8164f | bellard | int ret;
|
445 | d4e8164f | bellard | unsigned long one; |
446 | d4e8164f | bellard | |
447 | d4e8164f | bellard | __asm__ __volatile__ ("0: mov 1,%2\n"
|
448 | d4e8164f | bellard | " ldl_l %0,%1\n"
|
449 | d4e8164f | bellard | " stl_c %2,%1\n"
|
450 | d4e8164f | bellard | " beq %2,1f\n"
|
451 | d4e8164f | bellard | ".subsection 2\n"
|
452 | d4e8164f | bellard | "1: br 0b\n"
|
453 | d4e8164f | bellard | ".previous"
|
454 | d4e8164f | bellard | : "=r" (ret), "=m" (*p), "=r" (one) |
455 | d4e8164f | bellard | : "m" (*p));
|
456 | d4e8164f | bellard | return ret;
|
457 | d4e8164f | bellard | } |
458 | d4e8164f | bellard | #endif
|
459 | d4e8164f | bellard | |
460 | d4e8164f | bellard | #ifdef __sparc__
|
461 | d4e8164f | bellard | static inline int testandset (int *p) |
462 | d4e8164f | bellard | { |
463 | d4e8164f | bellard | int ret;
|
464 | d4e8164f | bellard | |
465 | d4e8164f | bellard | __asm__ __volatile__("ldstub [%1], %0"
|
466 | d4e8164f | bellard | : "=r" (ret)
|
467 | d4e8164f | bellard | : "r" (p)
|
468 | d4e8164f | bellard | : "memory");
|
469 | d4e8164f | bellard | |
470 | d4e8164f | bellard | return (ret ? 1 : 0); |
471 | d4e8164f | bellard | } |
472 | d4e8164f | bellard | #endif
|
473 | d4e8164f | bellard | |
474 | a95c6790 | bellard | #ifdef __arm__
|
475 | a95c6790 | bellard | static inline int testandset (int *spinlock) |
476 | a95c6790 | bellard | { |
477 | a95c6790 | bellard | register unsigned int ret; |
478 | a95c6790 | bellard | __asm__ __volatile__("swp %0, %1, [%2]"
|
479 | a95c6790 | bellard | : "=r"(ret)
|
480 | a95c6790 | bellard | : "0"(1), "r"(spinlock)); |
481 | a95c6790 | bellard | |
482 | a95c6790 | bellard | return ret;
|
483 | a95c6790 | bellard | } |
484 | a95c6790 | bellard | #endif
|
485 | a95c6790 | bellard | |
486 | 38e584a0 | bellard | #ifdef __mc68000
|
487 | 38e584a0 | bellard | static inline int testandset (int *p) |
488 | 38e584a0 | bellard | { |
489 | 38e584a0 | bellard | char ret;
|
490 | 38e584a0 | bellard | __asm__ __volatile__("tas %1; sne %0"
|
491 | 38e584a0 | bellard | : "=r" (ret)
|
492 | 38e584a0 | bellard | : "m" (p)
|
493 | 38e584a0 | bellard | : "cc","memory"); |
494 | 38e584a0 | bellard | return ret == 0; |
495 | 38e584a0 | bellard | } |
496 | 38e584a0 | bellard | #endif
|
497 | 38e584a0 | bellard | |
498 | d4e8164f | bellard | typedef int spinlock_t; |
499 | d4e8164f | bellard | |
500 | d4e8164f | bellard | #define SPIN_LOCK_UNLOCKED 0 |
501 | d4e8164f | bellard | |
502 | aebcb60e | bellard | #if defined(CONFIG_USER_ONLY)
|
503 | d4e8164f | bellard | static inline void spin_lock(spinlock_t *lock) |
504 | d4e8164f | bellard | { |
505 | d4e8164f | bellard | while (testandset(lock));
|
506 | d4e8164f | bellard | } |
507 | d4e8164f | bellard | |
508 | d4e8164f | bellard | static inline void spin_unlock(spinlock_t *lock) |
509 | d4e8164f | bellard | { |
510 | d4e8164f | bellard | *lock = 0;
|
511 | d4e8164f | bellard | } |
512 | d4e8164f | bellard | |
513 | d4e8164f | bellard | static inline int spin_trylock(spinlock_t *lock) |
514 | d4e8164f | bellard | { |
515 | d4e8164f | bellard | return !testandset(lock);
|
516 | d4e8164f | bellard | } |
517 | 3c1cf9fa | bellard | #else
|
518 | 3c1cf9fa | bellard | static inline void spin_lock(spinlock_t *lock) |
519 | 3c1cf9fa | bellard | { |
520 | 3c1cf9fa | bellard | } |
521 | 3c1cf9fa | bellard | |
522 | 3c1cf9fa | bellard | static inline void spin_unlock(spinlock_t *lock) |
523 | 3c1cf9fa | bellard | { |
524 | 3c1cf9fa | bellard | } |
525 | 3c1cf9fa | bellard | |
526 | 3c1cf9fa | bellard | static inline int spin_trylock(spinlock_t *lock) |
527 | 3c1cf9fa | bellard | { |
528 | 3c1cf9fa | bellard | return 1; |
529 | 3c1cf9fa | bellard | } |
530 | 3c1cf9fa | bellard | #endif
|
531 | d4e8164f | bellard | |
532 | d4e8164f | bellard | extern spinlock_t tb_lock;
|
533 | d4e8164f | bellard | |
534 | 36bdbe54 | bellard | extern int tb_invalidated_flag; |
535 | 6e59c1db | bellard | |
536 | 9886cc16 | bellard | #if (defined(TARGET_I386) || defined(TARGET_PPC)) && \
|
537 | 9886cc16 | bellard | !defined(CONFIG_USER_ONLY) |
538 | 6e59c1db | bellard | |
539 | 6e59c1db | bellard | void tlb_fill(unsigned long addr, int is_write, int is_user, |
540 | 6e59c1db | bellard | void *retaddr);
|
541 | 6e59c1db | bellard | |
542 | 6e59c1db | bellard | #define ACCESS_TYPE 3 |
543 | 6e59c1db | bellard | #define MEMSUFFIX _code
|
544 | 6e59c1db | bellard | #define env cpu_single_env
|
545 | 6e59c1db | bellard | |
546 | 6e59c1db | bellard | #define DATA_SIZE 1 |
547 | 6e59c1db | bellard | #include "softmmu_header.h" |
548 | 6e59c1db | bellard | |
549 | 6e59c1db | bellard | #define DATA_SIZE 2 |
550 | 6e59c1db | bellard | #include "softmmu_header.h" |
551 | 6e59c1db | bellard | |
552 | 6e59c1db | bellard | #define DATA_SIZE 4 |
553 | 6e59c1db | bellard | #include "softmmu_header.h" |
554 | 6e59c1db | bellard | |
555 | 6e59c1db | bellard | #undef ACCESS_TYPE
|
556 | 6e59c1db | bellard | #undef MEMSUFFIX
|
557 | 6e59c1db | bellard | #undef env
|
558 | 6e59c1db | bellard | |
559 | 6e59c1db | bellard | #endif
|
560 | 4390df51 | bellard | |
561 | 4390df51 | bellard | #if defined(CONFIG_USER_ONLY)
|
562 | 4390df51 | bellard | static inline target_ulong get_phys_addr_code(CPUState *env, target_ulong addr) |
563 | 4390df51 | bellard | { |
564 | 4390df51 | bellard | return addr;
|
565 | 4390df51 | bellard | } |
566 | 4390df51 | bellard | #else
|
567 | 4390df51 | bellard | /* NOTE: this function can trigger an exception */
|
568 | 1ccde1cb | bellard | /* NOTE2: the returned address is not exactly the physical address: it
|
569 | 1ccde1cb | bellard | is the offset relative to phys_ram_base */
|
570 | 4390df51 | bellard | /* XXX: i386 target specific */
|
571 | 4390df51 | bellard | static inline target_ulong get_phys_addr_code(CPUState *env, target_ulong addr) |
572 | 4390df51 | bellard | { |
573 | 4390df51 | bellard | int is_user, index;
|
574 | 4390df51 | bellard | |
575 | 4390df51 | bellard | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
576 | 3f5dcc34 | bellard | #if defined(TARGET_I386)
|
577 | 4390df51 | bellard | is_user = ((env->hflags & HF_CPL_MASK) == 3);
|
578 | 3f5dcc34 | bellard | #elif defined (TARGET_PPC)
|
579 | 3f5dcc34 | bellard | is_user = msr_pr; |
580 | 3f5dcc34 | bellard | #else
|
581 | 3f5dcc34 | bellard | #error "Unimplemented !" |
582 | 3f5dcc34 | bellard | #endif
|
583 | 4390df51 | bellard | if (__builtin_expect(env->tlb_read[is_user][index].address !=
|
584 | 4390df51 | bellard | (addr & TARGET_PAGE_MASK), 0)) {
|
585 | a541f297 | bellard | #if defined (TARGET_PPC)
|
586 | a541f297 | bellard | env->access_type = ACCESS_CODE; |
587 | a541f297 | bellard | ldub_code((void *)addr);
|
588 | a541f297 | bellard | env->access_type = ACCESS_INT; |
589 | a541f297 | bellard | #else
|
590 | 4390df51 | bellard | ldub_code((void *)addr);
|
591 | a541f297 | bellard | #endif
|
592 | 4390df51 | bellard | } |
593 | 4390df51 | bellard | return addr + env->tlb_read[is_user][index].addend - (unsigned long)phys_ram_base; |
594 | 4390df51 | bellard | } |
595 | 4390df51 | bellard | #endif |