]> git.proxmox.com Git - qemu.git/blame - softmmu_header.h
fixed register constraint
[qemu.git] / softmmu_header.h
CommitLineData
b92e5a22
FB
1/*
2 * Software MMU support
5fafdf24 3 *
b92e5a22
FB
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#if DATA_SIZE == 8
21#define SUFFIX q
61382a50 22#define USUFFIX q
b92e5a22
FB
23#define DATA_TYPE uint64_t
24#elif DATA_SIZE == 4
25#define SUFFIX l
61382a50 26#define USUFFIX l
b92e5a22
FB
27#define DATA_TYPE uint32_t
28#elif DATA_SIZE == 2
29#define SUFFIX w
61382a50 30#define USUFFIX uw
b92e5a22
FB
31#define DATA_TYPE uint16_t
32#define DATA_STYPE int16_t
33#elif DATA_SIZE == 1
34#define SUFFIX b
61382a50 35#define USUFFIX ub
b92e5a22
FB
36#define DATA_TYPE uint8_t
37#define DATA_STYPE int8_t
38#else
39#error unsupported data size
40#endif
41
6ebbf390 42#if ACCESS_TYPE < (NB_MMU_MODES)
61382a50 43
6ebbf390 44#define CPU_MMU_INDEX ACCESS_TYPE
61382a50
FB
45#define MMUSUFFIX _mmu
46
6ebbf390 47#elif ACCESS_TYPE == (NB_MMU_MODES)
61382a50 48
6ebbf390 49#define CPU_MMU_INDEX (cpu_mmu_index(env))
61382a50
FB
50#define MMUSUFFIX _mmu
51
6ebbf390 52#elif ACCESS_TYPE == (NB_MMU_MODES + 1)
61382a50 53
6ebbf390 54#define CPU_MMU_INDEX (cpu_mmu_index(env))
61382a50
FB
55#define MMUSUFFIX _cmmu
56
b92e5a22 57#else
61382a50 58#error invalid ACCESS_TYPE
b92e5a22
FB
59#endif
60
61#if DATA_SIZE == 8
62#define RES_TYPE uint64_t
63#else
64#define RES_TYPE int
65#endif
66
6ebbf390 67#if ACCESS_TYPE == (NB_MMU_MODES + 1)
84b7b8e7
FB
68#define ADDR_READ addr_code
69#else
70#define ADDR_READ addr_read
71#endif
b92e5a22 72
c27004ec 73DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
6ebbf390
JM
74 int mmu_idx);
75void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr, DATA_TYPE v, int mmu_idx);
b92e5a22 76
c27004ec 77#if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
6ebbf390 78 (ACCESS_TYPE < NB_MMU_MODES) && defined(ASM_SOFTMMU)
e16c53fa 79
84b7b8e7
FB
80#define CPU_TLB_ENTRY_BITS 4
81
c27004ec 82static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
e16c53fa
FB
83{
84 int res;
85
86 asm volatile ("movl %1, %%edx\n"
87 "movl %1, %%eax\n"
88 "shrl %3, %%edx\n"
89 "andl %4, %%eax\n"
90 "andl %2, %%edx\n"
91 "leal %5(%%edx, %%ebp), %%edx\n"
92 "cmpl (%%edx), %%eax\n"
93 "movl %1, %%eax\n"
94 "je 1f\n"
95 "pushl %6\n"
96 "call %7\n"
97 "popl %%edx\n"
98 "movl %%eax, %0\n"
99 "jmp 2f\n"
100 "1:\n"
84b7b8e7 101 "addl 12(%%edx), %%eax\n"
e16c53fa
FB
102#if DATA_SIZE == 1
103 "movzbl (%%eax), %0\n"
104#elif DATA_SIZE == 2
105 "movzwl (%%eax), %0\n"
106#elif DATA_SIZE == 4
107 "movl (%%eax), %0\n"
108#else
109#error unsupported size
110#endif
111 "2:\n"
112 : "=r" (res)
5fafdf24
TS
113 : "r" (ptr),
114 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
115 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
e16c53fa 116 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
6ebbf390
JM
117 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_read)),
118 "i" (CPU_MMU_INDEX),
e16c53fa
FB
119 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
120 : "%eax", "%ecx", "%edx", "memory", "cc");
121 return res;
122}
123
124#if DATA_SIZE <= 2
c27004ec 125static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
e16c53fa
FB
126{
127 int res;
128
129 asm volatile ("movl %1, %%edx\n"
130 "movl %1, %%eax\n"
131 "shrl %3, %%edx\n"
132 "andl %4, %%eax\n"
133 "andl %2, %%edx\n"
134 "leal %5(%%edx, %%ebp), %%edx\n"
135 "cmpl (%%edx), %%eax\n"
136 "movl %1, %%eax\n"
137 "je 1f\n"
138 "pushl %6\n"
139 "call %7\n"
140 "popl %%edx\n"
141#if DATA_SIZE == 1
142 "movsbl %%al, %0\n"
143#elif DATA_SIZE == 2
144 "movswl %%ax, %0\n"
145#else
146#error unsupported size
147#endif
148 "jmp 2f\n"
149 "1:\n"
84b7b8e7 150 "addl 12(%%edx), %%eax\n"
e16c53fa
FB
151#if DATA_SIZE == 1
152 "movsbl (%%eax), %0\n"
153#elif DATA_SIZE == 2
154 "movswl (%%eax), %0\n"
155#else
156#error unsupported size
157#endif
158 "2:\n"
159 : "=r" (res)
5fafdf24
TS
160 : "r" (ptr),
161 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
162 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
e16c53fa 163 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
6ebbf390
JM
164 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_read)),
165 "i" (CPU_MMU_INDEX),
e16c53fa
FB
166 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
167 : "%eax", "%ecx", "%edx", "memory", "cc");
168 return res;
169}
170#endif
171
c27004ec 172static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
e16c53fa
FB
173{
174 asm volatile ("movl %0, %%edx\n"
175 "movl %0, %%eax\n"
176 "shrl %3, %%edx\n"
177 "andl %4, %%eax\n"
178 "andl %2, %%edx\n"
179 "leal %5(%%edx, %%ebp), %%edx\n"
180 "cmpl (%%edx), %%eax\n"
181 "movl %0, %%eax\n"
182 "je 1f\n"
183#if DATA_SIZE == 1
184 "movzbl %b1, %%edx\n"
185#elif DATA_SIZE == 2
186 "movzwl %w1, %%edx\n"
187#elif DATA_SIZE == 4
188 "movl %1, %%edx\n"
189#else
190#error unsupported size
191#endif
192 "pushl %6\n"
193 "call %7\n"
194 "popl %%eax\n"
195 "jmp 2f\n"
196 "1:\n"
84b7b8e7 197 "addl 8(%%edx), %%eax\n"
e16c53fa
FB
198#if DATA_SIZE == 1
199 "movb %b1, (%%eax)\n"
200#elif DATA_SIZE == 2
201 "movw %w1, (%%eax)\n"
202#elif DATA_SIZE == 4
203 "movl %1, (%%eax)\n"
204#else
205#error unsupported size
206#endif
207 "2:\n"
5fafdf24
TS
208 :
209 : "r" (ptr),
f220f4e3
FB
210#if DATA_SIZE == 1
211 "q" (v),
212#else
5fafdf24 213 "r" (v),
f220f4e3 214#endif
5fafdf24
TS
215 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
216 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
e16c53fa 217 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
6ebbf390
JM
218 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_write)),
219 "i" (CPU_MMU_INDEX),
e16c53fa
FB
220 "m" (*(uint8_t *)&glue(glue(__st, SUFFIX), MMUSUFFIX))
221 : "%eax", "%ecx", "%edx", "memory", "cc");
222}
223
224#else
225
226/* generic load/store macros */
227
c27004ec 228static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
b92e5a22
FB
229{
230 int index;
231 RES_TYPE res;
c27004ec
FB
232 target_ulong addr;
233 unsigned long physaddr;
6ebbf390 234 int mmu_idx;
61382a50 235
c27004ec 236 addr = ptr;
b92e5a22 237 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
6ebbf390
JM
238 mmu_idx = CPU_MMU_INDEX;
239 if (__builtin_expect(env->tlb_table[mmu_idx][index].ADDR_READ !=
b92e5a22 240 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
6ebbf390 241 res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
b92e5a22 242 } else {
6ebbf390 243 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
61382a50 244 res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
b92e5a22
FB
245 }
246 return res;
247}
248
249#if DATA_SIZE <= 2
c27004ec 250static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
b92e5a22
FB
251{
252 int res, index;
c27004ec
FB
253 target_ulong addr;
254 unsigned long physaddr;
6ebbf390 255 int mmu_idx;
61382a50 256
c27004ec 257 addr = ptr;
b92e5a22 258 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
6ebbf390
JM
259 mmu_idx = CPU_MMU_INDEX;
260 if (__builtin_expect(env->tlb_table[mmu_idx][index].ADDR_READ !=
b92e5a22 261 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
6ebbf390 262 res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
b92e5a22 263 } else {
6ebbf390 264 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
b92e5a22
FB
265 res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
266 }
267 return res;
268}
269#endif
270
6ebbf390 271#if ACCESS_TYPE != (NB_MMU_MODES + 1)
84b7b8e7 272
e16c53fa
FB
273/* generic store macro */
274
c27004ec 275static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
b92e5a22
FB
276{
277 int index;
c27004ec
FB
278 target_ulong addr;
279 unsigned long physaddr;
6ebbf390 280 int mmu_idx;
61382a50 281
c27004ec 282 addr = ptr;
b92e5a22 283 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
6ebbf390
JM
284 mmu_idx = CPU_MMU_INDEX;
285 if (__builtin_expect(env->tlb_table[mmu_idx][index].addr_write !=
b92e5a22 286 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
6ebbf390 287 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, mmu_idx);
b92e5a22 288 } else {
6ebbf390 289 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
b92e5a22
FB
290 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
291 }
292}
293
6ebbf390 294#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
84b7b8e7
FB
295
296#endif /* !asm */
297
6ebbf390 298#if ACCESS_TYPE != (NB_MMU_MODES + 1)
e16c53fa 299
2d603d22 300#if DATA_SIZE == 8
3f87bf69 301static inline float64 glue(ldfq, MEMSUFFIX)(target_ulong ptr)
2d603d22
FB
302{
303 union {
3f87bf69 304 float64 d;
2d603d22
FB
305 uint64_t i;
306 } u;
307 u.i = glue(ldq, MEMSUFFIX)(ptr);
308 return u.d;
309}
310
3f87bf69 311static inline void glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
2d603d22
FB
312{
313 union {
3f87bf69 314 float64 d;
2d603d22
FB
315 uint64_t i;
316 } u;
317 u.d = v;
318 glue(stq, MEMSUFFIX)(ptr, u.i);
319}
320#endif /* DATA_SIZE == 8 */
321
322#if DATA_SIZE == 4
3f87bf69 323static inline float32 glue(ldfl, MEMSUFFIX)(target_ulong ptr)
2d603d22
FB
324{
325 union {
3f87bf69 326 float32 f;
2d603d22
FB
327 uint32_t i;
328 } u;
329 u.i = glue(ldl, MEMSUFFIX)(ptr);
330 return u.f;
331}
332
3f87bf69 333static inline void glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
2d603d22
FB
334{
335 union {
3f87bf69 336 float32 f;
2d603d22
FB
337 uint32_t i;
338 } u;
339 u.f = v;
340 glue(stl, MEMSUFFIX)(ptr, u.i);
341}
342#endif /* DATA_SIZE == 4 */
343
6ebbf390 344#endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
84b7b8e7 345
b92e5a22
FB
346#undef RES_TYPE
347#undef DATA_TYPE
348#undef DATA_STYPE
349#undef SUFFIX
61382a50 350#undef USUFFIX
b92e5a22 351#undef DATA_SIZE
6ebbf390 352#undef CPU_MMU_INDEX
61382a50 353#undef MMUSUFFIX
84b7b8e7 354#undef ADDR_READ