1 | /*
|
---|
2 | * Software MMU support
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003 Fabrice Bellard
|
---|
5 | *
|
---|
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.
|
---|
10 | *
|
---|
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.
|
---|
15 | *
|
---|
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
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 | #if DATA_SIZE == 8
|
---|
30 | #define SUFFIX q
|
---|
31 | #define USUFFIX q
|
---|
32 | #define DATA_TYPE uint64_t
|
---|
33 | #elif DATA_SIZE == 4
|
---|
34 | #define SUFFIX l
|
---|
35 | #define USUFFIX l
|
---|
36 | #define DATA_TYPE uint32_t
|
---|
37 | #elif DATA_SIZE == 2
|
---|
38 | #define SUFFIX w
|
---|
39 | #define USUFFIX uw
|
---|
40 | #define DATA_TYPE uint16_t
|
---|
41 | #define DATA_STYPE int16_t
|
---|
42 | #elif DATA_SIZE == 1
|
---|
43 | #define SUFFIX b
|
---|
44 | #define USUFFIX ub
|
---|
45 | #define DATA_TYPE uint8_t
|
---|
46 | #define DATA_STYPE int8_t
|
---|
47 | #else
|
---|
48 | #error unsupported data size
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #if ACCESS_TYPE < (NB_MMU_MODES)
|
---|
52 |
|
---|
53 | #define CPU_MMU_INDEX ACCESS_TYPE
|
---|
54 | #define MMUSUFFIX _mmu
|
---|
55 |
|
---|
56 | #elif ACCESS_TYPE == (NB_MMU_MODES)
|
---|
57 |
|
---|
58 | #define CPU_MMU_INDEX (cpu_mmu_index(env))
|
---|
59 | #define MMUSUFFIX _mmu
|
---|
60 |
|
---|
61 | #elif ACCESS_TYPE == (NB_MMU_MODES + 1)
|
---|
62 |
|
---|
63 | #define CPU_MMU_INDEX (cpu_mmu_index(env))
|
---|
64 | #define MMUSUFFIX _cmmu
|
---|
65 |
|
---|
66 | #else
|
---|
67 | #error invalid ACCESS_TYPE
|
---|
68 | #endif
|
---|
69 |
|
---|
70 | #if DATA_SIZE == 8
|
---|
71 | #define RES_TYPE uint64_t
|
---|
72 | #else
|
---|
73 | #define RES_TYPE int
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #if ACCESS_TYPE == (NB_MMU_MODES + 1)
|
---|
77 | #define ADDR_READ addr_code
|
---|
78 | #else
|
---|
79 | #define ADDR_READ addr_read
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | #if (DATA_SIZE <= 4) && (TARGET_LONG_BITS == 32) && defined(__i386__) && \
|
---|
83 | (ACCESS_TYPE < NB_MMU_MODES) && defined(ASM_SOFTMMU)
|
---|
84 |
|
---|
85 | #ifdef VBOX
|
---|
86 | /* generic store macro */
|
---|
87 |
|
---|
88 | static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
|
---|
89 | {
|
---|
90 | int index;
|
---|
91 | target_ulong addr;
|
---|
92 | unsigned long physaddr;
|
---|
93 | int is_user;
|
---|
94 |
|
---|
95 | addr = ptr;
|
---|
96 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
---|
97 | is_user = CPU_MMU_INDEX;
|
---|
98 | if (__builtin_expect(env->tlb_table[is_user][index].addr_write !=
|
---|
99 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
|
---|
100 | glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user);
|
---|
101 | } else {
|
---|
102 | physaddr = addr + env->tlb_table[is_user][index].addend;
|
---|
103 | glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | #else /* !VBOX */
|
---|
108 |
|
---|
109 | static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
|
---|
110 | {
|
---|
111 | asm volatile ("movl %0, %%edx\n"
|
---|
112 | "movl %0, %%eax\n"
|
---|
113 | "shrl %3, %%edx\n"
|
---|
114 | "andl %4, %%eax\n"
|
---|
115 | "andl %2, %%edx\n"
|
---|
116 | "leal %5(%%edx, %%ebp), %%edx\n"
|
---|
117 | "cmpl (%%edx), %%eax\n"
|
---|
118 | "movl %0, %%eax\n"
|
---|
119 | "je 1f\n"
|
---|
120 | #if DATA_SIZE == 1
|
---|
121 | "movzbl %b1, %%edx\n"
|
---|
122 | #elif DATA_SIZE == 2
|
---|
123 | "movzwl %w1, %%edx\n"
|
---|
124 | #elif DATA_SIZE == 4
|
---|
125 | "movl %1, %%edx\n"
|
---|
126 | #else
|
---|
127 | #error unsupported size
|
---|
128 | #endif
|
---|
129 | "pushl %6\n"
|
---|
130 | "call %7\n"
|
---|
131 | "popl %%eax\n"
|
---|
132 | "jmp 2f\n"
|
---|
133 | "1:\n"
|
---|
134 | "addl 8(%%edx), %%eax\n"
|
---|
135 | #if DATA_SIZE == 1
|
---|
136 | "movb %b1, (%%eax)\n"
|
---|
137 | #elif DATA_SIZE == 2
|
---|
138 | "movw %w1, (%%eax)\n"
|
---|
139 | #elif DATA_SIZE == 4
|
---|
140 | "movl %1, (%%eax)\n"
|
---|
141 | #else
|
---|
142 | #error unsupported size
|
---|
143 | #endif
|
---|
144 | "2:\n"
|
---|
145 | :
|
---|
146 | : "r" (ptr),
|
---|
147 | /* NOTE: 'q' would be needed as constraint, but we could not use it
|
---|
148 | with T1 ! */
|
---|
149 | "r" (v),
|
---|
150 | "i" ((CPU_TLB_SIZE - 1) << CPU_TLB_ENTRY_BITS),
|
---|
151 | "i" (TARGET_PAGE_BITS - CPU_TLB_ENTRY_BITS),
|
---|
152 | "i" (TARGET_PAGE_MASK | (DATA_SIZE - 1)),
|
---|
153 | "m" (*(uint32_t *)offsetof(CPUState, tlb_table[CPU_MMU_INDEX][0].addr_write)),
|
---|
154 | "i" (CPU_MMU_INDEX),
|
---|
155 | "m" (*(uint8_t *)&glue(glue(__st, SUFFIX), MMUSUFFIX))
|
---|
156 | : "%eax", "%ecx", "%edx", "memory", "cc");
|
---|
157 | }
|
---|
158 | #endif /* !VBOX */
|
---|
159 |
|
---|
160 | #else
|
---|
161 |
|
---|
162 | /* generic load/store macros */
|
---|
163 |
|
---|
164 | static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(target_ulong ptr)
|
---|
165 | {
|
---|
166 | int index;
|
---|
167 | RES_TYPE res;
|
---|
168 | target_ulong addr;
|
---|
169 | unsigned long physaddr;
|
---|
170 | int is_user;
|
---|
171 |
|
---|
172 | addr = ptr;
|
---|
173 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
---|
174 | is_user = CPU_MMU_INDEX;
|
---|
175 | if (__builtin_expect(env->tlb_table[is_user][index].ADDR_READ !=
|
---|
176 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
|
---|
177 | res = glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
|
---|
178 | } else {
|
---|
179 | physaddr = addr + env->tlb_table[is_user][index].addend;
|
---|
180 | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)physaddr);
|
---|
181 | }
|
---|
182 | return res;
|
---|
183 | }
|
---|
184 |
|
---|
185 | #if DATA_SIZE <= 2
|
---|
186 | static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(target_ulong ptr)
|
---|
187 | {
|
---|
188 | int res, index;
|
---|
189 | target_ulong addr;
|
---|
190 | unsigned long physaddr;
|
---|
191 | int is_user;
|
---|
192 |
|
---|
193 | addr = ptr;
|
---|
194 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
---|
195 | is_user = CPU_MMU_INDEX;
|
---|
196 | if (__builtin_expect(env->tlb_table[is_user][index].ADDR_READ !=
|
---|
197 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
|
---|
198 | res = (DATA_STYPE)glue(glue(__ld, SUFFIX), MMUSUFFIX)(addr, is_user);
|
---|
199 | } else {
|
---|
200 | physaddr = addr + env->tlb_table[is_user][index].addend;
|
---|
201 | res = glue(glue(lds, SUFFIX), _raw)((uint8_t *)physaddr);
|
---|
202 | }
|
---|
203 | return res;
|
---|
204 | }
|
---|
205 | #endif
|
---|
206 |
|
---|
207 | #if ACCESS_TYPE != (NB_MMU_MODES + 1)
|
---|
208 |
|
---|
209 | /* generic store macro */
|
---|
210 |
|
---|
211 | static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(target_ulong ptr, RES_TYPE v)
|
---|
212 | {
|
---|
213 | int index;
|
---|
214 | target_ulong addr;
|
---|
215 | unsigned long physaddr;
|
---|
216 | int is_user;
|
---|
217 |
|
---|
218 | addr = ptr;
|
---|
219 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
|
---|
220 | is_user = CPU_MMU_INDEX;
|
---|
221 | if (__builtin_expect(env->tlb_table[is_user][index].addr_write !=
|
---|
222 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))), 0)) {
|
---|
223 | glue(glue(__st, SUFFIX), MMUSUFFIX)(addr, v, is_user);
|
---|
224 | } else {
|
---|
225 | physaddr = addr + env->tlb_table[is_user][index].addend;
|
---|
226 | glue(glue(st, SUFFIX), _raw)((uint8_t *)physaddr, v);
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
|
---|
231 |
|
---|
232 | #endif /* !asm */
|
---|
233 |
|
---|
234 | #if ACCESS_TYPE != (NB_MMU_MODES + 1)
|
---|
235 |
|
---|
236 | #if DATA_SIZE == 8
|
---|
237 | static inline float64 glue(ldfq, MEMSUFFIX)(target_ulong ptr)
|
---|
238 | {
|
---|
239 | union {
|
---|
240 | float64 d;
|
---|
241 | uint64_t i;
|
---|
242 | } u;
|
---|
243 | u.i = glue(ldq, MEMSUFFIX)(ptr);
|
---|
244 | return u.d;
|
---|
245 | }
|
---|
246 |
|
---|
247 | static inline void glue(stfq, MEMSUFFIX)(target_ulong ptr, float64 v)
|
---|
248 | {
|
---|
249 | union {
|
---|
250 | float64 d;
|
---|
251 | uint64_t i;
|
---|
252 | } u;
|
---|
253 | u.d = v;
|
---|
254 | glue(stq, MEMSUFFIX)(ptr, u.i);
|
---|
255 | }
|
---|
256 | #endif /* DATA_SIZE == 8 */
|
---|
257 |
|
---|
258 | #if DATA_SIZE == 4
|
---|
259 | static inline float32 glue(ldfl, MEMSUFFIX)(target_ulong ptr)
|
---|
260 | {
|
---|
261 | union {
|
---|
262 | float32 f;
|
---|
263 | uint32_t i;
|
---|
264 | } u;
|
---|
265 | u.i = glue(ldl, MEMSUFFIX)(ptr);
|
---|
266 | return u.f;
|
---|
267 | }
|
---|
268 |
|
---|
269 | static inline void glue(stfl, MEMSUFFIX)(target_ulong ptr, float32 v)
|
---|
270 | {
|
---|
271 | union {
|
---|
272 | float32 f;
|
---|
273 | uint32_t i;
|
---|
274 | } u;
|
---|
275 | u.f = v;
|
---|
276 | glue(stl, MEMSUFFIX)(ptr, u.i);
|
---|
277 | }
|
---|
278 | #endif /* DATA_SIZE == 4 */
|
---|
279 |
|
---|
280 | #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */
|
---|
281 |
|
---|
282 | #undef RES_TYPE
|
---|
283 | #undef DATA_TYPE
|
---|
284 | #undef DATA_STYPE
|
---|
285 | #undef SUFFIX
|
---|
286 | #undef USUFFIX
|
---|
287 | #undef DATA_SIZE
|
---|
288 | #undef CPU_MMU_INDEX
|
---|
289 | #undef MMUSUFFIX
|
---|
290 | #undef ADDR_READ
|
---|