root / exec-all.h @ c321f673
History | View | Annotate | Download (11.7 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 | b346ff46 | bellard | #if defined(TARGET_I386)
|
63 | b346ff46 | bellard | |
64 | 33417e70 | bellard | void optimize_flags_init(void); |
65 | d4e8164f | bellard | |
66 | b346ff46 | bellard | #endif
|
67 | b346ff46 | bellard | |
68 | b346ff46 | bellard | extern FILE *logfile;
|
69 | b346ff46 | bellard | extern int loglevel; |
70 | b346ff46 | bellard | |
71 | 4c3a88a2 | bellard | int gen_intermediate_code(CPUState *env, struct TranslationBlock *tb); |
72 | 4c3a88a2 | bellard | int gen_intermediate_code_pc(CPUState *env, struct TranslationBlock *tb); |
73 | b346ff46 | bellard | void dump_ops(const uint16_t *opc_buf, const uint32_t *opparam_buf); |
74 | 4c3a88a2 | bellard | int cpu_gen_code(CPUState *env, struct TranslationBlock *tb, |
75 | b346ff46 | bellard | int max_code_size, int *gen_code_size_ptr); |
76 | 66e85a21 | bellard | int cpu_restore_state(struct TranslationBlock *tb, |
77 | 66e85a21 | bellard | CPUState *env, unsigned long searched_pc); |
78 | b346ff46 | bellard | void cpu_exec_init(void); |
79 | d4e8164f | bellard | int page_unprotect(unsigned long address); |
80 | 66e85a21 | bellard | void page_unmap(void); |
81 | 33417e70 | bellard | void tlb_flush_page(CPUState *env, uint32_t addr);
|
82 | 6e59c1db | bellard | void tlb_flush_page_write(CPUState *env, uint32_t addr);
|
83 | 33417e70 | bellard | void tlb_flush(CPUState *env);
|
84 | d4e8164f | bellard | |
85 | d4e8164f | bellard | #define CODE_GEN_MAX_SIZE 65536 |
86 | d4e8164f | bellard | #define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */ |
87 | d4e8164f | bellard | |
88 | d4e8164f | bellard | #define CODE_GEN_HASH_BITS 15 |
89 | d4e8164f | bellard | #define CODE_GEN_HASH_SIZE (1 << CODE_GEN_HASH_BITS) |
90 | d4e8164f | bellard | |
91 | d4e8164f | bellard | /* maximum total translate dcode allocated */
|
92 | d4e8164f | bellard | #define CODE_GEN_BUFFER_SIZE (2048 * 1024) |
93 | d4e8164f | bellard | //#define CODE_GEN_BUFFER_SIZE (128 * 1024)
|
94 | d4e8164f | bellard | |
95 | d4e8164f | bellard | #if defined(__powerpc__)
|
96 | d4e8164f | bellard | #define USE_DIRECT_JUMP
|
97 | d4e8164f | bellard | #endif
|
98 | d4e8164f | bellard | |
99 | d4e8164f | bellard | typedef struct TranslationBlock { |
100 | d4e8164f | bellard | unsigned long pc; /* simulated PC corresponding to this block (EIP + CS base) */ |
101 | d4e8164f | bellard | unsigned long cs_base; /* CS base for this block */ |
102 | d4e8164f | bellard | unsigned int flags; /* flags defining in which context the code was generated */ |
103 | d4e8164f | bellard | uint16_t size; /* size of target code for this block (1 <=
|
104 | d4e8164f | bellard | size <= TARGET_PAGE_SIZE) */
|
105 | d4e8164f | bellard | uint8_t *tc_ptr; /* pointer to the translated code */
|
106 | d4e8164f | bellard | struct TranslationBlock *hash_next; /* next matching block */ |
107 | d4e8164f | bellard | struct TranslationBlock *page_next[2]; /* next blocks in even/odd page */ |
108 | d4e8164f | bellard | /* the following data are used to directly call another TB from
|
109 | d4e8164f | bellard | the code of this one. */
|
110 | d4e8164f | bellard | uint16_t tb_next_offset[2]; /* offset of original jump target */ |
111 | d4e8164f | bellard | #ifdef USE_DIRECT_JUMP
|
112 | 4cbb86e1 | bellard | uint16_t tb_jmp_offset[4]; /* offset of jump instruction */ |
113 | d4e8164f | bellard | #else
|
114 | 95f7652d | bellard | uint32_t tb_next[2]; /* address of jump generated code */ |
115 | d4e8164f | bellard | #endif
|
116 | d4e8164f | bellard | /* list of TBs jumping to this one. This is a circular list using
|
117 | d4e8164f | bellard | the two least significant bits of the pointers to tell what is
|
118 | d4e8164f | bellard | the next pointer: 0 = jmp_next[0], 1 = jmp_next[1], 2 =
|
119 | d4e8164f | bellard | jmp_first */
|
120 | d4e8164f | bellard | struct TranslationBlock *jmp_next[2]; |
121 | d4e8164f | bellard | struct TranslationBlock *jmp_first;
|
122 | d4e8164f | bellard | } TranslationBlock; |
123 | d4e8164f | bellard | |
124 | d4e8164f | bellard | static inline unsigned int tb_hash_func(unsigned long pc) |
125 | d4e8164f | bellard | { |
126 | d4e8164f | bellard | return pc & (CODE_GEN_HASH_SIZE - 1); |
127 | d4e8164f | bellard | } |
128 | d4e8164f | bellard | |
129 | d4e8164f | bellard | TranslationBlock *tb_alloc(unsigned long pc); |
130 | d4e8164f | bellard | void tb_flush(void); |
131 | d4e8164f | bellard | void tb_link(TranslationBlock *tb);
|
132 | d4e8164f | bellard | |
133 | d4e8164f | bellard | extern TranslationBlock *tb_hash[CODE_GEN_HASH_SIZE];
|
134 | d4e8164f | bellard | |
135 | d4e8164f | bellard | extern uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE];
|
136 | d4e8164f | bellard | extern uint8_t *code_gen_ptr;
|
137 | d4e8164f | bellard | |
138 | d4e8164f | bellard | /* find a translation block in the translation cache. If not found,
|
139 | d4e8164f | bellard | return NULL and the pointer to the last element of the list in pptb */
|
140 | d4e8164f | bellard | static inline TranslationBlock *tb_find(TranslationBlock ***pptb, |
141 | d4e8164f | bellard | unsigned long pc, |
142 | d4e8164f | bellard | unsigned long cs_base, |
143 | d4e8164f | bellard | unsigned int flags) |
144 | d4e8164f | bellard | { |
145 | d4e8164f | bellard | TranslationBlock **ptb, *tb; |
146 | d4e8164f | bellard | unsigned int h; |
147 | d4e8164f | bellard | |
148 | d4e8164f | bellard | h = tb_hash_func(pc); |
149 | d4e8164f | bellard | ptb = &tb_hash[h]; |
150 | d4e8164f | bellard | for(;;) {
|
151 | d4e8164f | bellard | tb = *ptb; |
152 | d4e8164f | bellard | if (!tb)
|
153 | d4e8164f | bellard | break;
|
154 | d4e8164f | bellard | if (tb->pc == pc && tb->cs_base == cs_base && tb->flags == flags)
|
155 | d4e8164f | bellard | return tb;
|
156 | d4e8164f | bellard | ptb = &tb->hash_next; |
157 | d4e8164f | bellard | } |
158 | d4e8164f | bellard | *pptb = ptb; |
159 | d4e8164f | bellard | return NULL; |
160 | d4e8164f | bellard | } |
161 | d4e8164f | bellard | |
162 | d4e8164f | bellard | #if defined(__powerpc__)
|
163 | d4e8164f | bellard | |
164 | 4cbb86e1 | bellard | static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long addr) |
165 | d4e8164f | bellard | { |
166 | d4e8164f | bellard | uint32_t val, *ptr; |
167 | d4e8164f | bellard | |
168 | d4e8164f | bellard | /* patch the branch destination */
|
169 | 4cbb86e1 | bellard | ptr = (uint32_t *)jmp_addr; |
170 | d4e8164f | bellard | val = *ptr; |
171 | 4cbb86e1 | bellard | val = (val & ~0x03fffffc) | ((addr - jmp_addr) & 0x03fffffc); |
172 | d4e8164f | bellard | *ptr = val; |
173 | d4e8164f | bellard | /* flush icache */
|
174 | d4e8164f | bellard | asm volatile ("dcbst 0,%0" : : "r"(ptr) : "memory"); |
175 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
176 | d4e8164f | bellard | asm volatile ("icbi 0,%0" : : "r"(ptr) : "memory"); |
177 | d4e8164f | bellard | asm volatile ("sync" : : : "memory"); |
178 | d4e8164f | bellard | asm volatile ("isync" : : : "memory"); |
179 | d4e8164f | bellard | } |
180 | d4e8164f | bellard | |
181 | 4cbb86e1 | bellard | static inline void tb_set_jmp_target(TranslationBlock *tb, |
182 | 4cbb86e1 | bellard | int n, unsigned long addr) |
183 | 4cbb86e1 | bellard | { |
184 | 4cbb86e1 | bellard | unsigned long offset; |
185 | 4cbb86e1 | bellard | |
186 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n]; |
187 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
188 | 4cbb86e1 | bellard | offset = tb->tb_jmp_offset[n + 2];
|
189 | 4cbb86e1 | bellard | if (offset != 0xffff) |
190 | 4cbb86e1 | bellard | tb_set_jmp_target1((unsigned long)(tb->tc_ptr + offset), addr); |
191 | 4cbb86e1 | bellard | } |
192 | 4cbb86e1 | bellard | |
193 | d4e8164f | bellard | #else
|
194 | d4e8164f | bellard | |
195 | d4e8164f | bellard | /* set the jump target */
|
196 | d4e8164f | bellard | static inline void tb_set_jmp_target(TranslationBlock *tb, |
197 | d4e8164f | bellard | int n, unsigned long addr) |
198 | d4e8164f | bellard | { |
199 | 95f7652d | bellard | tb->tb_next[n] = addr; |
200 | d4e8164f | bellard | } |
201 | d4e8164f | bellard | |
202 | d4e8164f | bellard | #endif
|
203 | d4e8164f | bellard | |
204 | d4e8164f | bellard | static inline void tb_add_jump(TranslationBlock *tb, int n, |
205 | d4e8164f | bellard | TranslationBlock *tb_next) |
206 | d4e8164f | bellard | { |
207 | cf25629d | bellard | /* NOTE: this test is only needed for thread safety */
|
208 | cf25629d | bellard | if (!tb->jmp_next[n]) {
|
209 | cf25629d | bellard | /* patch the native jump address */
|
210 | cf25629d | bellard | tb_set_jmp_target(tb, n, (unsigned long)tb_next->tc_ptr); |
211 | cf25629d | bellard | |
212 | cf25629d | bellard | /* add in TB jmp circular list */
|
213 | cf25629d | bellard | tb->jmp_next[n] = tb_next->jmp_first; |
214 | cf25629d | bellard | tb_next->jmp_first = (TranslationBlock *)((long)(tb) | (n));
|
215 | cf25629d | bellard | } |
216 | d4e8164f | bellard | } |
217 | d4e8164f | bellard | |
218 | a513fe19 | bellard | TranslationBlock *tb_find_pc(unsigned long pc_ptr); |
219 | a513fe19 | bellard | |
220 | d4e8164f | bellard | #ifndef offsetof
|
221 | d4e8164f | bellard | #define offsetof(type, field) ((size_t) &((type *)0)->field) |
222 | d4e8164f | bellard | #endif
|
223 | d4e8164f | bellard | |
224 | b346ff46 | bellard | #if defined(__powerpc__)
|
225 | b346ff46 | bellard | |
226 | b346ff46 | bellard | /* on PowerPC we patch the jump instruction directly */
|
227 | 9257a9e4 | bellard | #define JUMP_TB(opname, tbparam, n, eip)\
|
228 | b346ff46 | bellard | do {\
|
229 | 9257a9e4 | bellard | asm volatile (".section \".data\"\n"\ |
230 | 9257a9e4 | bellard | "__op_label" #n "." stringify(opname) ":\n"\ |
231 | 9257a9e4 | bellard | ".long 1f\n"\
|
232 | 9257a9e4 | bellard | ".previous\n"\
|
233 | 9257a9e4 | bellard | "b __op_jmp" #n "\n"\ |
234 | 9257a9e4 | bellard | "1:\n");\
|
235 | b346ff46 | bellard | T0 = (long)(tbparam) + (n);\
|
236 | b346ff46 | bellard | EIP = eip;\ |
237 | 31e8f3c8 | bellard | EXIT_TB();\ |
238 | b346ff46 | bellard | } while (0) |
239 | b346ff46 | bellard | |
240 | 4cbb86e1 | bellard | #define JUMP_TB2(opname, tbparam, n)\
|
241 | 4cbb86e1 | bellard | do {\
|
242 | 4cbb86e1 | bellard | asm volatile ("b __op_jmp%0\n" : : "i" (n + 2));\ |
243 | 4cbb86e1 | bellard | } while (0) |
244 | 4cbb86e1 | bellard | |
245 | b346ff46 | bellard | #else
|
246 | b346ff46 | bellard | |
247 | b346ff46 | bellard | /* jump to next block operations (more portable code, does not need
|
248 | b346ff46 | bellard | cache flushing, but slower because of indirect jump) */
|
249 | 9257a9e4 | bellard | #define JUMP_TB(opname, tbparam, n, eip)\
|
250 | b346ff46 | bellard | do {\
|
251 | b346ff46 | bellard | static void __attribute__((unused)) *__op_label ## n = &&label ## n;\ |
252 | 2f62b397 | bellard | static void __attribute__((unused)) *dummy ## n = &&dummy_label ## n;\ |
253 | b346ff46 | bellard | goto *(void *)(((TranslationBlock *)tbparam)->tb_next[n]);\ |
254 | b346ff46 | bellard | label ## n:\ |
255 | b346ff46 | bellard | T0 = (long)(tbparam) + (n);\
|
256 | b346ff46 | bellard | EIP = eip;\ |
257 | 2f62b397 | bellard | dummy_label ## n:\ |
258 | 9621339d | bellard | EXIT_TB();\ |
259 | b346ff46 | bellard | } while (0) |
260 | b346ff46 | bellard | |
261 | 4cbb86e1 | bellard | /* second jump to same destination 'n' */
|
262 | 4cbb86e1 | bellard | #define JUMP_TB2(opname, tbparam, n)\
|
263 | 4cbb86e1 | bellard | do {\
|
264 | 4cbb86e1 | bellard | goto *(void *)(((TranslationBlock *)tbparam)->tb_next[n]);\ |
265 | 4cbb86e1 | bellard | } while (0) |
266 | 4cbb86e1 | bellard | |
267 | b346ff46 | bellard | #endif
|
268 | b346ff46 | bellard | |
269 | 33417e70 | bellard | /* physical memory access */
|
270 | 33417e70 | bellard | #define IO_MEM_NB_ENTRIES 256 |
271 | 33417e70 | bellard | #define TLB_INVALID_MASK (1 << 3) |
272 | 33417e70 | bellard | #define IO_MEM_SHIFT 4 |
273 | 33417e70 | bellard | #define IO_MEM_UNASSIGNED (1 << IO_MEM_SHIFT) |
274 | 33417e70 | bellard | |
275 | 33417e70 | bellard | unsigned long physpage_find(unsigned long page); |
276 | 33417e70 | bellard | |
277 | 33417e70 | bellard | extern CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; |
278 | 33417e70 | bellard | extern CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; |
279 | 33417e70 | bellard | |
280 | d4e8164f | bellard | #ifdef __powerpc__
|
281 | d4e8164f | bellard | static inline int testandset (int *p) |
282 | d4e8164f | bellard | { |
283 | d4e8164f | bellard | int ret;
|
284 | d4e8164f | bellard | __asm__ __volatile__ ( |
285 | d4e8164f | bellard | "0: lwarx %0,0,%1 ;"
|
286 | d4e8164f | bellard | " xor. %0,%3,%0;"
|
287 | d4e8164f | bellard | " bne 1f;"
|
288 | d4e8164f | bellard | " stwcx. %2,0,%1;"
|
289 | d4e8164f | bellard | " bne- 0b;"
|
290 | d4e8164f | bellard | "1: "
|
291 | d4e8164f | bellard | : "=&r" (ret)
|
292 | d4e8164f | bellard | : "r" (p), "r" (1), "r" (0) |
293 | d4e8164f | bellard | : "cr0", "memory"); |
294 | d4e8164f | bellard | return ret;
|
295 | d4e8164f | bellard | } |
296 | d4e8164f | bellard | #endif
|
297 | d4e8164f | bellard | |
298 | d4e8164f | bellard | #ifdef __i386__
|
299 | d4e8164f | bellard | static inline int testandset (int *p) |
300 | d4e8164f | bellard | { |
301 | d4e8164f | bellard | char ret;
|
302 | d4e8164f | bellard | long int readval; |
303 | d4e8164f | bellard | |
304 | d4e8164f | bellard | __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0"
|
305 | d4e8164f | bellard | : "=q" (ret), "=m" (*p), "=a" (readval) |
306 | d4e8164f | bellard | : "r" (1), "m" (*p), "a" (0) |
307 | d4e8164f | bellard | : "memory");
|
308 | d4e8164f | bellard | return ret;
|
309 | d4e8164f | bellard | } |
310 | d4e8164f | bellard | #endif
|
311 | d4e8164f | bellard | |
312 | d4e8164f | bellard | #ifdef __s390__
|
313 | d4e8164f | bellard | static inline int testandset (int *p) |
314 | d4e8164f | bellard | { |
315 | d4e8164f | bellard | int ret;
|
316 | d4e8164f | bellard | |
317 | d4e8164f | bellard | __asm__ __volatile__ ("0: cs %0,%1,0(%2)\n"
|
318 | d4e8164f | bellard | " jl 0b"
|
319 | d4e8164f | bellard | : "=&d" (ret)
|
320 | d4e8164f | bellard | : "r" (1), "a" (p), "0" (*p) |
321 | d4e8164f | bellard | : "cc", "memory" ); |
322 | d4e8164f | bellard | return ret;
|
323 | d4e8164f | bellard | } |
324 | d4e8164f | bellard | #endif
|
325 | d4e8164f | bellard | |
326 | d4e8164f | bellard | #ifdef __alpha__
|
327 | 2f87c607 | bellard | static inline int testandset (int *p) |
328 | d4e8164f | bellard | { |
329 | d4e8164f | bellard | int ret;
|
330 | d4e8164f | bellard | unsigned long one; |
331 | d4e8164f | bellard | |
332 | d4e8164f | bellard | __asm__ __volatile__ ("0: mov 1,%2\n"
|
333 | d4e8164f | bellard | " ldl_l %0,%1\n"
|
334 | d4e8164f | bellard | " stl_c %2,%1\n"
|
335 | d4e8164f | bellard | " beq %2,1f\n"
|
336 | d4e8164f | bellard | ".subsection 2\n"
|
337 | d4e8164f | bellard | "1: br 0b\n"
|
338 | d4e8164f | bellard | ".previous"
|
339 | d4e8164f | bellard | : "=r" (ret), "=m" (*p), "=r" (one) |
340 | d4e8164f | bellard | : "m" (*p));
|
341 | d4e8164f | bellard | return ret;
|
342 | d4e8164f | bellard | } |
343 | d4e8164f | bellard | #endif
|
344 | d4e8164f | bellard | |
345 | d4e8164f | bellard | #ifdef __sparc__
|
346 | d4e8164f | bellard | static inline int testandset (int *p) |
347 | d4e8164f | bellard | { |
348 | d4e8164f | bellard | int ret;
|
349 | d4e8164f | bellard | |
350 | d4e8164f | bellard | __asm__ __volatile__("ldstub [%1], %0"
|
351 | d4e8164f | bellard | : "=r" (ret)
|
352 | d4e8164f | bellard | : "r" (p)
|
353 | d4e8164f | bellard | : "memory");
|
354 | d4e8164f | bellard | |
355 | d4e8164f | bellard | return (ret ? 1 : 0); |
356 | d4e8164f | bellard | } |
357 | d4e8164f | bellard | #endif
|
358 | d4e8164f | bellard | |
359 | a95c6790 | bellard | #ifdef __arm__
|
360 | a95c6790 | bellard | static inline int testandset (int *spinlock) |
361 | a95c6790 | bellard | { |
362 | a95c6790 | bellard | register unsigned int ret; |
363 | a95c6790 | bellard | __asm__ __volatile__("swp %0, %1, [%2]"
|
364 | a95c6790 | bellard | : "=r"(ret)
|
365 | a95c6790 | bellard | : "0"(1), "r"(spinlock)); |
366 | a95c6790 | bellard | |
367 | a95c6790 | bellard | return ret;
|
368 | a95c6790 | bellard | } |
369 | a95c6790 | bellard | #endif
|
370 | a95c6790 | bellard | |
371 | 38e584a0 | bellard | #ifdef __mc68000
|
372 | 38e584a0 | bellard | static inline int testandset (int *p) |
373 | 38e584a0 | bellard | { |
374 | 38e584a0 | bellard | char ret;
|
375 | 38e584a0 | bellard | __asm__ __volatile__("tas %1; sne %0"
|
376 | 38e584a0 | bellard | : "=r" (ret)
|
377 | 38e584a0 | bellard | : "m" (p)
|
378 | 38e584a0 | bellard | : "cc","memory"); |
379 | 38e584a0 | bellard | return ret == 0; |
380 | 38e584a0 | bellard | } |
381 | 38e584a0 | bellard | #endif
|
382 | 38e584a0 | bellard | |
383 | d4e8164f | bellard | typedef int spinlock_t; |
384 | d4e8164f | bellard | |
385 | d4e8164f | bellard | #define SPIN_LOCK_UNLOCKED 0 |
386 | d4e8164f | bellard | |
387 | aebcb60e | bellard | #if defined(CONFIG_USER_ONLY)
|
388 | d4e8164f | bellard | static inline void spin_lock(spinlock_t *lock) |
389 | d4e8164f | bellard | { |
390 | d4e8164f | bellard | while (testandset(lock));
|
391 | d4e8164f | bellard | } |
392 | d4e8164f | bellard | |
393 | d4e8164f | bellard | static inline void spin_unlock(spinlock_t *lock) |
394 | d4e8164f | bellard | { |
395 | d4e8164f | bellard | *lock = 0;
|
396 | d4e8164f | bellard | } |
397 | d4e8164f | bellard | |
398 | d4e8164f | bellard | static inline int spin_trylock(spinlock_t *lock) |
399 | d4e8164f | bellard | { |
400 | d4e8164f | bellard | return !testandset(lock);
|
401 | d4e8164f | bellard | } |
402 | 3c1cf9fa | bellard | #else
|
403 | 3c1cf9fa | bellard | static inline void spin_lock(spinlock_t *lock) |
404 | 3c1cf9fa | bellard | { |
405 | 3c1cf9fa | bellard | } |
406 | 3c1cf9fa | bellard | |
407 | 3c1cf9fa | bellard | static inline void spin_unlock(spinlock_t *lock) |
408 | 3c1cf9fa | bellard | { |
409 | 3c1cf9fa | bellard | } |
410 | 3c1cf9fa | bellard | |
411 | 3c1cf9fa | bellard | static inline int spin_trylock(spinlock_t *lock) |
412 | 3c1cf9fa | bellard | { |
413 | 3c1cf9fa | bellard | return 1; |
414 | 3c1cf9fa | bellard | } |
415 | 3c1cf9fa | bellard | #endif
|
416 | d4e8164f | bellard | |
417 | d4e8164f | bellard | extern spinlock_t tb_lock;
|
418 | d4e8164f | bellard | |
419 | 6e59c1db | bellard | |
420 | 6e59c1db | bellard | #if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
|
421 | 6e59c1db | bellard | |
422 | 6e59c1db | bellard | void tlb_fill(unsigned long addr, int is_write, int is_user, |
423 | 6e59c1db | bellard | void *retaddr);
|
424 | 6e59c1db | bellard | |
425 | 6e59c1db | bellard | #define ACCESS_TYPE 3 |
426 | 6e59c1db | bellard | #define MEMSUFFIX _code
|
427 | 6e59c1db | bellard | #define env cpu_single_env
|
428 | 6e59c1db | bellard | |
429 | 6e59c1db | bellard | #define DATA_SIZE 1 |
430 | 6e59c1db | bellard | #include "softmmu_header.h" |
431 | 6e59c1db | bellard | |
432 | 6e59c1db | bellard | #define DATA_SIZE 2 |
433 | 6e59c1db | bellard | #include "softmmu_header.h" |
434 | 6e59c1db | bellard | |
435 | 6e59c1db | bellard | #define DATA_SIZE 4 |
436 | 6e59c1db | bellard | #include "softmmu_header.h" |
437 | 6e59c1db | bellard | |
438 | 6e59c1db | bellard | #undef ACCESS_TYPE
|
439 | 6e59c1db | bellard | #undef MEMSUFFIX
|
440 | 6e59c1db | bellard | #undef env
|
441 | 6e59c1db | bellard | |
442 | 6e59c1db | bellard | #endif |