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
54 #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3)
55 #define MMUSUFFIX _mmu
57 #elif ACCESS_TYPE == 3
59 #define CPU_MEM_INDEX ((env->hflags & HF_CPL_MASK) == 3)
60 #define MMUSUFFIX _cmmu
63 #error invalid ACCESS_TYPE
67 #define RES_TYPE uint64_t
73 DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(unsigned long addr,
75 void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(unsigned long addr, DATA_TYPE v, int is_user);
77 #if (DATA_SIZE <= 4) && defined(__i386__) && (ACCESS_TYPE <= 1) && defined(ASM_SOFTMMU)
79 static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr)
83 asm volatile ("movl %1, %%edx\n"
88 "leal %5(%%edx, %%ebp), %%edx\n"
89 "cmpl (%%edx), %%eax\n"
98 "addl 4(%%edx), %%eax\n"
100 "movzbl (%%eax), %0\n"
102 "movzwl (%%eax), %0\n"
106 #error unsupported size
111 "i" ((CPU_TLB_SIZE - 1) << 3),
112 "i" (TARGET_PAGE_BITS - 3),
113 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
114 "m" (*(uint32_t *)offsetof(CPUState, tlb_read[CPU_MEM_INDEX][0].address)),
116 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
117 : "%eax", "%ecx", "%edx", "memory", "cc");
122 static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(void *ptr)
126 asm volatile ("movl %1, %%edx\n"
131 "leal %5(%%edx, %%ebp), %%edx\n"
132 "cmpl (%%edx), %%eax\n"
143 #error unsupported size
147 "addl 4(%%edx), %%eax\n"
149 "movsbl (%%eax), %0\n"
151 "movswl (%%eax), %0\n"
153 #error unsupported size
158 "i" ((CPU_TLB_SIZE - 1) << 3),
159 "i" (TARGET_PAGE_BITS - 3),
160 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
161 "m" (*(uint32_t *)offsetof(CPUState, tlb_read[CPU_MEM_INDEX][0].address)),
163 "m" (*(uint8_t *)&glue(glue(__ld, SUFFIX), MMUSUFFIX))
164 : "%eax", "%ecx", "%edx", "memory", "cc");
169 static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(void *ptr, RES_TYPE v)
171 asm volatile ("movl %0, %%edx\n"
176 "leal %5(%%edx, %%ebp), %%edx\n"
177 "cmpl (%%edx), %%eax\n"
181 "movzbl %b1, %%edx\n"
183 "movzwl %w1, %%edx\n"
187 #error unsupported size
194 "addl 4(%%edx), %%eax\n"
196 "movb %b1, (%%eax)\n"
198 "movw %w1, (%%eax)\n"
202 #error unsupported size
207 /* NOTE: 'q' would be needed as constraint, but we could not use it
210 "i" ((CPU_TLB_SIZE - 1) << 3),
211 "i" (TARGET_PAGE_BITS - 3),
212 "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
213 "m" (*(uint32_t *)offsetof(CPUState, tlb_write[CPU_MEM_INDEX][0].address)),
215 "m" (*(uint8_t *)&glue(glue(__st, SUFFIX), MMUSUFFIX))
216 : "%eax", "%ecx", "%edx", "memory", "cc");
221 /* generic load/store macros */
223 static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr)
227 unsigned long addr, physaddr;
230 addr = (unsigned long)ptr;
231 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
232 is_user = CPU_MEM_INDEX;
233 if (__builtin_expect(env->tlb_read[is_user][index].address !=
234 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
235 res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
237 physaddr = addr + env->tlb_read[is_user][index].addend;
238 res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
244 static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(void *ptr)
247 unsigned long addr, physaddr;
250 addr = (unsigned long)ptr;
251 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
252 is_user = CPU_MEM_INDEX;
253 if (__builtin_expect(env->tlb_read[is_user][index].address !=
254 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
255 res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
257 physaddr = addr + env->tlb_read[is_user][index].addend;
258 res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
264 /* generic store macro */
266 static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(void *ptr, RES_TYPE v)
269 unsigned long addr, physaddr;
272 addr = (unsigned long)ptr;
273 index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
274 is_user = CPU_MEM_INDEX;
275 if (__builtin_expect(env->tlb_write[is_user][index].address !=
276 (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
277 glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user);
279 physaddr = addr + env->tlb_write[is_user][index].addend;
280 glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);