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 #define ADDR_READ addr_code
99 #define ADDR_READ addr_read
102 DATA_TYPE
REGPARM(1) glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
,
104 void REGPARM(2) glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(target_ulong addr
, DATA_TYPE v
, int is_user
);
106 #if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
107 (ACCESS_TYPE <= 1) && defined(ASM_SOFTMMU)
109 #define CPU_TLB_ENTRY_BITS 4
111 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
115 asm volatile ("movl %1, %%edx\n"
120 "leal %5(%%edx, %%ebp), %%edx\n"
121 "cmpl (%%edx), %%eax\n"
130 "addl 12(%%edx), %%eax\n"
132 "movzbl (%%eax), %0\n"
134 "movzwl (%%eax), %0\n"
138 #error unsupported size
143 "i" ((CPU_TLB_SIZE
- 1) << CPU_TLB_ENTRY_BITS
),
144 "i" (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
),
145 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
146 "m" (*(uint32_t *)offsetof(CPUState
, tlb_table
[CPU_MEM_INDEX
][0].addr_read
)),
148 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
149 : "%eax", "%ecx", "%edx", "memory", "cc");
154 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
158 asm volatile ("movl %1, %%edx\n"
163 "leal %5(%%edx, %%ebp), %%edx\n"
164 "cmpl (%%edx), %%eax\n"
175 #error unsupported size
179 "addl 12(%%edx), %%eax\n"
181 "movsbl (%%eax), %0\n"
183 "movswl (%%eax), %0\n"
185 #error unsupported size
190 "i" ((CPU_TLB_SIZE
- 1) << CPU_TLB_ENTRY_BITS
),
191 "i" (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
),
192 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
193 "m" (*(uint32_t *)offsetof(CPUState
, tlb_table
[CPU_MEM_INDEX
][0].addr_read
)),
195 "m" (*(uint8_t *)&glue(glue(__ld
, SUFFIX
), MMUSUFFIX
))
196 : "%eax", "%ecx", "%edx", "memory", "cc");
201 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
203 asm volatile ("movl %0, %%edx\n"
208 "leal %5(%%edx, %%ebp), %%edx\n"
209 "cmpl (%%edx), %%eax\n"
213 "movzbl %b1, %%edx\n"
215 "movzwl %w1, %%edx\n"
219 #error unsupported size
226 "addl 8(%%edx), %%eax\n"
228 "movb %b1, (%%eax)\n"
230 "movw %w1, (%%eax)\n"
234 #error unsupported size
239 /* NOTE: 'q' would be needed as constraint, but we could not use it
242 "i" ((CPU_TLB_SIZE
- 1) << CPU_TLB_ENTRY_BITS
),
243 "i" (TARGET_PAGE_BITS
- CPU_TLB_ENTRY_BITS
),
244 "i" (TARGET_PAGE_MASK
| (DATA_SIZE
- 1)),
245 "m" (*(uint32_t *)offsetof(CPUState
, tlb_table
[CPU_MEM_INDEX
][0].addr_write
)),
247 "m" (*(uint8_t *)&glue(glue(__st
, SUFFIX
), MMUSUFFIX
))
248 : "%eax", "%ecx", "%edx", "memory", "cc");
253 /* generic load/store macros */
255 static inline RES_TYPE
glue(glue(ld
, USUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
260 unsigned long physaddr
;
264 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
265 is_user
= CPU_MEM_INDEX
;
266 if (__builtin_expect(env
->tlb_table
[is_user
][index
].ADDR_READ
!=
267 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
268 res
= glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
270 physaddr
= addr
+ env
->tlb_table
[is_user
][index
].addend
;
271 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)physaddr
);
277 static inline int glue(glue(lds
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
)
281 unsigned long physaddr
;
285 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
286 is_user
= CPU_MEM_INDEX
;
287 if (__builtin_expect(env
->tlb_table
[is_user
][index
].ADDR_READ
!=
288 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
289 res
= (DATA_STYPE
)glue(glue(__ld
, SUFFIX
), MMUSUFFIX
)(addr
, is_user
);
291 physaddr
= addr
+ env
->tlb_table
[is_user
][index
].addend
;
292 res
= glue(glue(lds
, SUFFIX
), _raw
)((uint8_t *)physaddr
);
300 /* generic store macro */
302 static inline void glue(glue(st
, SUFFIX
), MEMSUFFIX
)(target_ulong ptr
, RES_TYPE v
)
306 unsigned long physaddr
;
310 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
311 is_user
= CPU_MEM_INDEX
;
312 if (__builtin_expect(env
->tlb_table
[is_user
][index
].addr_write
!=
313 (addr
& (TARGET_PAGE_MASK
| (DATA_SIZE
- 1))), 0)) {
314 glue(glue(__st
, SUFFIX
), MMUSUFFIX
)(addr
, v
, is_user
);
316 physaddr
= addr
+ env
->tlb_table
[is_user
][index
].addend
;
317 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)physaddr
, v
);
321 #endif /* ACCESS_TYPE != 3 */
328 static inline float64
glue(ldfq
, MEMSUFFIX
)(target_ulong ptr
)
334 u
.i
= glue(ldq
, MEMSUFFIX
)(ptr
);
338 static inline void glue(stfq
, MEMSUFFIX
)(target_ulong ptr
, float64 v
)
345 glue(stq
, MEMSUFFIX
)(ptr
, u
.i
);
347 #endif /* DATA_SIZE == 8 */
350 static inline float32
glue(ldfl
, MEMSUFFIX
)(target_ulong ptr
)
356 u
.i
= glue(ldl
, MEMSUFFIX
)(ptr
);
360 static inline void glue(stfl
, MEMSUFFIX
)(target_ulong ptr
, float32 v
)
367 glue(stl
, MEMSUFFIX
)(ptr
, u
.i
);
369 #endif /* DATA_SIZE == 4 */
371 #endif /* ACCESS_TYPE != 3 */