root / exec-all.h @ eb173de6
History | View | Annotate | Download (17.8 kB)
1 | d4e8164f | bellard | /*
|
---|---|---|---|
2 | d4e8164f | bellard | * internal execution defines for qemu
|
3 | 5fafdf24 | ths | *
|
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 | cb7cca1a | aurel32 | #define DEBUG_DISAS
|
23 | b346ff46 | bellard | |
24 | b346ff46 | bellard | /* is_jmp field values */
|
25 | b346ff46 | bellard | #define DISAS_NEXT 0 /* next instruction can be analyzed */ |
26 | b346ff46 | bellard | #define DISAS_JUMP 1 /* only pc was modified dynamically */ |
27 | b346ff46 | bellard | #define DISAS_UPDATE 2 /* cpu state was modified dynamically */ |
28 | b346ff46 | bellard | #define DISAS_TB_JUMP 3 /* only pc was modified statically */ |
29 | b346ff46 | bellard | |
30 | b346ff46 | bellard | struct TranslationBlock;
|
31 | b346ff46 | bellard | |
32 | b346ff46 | bellard | /* XXX: make safe guess about sizes */
|
33 | e83a8673 | edgar_igl | #define MAX_OP_PER_INSTR 64 |
34 | 0115be31 | pbrook | /* A Call op needs up to 6 + 2N parameters (N = number of arguments). */
|
35 | 0115be31 | pbrook | #define MAX_OPC_PARAM 10 |
36 | b346ff46 | bellard | #define OPC_BUF_SIZE 512 |
37 | b346ff46 | bellard | #define OPC_MAX_SIZE (OPC_BUF_SIZE - MAX_OP_PER_INSTR)
|
38 | b346ff46 | bellard | |
39 | a208e54a | pbrook | /* Maximum size a TCG op can expand to. This is complicated because a
|
40 | a208e54a | pbrook | single op may require several host instructions and regirster reloads.
|
41 | a208e54a | pbrook | For now take a wild guess at 128 bytes, which should allow at least
|
42 | a208e54a | pbrook | a couple of fixup instructions per argument. */
|
43 | a208e54a | pbrook | #define TCG_MAX_OP_SIZE 128 |
44 | a208e54a | pbrook | |
45 | 0115be31 | pbrook | #define OPPARAM_BUF_SIZE (OPC_BUF_SIZE * MAX_OPC_PARAM)
|
46 | b346ff46 | bellard | |
47 | c27004ec | bellard | extern target_ulong gen_opc_pc[OPC_BUF_SIZE];
|
48 | c27004ec | bellard | extern target_ulong gen_opc_npc[OPC_BUF_SIZE];
|
49 | 66e85a21 | bellard | extern uint8_t gen_opc_cc_op[OPC_BUF_SIZE];
|
50 | b346ff46 | bellard | extern uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
|
51 | c3278b7b | bellard | extern target_ulong gen_opc_jump_pc[2]; |
52 | 30d6cb84 | bellard | extern uint32_t gen_opc_hflags[OPC_BUF_SIZE];
|
53 | b346ff46 | bellard | |
54 | 9886cc16 | bellard | typedef void (GenOpFunc)(void); |
55 | 9886cc16 | bellard | typedef void (GenOpFunc1)(long); |
56 | 9886cc16 | bellard | typedef void (GenOpFunc2)(long, long); |
57 | 9886cc16 | bellard | typedef void (GenOpFunc3)(long, long, long); |
58 | 3b46e624 | ths | |
59 | b346ff46 | bellard | #if defined(TARGET_I386)
|
60 | b346ff46 | bellard | |
61 | 33417e70 | bellard | void optimize_flags_init(void); |
62 | d4e8164f | bellard | |
63 | b346ff46 | bellard | #endif
|
64 | b346ff46 | bellard | |
65 | b346ff46 | bellard | extern FILE *logfile;
|
66 | b346ff46 | bellard | extern int loglevel; |
67 | b346ff46 | bellard | |
68 | 4c3a88a2 | bellard | int gen_intermediate_code(CPUState *env, struct TranslationBlock *tb); |
69 | 4c3a88a2 | bellard | int gen_intermediate_code_pc(CPUState *env, struct TranslationBlock *tb); |
70 | d2856f1a | aurel32 | void gen_pc_load(CPUState *env, struct TranslationBlock *tb, |
71 | d2856f1a | aurel32 | unsigned long searched_pc, int pc_pos, void *puc); |
72 | d2856f1a | aurel32 | |
73 | d07bde88 | blueswir1 | unsigned long code_gen_max_block_size(void); |
74 | 57fec1fe | bellard | void cpu_gen_init(void); |
75 | 4c3a88a2 | bellard | int cpu_gen_code(CPUState *env, struct TranslationBlock *tb, |
76 | d07bde88 | blueswir1 | int *gen_code_size_ptr);
|
77 | 5fafdf24 | ths | int cpu_restore_state(struct TranslationBlock *tb, |
78 | 58fe2f10 | bellard | CPUState *env, unsigned long searched_pc, |
79 | 58fe2f10 | bellard | void *puc);
|
80 | 58fe2f10 | bellard | int cpu_gen_code_copy(CPUState *env, struct TranslationBlock *tb, |
81 | 58fe2f10 | bellard | int max_code_size, int *gen_code_size_ptr); |
82 | 5fafdf24 | ths | int cpu_restore_state_copy(struct TranslationBlock *tb, |
83 | 58fe2f10 | bellard | CPUState *env, unsigned long searched_pc, |
84 | 58fe2f10 | bellard | void *puc);
|
85 | 2e12669a | bellard | void cpu_resume_from_signal(CPUState *env1, void *puc); |
86 | 6a00d601 | bellard | void cpu_exec_init(CPUState *env);
|
87 | 53a5960a | pbrook | int page_unprotect(target_ulong address, unsigned long pc, void *puc); |
88 | 00f82b8a | aurel32 | void tb_invalidate_phys_page_range(target_phys_addr_t start, target_phys_addr_t end,
|
89 | 2e12669a | bellard | int is_cpu_write_access);
|
90 | 4390df51 | bellard | void tb_invalidate_page_range(target_ulong start, target_ulong end);
|
91 | 2e12669a | bellard | void tlb_flush_page(CPUState *env, target_ulong addr);
|
92 | ee8b7021 | bellard | void tlb_flush(CPUState *env, int flush_global); |
93 | 5fafdf24 | ths | int tlb_set_page_exec(CPUState *env, target_ulong vaddr,
|
94 | 5fafdf24 | ths | target_phys_addr_t paddr, int prot,
|
95 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu); |
96 | 4d7a0880 | blueswir1 | static inline int tlb_set_page(CPUState *env1, target_ulong vaddr, |
97 | 5fafdf24 | ths | target_phys_addr_t paddr, int prot,
|
98 | 6ebbf390 | j_mayer | int mmu_idx, int is_softmmu) |
99 | 84b7b8e7 | bellard | { |
100 | 84b7b8e7 | bellard | if (prot & PAGE_READ)
|
101 | 84b7b8e7 | bellard | prot |= PAGE_EXEC; |
102 | 4d7a0880 | blueswir1 | return tlb_set_page_exec(env1, vaddr, paddr, prot, mmu_idx, is_softmmu);
|
103 | 84b7b8e7 | bellard | } |
104 | d4e8164f | bellard | |
105 | d4e8164f | bellard | #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ |
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 | b8076a74 | bellard | #elif defined(__ia64)
|
126 | b8076a74 | bellard | #define CODE_GEN_BUFFER_SIZE (4 * 1024 * 1024) /* range of addl */ |
127 | 4390df51 | bellard | #elif defined(__powerpc__)
|
128 | c4c7e3e6 | bellard | #define CODE_GEN_BUFFER_SIZE (6 * 1024 * 1024) |
129 | 4390df51 | bellard | #else
|
130 | 57fec1fe | bellard | /* XXX: make it dynamic on x86 */
|
131 | c98baaac | bellard | #define CODE_GEN_BUFFER_SIZE (16 * 1024 * 1024) |
132 | 4390df51 | bellard | #endif
|
133 | 4390df51 | bellard | |
134 | d4e8164f | bellard | //#define CODE_GEN_BUFFER_SIZE (128 * 1024)
|
135 | d4e8164f | bellard | |
136 | 4390df51 | bellard | /* estimated block size for TB allocation */
|
137 | 4390df51 | bellard | /* XXX: use a per code average code fragment size and modulate it
|
138 | 4390df51 | bellard | according to the host CPU */
|
139 | 4390df51 | bellard | #if defined(CONFIG_SOFTMMU)
|
140 | 4390df51 | bellard | #define CODE_GEN_AVG_BLOCK_SIZE 128 |
141 | 4390df51 | bellard | #else
|
142 | 4390df51 | bellard | #define CODE_GEN_AVG_BLOCK_SIZE 64 |
143 | 4390df51 | bellard | #endif
|
144 | 4390df51 | bellard | |
145 | 4390df51 | bellard | #define CODE_GEN_MAX_BLOCKS (CODE_GEN_BUFFER_SIZE / CODE_GEN_AVG_BLOCK_SIZE)
|
146 | 4390df51 | bellard | |
147 | 57fec1fe | bellard | #if defined(__powerpc__) || defined(__x86_64__)
|
148 | 4390df51 | bellard | #define USE_DIRECT_JUMP
|
149 | 4390df51 | bellard | #endif
|
150 | 67b915a5 | bellard | #if defined(__i386__) && !defined(_WIN32)
|
151 | d4e8164f | bellard | #define USE_DIRECT_JUMP
|
152 | d4e8164f | bellard | #endif
|
153 | d4e8164f | bellard | |
154 | d4e8164f | bellard | typedef struct TranslationBlock { |
155 | 2e12669a | bellard | target_ulong pc; /* simulated PC corresponding to this block (EIP + CS base) */
|
156 | 2e12669a | bellard | target_ulong cs_base; /* CS base for this block */
|
157 | c068688b | j_mayer | uint64_t flags; /* flags defining in which context the code was generated */
|
158 | d4e8164f | bellard | uint16_t size; /* size of target code for this block (1 <=
|
159 | d4e8164f | bellard | size <= TARGET_PAGE_SIZE) */
|
160 | 58fe2f10 | bellard | uint16_t cflags; /* compile flags */
|
161 | bf088061 | bellard | #define CF_CODE_COPY 0x0001 /* block was generated in code copy mode */ |
162 | bf088061 | bellard | #define CF_TB_FP_USED 0x0002 /* fp ops are used in the TB */ |
163 | bf088061 | bellard | #define CF_FP_USED 0x0004 /* fp ops are used in the TB or in a chained TB */ |
164 | 2e12669a | bellard | #define CF_SINGLE_INSN 0x0008 /* compile only a single instruction */ |
165 | 58fe2f10 | bellard | |
166 | d4e8164f | bellard | uint8_t *tc_ptr; /* pointer to the translated code */
|
167 | 4390df51 | bellard | /* next matching tb for physical address. */
|
168 | 5fafdf24 | ths | struct TranslationBlock *phys_hash_next;
|
169 | 4390df51 | bellard | /* first and second physical page containing code. The lower bit
|
170 | 4390df51 | bellard | of the pointer tells the index in page_next[] */
|
171 | 5fafdf24 | ths | struct TranslationBlock *page_next[2]; |
172 | 5fafdf24 | ths | target_ulong page_addr[2];
|
173 | 4390df51 | bellard | |
174 | d4e8164f | bellard | /* the following data are used to directly call another TB from
|
175 | d4e8164f | bellard | the code of this one. */
|
176 | d4e8164f | bellard | uint16_t tb_next_offset[2]; /* offset of original jump target */ |
177 | d4e8164f | bellard | #ifdef USE_DIRECT_JUMP
|
178 | 4cbb86e1 | bellard | uint16_t tb_jmp_offset[4]; /* offset of jump instruction */ |
179 | d4e8164f | bellard | #else
|
180 | 57fec1fe | bellard | unsigned long tb_next[2]; /* address of jump generated code */ |
181 | d4e8164f | bellard | #endif
|
182 | d4e8164f | bellard | /* list of TBs jumping to this one. This is a circular list using
|
183 | d4e8164f | bellard | the two least significant bits of the pointers to tell what is
|
184 | d4e8164f | bellard | the next pointer: 0 = jmp_next[0], 1 = jmp_next[1], 2 =
|
185 | d4e8164f | bellard | jmp_first */
|
186 | 5fafdf24 | ths | struct TranslationBlock *jmp_next[2]; |
187 | d4e8164f | bellard | struct TranslationBlock *jmp_first;
|
188 | d4e8164f | bellard | } TranslationBlock; |
189 | d4e8164f | bellard | |
190 | b362e5e0 | pbrook | static inline unsigned int tb_jmp_cache_hash_page(target_ulong pc) |
191 | b362e5e0 | pbrook | { |
192 | b362e5e0 | pbrook | target_ulong tmp; |
193 | b362e5e0 | pbrook | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
194 | b5e19d4c | edgar_igl | return (tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK;
|
195 | b362e5e0 | pbrook | } |
196 | b362e5e0 | pbrook | |
197 | 8a40a180 | bellard | static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc) |
198 | d4e8164f | bellard | { |
199 | b362e5e0 | pbrook | target_ulong tmp; |
200 | b362e5e0 | pbrook | tmp = pc ^ (pc >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)); |
201 | b5e19d4c | edgar_igl | return (((tmp >> (TARGET_PAGE_BITS - TB_JMP_PAGE_BITS)) & TB_JMP_PAGE_MASK)
|
202 | b5e19d4c | edgar_igl | | (tmp & TB_JMP_ADDR_MASK)); |
203 | d4e8164f | bellard | } |
204 | d4e8164f | bellard | |
205 | 4390df51 | bellard | static inline unsigned int tb_phys_hash_func(unsigned long pc) |
206 | 4390df51 | bellard | { |
207 | 4390df51 | bellard | return pc & (CODE_GEN_PHYS_HASH_SIZE - 1); |
208 | 4390df51 | bellard | } |
209 | 4390df51 | bellard | |
210 | c27004ec | bellard | TranslationBlock *tb_alloc(target_ulong pc); |
211 | 0124311e | bellard | void tb_flush(CPUState *env);
|
212 | 5fafdf24 | ths | void tb_link_phys(TranslationBlock *tb,
|
213 | 4390df51 | bellard | target_ulong phys_pc, target_ulong phys_page2); |
214 | d4e8164f | bellard | |
215 | 4390df51 | bellard | extern TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE];
|
216 | d4e8164f | bellard | |
217 | d4e8164f | bellard | extern uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE];
|
218 | d4e8164f | bellard | extern uint8_t *code_gen_ptr;
|
219 | d4e8164f | bellard | |
220 | 4390df51 | bellard | #if defined(USE_DIRECT_JUMP)
|
221 | 4390df51 | bellard | |
222 | 4390df51 | bellard | #if defined(__powerpc__)
|
223 | 4cbb86e1 | bellard | static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr) |
224 | d4e8164f | bellard | { |
225 | d4e8164f | bellard | uint32_t val, *ptr; |
226 | d4e8164f | bellard | |
227 | d4e8164f | bellard | /* patch the branch destination */
|
228 | 4cbb86e1 | bellard | ptr = (uint32_t *)jmp_addr; |
229 | d4e8164f | bellard | val = *ptr; |
230 | 4cbb86e1 | bellard | val = (val & ~0x03fffffc) | ((addr - jmp_addr) & 0x03fffffc); |
231 | d4e8164f | bellard | *ptr = val; |
232 | d4e8164f | bellard | /* flush icache */
|
233 | d4e8164f | bellard | asm volatile ("dcbst 0,%0" : : "r"(ptr) : "memory"); |
234 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
235 | d4e8164f | bellard | asm volatile ("icbi 0,%0" : : "r"(ptr) : "memory"); |
236 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
237 | d4e8164f | bellard | asm volatile ("isync" : : : "memory"); |
238 | d4e8164f | bellard | } |
239 | 57fec1fe | bellard | #elif defined(__i386__) || defined(__x86_64__)
|
240 | 4390df51 | bellard | static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr) |
241 | 4390df51 | bellard | { |
242 | 4390df51 | bellard | /* patch the branch destination */
|
243 | 4390df51 | bellard | *(uint32_t *)jmp_addr = addr - (jmp_addr + 4);
|
244 | 4390df51 | bellard | /* no need to flush icache explicitely */
|
245 | 4390df51 | bellard | } |
246 | 4390df51 | bellard | #endif
|
247 | d4e8164f | bellard | |
248 | 5fafdf24 | ths | static inline void tb_set_jmp_target(TranslationBlock *tb, |
249 | 4cbb86e1 | bellard | int n, unsigned long addr) |
250 | 4cbb86e1 | bellard | { |
251 | 4cbb86e1 | bellard | unsigned long offset; |
252 | 4cbb86e1 | bellard | |
253 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n]; |
254 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
255 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n + 2];
|
256 | 4cbb86e1 | bellard | if (offset != 0xffff) |
257 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
258 | 4cbb86e1 | bellard | } |
259 | 4cbb86e1 | bellard | |
260 | d4e8164f | bellard | #else
|
261 | d4e8164f | bellard | |
262 | d4e8164f | bellard | /* set the jump target */
|
263 | 5fafdf24 | ths | static inline void tb_set_jmp_target(TranslationBlock *tb, |
264 | d4e8164f | bellard | int n, unsigned long addr) |
265 | d4e8164f | bellard | { |
266 | 95f7652d | bellard | tb->tb_next[n] = addr; |
267 | d4e8164f | bellard | } |
268 | d4e8164f | bellard | |
269 | d4e8164f | bellard | #endif
|
270 | d4e8164f | bellard | |
271 | 5fafdf24 | ths | static inline void tb_add_jump(TranslationBlock *tb, int n, |
272 | d4e8164f | bellard | TranslationBlock *tb_next) |
273 | d4e8164f | bellard | { |
274 | cf25629d | bellard | /* NOTE: this test is only needed for thread safety */
|
275 | cf25629d | bellard | if (!tb->jmp_next[n]) {
|
276 | cf25629d | bellard | /* patch the native jump address */
|
277 | cf25629d | bellard | tb_set_jmp_target(tb, n, (unsigned long)tb_next->tc_ptr); |
278 | 3b46e624 | ths | |
279 | cf25629d | bellard | /* add in TB jmp circular list */
|
280 | cf25629d | bellard | tb->jmp_next[n] = tb_next->jmp_first; |
281 | cf25629d | bellard | tb_next->jmp_first = (TranslationBlock *)((long)(tb) | (n));
|
282 | cf25629d | bellard | } |
283 | d4e8164f | bellard | } |
284 | d4e8164f | bellard | |
285 | a513fe19 | bellard | TranslationBlock *tb_find_pc(unsigned long pc_ptr); |
286 | a513fe19 | bellard | |
287 | d4e8164f | bellard | #ifndef offsetof
|
288 | d4e8164f | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
289 | d4e8164f | bellard | #endif
|
290 | d4e8164f | bellard | |
291 | d549f7d9 | bellard | #if defined(_WIN32)
|
292 | d549f7d9 | bellard | #define ASM_DATA_SECTION ".section \".data\"\n" |
293 | d549f7d9 | bellard | #define ASM_PREVIOUS_SECTION ".section .text\n" |
294 | d549f7d9 | bellard | #elif defined(__APPLE__)
|
295 | d549f7d9 | bellard | #define ASM_DATA_SECTION ".data\n" |
296 | d549f7d9 | bellard | #define ASM_PREVIOUS_SECTION ".text\n" |
297 | d549f7d9 | bellard | #else
|
298 | d549f7d9 | bellard | #define ASM_DATA_SECTION ".section \".data\"\n" |
299 | d549f7d9 | bellard | #define ASM_PREVIOUS_SECTION ".previous\n" |
300 | d549f7d9 | bellard | #endif
|
301 | d549f7d9 | bellard | |
302 | 75913b72 | bellard | #define ASM_OP_LABEL_NAME(n, opname) \
|
303 | 75913b72 | bellard | ASM_NAME(__op_label) #n "." ASM_NAME(opname) |
304 | 75913b72 | bellard | |
305 | 33417e70 | bellard | extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; |
306 | 33417e70 | bellard | extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; |
307 | a4193c8a | bellard | extern void *io_mem_opaque[IO_MEM_NB_ENTRIES]; |
308 | 33417e70 | bellard | |
309 | 15a51156 | aurel32 | #if defined(__hppa__)
|
310 | 15a51156 | aurel32 | |
311 | 15a51156 | aurel32 | typedef int spinlock_t[4]; |
312 | 15a51156 | aurel32 | |
313 | 15a51156 | aurel32 | #define SPIN_LOCK_UNLOCKED { 1, 1, 1, 1 } |
314 | 15a51156 | aurel32 | |
315 | 15a51156 | aurel32 | static inline void resetlock (spinlock_t *p) |
316 | 15a51156 | aurel32 | { |
317 | 15a51156 | aurel32 | (*p)[0] = (*p)[1] = (*p)[2] = (*p)[3] = 1; |
318 | 15a51156 | aurel32 | } |
319 | 15a51156 | aurel32 | |
320 | 15a51156 | aurel32 | #else
|
321 | 15a51156 | aurel32 | |
322 | 15a51156 | aurel32 | typedef int spinlock_t; |
323 | 15a51156 | aurel32 | |
324 | 15a51156 | aurel32 | #define SPIN_LOCK_UNLOCKED 0 |
325 | 15a51156 | aurel32 | |
326 | 15a51156 | aurel32 | static inline void resetlock (spinlock_t *p) |
327 | 15a51156 | aurel32 | { |
328 | 15a51156 | aurel32 | *p = SPIN_LOCK_UNLOCKED; |
329 | 15a51156 | aurel32 | } |
330 | 15a51156 | aurel32 | |
331 | 15a51156 | aurel32 | #endif
|
332 | 15a51156 | aurel32 | |
333 | 204a1b8d | ths | #if defined(__powerpc__)
|
334 | d4e8164f | bellard | static inline int testandset (int *p) |
335 | d4e8164f | bellard | { |
336 | d4e8164f | bellard | int ret;
|
337 | d4e8164f | bellard | __asm__ __volatile__ ( |
338 | 02e1ec9b | bellard | "0: lwarx %0,0,%1\n"
|
339 | 02e1ec9b | bellard | " xor. %0,%3,%0\n"
|
340 | 02e1ec9b | bellard | " bne 1f\n"
|
341 | 02e1ec9b | bellard | " stwcx. %2,0,%1\n"
|
342 | 02e1ec9b | bellard | " bne- 0b\n"
|
343 | d4e8164f | bellard | "1: "
|
344 | d4e8164f | bellard | : "=&r" (ret)
|
345 | d4e8164f | bellard | : "r" (p), "r" (1), "r" (0) |
346 | d4e8164f | bellard | : "cr0", "memory"); |
347 | d4e8164f | bellard | return ret;
|
348 | d4e8164f | bellard | } |
349 | 204a1b8d | ths | #elif defined(__i386__)
|
350 | d4e8164f | bellard | static inline int testandset (int *p) |
351 | d4e8164f | bellard | { |
352 | 4955a2cd | bellard | long int readval = 0; |
353 | 3b46e624 | ths | |
354 | 4955a2cd | bellard | __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
|
355 | 4955a2cd | bellard | : "+m" (*p), "+a" (readval) |
356 | 4955a2cd | bellard | : "r" (1) |
357 | 4955a2cd | bellard | : "cc");
|
358 | 4955a2cd | bellard | return readval;
|
359 | d4e8164f | bellard | } |
360 | 204a1b8d | ths | #elif defined(__x86_64__)
|
361 | bc51c5c9 | bellard | static inline int testandset (int *p) |
362 | bc51c5c9 | bellard | { |
363 | 4955a2cd | bellard | long int readval = 0; |
364 | 3b46e624 | ths | |
365 | 4955a2cd | bellard | __asm__ __volatile__ ("lock; cmpxchgl %2, %0"
|
366 | 4955a2cd | bellard | : "+m" (*p), "+a" (readval) |
367 | 4955a2cd | bellard | : "r" (1) |
368 | 4955a2cd | bellard | : "cc");
|
369 | 4955a2cd | bellard | return readval;
|
370 | bc51c5c9 | bellard | } |
371 | 204a1b8d | ths | #elif defined(__s390__)
|
372 | d4e8164f | bellard | static inline int testandset (int *p) |
373 | d4e8164f | bellard | { |
374 | d4e8164f | bellard | int ret;
|
375 | d4e8164f | bellard | |
376 | d4e8164f | bellard | __asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
|
377 | d4e8164f | bellard | " jl 0b"
|
378 | d4e8164f | bellard | : "=&d" (ret)
|
379 | 5fafdf24 | ths | : "r" (1), "a" (p), "0" (*p) |
380 | d4e8164f | bellard | : "cc", "memory" ); |
381 | d4e8164f | bellard | return ret;
|
382 | d4e8164f | bellard | } |
383 | 204a1b8d | ths | #elif defined(__alpha__)
|
384 | 2f87c607 | bellard | static inline int testandset (int *p) |
385 | d4e8164f | bellard | { |
386 | d4e8164f | bellard | int ret;
|
387 | d4e8164f | bellard | unsigned long one; |
388 | d4e8164f | bellard | |
389 | d4e8164f | bellard | __asm__ __volatile__ ("0: mov 1,%2\n"
|
390 | d4e8164f | bellard | " ldl_l %0,%1\n"
|
391 | d4e8164f | bellard | " stl_c %2,%1\n"
|
392 | d4e8164f | bellard | " beq %2,1f\n"
|
393 | d4e8164f | bellard | ".subsection 2\n"
|
394 | d4e8164f | bellard | "1: br 0b\n"
|
395 | d4e8164f | bellard | ".previous"
|
396 | d4e8164f | bellard | : "=r" (ret), "=m" (*p), "=r" (one) |
397 | d4e8164f | bellard | : "m" (*p));
|
398 | d4e8164f | bellard | return ret;
|
399 | d4e8164f | bellard | } |
400 | 204a1b8d | ths | #elif defined(__sparc__)
|
401 | d4e8164f | bellard | static inline int testandset (int *p) |
402 | d4e8164f | bellard | { |
403 | d4e8164f | bellard | int ret;
|
404 | d4e8164f | bellard | |
405 | d4e8164f | bellard | __asm__ __volatile__("ldstub [%1], %0"
|
406 | d4e8164f | bellard | : "=r" (ret)
|
407 | d4e8164f | bellard | : "r" (p)
|
408 | d4e8164f | bellard | : "memory");
|
409 | d4e8164f | bellard | |
410 | d4e8164f | bellard | return (ret ? 1 : 0); |
411 | d4e8164f | bellard | } |
412 | 204a1b8d | ths | #elif defined(__arm__)
|
413 | a95c6790 | bellard | static inline int testandset (int *spinlock) |
414 | a95c6790 | bellard | { |
415 | a95c6790 | bellard | register unsigned int ret; |
416 | a95c6790 | bellard | __asm__ __volatile__("swp %0, %1, [%2]"
|
417 | a95c6790 | bellard | : "=r"(ret)
|
418 | a95c6790 | bellard | : "0"(1), "r"(spinlock)); |
419 | 3b46e624 | ths | |
420 | a95c6790 | bellard | return ret;
|
421 | a95c6790 | bellard | } |
422 | 204a1b8d | ths | #elif defined(__mc68000)
|
423 | 38e584a0 | bellard | static inline int testandset (int *p) |
424 | 38e584a0 | bellard | { |
425 | 38e584a0 | bellard | char ret;
|
426 | 38e584a0 | bellard | __asm__ __volatile__("tas %1; sne %0"
|
427 | 38e584a0 | bellard | : "=r" (ret)
|
428 | 38e584a0 | bellard | : "m" (p)
|
429 | 38e584a0 | bellard | : "cc","memory"); |
430 | 4955a2cd | bellard | return ret;
|
431 | 38e584a0 | bellard | } |
432 | 15a51156 | aurel32 | #elif defined(__hppa__)
|
433 | 15a51156 | aurel32 | |
434 | 15a51156 | aurel32 | /* Because malloc only guarantees 8-byte alignment for malloc'd data,
|
435 | 15a51156 | aurel32 | and GCC only guarantees 8-byte alignment for stack locals, we can't
|
436 | 15a51156 | aurel32 | be assured of 16-byte alignment for atomic lock data even if we
|
437 | 15a51156 | aurel32 | specify "__attribute ((aligned(16)))" in the type declaration. So,
|
438 | 15a51156 | aurel32 | we use a struct containing an array of four ints for the atomic lock
|
439 | 15a51156 | aurel32 | type and dynamically select the 16-byte aligned int from the array
|
440 | 15a51156 | aurel32 | for the semaphore. */
|
441 | 15a51156 | aurel32 | #define __PA_LDCW_ALIGNMENT 16 |
442 | 15a51156 | aurel32 | static inline void *ldcw_align (void *p) { |
443 | 15a51156 | aurel32 | unsigned long a = (unsigned long)p; |
444 | 15a51156 | aurel32 | a = (a + __PA_LDCW_ALIGNMENT - 1) & ~(__PA_LDCW_ALIGNMENT - 1); |
445 | 15a51156 | aurel32 | return (void *)a; |
446 | 15a51156 | aurel32 | } |
447 | 15a51156 | aurel32 | |
448 | 15a51156 | aurel32 | static inline int testandset (spinlock_t *p) |
449 | 15a51156 | aurel32 | { |
450 | 15a51156 | aurel32 | unsigned int ret; |
451 | 15a51156 | aurel32 | p = ldcw_align(p); |
452 | 15a51156 | aurel32 | __asm__ __volatile__("ldcw 0(%1),%0"
|
453 | 15a51156 | aurel32 | : "=r" (ret)
|
454 | 15a51156 | aurel32 | : "r" (p)
|
455 | 15a51156 | aurel32 | : "memory" );
|
456 | 15a51156 | aurel32 | return !ret;
|
457 | 15a51156 | aurel32 | } |
458 | 15a51156 | aurel32 | |
459 | 204a1b8d | ths | #elif defined(__ia64)
|
460 | 38e584a0 | bellard | |
461 | b8076a74 | bellard | #include <ia64intrin.h> |
462 | b8076a74 | bellard | |
463 | b8076a74 | bellard | static inline int testandset (int *p) |
464 | b8076a74 | bellard | { |
465 | b8076a74 | bellard | return __sync_lock_test_and_set (p, 1); |
466 | b8076a74 | bellard | } |
467 | 204a1b8d | ths | #elif defined(__mips__)
|
468 | c4b89d18 | ths | static inline int testandset (int *p) |
469 | c4b89d18 | ths | { |
470 | c4b89d18 | ths | int ret;
|
471 | c4b89d18 | ths | |
472 | c4b89d18 | ths | __asm__ __volatile__ ( |
473 | c4b89d18 | ths | " .set push \n"
|
474 | c4b89d18 | ths | " .set noat \n"
|
475 | c4b89d18 | ths | " .set mips2 \n"
|
476 | c4b89d18 | ths | "1: li $1, 1 \n"
|
477 | c4b89d18 | ths | " ll %0, %1 \n"
|
478 | c4b89d18 | ths | " sc $1, %1 \n"
|
479 | 976a0d0d | ths | " beqz $1, 1b \n"
|
480 | c4b89d18 | ths | " .set pop "
|
481 | c4b89d18 | ths | : "=r" (ret), "+R" (*p) |
482 | c4b89d18 | ths | : |
483 | c4b89d18 | ths | : "memory");
|
484 | c4b89d18 | ths | |
485 | c4b89d18 | ths | return ret;
|
486 | c4b89d18 | ths | } |
487 | 204a1b8d | ths | #else
|
488 | 204a1b8d | ths | #error unimplemented CPU support
|
489 | c4b89d18 | ths | #endif
|
490 | c4b89d18 | ths | |
491 | aebcb60e | bellard | #if defined(CONFIG_USER_ONLY)
|
492 | d4e8164f | bellard | static inline void spin_lock(spinlock_t *lock) |
493 | d4e8164f | bellard | { |
494 | d4e8164f | bellard | while (testandset(lock));
|
495 | d4e8164f | bellard | } |
496 | d4e8164f | bellard | |
497 | d4e8164f | bellard | static inline void spin_unlock(spinlock_t *lock) |
498 | d4e8164f | bellard | { |
499 | 15a51156 | aurel32 | resetlock(lock); |
500 | d4e8164f | bellard | } |
501 | d4e8164f | bellard | |
502 | d4e8164f | bellard | static inline int spin_trylock(spinlock_t *lock) |
503 | d4e8164f | bellard | { |
504 | d4e8164f | bellard | return !testandset(lock);
|
505 | d4e8164f | bellard | } |
506 | 3c1cf9fa | bellard | #else
|
507 | 3c1cf9fa | bellard | static inline void spin_lock(spinlock_t *lock) |
508 | 3c1cf9fa | bellard | { |
509 | 3c1cf9fa | bellard | } |
510 | 3c1cf9fa | bellard | |
511 | 3c1cf9fa | bellard | static inline void spin_unlock(spinlock_t *lock) |
512 | 3c1cf9fa | bellard | { |
513 | 3c1cf9fa | bellard | } |
514 | 3c1cf9fa | bellard | |
515 | 3c1cf9fa | bellard | static inline int spin_trylock(spinlock_t *lock) |
516 | 3c1cf9fa | bellard | { |
517 | 3c1cf9fa | bellard | return 1; |
518 | 3c1cf9fa | bellard | } |
519 | 3c1cf9fa | bellard | #endif
|
520 | d4e8164f | bellard | |
521 | d4e8164f | bellard | extern spinlock_t tb_lock;
|
522 | d4e8164f | bellard | |
523 | 36bdbe54 | bellard | extern int tb_invalidated_flag; |
524 | 6e59c1db | bellard | |
525 | e95c8d51 | bellard | #if !defined(CONFIG_USER_ONLY)
|
526 | 6e59c1db | bellard | |
527 | 6ebbf390 | j_mayer | void tlb_fill(target_ulong addr, int is_write, int mmu_idx, |
528 | 6e59c1db | bellard | void *retaddr);
|
529 | 6e59c1db | bellard | |
530 | 6ebbf390 | j_mayer | #define ACCESS_TYPE (NB_MMU_MODES + 1) |
531 | 6e59c1db | bellard | #define MEMSUFFIX _code
|
532 | 6e59c1db | bellard | #define env cpu_single_env
|
533 | 6e59c1db | bellard | |
534 | 6e59c1db | bellard | #define DATA_SIZE 1 |
535 | 6e59c1db | bellard | #include "softmmu_header.h" |
536 | 6e59c1db | bellard | |
537 | 6e59c1db | bellard | #define DATA_SIZE 2 |
538 | 6e59c1db | bellard | #include "softmmu_header.h" |
539 | 6e59c1db | bellard | |
540 | 6e59c1db | bellard | #define DATA_SIZE 4 |
541 | 6e59c1db | bellard | #include "softmmu_header.h" |
542 | 6e59c1db | bellard | |
543 | c27004ec | bellard | #define DATA_SIZE 8 |
544 | c27004ec | bellard | #include "softmmu_header.h" |
545 | c27004ec | bellard | |
546 | 6e59c1db | bellard | #undef ACCESS_TYPE
|
547 | 6e59c1db | bellard | #undef MEMSUFFIX
|
548 | 6e59c1db | bellard | #undef env
|
549 | 6e59c1db | bellard | |
550 | 6e59c1db | bellard | #endif
|
551 | 4390df51 | bellard | |
552 | 4390df51 | bellard | #if defined(CONFIG_USER_ONLY)
|
553 | 4d7a0880 | blueswir1 | static inline target_ulong get_phys_addr_code(CPUState *env1, target_ulong addr) |
554 | 4390df51 | bellard | { |
555 | 4390df51 | bellard | return addr;
|
556 | 4390df51 | bellard | } |
557 | 4390df51 | bellard | #else
|
558 | 4390df51 | bellard | /* NOTE: this function can trigger an exception */
|
559 | 1ccde1cb | bellard | /* NOTE2: the returned address is not exactly the physical address: it
|
560 | 1ccde1cb | bellard | is the offset relative to phys_ram_base */
|
561 | 4d7a0880 | blueswir1 | static inline target_ulong get_phys_addr_code(CPUState *env1, target_ulong addr) |
562 | 4390df51 | bellard | { |
563 | 4d7a0880 | blueswir1 | int mmu_idx, page_index, pd;
|
564 | 4390df51 | bellard | |
565 | 4d7a0880 | blueswir1 | page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
566 | 4d7a0880 | blueswir1 | mmu_idx = cpu_mmu_index(env1); |
567 | 4d7a0880 | blueswir1 | if (__builtin_expect(env1->tlb_table[mmu_idx][page_index].addr_code !=
|
568 | 4390df51 | bellard | (addr & TARGET_PAGE_MASK), 0)) {
|
569 | c27004ec | bellard | ldub_code(addr); |
570 | c27004ec | bellard | } |
571 | 4d7a0880 | blueswir1 | pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK; |
572 | 2a4188a3 | bellard | if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
|
573 | 647de6ca | ths | #if defined(TARGET_SPARC) || defined(TARGET_MIPS)
|
574 | 6c36d3fa | blueswir1 | do_unassigned_access(addr, 0, 1, 0); |
575 | 6c36d3fa | blueswir1 | #else
|
576 | 4d7a0880 | blueswir1 | cpu_abort(env1, "Trying to execute code outside RAM or ROM at 0x" TARGET_FMT_lx "\n", addr); |
577 | 6c36d3fa | blueswir1 | #endif
|
578 | 4390df51 | bellard | } |
579 | 4d7a0880 | blueswir1 | return addr + env1->tlb_table[mmu_idx][page_index].addend - (unsigned long)phys_ram_base; |
580 | 4390df51 | bellard | } |
581 | 4390df51 | bellard | #endif
|
582 | 9df217a3 | bellard | |
583 | 9df217a3 | bellard | #ifdef USE_KQEMU
|
584 | f32fc648 | bellard | #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG)) |
585 | f32fc648 | bellard | |
586 | 9df217a3 | bellard | int kqemu_init(CPUState *env);
|
587 | 9df217a3 | bellard | int kqemu_cpu_exec(CPUState *env);
|
588 | 9df217a3 | bellard | void kqemu_flush_page(CPUState *env, target_ulong addr);
|
589 | 9df217a3 | bellard | void kqemu_flush(CPUState *env, int global); |
590 | 4b7df22f | bellard | void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
|
591 | f32fc648 | bellard | void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
|
592 | a332e112 | bellard | void kqemu_cpu_interrupt(CPUState *env);
|
593 | f32fc648 | bellard | void kqemu_record_dump(void); |
594 | 9df217a3 | bellard | |
595 | 9df217a3 | bellard | static inline int kqemu_is_ok(CPUState *env) |
596 | 9df217a3 | bellard | { |
597 | 9df217a3 | bellard | return(env->kqemu_enabled &&
|
598 | 5fafdf24 | ths | (env->cr[0] & CR0_PE_MASK) &&
|
599 | f32fc648 | bellard | !(env->hflags & HF_INHIBIT_IRQ_MASK) && |
600 | 9df217a3 | bellard | (env->eflags & IF_MASK) && |
601 | f32fc648 | bellard | !(env->eflags & VM_MASK) && |
602 | 5fafdf24 | ths | (env->kqemu_enabled == 2 ||
|
603 | f32fc648 | bellard | ((env->hflags & HF_CPL_MASK) == 3 &&
|
604 | f32fc648 | bellard | (env->eflags & IOPL_MASK) != IOPL_MASK))); |
605 | 9df217a3 | bellard | } |
606 | 9df217a3 | bellard | |
607 | 9df217a3 | bellard | #endif |