move hw cursor pos from cirrus to vga
[qemu.git] / include / exec / cpu_ldst.h
blobe5550e717534f13e0c30fd54e8fa5af76245c7ed
1 /*
2 * Software MMU support
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
22 * sizes.
24 * Used by target op helpers.
26 * MMU mode suffixes are defined in target cpu.h.
28 #ifndef CPU_LDST_H
29 #define CPU_LDST_H
31 #if defined(CONFIG_USER_ONLY)
32 /* All direct uses of g2h and h2g need to go away for usermode softmmu. */
33 #define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + GUEST_BASE))
35 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
36 #define h2g_valid(x) 1
37 #else
38 #define h2g_valid(x) ({ \
39 unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
40 (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \
41 (!RESERVED_VA || (__guest < RESERVED_VA)); \
43 #endif
45 #define h2g_nocheck(x) ({ \
46 unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
47 (abi_ulong)__ret; \
50 #define h2g(x) ({ \
51 /* Check if given address fits target address space */ \
52 assert(h2g_valid(x)); \
53 h2g_nocheck(x); \
56 #define saddr(x) g2h(x)
57 #define laddr(x) g2h(x)
59 #else /* !CONFIG_USER_ONLY */
60 /* NOTE: we use double casts if pointers and target_ulong have
61 different sizes */
62 #define saddr(x) (uint8_t *)(intptr_t)(x)
63 #define laddr(x) (uint8_t *)(intptr_t)(x)
64 #endif
66 #define ldub_raw(p) ldub_p(laddr((p)))
67 #define ldsb_raw(p) ldsb_p(laddr((p)))
68 #define lduw_raw(p) lduw_p(laddr((p)))
69 #define ldsw_raw(p) ldsw_p(laddr((p)))
70 #define ldl_raw(p) ldl_p(laddr((p)))
71 #define ldq_raw(p) ldq_p(laddr((p)))
72 #define ldfl_raw(p) ldfl_p(laddr((p)))
73 #define ldfq_raw(p) ldfq_p(laddr((p)))
74 #define stb_raw(p, v) stb_p(saddr((p)), v)
75 #define stw_raw(p, v) stw_p(saddr((p)), v)
76 #define stl_raw(p, v) stl_p(saddr((p)), v)
77 #define stq_raw(p, v) stq_p(saddr((p)), v)
78 #define stfl_raw(p, v) stfl_p(saddr((p)), v)
79 #define stfq_raw(p, v) stfq_p(saddr((p)), v)
82 #if defined(CONFIG_USER_ONLY)
84 /* if user mode, no other memory access functions */
85 #define ldub(p) ldub_raw(p)
86 #define ldsb(p) ldsb_raw(p)
87 #define lduw(p) lduw_raw(p)
88 #define ldsw(p) ldsw_raw(p)
89 #define ldl(p) ldl_raw(p)
90 #define ldq(p) ldq_raw(p)
91 #define ldfl(p) ldfl_raw(p)
92 #define ldfq(p) ldfq_raw(p)
93 #define stb(p, v) stb_raw(p, v)
94 #define stw(p, v) stw_raw(p, v)
95 #define stl(p, v) stl_raw(p, v)
96 #define stq(p, v) stq_raw(p, v)
97 #define stfl(p, v) stfl_raw(p, v)
98 #define stfq(p, v) stfq_raw(p, v)
100 #define cpu_ldub_code(env1, p) ldub_raw(p)
101 #define cpu_ldsb_code(env1, p) ldsb_raw(p)
102 #define cpu_lduw_code(env1, p) lduw_raw(p)
103 #define cpu_ldsw_code(env1, p) ldsw_raw(p)
104 #define cpu_ldl_code(env1, p) ldl_raw(p)
105 #define cpu_ldq_code(env1, p) ldq_raw(p)
107 #define cpu_ldub_data(env, addr) ldub_raw(addr)
108 #define cpu_lduw_data(env, addr) lduw_raw(addr)
109 #define cpu_ldsw_data(env, addr) ldsw_raw(addr)
110 #define cpu_ldl_data(env, addr) ldl_raw(addr)
111 #define cpu_ldq_data(env, addr) ldq_raw(addr)
113 #define cpu_stb_data(env, addr, data) stb_raw(addr, data)
114 #define cpu_stw_data(env, addr, data) stw_raw(addr, data)
115 #define cpu_stl_data(env, addr, data) stl_raw(addr, data)
116 #define cpu_stq_data(env, addr, data) stq_raw(addr, data)
118 #define cpu_ldub_kernel(env, addr) ldub_raw(addr)
119 #define cpu_lduw_kernel(env, addr) lduw_raw(addr)
120 #define cpu_ldsw_kernel(env, addr) ldsw_raw(addr)
121 #define cpu_ldl_kernel(env, addr) ldl_raw(addr)
122 #define cpu_ldq_kernel(env, addr) ldq_raw(addr)
124 #define cpu_stb_kernel(env, addr, data) stb_raw(addr, data)
125 #define cpu_stw_kernel(env, addr, data) stw_raw(addr, data)
126 #define cpu_stl_kernel(env, addr, data) stl_raw(addr, data)
127 #define cpu_stq_kernel(env, addr, data) stq_raw(addr, data)
129 #define ldub_kernel(p) ldub_raw(p)
130 #define ldsb_kernel(p) ldsb_raw(p)
131 #define lduw_kernel(p) lduw_raw(p)
132 #define ldsw_kernel(p) ldsw_raw(p)
133 #define ldl_kernel(p) ldl_raw(p)
134 #define ldq_kernel(p) ldq_raw(p)
135 #define ldfl_kernel(p) ldfl_raw(p)
136 #define ldfq_kernel(p) ldfq_raw(p)
137 #define stb_kernel(p, v) stb_raw(p, v)
138 #define stw_kernel(p, v) stw_raw(p, v)
139 #define stl_kernel(p, v) stl_raw(p, v)
140 #define stq_kernel(p, v) stq_raw(p, v)
141 #define stfl_kernel(p, v) stfl_raw(p, v)
142 #define stfq_kernel(p, vt) stfq_raw(p, v)
144 #define cpu_ldub_data(env, addr) ldub_raw(addr)
145 #define cpu_lduw_data(env, addr) lduw_raw(addr)
146 #define cpu_ldl_data(env, addr) ldl_raw(addr)
148 #define cpu_stb_data(env, addr, data) stb_raw(addr, data)
149 #define cpu_stw_data(env, addr, data) stw_raw(addr, data)
150 #define cpu_stl_data(env, addr, data) stl_raw(addr, data)
152 #else
154 /* XXX: find something cleaner.
155 * Furthermore, this is false for 64 bits targets
157 #define ldul_user ldl_user
158 #define ldul_kernel ldl_kernel
159 #define ldul_hypv ldl_hypv
160 #define ldul_executive ldl_executive
161 #define ldul_supervisor ldl_supervisor
163 /* The memory helpers for tcg-generated code need tcg_target_long etc. */
164 #include "tcg.h"
166 uint8_t helper_ldb_mmu(CPUArchState *env, target_ulong addr, int mmu_idx);
167 uint16_t helper_ldw_mmu(CPUArchState *env, target_ulong addr, int mmu_idx);
168 uint32_t helper_ldl_mmu(CPUArchState *env, target_ulong addr, int mmu_idx);
169 uint64_t helper_ldq_mmu(CPUArchState *env, target_ulong addr, int mmu_idx);
171 void helper_stb_mmu(CPUArchState *env, target_ulong addr,
172 uint8_t val, int mmu_idx);
173 void helper_stw_mmu(CPUArchState *env, target_ulong addr,
174 uint16_t val, int mmu_idx);
175 void helper_stl_mmu(CPUArchState *env, target_ulong addr,
176 uint32_t val, int mmu_idx);
177 void helper_stq_mmu(CPUArchState *env, target_ulong addr,
178 uint64_t val, int mmu_idx);
180 uint8_t helper_ldb_cmmu(CPUArchState *env, target_ulong addr, int mmu_idx);
181 uint16_t helper_ldw_cmmu(CPUArchState *env, target_ulong addr, int mmu_idx);
182 uint32_t helper_ldl_cmmu(CPUArchState *env, target_ulong addr, int mmu_idx);
183 uint64_t helper_ldq_cmmu(CPUArchState *env, target_ulong addr, int mmu_idx);
185 #define CPU_MMU_INDEX 0
186 #define MEMSUFFIX MMU_MODE0_SUFFIX
187 #define DATA_SIZE 1
188 #include "exec/cpu_ldst_template.h"
190 #define DATA_SIZE 2
191 #include "exec/cpu_ldst_template.h"
193 #define DATA_SIZE 4
194 #include "exec/cpu_ldst_template.h"
196 #define DATA_SIZE 8
197 #include "exec/cpu_ldst_template.h"
198 #undef CPU_MMU_INDEX
199 #undef MEMSUFFIX
201 #define CPU_MMU_INDEX 1
202 #define MEMSUFFIX MMU_MODE1_SUFFIX
203 #define DATA_SIZE 1
204 #include "exec/cpu_ldst_template.h"
206 #define DATA_SIZE 2
207 #include "exec/cpu_ldst_template.h"
209 #define DATA_SIZE 4
210 #include "exec/cpu_ldst_template.h"
212 #define DATA_SIZE 8
213 #include "exec/cpu_ldst_template.h"
214 #undef CPU_MMU_INDEX
215 #undef MEMSUFFIX
217 #if (NB_MMU_MODES >= 3)
219 #define CPU_MMU_INDEX 2
220 #define MEMSUFFIX MMU_MODE2_SUFFIX
221 #define DATA_SIZE 1
222 #include "exec/cpu_ldst_template.h"
224 #define DATA_SIZE 2
225 #include "exec/cpu_ldst_template.h"
227 #define DATA_SIZE 4
228 #include "exec/cpu_ldst_template.h"
230 #define DATA_SIZE 8
231 #include "exec/cpu_ldst_template.h"
232 #undef CPU_MMU_INDEX
233 #undef MEMSUFFIX
234 #endif /* (NB_MMU_MODES >= 3) */
236 #if (NB_MMU_MODES >= 4)
238 #define CPU_MMU_INDEX 3
239 #define MEMSUFFIX MMU_MODE3_SUFFIX
240 #define DATA_SIZE 1
241 #include "exec/cpu_ldst_template.h"
243 #define DATA_SIZE 2
244 #include "exec/cpu_ldst_template.h"
246 #define DATA_SIZE 4
247 #include "exec/cpu_ldst_template.h"
249 #define DATA_SIZE 8
250 #include "exec/cpu_ldst_template.h"
251 #undef CPU_MMU_INDEX
252 #undef MEMSUFFIX
253 #endif /* (NB_MMU_MODES >= 4) */
255 #if (NB_MMU_MODES >= 5)
257 #define CPU_MMU_INDEX 4
258 #define MEMSUFFIX MMU_MODE4_SUFFIX
259 #define DATA_SIZE 1
260 #include "exec/cpu_ldst_template.h"
262 #define DATA_SIZE 2
263 #include "exec/cpu_ldst_template.h"
265 #define DATA_SIZE 4
266 #include "exec/cpu_ldst_template.h"
268 #define DATA_SIZE 8
269 #include "exec/cpu_ldst_template.h"
270 #undef CPU_MMU_INDEX
271 #undef MEMSUFFIX
272 #endif /* (NB_MMU_MODES >= 5) */
274 #if (NB_MMU_MODES >= 6)
276 #define CPU_MMU_INDEX 5
277 #define MEMSUFFIX MMU_MODE5_SUFFIX
278 #define DATA_SIZE 1
279 #include "exec/cpu_ldst_template.h"
281 #define DATA_SIZE 2
282 #include "exec/cpu_ldst_template.h"
284 #define DATA_SIZE 4
285 #include "exec/cpu_ldst_template.h"
287 #define DATA_SIZE 8
288 #include "exec/cpu_ldst_template.h"
289 #undef CPU_MMU_INDEX
290 #undef MEMSUFFIX
291 #endif /* (NB_MMU_MODES >= 6) */
293 #if (NB_MMU_MODES > 6)
294 #error "NB_MMU_MODES > 6 is not supported for now"
295 #endif /* (NB_MMU_MODES > 6) */
297 /* these access are slower, they must be as rare as possible */
298 #define CPU_MMU_INDEX (cpu_mmu_index(env))
299 #define MEMSUFFIX _data
300 #define DATA_SIZE 1
301 #include "exec/cpu_ldst_template.h"
303 #define DATA_SIZE 2
304 #include "exec/cpu_ldst_template.h"
306 #define DATA_SIZE 4
307 #include "exec/cpu_ldst_template.h"
309 #define DATA_SIZE 8
310 #include "exec/cpu_ldst_template.h"
311 #undef CPU_MMU_INDEX
312 #undef MEMSUFFIX
314 #define ldub(p) ldub_data(p)
315 #define ldsb(p) ldsb_data(p)
316 #define lduw(p) lduw_data(p)
317 #define ldsw(p) ldsw_data(p)
318 #define ldl(p) ldl_data(p)
319 #define ldq(p) ldq_data(p)
321 #define stb(p, v) stb_data(p, v)
322 #define stw(p, v) stw_data(p, v)
323 #define stl(p, v) stl_data(p, v)
324 #define stq(p, v) stq_data(p, v)
326 #define CPU_MMU_INDEX (cpu_mmu_index(env))
327 #define MEMSUFFIX _code
328 #define SOFTMMU_CODE_ACCESS
330 #define DATA_SIZE 1
331 #include "exec/cpu_ldst_template.h"
333 #define DATA_SIZE 2
334 #include "exec/cpu_ldst_template.h"
336 #define DATA_SIZE 4
337 #include "exec/cpu_ldst_template.h"
339 #define DATA_SIZE 8
340 #include "exec/cpu_ldst_template.h"
342 #undef CPU_MMU_INDEX
343 #undef MEMSUFFIX
344 #undef SOFTMMU_CODE_ACCESS
347 * tlb_vaddr_to_host:
348 * @env: CPUArchState
349 * @addr: guest virtual address to look up
350 * @access_type: 0 for read, 1 for write, 2 for execute
351 * @mmu_idx: MMU index to use for lookup
353 * Look up the specified guest virtual index in the TCG softmmu TLB.
354 * If the TLB contains a host virtual address suitable for direct RAM
355 * access, then return it. Otherwise (TLB miss, TLB entry is for an
356 * I/O access, etc) return NULL.
358 * This is the equivalent of the initial fast-path code used by
359 * TCG backends for guest load and store accesses.
361 static inline void *tlb_vaddr_to_host(CPUArchState *env, target_ulong addr,
362 int access_type, int mmu_idx)
364 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
365 CPUTLBEntry *tlbentry = &env->tlb_table[mmu_idx][index];
366 target_ulong tlb_addr;
367 uintptr_t haddr;
369 switch (access_type) {
370 case 0:
371 tlb_addr = tlbentry->addr_read;
372 break;
373 case 1:
374 tlb_addr = tlbentry->addr_write;
375 break;
376 case 2:
377 tlb_addr = tlbentry->addr_code;
378 break;
379 default:
380 g_assert_not_reached();
383 if ((addr & TARGET_PAGE_MASK)
384 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
385 /* TLB entry is for a different page */
386 return NULL;
389 if (tlb_addr & ~TARGET_PAGE_MASK) {
390 /* IO access */
391 return NULL;
394 haddr = addr + env->tlb_table[mmu_idx][index].addend;
395 return (void *)haddr;
398 #endif /* defined(CONFIG_USER_ONLY) */
400 #endif /* CPU_LDST_H */