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)
63 #define MMUSUFFIX _mmu
65 #elif ACCESS_TYPE == 3
68 #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3)
69 #elif defined (TARGET_PPC)
70 #define CPU_MEM_INDEX (msr_pr)
71 #elif defined (TARGET_MIPS)
72 #define CPU_MEM_INDEX ((env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM)
73 #elif defined (TARGET_SPARC)
74 #define CPU_MEM_INDEX ((env->psrs) == 0)
76 #define MMUSUFFIX _cmmu
79 #error invalid ACCESS_TYPE
83 #define RES_TYPE uint64_t
89 DATA_TYPE
REGPARM(1) glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
,
91 void REGPARM(2) glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
, DATA_TYPE v
, int is_user
);
93 #if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
94 (ACCESS_TYPE <= 1) && defined(ASM_SOFTMMU)
96 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
100 asm volatile ("movl %1, %%edx\n"
105 "leal %5(%%edx, %%ebp), %%edx\n"
106 "cmpl (%%edx), %%eax\n"
115 "addl 4(%%edx), %%eax\n"
117 "movzbl (%%eax), %0\n"
119 "movzwl (%%eax), %0\n"
123 #error unsupported size
128 "i" ((CPU_TLB_SIZE
- 1) << 3),
129 "i" (TARGET_PAGE_BITS
- 3),
130 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
131 "m" (*(uint32_t *)offsetof(CPUState
, tlb_read
[CPU_MEM_INDEX
][0].address
)),
133 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
134 : "%eax", "%ecx", "%edx", "memory", "cc");
139 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
143 asm volatile ("movl %1, %%edx\n"
148 "leal %5(%%edx, %%ebp), %%edx\n"
149 "cmpl (%%edx), %%eax\n"
160 #error unsupported size
164 "addl 4(%%edx), %%eax\n"
166 "movsbl (%%eax), %0\n"
168 "movswl (%%eax), %0\n"
170 #error unsupported size
175 "i" ((CPU_TLB_SIZE
- 1) << 3),
176 "i" (TARGET_PAGE_BITS
- 3),
177 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
178 "m" (*(uint32_t *)offsetof(CPUState
, tlb_read
[CPU_MEM_INDEX
][0].address
)),
180 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
181 : "%eax", "%ecx", "%edx", "memory", "cc");
186 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
188 asm volatile ("movl %0, %%edx\n"
193 "leal %5(%%edx, %%ebp), %%edx\n"
194 "cmpl (%%edx), %%eax\n"
198 "movzbl %b1, %%edx\n"
200 "movzwl %w1, %%edx\n"
204 #error unsupported size
211 "addl 4(%%edx), %%eax\n"
213 "movb %b1, (%%eax)\n"
215 "movw %w1, (%%eax)\n"
219 #error unsupported size
224 /* NOTE: 'q' would be needed as constraint, but we could not use it
227 "i" ((CPU_TLB_SIZE
- 1) << 3),
228 "i" (TARGET_PAGE_BITS
- 3),
229 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
230 "m" (*(uint32_t *)offsetof(CPUState
, tlb_write
[CPU_MEM_INDEX
][0].address
)),
232 "m" (*(uint8_t *)&glue(glue(__st
, SUFFIX
), MMUSUFFIX
))
233 : "%eax", "%ecx", "%edx", "memory", "cc");
238 /* generic load/store macros */
240 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
245 unsigned long physaddr
;
249 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
250 is_user
= CPU_MEM_INDEX
;
251 if (__builtin_expect(env
->tlb_read
[is_user
][index
].address
!=
252 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
253 res
= glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
255 physaddr
= addr
+ env
->tlb_read
[is_user
][index
].addend
;
256 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)physaddr
);
262 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
266 unsigned long physaddr
;
270 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
271 is_user
= CPU_MEM_INDEX
;
272 if (__builtin_expect(env
->tlb_read
[is_user
][index
].address
!=
273 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
274 res
= (DATA_STYPE
)glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
276 physaddr
= addr
+ env
->tlb_read
[is_user
][index
].addend
;
277 res
= glue(glue(lds
, SUFFIX
), _raw
)((uint8_t *)physaddr
);
283 /* generic store macro */
285 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
289 unsigned long physaddr
;
293 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
294 is_user
= CPU_MEM_INDEX
;
295 if (__builtin_expect(env
->tlb_write
[is_user
][index
].address
!=
296 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
297 glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(addr
, v
, is_user
);
299 physaddr
= addr
+ env
->tlb_write
[is_user
][index
].addend
;
300 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)physaddr
, v
);
307 static inline double glue(ldfq
, MEMSUFFIX
)(target_ulong ptr
)
313 u
.i
= glue(ldq
, MEMSUFFIX
)(ptr
);
317 static inline void glue(stfq
, MEMSUFFIX
)(target_ulong ptr
, double v
)
324 glue(stq
, MEMSUFFIX
)(ptr
, u
.i
);
326 #endif /* DATA_SIZE == 8 */
329 static inline float glue(ldfl
, MEMSUFFIX
)(target_ulong ptr
)
335 u
.i
= glue(ldl
, MEMSUFFIX
)(ptr
);
339 static inline void glue(stfl
, MEMSUFFIX
)(target_ulong ptr
, float v
)
346 glue(stl
, MEMSUFFIX
)(ptr
, u
.i
);
348 #endif /* DATA_SIZE == 4 */