Fix timer rearm fallout from last qemu merge
[qemu-kvm/fedora.git] / softmmu_header.h
blobfbf22b160364c59b0b71c10b0e741e48fb5f7035
1 /*
2 * Software MMU support
4 * Copyright (c) 2003 Fabrice Bellard
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.
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.
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
20 #if DATA_SIZE == 8
21 #define SUFFIX q
22 #define USUFFIX q
23 #define DATA_TYPE uint64_t
24 #elif DATA_SIZE == 4
25 #define SUFFIX l
26 #define USUFFIX l
27 #define DATA_TYPE uint32_t
28 #elif DATA_SIZE == 2
29 #define SUFFIX w
30 #define USUFFIX uw
31 #define DATA_TYPE uint16_t
32 #define DATA_STYPE int16_t
33 #elif DATA_SIZE == 1
34 #define SUFFIX b
35 #define USUFFIX ub
36 #define DATA_TYPE uint8_t
37 #define DATA_STYPE int8_t
38 #else
39 #error unsupported data size
40 #endif
42 #if ACCESS_TYPE < (NB_MMU_MODES)
44 #define CPU_MMU_INDEX ACCESS_TYPE
45 #define MMUSUFFIX _mmu
47 #elif ACCESS_TYPE == (NB_MMU_MODES)
49 #define CPU_MMU_INDEX (cpu_mmu_index(env))
50 #define MMUSUFFIX _mmu
52 #elif ACCESS_TYPE == (NB_MMU_MODES + 1)
54 #define CPU_MMU_INDEX (cpu_mmu_index(env))
55 #define MMUSUFFIX _cmmu
57 #else
58 #error invalid ACCESS_TYPE
59 #endif
61 #if DATA_SIZE == 8
62 #define RES_TYPE uint64_t
63 #else
64 #define RES_TYPE int
65 #endif
67 #if ACCESS_TYPE == (NB_MMU_MODES + 1)
68 #define ADDR_READ addr_code
69 #else
70 #define ADDR_READ addr_read
71 #endif
73 DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
74 int mmu_idx);
75 void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr, DATA_TYPE v, int mmu_idx);
77 #if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
78 (ACCESS_TYPE < NB_MMU_MODES) && defined(ASM_SOFTMMU)
80 #define CPU_TLB_ENTRY_BITS 4
82 static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
84 int res;
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"
101 "addl 12(%%edx), %%eax\n"
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)
113 : "r" (ptr),
114 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
115 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
116 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
117 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_read)),
118 "i" (CPU_MMU_INDEX),
119 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
120 : "%eax", "%ecx", "%edx", "memory", "cc");
121 return res;
124 #if DATA_SIZE <= 2
125 static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
127 int res;
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"
150 "addl 12(%%edx), %%eax\n"
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)
160 : "r" (ptr),
161 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
162 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
163 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
164 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_read)),
165 "i" (CPU_MMU_INDEX),
166 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
167 : "%eax", "%ecx", "%edx", "memory", "cc");
168 return res;
170 #endif
172 static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
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"
197 "addl 8(%%edx), %%eax\n"
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"
209 : "r" (ptr),
210 #if DATA_SIZE == 1
211 "q" (v),
212 #else
213 "r" (v),
214 #endif
215 "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
216 "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
217 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
218 "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_write)),
219 "i" (CPU_MMU_INDEX),
220 "m" (*(uint8_t *)&glue(glue(__st, SUFFIX), MMUSUFFIX))
221 : "%eax", "%ecx", "%edx", "memory", "cc");
224 #else
226 /* generic load/store macros */
228 static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
230 int index;
231 RES_TYPE res;
232 target_ulong addr;
233 unsigned long physaddr;
234 int mmu_idx;
236 addr = ptr;
237 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
238 mmu_idx = CPU_MMU_INDEX;
239 if (__builtin_expect(env->tlb_table[mmu_idx][index].ADDR_READ !=
240 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
241 res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
242 } else {
243 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
244 res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
246 return res;
249 #if DATA_SIZE <= 2
250 static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
252 int res, index;
253 target_ulong addr;
254 unsigned long physaddr;
255 int mmu_idx;
257 addr = ptr;
258 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
259 mmu_idx = CPU_MMU_INDEX;
260 if (__builtin_expect(env->tlb_table[mmu_idx][index].ADDR_READ !=
261 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
262 res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, mmu_idx);
263 } else {
264 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
265 res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
267 return res;
269 #endif
271 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
273 /* generic store macro */
275 static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
277 int index;
278 target_ulong addr;
279 unsigned long physaddr;
280 int mmu_idx;
282 addr = ptr;
283 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
284 mmu_idx = CPU_MMU_INDEX;
285 if (__builtin_expect(env->tlb_table[mmu_idx][index].addr_write !=
286 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
287 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, mmu_idx);
288 } else {
289 physaddr = addr + env->tlb_table[mmu_idx][index].addend;
290 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
294 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
296 #endif /* !asm */
298 #if ACCESS_TYPE != (NB_MMU_MODES + 1)
300 #if DATA_SIZE == 8
301 static inline float64 glue(ldfq, MEMSUFFIX)(target_ulong ptr)
303 union {
304 float64 d;
305 uint64_t i;
306 } u;
307 u.i = glue(ldq, MEMSUFFIX)(ptr);
308 return u.d;
311 static inline void glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
313 union {
314 float64 d;
315 uint64_t i;
316 } u;
317 u.d = v;
318 glue(stq, MEMSUFFIX)(ptr, u.i);
320 #endif /* DATA_SIZE == 8 */
322 #if DATA_SIZE == 4
323 static inline float32 glue(ldfl, MEMSUFFIX)(target_ulong ptr)
325 union {
326 float32 f;
327 uint32_t i;
328 } u;
329 u.i = glue(ldl, MEMSUFFIX)(ptr);
330 return u.f;
333 static inline void glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
335 union {
336 float32 f;
337 uint32_t i;
338 } u;
339 u.f = v;
340 glue(stl, MEMSUFFIX)(ptr, u.i);
342 #endif /* DATA_SIZE == 4 */
344 #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
346 #undef RES_TYPE
347 #undef DATA_TYPE
348 #undef DATA_STYPE
349 #undef SUFFIX
350 #undef USUFFIX
351 #undef DATA_SIZE
352 #undef CPU_MMU_INDEX
353 #undef MMUSUFFIX
354 #undef ADDR_READ