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