4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 * Generate inline load/store functions for all MMU modes (typically
21 * at least _user and _kernel) as well as _data versions, for all data
24 * Used by target op helpers.
26 * The syntax for the accessors is:
28 * load: cpu_ld{sign}{size}_{mmusuffix}(env, ptr)
30 * store: cpu_st{sign}{size}_{mmusuffix}(env, ptr, val)
33 * (empty): for 32 and 64 bit sizes
43 * mmusuffix is one of the generic suffixes "data" or "code", or
44 * (for softmmu configs) a target-specific MMU mode suffix as defined
50 #if defined(CONFIG_USER_ONLY)
51 /* All direct uses of g2h and h2g need to go away for usermode softmmu. */
52 #define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + guest_base))
54 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
55 #define h2g_valid(x) 1
57 #define h2g_valid(x) ({ \
58 unsigned long __guest = (unsigned long)(x) - guest_base; \
59 (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
60 (!reserved_va || (__guest < reserved_va)); \
64 #define h2g_nocheck(x) ({ \
65 unsigned long __ret = (unsigned long)(x) - guest_base; \
70 /* Check if given address fits target address space */ \
71 assert(h2g_valid(x)); \
77 #if defined(CONFIG_USER_ONLY)
79 extern __thread
uintptr_t helper_retaddr
;
81 /* In user-only mode we provide only the _code and _data accessors. */
83 #define MEMSUFFIX _data
85 #include "exec/cpu_ldst_useronly_template.h"
88 #include "exec/cpu_ldst_useronly_template.h"
91 #include "exec/cpu_ldst_useronly_template.h"
94 #include "exec/cpu_ldst_useronly_template.h"
97 #define MEMSUFFIX _code
100 #include "exec/cpu_ldst_useronly_template.h"
103 #include "exec/cpu_ldst_useronly_template.h"
106 #include "exec/cpu_ldst_useronly_template.h"
109 #include "exec/cpu_ldst_useronly_template.h"
115 /* The memory helpers for tcg-generated code need tcg_target_long etc. */
118 #ifdef MMU_MODE0_SUFFIX
119 #define CPU_MMU_INDEX 0
120 #define MEMSUFFIX MMU_MODE0_SUFFIX
122 #include "exec/cpu_ldst_template.h"
125 #include "exec/cpu_ldst_template.h"
128 #include "exec/cpu_ldst_template.h"
131 #include "exec/cpu_ldst_template.h"
136 #if (NB_MMU_MODES >= 2) && defined(MMU_MODE1_SUFFIX)
137 #define CPU_MMU_INDEX 1
138 #define MEMSUFFIX MMU_MODE1_SUFFIX
140 #include "exec/cpu_ldst_template.h"
143 #include "exec/cpu_ldst_template.h"
146 #include "exec/cpu_ldst_template.h"
149 #include "exec/cpu_ldst_template.h"
154 #if (NB_MMU_MODES >= 3) && defined(MMU_MODE2_SUFFIX)
156 #define CPU_MMU_INDEX 2
157 #define MEMSUFFIX MMU_MODE2_SUFFIX
159 #include "exec/cpu_ldst_template.h"
162 #include "exec/cpu_ldst_template.h"
165 #include "exec/cpu_ldst_template.h"
168 #include "exec/cpu_ldst_template.h"
171 #endif /* (NB_MMU_MODES >= 3) */
173 #if (NB_MMU_MODES >= 4) && defined(MMU_MODE3_SUFFIX)
175 #define CPU_MMU_INDEX 3
176 #define MEMSUFFIX MMU_MODE3_SUFFIX
178 #include "exec/cpu_ldst_template.h"
181 #include "exec/cpu_ldst_template.h"
184 #include "exec/cpu_ldst_template.h"
187 #include "exec/cpu_ldst_template.h"
190 #endif /* (NB_MMU_MODES >= 4) */
192 #if (NB_MMU_MODES >= 5) && defined(MMU_MODE4_SUFFIX)
194 #define CPU_MMU_INDEX 4
195 #define MEMSUFFIX MMU_MODE4_SUFFIX
197 #include "exec/cpu_ldst_template.h"
200 #include "exec/cpu_ldst_template.h"
203 #include "exec/cpu_ldst_template.h"
206 #include "exec/cpu_ldst_template.h"
209 #endif /* (NB_MMU_MODES >= 5) */
211 #if (NB_MMU_MODES >= 6) && defined(MMU_MODE5_SUFFIX)
213 #define CPU_MMU_INDEX 5
214 #define MEMSUFFIX MMU_MODE5_SUFFIX
216 #include "exec/cpu_ldst_template.h"
219 #include "exec/cpu_ldst_template.h"
222 #include "exec/cpu_ldst_template.h"
225 #include "exec/cpu_ldst_template.h"
228 #endif /* (NB_MMU_MODES >= 6) */
230 #if (NB_MMU_MODES >= 7) && defined(MMU_MODE6_SUFFIX)
232 #define CPU_MMU_INDEX 6
233 #define MEMSUFFIX MMU_MODE6_SUFFIX
235 #include "exec/cpu_ldst_template.h"
238 #include "exec/cpu_ldst_template.h"
241 #include "exec/cpu_ldst_template.h"
244 #include "exec/cpu_ldst_template.h"
247 #endif /* (NB_MMU_MODES >= 7) */
249 #if (NB_MMU_MODES >= 8) && defined(MMU_MODE7_SUFFIX)
251 #define CPU_MMU_INDEX 7
252 #define MEMSUFFIX MMU_MODE7_SUFFIX
254 #include "exec/cpu_ldst_template.h"
257 #include "exec/cpu_ldst_template.h"
260 #include "exec/cpu_ldst_template.h"
263 #include "exec/cpu_ldst_template.h"
266 #endif /* (NB_MMU_MODES >= 8) */
268 #if (NB_MMU_MODES >= 9) && defined(MMU_MODE8_SUFFIX)
270 #define CPU_MMU_INDEX 8
271 #define MEMSUFFIX MMU_MODE8_SUFFIX
273 #include "exec/cpu_ldst_template.h"
276 #include "exec/cpu_ldst_template.h"
279 #include "exec/cpu_ldst_template.h"
282 #include "exec/cpu_ldst_template.h"
285 #endif /* (NB_MMU_MODES >= 9) */
287 #if (NB_MMU_MODES >= 10) && defined(MMU_MODE9_SUFFIX)
289 #define CPU_MMU_INDEX 9
290 #define MEMSUFFIX MMU_MODE9_SUFFIX
292 #include "exec/cpu_ldst_template.h"
295 #include "exec/cpu_ldst_template.h"
298 #include "exec/cpu_ldst_template.h"
301 #include "exec/cpu_ldst_template.h"
304 #endif /* (NB_MMU_MODES >= 10) */
306 #if (NB_MMU_MODES >= 11) && defined(MMU_MODE10_SUFFIX)
308 #define CPU_MMU_INDEX 10
309 #define MEMSUFFIX MMU_MODE10_SUFFIX
311 #include "exec/cpu_ldst_template.h"
314 #include "exec/cpu_ldst_template.h"
317 #include "exec/cpu_ldst_template.h"
320 #include "exec/cpu_ldst_template.h"
323 #endif /* (NB_MMU_MODES >= 11) */
325 #if (NB_MMU_MODES >= 12) && defined(MMU_MODE11_SUFFIX)
327 #define CPU_MMU_INDEX 11
328 #define MEMSUFFIX MMU_MODE11_SUFFIX
330 #include "exec/cpu_ldst_template.h"
333 #include "exec/cpu_ldst_template.h"
336 #include "exec/cpu_ldst_template.h"
339 #include "exec/cpu_ldst_template.h"
342 #endif /* (NB_MMU_MODES >= 12) */
344 #if (NB_MMU_MODES > 12)
345 #error "NB_MMU_MODES > 12 is not supported for now"
346 #endif /* (NB_MMU_MODES > 12) */
348 /* these access are slower, they must be as rare as possible */
349 #define CPU_MMU_INDEX (cpu_mmu_index(env, false))
350 #define MEMSUFFIX _data
352 #include "exec/cpu_ldst_template.h"
355 #include "exec/cpu_ldst_template.h"
358 #include "exec/cpu_ldst_template.h"
361 #include "exec/cpu_ldst_template.h"
365 #define CPU_MMU_INDEX (cpu_mmu_index(env, true))
366 #define MEMSUFFIX _code
367 #define SOFTMMU_CODE_ACCESS
370 #include "exec/cpu_ldst_template.h"
373 #include "exec/cpu_ldst_template.h"
376 #include "exec/cpu_ldst_template.h"
379 #include "exec/cpu_ldst_template.h"
383 #undef SOFTMMU_CODE_ACCESS
385 #endif /* defined(CONFIG_USER_ONLY) */
390 * @addr: guest virtual address to look up
391 * @access_type: 0 for read, 1 for write, 2 for execute
392 * @mmu_idx: MMU index to use for lookup
394 * Look up the specified guest virtual index in the TCG softmmu TLB.
395 * If the TLB contains a host virtual address suitable for direct RAM
396 * access, then return it. Otherwise (TLB miss, TLB entry is for an
397 * I/O access, etc) return NULL.
399 * This is the equivalent of the initial fast-path code used by
400 * TCG backends for guest load and store accesses.
402 static inline void *tlb_vaddr_to_host(CPUArchState
*env
, target_ulong addr
,
403 int access_type
, int mmu_idx
)
405 #if defined(CONFIG_USER_ONLY)
408 int index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
409 CPUTLBEntry
*tlbentry
= &env
->tlb_table
[mmu_idx
][index
];
410 target_ulong tlb_addr
;
413 switch (access_type
) {
415 tlb_addr
= tlbentry
->addr_read
;
418 tlb_addr
= tlbentry
->addr_write
;
421 tlb_addr
= tlbentry
->addr_code
;
424 g_assert_not_reached();
427 if ((addr
& TARGET_PAGE_MASK
)
428 != (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
429 /* TLB entry is for a different page */
433 if (tlb_addr
& ~TARGET_PAGE_MASK
) {
438 haddr
= addr
+ env
->tlb_table
[mmu_idx
][index
].addend
;
439 return (void *)haddr
;
440 #endif /* defined(CONFIG_USER_ONLY) */
443 #endif /* CPU_LDST_H */