]>
git.proxmox.com Git - qemu.git/blob - softmmu_header.h
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
23 #define DATA_TYPE uint64_t
27 #define DATA_TYPE uint32_t
31 #define DATA_TYPE uint16_t
32 #define DATA_STYPE int16_t
36 #define DATA_TYPE uint8_t
37 #define DATA_STYPE int8_t
39 #error unsupported data size
44 #define CPU_MEM_INDEX 0
45 #define MMUSUFFIX _mmu
47 #elif ACCESS_TYPE == 1
49 #define CPU_MEM_INDEX 1
50 #define MMUSUFFIX _mmu
52 #elif ACCESS_TYPE == 2
55 #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3)
56 #elif defined (TARGET_PPC)
57 #define CPU_MEM_INDEX (msr_pr)
58 #elif defined (TARGET_MIPS)
59 #define CPU_MEM_INDEX ((env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM)
60 #elif defined (TARGET_SPARC)
61 #define CPU_MEM_INDEX ((env->psrs) == 0)
62 #elif defined (TARGET_ARM)
63 #define CPU_MEM_INDEX ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR)
65 #error unsupported CPU
67 #define MMUSUFFIX _mmu
69 #elif ACCESS_TYPE == 3
72 #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3)
73 #elif defined (TARGET_PPC)
74 #define CPU_MEM_INDEX (msr_pr)
75 #elif defined (TARGET_MIPS)
76 #define CPU_MEM_INDEX ((env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM)
77 #elif defined (TARGET_SPARC)
78 #define CPU_MEM_INDEX ((env->psrs) == 0)
79 #elif defined (TARGET_ARM)
80 #define CPU_MEM_INDEX ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR)
82 #error unsupported CPU
84 #define MMUSUFFIX _cmmu
87 #error invalid ACCESS_TYPE
91 #define RES_TYPE uint64_t
97 DATA_TYPE
REGPARM(1) glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
,
99 void REGPARM(2) glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
, DATA_TYPE v
, int is_user
);
101 #if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
102 (ACCESS_TYPE <= 1) && defined(ASM_SOFTMMU)
104 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
108 asm volatile ("movl %1, %%edx\n"
113 "leal %5(%%edx, %%ebp), %%edx\n"
114 "cmpl (%%edx), %%eax\n"
123 "addl 4(%%edx), %%eax\n"
125 "movzbl (%%eax), %0\n"
127 "movzwl (%%eax), %0\n"
131 #error unsupported size
136 "i" ((CPU_TLB_SIZE
- 1) << 3),
137 "i" (TARGET_PAGE_BITS
- 3),
138 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
139 "m" (*(uint32_t *)offsetof(CPUState
, tlb_read
[CPU_MEM_INDEX
][0].address
)),
141 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
142 : "%eax", "%ecx", "%edx", "memory", "cc");
147 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
151 asm volatile ("movl %1, %%edx\n"
156 "leal %5(%%edx, %%ebp), %%edx\n"
157 "cmpl (%%edx), %%eax\n"
168 #error unsupported size
172 "addl 4(%%edx), %%eax\n"
174 "movsbl (%%eax), %0\n"
176 "movswl (%%eax), %0\n"
178 #error unsupported size
183 "i" ((CPU_TLB_SIZE
- 1) << 3),
184 "i" (TARGET_PAGE_BITS
- 3),
185 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
186 "m" (*(uint32_t *)offsetof(CPUState
, tlb_read
[CPU_MEM_INDEX
][0].address
)),
188 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
189 : "%eax", "%ecx", "%edx", "memory", "cc");
194 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
196 asm volatile ("movl %0, %%edx\n"
201 "leal %5(%%edx, %%ebp), %%edx\n"
202 "cmpl (%%edx), %%eax\n"
206 "movzbl %b1, %%edx\n"
208 "movzwl %w1, %%edx\n"
212 #error unsupported size
219 "addl 4(%%edx), %%eax\n"
221 "movb %b1, (%%eax)\n"
223 "movw %w1, (%%eax)\n"
227 #error unsupported size
232 /* NOTE: 'q' would be needed as constraint, but we could not use it
235 "i" ((CPU_TLB_SIZE
- 1) << 3),
236 "i" (TARGET_PAGE_BITS
- 3),
237 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
238 "m" (*(uint32_t *)offsetof(CPUState
, tlb_write
[CPU_MEM_INDEX
][0].address
)),
240 "m" (*(uint8_t *)&glue(glue(__st
, SUFFIX
), MMUSUFFIX
))
241 : "%eax", "%ecx", "%edx", "memory", "cc");
246 /* generic load/store macros */
248 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
253 unsigned long physaddr
;
257 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
258 is_user
= CPU_MEM_INDEX
;
259 if (__builtin_expect(env
->tlb_read
[is_user
][index
].address
!=
260 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
261 res
= glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
263 physaddr
= addr
+ env
->tlb_read
[is_user
][index
].addend
;
264 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)physaddr
);
270 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
274 unsigned long physaddr
;
278 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
279 is_user
= CPU_MEM_INDEX
;
280 if (__builtin_expect(env
->tlb_read
[is_user
][index
].address
!=
281 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
282 res
= (DATA_STYPE
)glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
284 physaddr
= addr
+ env
->tlb_read
[is_user
][index
].addend
;
285 res
= glue(glue(lds
, SUFFIX
), _raw
)((uint8_t *)physaddr
);
291 /* generic store macro */
293 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
297 unsigned long physaddr
;
301 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
302 is_user
= CPU_MEM_INDEX
;
303 if (__builtin_expect(env
->tlb_write
[is_user
][index
].address
!=
304 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
305 glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(addr
, v
, is_user
);
307 physaddr
= addr
+ env
->tlb_write
[is_user
][index
].addend
;
308 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)physaddr
, v
);
315 static inline float64
glue(ldfq
, MEMSUFFIX
)(target_ulong ptr
)
321 u
.i
= glue(ldq
, MEMSUFFIX
)(ptr
);
325 static inline void glue(stfq
, MEMSUFFIX
)(target_ulong ptr
, float64 v
)
332 glue(stq
, MEMSUFFIX
)(ptr
, u
.i
);
334 #endif /* DATA_SIZE == 8 */
337 static inline float32
glue(ldfl
, MEMSUFFIX
)(target_ulong ptr
)
343 u
.i
= glue(ldl
, MEMSUFFIX
)(ptr
);
347 static inline void glue(stfl
, MEMSUFFIX
)(target_ulong ptr
, float32 v
)
354 glue(stl
, MEMSUFFIX
)(ptr
, u
.i
);
356 #endif /* DATA_SIZE == 4 */