VirtualBox

source: vbox/trunk/src/recompiler_new/softmmu_header.h@ 13458

最後變更 在這個檔案從13458是 13382,由 vboxsync 提交於 16 年 前

more MSVC-related stuff

  • 屬性 svn:eol-style 設為 native
檔案大小: 9.0 KB
 
1/*
2 * Software MMU support
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
23 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
24 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
25 * a choice of LGPL license versions is made available with the language indicating
26 * that LGPLv2 or any later version may be used, or where a choice of which version
27 * of the LGPL is applied is otherwise unspecified.
28 */
29#if DATA_SIZE == 8
30#define SUFFIX q
31#define USUFFIX q
32#define DATA_TYPE uint64_t
33#elif DATA_SIZE == 4
34#define SUFFIX l
35#define USUFFIX l
36#define DATA_TYPE uint32_t
37#elif DATA_SIZE == 2
38#define SUFFIX w
39#define USUFFIX uw
40#define DATA_TYPE uint16_t
41#define DATA_STYPE int16_t
42#elif DATA_SIZE == 1
43#define SUFFIX b
44#define USUFFIX ub
45#define DATA_TYPE uint8_t
46#define DATA_STYPE int8_t
47#else
48#error unsupported data size
49#endif
50
51#if ACCESS_TYPE < (NB_MMU_MODES)
52
53#define CPU_MMU_INDEX ACCESS_TYPE
54#define MMUSUFFIX _mmu
55
56#elif ACCESS_TYPE == (NB_MMU_MODES)
57
58#define CPU_MMU_INDEX (cpu_mmu_index(env))
59#define MMUSUFFIX _mmu
60
61#elif ACCESS_TYPE == (NB_MMU_MODES + 1)
62
63#define CPU_MMU_INDEX (cpu_mmu_index(env))
64#define MMUSUFFIX _cmmu
65
66#else
67#error invalid ACCESS_TYPE
68#endif
69
70#if DATA_SIZE == 8
71#define RES_TYPE uint64_t
72#else
73#define RES_TYPE int
74#endif
75
76#if ACCESS_TYPE == (NB_MMU_MODES + 1)
77#define ADDR_READ addr_code
78#else
79#define ADDR_READ addr_read
80#endif
81
82#if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
83 (ACCESS_TYPE < NB_MMU_MODES) && defined(ASM_SOFTMMU)
84
85#ifdef VBOX
86/* generic store macro */
87
88DELCINLINE(void) glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
89{
90 int index;
91 target_ulong addr;
92 unsigned long physaddr;
93 int is_user;
94
95 addr = ptr;
96 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
97 is_user = CPU_MMU_INDEX;
98 if (__builtin_expect(env->tlb_table[is_user][index].addr_write !=
99 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
100 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user);
101 } else {
102 physaddr = addr + env->tlb_table[is_user][index].addend;
103 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
104 }
105}
106
107#else /* !VBOX */
108
109static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
110{
111 asm volatile ("movl %0, %%edx\n"
112 "movl %0, %%eax\n"
113 "shrl %3, %%edx\n"
114 "andl %4, %%eax\n"
115 "andl %2, %%edx\n"
116 "leal %5(%%edx, %%ebp), %%edx\n"
117 "cmpl (%%edx), %%eax\n"
118 "movl %0, %%eax\n"
119 "je 1f\n"
120#if DATA_SIZE == 1
121 "movzbl %b1, %%edx\n"
122#elif DATA_SIZE == 2
123 "movzwl %w1, %%edx\n"
124#elif DATA_SIZE == 4
125 "movl %1, %%edx\n"
126#else
127#error unsupported size
128#endif
129 "pushl %6\n"
130 "call %7\n"
131 "popl %%eax\n"
132 "jmp 2f\n"
133 "1:\n"
134 "addl 8(%%edx), %%eax\n"
135#if DATA_SIZE == 1
136 "movb %b1, (%%eax)\n"
137#elif DATA_SIZE == 2
138 "movw %w1, (%%eax)\n"
139#elif DATA_SIZE == 4
140 "movl %1, (%%eax)\n"
141#else
142#error unsupported size
143#endif
144 "2:\n"
145 :
146 : "r" (ptr),
147/* NOTE: 'q' would be needed as constraint, but we could not use it
148 with T1 ! */
149 "r" (v),
150 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
151 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
152 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
153 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_write)),
154 "i" (CPU_MMU_INDEX),
155 "m" (*(uint8_t *)&glue(glue(__st, SUFFIX), MMUSUFFIX))
156 : "%eax", "%ecx", "%edx", "memory", "cc");
157}
158#endif /* !VBOX */
159
160#else
161
162/* generic load/store macros */
163
164#ifndef VBOX
165static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
166#else
167DECLINLINE(RES_TYPE) glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
168#endif
169{
170 int index;
171 RES_TYPE res;
172 target_ulong addr;
173 unsigned long physaddr;
174 int is_user;
175
176 addr = ptr;
177 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
178 is_user = CPU_MMU_INDEX;
179#ifndef VBOX
180 if (__builtin_expect(env->tlb_table[is_user][index].ADDR_READ !=
181 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
182#else
183 if (RT_UNLIKELY(env->tlb_table[is_user][index].ADDR_READ !=
184 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
185#endif
186 res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
187 } else {
188 physaddr = addr + env->tlb_table[is_user][index].addend;
189 res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
190 }
191 return res;
192}
193
194#if DATA_SIZE <= 2
195#ifndef VBOX
196static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
197#else
198DECLINLINE(int) glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
199#endif
200{
201 int res, index;
202 target_ulong addr;
203 unsigned long physaddr;
204 int is_user;
205
206 addr = ptr;
207 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
208 is_user = CPU_MMU_INDEX;
209#ifndef VBOX
210 if (__builtin_expect(env->tlb_table[is_user][index].ADDR_READ !=
211 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
212#else
213 if (RT_UNLIKELY(env->tlb_table[is_user][index].ADDR_READ !=
214 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
215#endif
216 res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
217 } else {
218 physaddr = addr + env->tlb_table[is_user][index].addend;
219 res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
220 }
221 return res;
222}
223#endif
224
225#if ACCESS_TYPE != (NB_MMU_MODES + 1)
226
227/* generic store macro */
228#ifndef VBOX
229static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
230#else
231DECLINLINE(void) glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
232#endif
233{
234 int index;
235 target_ulong addr;
236 unsigned long physaddr;
237 int is_user;
238
239 addr = ptr;
240 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
241 is_user = CPU_MMU_INDEX;
242#ifndef VBOX
243 if (__builtin_expect(env->tlb_table[is_user][index].addr_write !=
244 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
245#else
246 if (RT_UNLIKELY(env->tlb_table[is_user][index].addr_write !=
247 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) {
248#endif
249 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user);
250 } else {
251 physaddr = addr + env->tlb_table[is_user][index].addend;
252 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
253 }
254}
255
256#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
257
258#endif /* !asm */
259
260#if ACCESS_TYPE != (NB_MMU_MODES + 1)
261
262#if DATA_SIZE == 8
263#ifndef VBOX
264static inline float64 glue(ldfq, MEMSUFFIX)(target_ulong ptr)
265#else
266DECLINLINE(float64) glue(ldfq, MEMSUFFIX)(target_ulong ptr)
267#endif
268{
269 union {
270 float64 d;
271 uint64_t i;
272 } u;
273 u.i = glue(ldq, MEMSUFFIX)(ptr);
274 return u.d;
275}
276
277#ifndef VBOX
278static inline void glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
279#else
280DECLINLINE(void) glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
281#endif
282{
283 union {
284 float64 d;
285 uint64_t i;
286 } u;
287 u.d = v;
288 glue(stq, MEMSUFFIX)(ptr, u.i);
289}
290#endif /* DATA_SIZE == 8 */
291
292#if DATA_SIZE == 4
293#ifndef VBOX
294static inline float32 glue(ldfl, MEMSUFFIX)(target_ulong ptr)
295#else
296DECLINLINE(float32) glue(ldfl, MEMSUFFIX)(target_ulong ptr)
297#endif
298{
299 union {
300 float32 f;
301 uint32_t i;
302 } u;
303 u.i = glue(ldl, MEMSUFFIX)(ptr);
304 return u.f;
305}
306
307#ifndef VBOX
308static inline void glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
309#else
310DECLINLINE(void) glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
311#endif
312{
313 union {
314 float32 f;
315 uint32_t i;
316 } u;
317 u.f = v;
318 glue(stl, MEMSUFFIX)(ptr, u.i);
319}
320#endif /* DATA_SIZE == 4 */
321
322#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
323
324#undef RES_TYPE
325#undef DATA_TYPE
326#undef DATA_STYPE
327#undef SUFFIX
328#undef USUFFIX
329#undef DATA_SIZE
330#undef CPU_MMU_INDEX
331#undef MMUSUFFIX
332#undef ADDR_READ
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette