]> git.proxmox.com Git - mirror_qemu.git/blame - softmmu_template.h
block/parallels: create bat_entry_off helper
[mirror_qemu.git] / softmmu_template.h
CommitLineData
b92e5a22
FB
1/*
2 * Software MMU support
5fafdf24 3 *
efbf29b6
BS
4 * Generate helpers used by TCG for qemu_ld/st ops and code load
5 * functions.
6 *
7 * Included from target op helpers and exec.c.
8 *
b92e5a22
FB
9 * Copyright (c) 2003 Fabrice Bellard
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
8167ee88 22 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
b92e5a22 23 */
1de7afc9 24#include "qemu/timer.h"
77717094 25#include "exec/address-spaces.h"
022c62cb 26#include "exec/memory.h"
29e922b6 27
b92e5a22
FB
28#define DATA_SIZE (1 << SHIFT)
29
30#if DATA_SIZE == 8
31#define SUFFIX q
701e3a5c 32#define LSUFFIX q
c8f94df5 33#define SDATA_TYPE int64_t
dc9a353c 34#define DATA_TYPE uint64_t
b92e5a22
FB
35#elif DATA_SIZE == 4
36#define SUFFIX l
701e3a5c 37#define LSUFFIX l
c8f94df5 38#define SDATA_TYPE int32_t
dc9a353c 39#define DATA_TYPE uint32_t
b92e5a22
FB
40#elif DATA_SIZE == 2
41#define SUFFIX w
701e3a5c 42#define LSUFFIX uw
c8f94df5 43#define SDATA_TYPE int16_t
dc9a353c 44#define DATA_TYPE uint16_t
b92e5a22
FB
45#elif DATA_SIZE == 1
46#define SUFFIX b
701e3a5c 47#define LSUFFIX ub
c8f94df5 48#define SDATA_TYPE int8_t
dc9a353c 49#define DATA_TYPE uint8_t
b92e5a22
FB
50#else
51#error unsupported data size
52#endif
53
c8f94df5
RH
54
55/* For the benefit of TCG generated code, we want to avoid the complication
56 of ABI-specific return type promotion and always return a value extended
57 to the register size of the host. This is tcg_target_long, except in the
58 case of a 32-bit host and 64-bit data, and for that we always have
59 uint64_t. Don't bother with this widened value for SOFTMMU_CODE_ACCESS. */
60#if defined(SOFTMMU_CODE_ACCESS) || DATA_SIZE == 8
61# define WORD_TYPE DATA_TYPE
62# define USUFFIX SUFFIX
63#else
64# define WORD_TYPE tcg_target_ulong
65# define USUFFIX glue(u, SUFFIX)
66# define SSUFFIX glue(s, SUFFIX)
67#endif
68
b769d8fe 69#ifdef SOFTMMU_CODE_ACCESS
55e94093 70#define READ_ACCESS_TYPE MMU_INST_FETCH
84b7b8e7 71#define ADDR_READ addr_code
b769d8fe 72#else
55e94093 73#define READ_ACCESS_TYPE MMU_DATA_LOAD
84b7b8e7 74#define ADDR_READ addr_read
b769d8fe
FB
75#endif
76
867b3201
RH
77#if DATA_SIZE == 8
78# define BSWAP(X) bswap64(X)
79#elif DATA_SIZE == 4
80# define BSWAP(X) bswap32(X)
81#elif DATA_SIZE == 2
82# define BSWAP(X) bswap16(X)
83#else
84# define BSWAP(X) (X)
85#endif
86
87#ifdef TARGET_WORDS_BIGENDIAN
88# define TGT_BE(X) (X)
89# define TGT_LE(X) BSWAP(X)
90#else
91# define TGT_BE(X) BSWAP(X)
92# define TGT_LE(X) (X)
93#endif
94
95#if DATA_SIZE == 1
96# define helper_le_ld_name glue(glue(helper_ret_ld, USUFFIX), MMUSUFFIX)
97# define helper_be_ld_name helper_le_ld_name
98# define helper_le_lds_name glue(glue(helper_ret_ld, SSUFFIX), MMUSUFFIX)
99# define helper_be_lds_name helper_le_lds_name
100# define helper_le_st_name glue(glue(helper_ret_st, SUFFIX), MMUSUFFIX)
101# define helper_be_st_name helper_le_st_name
102#else
103# define helper_le_ld_name glue(glue(helper_le_ld, USUFFIX), MMUSUFFIX)
104# define helper_be_ld_name glue(glue(helper_be_ld, USUFFIX), MMUSUFFIX)
105# define helper_le_lds_name glue(glue(helper_le_ld, SSUFFIX), MMUSUFFIX)
106# define helper_be_lds_name glue(glue(helper_be_ld, SSUFFIX), MMUSUFFIX)
107# define helper_le_st_name glue(glue(helper_le_st, SUFFIX), MMUSUFFIX)
108# define helper_be_st_name glue(glue(helper_be_st, SUFFIX), MMUSUFFIX)
109#endif
110
111#ifdef TARGET_WORDS_BIGENDIAN
112# define helper_te_ld_name helper_be_ld_name
113# define helper_te_st_name helper_be_st_name
114#else
115# define helper_te_ld_name helper_le_ld_name
116# define helper_te_st_name helper_le_st_name
117#endif
118
88e89a57
XT
119/* macro to check the victim tlb */
120#define VICTIM_TLB_HIT(ty) \
121({ \
122 /* we are about to do a page table walk. our last hope is the \
123 * victim tlb. try to refill from the victim tlb before walking the \
124 * page table. */ \
125 int vidx; \
e469b22f 126 CPUIOTLBEntry tmpiotlb; \
88e89a57
XT
127 CPUTLBEntry tmptlb; \
128 for (vidx = CPU_VTLB_SIZE-1; vidx >= 0; --vidx) { \
129 if (env->tlb_v_table[mmu_idx][vidx].ty == (addr & TARGET_PAGE_MASK)) {\
130 /* found entry in victim tlb, swap tlb and iotlb */ \
131 tmptlb = env->tlb_table[mmu_idx][index]; \
132 env->tlb_table[mmu_idx][index] = env->tlb_v_table[mmu_idx][vidx]; \
133 env->tlb_v_table[mmu_idx][vidx] = tmptlb; \
134 tmpiotlb = env->iotlb[mmu_idx][index]; \
135 env->iotlb[mmu_idx][index] = env->iotlb_v[mmu_idx][vidx]; \
136 env->iotlb_v[mmu_idx][vidx] = tmpiotlb; \
137 break; \
138 } \
139 } \
140 /* return true when there is a vtlb hit, i.e. vidx >=0 */ \
141 vidx >= 0; \
142})
143
0f590e74 144#ifndef SOFTMMU_CODE_ACCESS
89c33337 145static inline DATA_TYPE glue(io_read, SUFFIX)(CPUArchState *env,
e469b22f 146 CPUIOTLBEntry *iotlbentry,
2e70f6ef 147 target_ulong addr,
20503968 148 uintptr_t retaddr)
b92e5a22 149{
791af8c8 150 uint64_t val;
09daed84 151 CPUState *cpu = ENV_GET_CPU(env);
e469b22f 152 hwaddr physaddr = iotlbentry->addr;
9d82b5a7 153 MemoryRegion *mr = iotlb_to_region(cpu, physaddr);
37ec01d4 154
0f459d16 155 physaddr = (physaddr & TARGET_PAGE_MASK) + addr;
93afeade 156 cpu->mem_io_pc = retaddr;
99df7dce 157 if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu_can_do_io(cpu)) {
90b40a69 158 cpu_io_recompile(cpu, retaddr);
2e70f6ef 159 }
b92e5a22 160
93afeade 161 cpu->mem_io_vaddr = addr;
3b643495 162 memory_region_dispatch_read(mr, physaddr, &val, 1 << SHIFT,
fadc1cbe 163 iotlbentry->attrs);
791af8c8 164 return val;
b92e5a22 165}
0f590e74 166#endif
b92e5a22 167
e25c3887 168#ifdef SOFTMMU_CODE_ACCESS
867b3201 169static __attribute__((unused))
e25c3887 170#endif
3972ef6f
RH
171WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr,
172 TCGMemOpIdx oi, uintptr_t retaddr)
b92e5a22 173{
3972ef6f 174 unsigned mmu_idx = get_mmuidx(oi);
aac1fb05
RH
175 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
176 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
177 uintptr_t haddr;
867b3201 178 DATA_TYPE res;
3b46e624 179
0f842f8a
RH
180 /* Adjust the given return address. */
181 retaddr -= GETPC_ADJ;
182
aac1fb05
RH
183 /* If the TLB entry is for a different page, reload and try again. */
184 if ((addr & TARGET_PAGE_MASK)
185 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
dfb36305
RH
186 if ((addr & (DATA_SIZE - 1)) != 0
187 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
93e22326
PB
188 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
189 mmu_idx, retaddr);
aac1fb05 190 }
88e89a57
XT
191 if (!VICTIM_TLB_HIT(ADDR_READ)) {
192 tlb_fill(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
193 mmu_idx, retaddr);
194 }
aac1fb05
RH
195 tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
196 }
197
198 /* Handle an IO access. */
199 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
e469b22f 200 CPUIOTLBEntry *iotlbentry;
aac1fb05
RH
201 if ((addr & (DATA_SIZE - 1)) != 0) {
202 goto do_unaligned_access;
b92e5a22 203 }
e469b22f 204 iotlbentry = &env->iotlb[mmu_idx][index];
867b3201
RH
205
206 /* ??? Note that the io helpers always read data in the target
207 byte ordering. We should push the LE/BE request down into io. */
e469b22f 208 res = glue(io_read, SUFFIX)(env, iotlbentry, addr, retaddr);
867b3201
RH
209 res = TGT_LE(res);
210 return res;
aac1fb05
RH
211 }
212
213 /* Handle slow unaligned access (it spans two pages or IO). */
214 if (DATA_SIZE > 1
215 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
216 >= TARGET_PAGE_SIZE)) {
217 target_ulong addr1, addr2;
867b3201 218 DATA_TYPE res1, res2;
aac1fb05
RH
219 unsigned shift;
220 do_unaligned_access:
dfb36305
RH
221 if ((get_memop(oi) & MO_AMASK) == MO_ALIGN) {
222 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
223 mmu_idx, retaddr);
224 }
aac1fb05
RH
225 addr1 = addr & ~(DATA_SIZE - 1);
226 addr2 = addr1 + DATA_SIZE;
0f842f8a
RH
227 /* Note the adjustment at the beginning of the function.
228 Undo that for the recursion. */
3972ef6f
RH
229 res1 = helper_le_ld_name(env, addr1, oi, retaddr + GETPC_ADJ);
230 res2 = helper_le_ld_name(env, addr2, oi, retaddr + GETPC_ADJ);
aac1fb05 231 shift = (addr & (DATA_SIZE - 1)) * 8;
867b3201
RH
232
233 /* Little-endian combine. */
aac1fb05 234 res = (res1 >> shift) | (res2 << ((DATA_SIZE * 8) - shift));
867b3201
RH
235 return res;
236 }
237
238 /* Handle aligned access or unaligned access in the same page. */
dfb36305
RH
239 if ((addr & (DATA_SIZE - 1)) != 0
240 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
93e22326
PB
241 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
242 mmu_idx, retaddr);
867b3201 243 }
867b3201
RH
244
245 haddr = addr + env->tlb_table[mmu_idx][index].addend;
246#if DATA_SIZE == 1
247 res = glue(glue(ld, LSUFFIX), _p)((uint8_t *)haddr);
248#else
249 res = glue(glue(ld, LSUFFIX), _le_p)((uint8_t *)haddr);
250#endif
251 return res;
252}
253
254#if DATA_SIZE > 1
255#ifdef SOFTMMU_CODE_ACCESS
256static __attribute__((unused))
257#endif
3972ef6f
RH
258WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr,
259 TCGMemOpIdx oi, uintptr_t retaddr)
867b3201 260{
3972ef6f 261 unsigned mmu_idx = get_mmuidx(oi);
867b3201
RH
262 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
263 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
264 uintptr_t haddr;
265 DATA_TYPE res;
266
267 /* Adjust the given return address. */
268 retaddr -= GETPC_ADJ;
269
270 /* If the TLB entry is for a different page, reload and try again. */
271 if ((addr & TARGET_PAGE_MASK)
272 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
dfb36305
RH
273 if ((addr & (DATA_SIZE - 1)) != 0
274 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
93e22326
PB
275 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
276 mmu_idx, retaddr);
867b3201 277 }
88e89a57
XT
278 if (!VICTIM_TLB_HIT(ADDR_READ)) {
279 tlb_fill(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
280 mmu_idx, retaddr);
281 }
867b3201
RH
282 tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
283 }
284
285 /* Handle an IO access. */
286 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
e469b22f 287 CPUIOTLBEntry *iotlbentry;
867b3201
RH
288 if ((addr & (DATA_SIZE - 1)) != 0) {
289 goto do_unaligned_access;
290 }
e469b22f 291 iotlbentry = &env->iotlb[mmu_idx][index];
867b3201
RH
292
293 /* ??? Note that the io helpers always read data in the target
294 byte ordering. We should push the LE/BE request down into io. */
e469b22f 295 res = glue(io_read, SUFFIX)(env, iotlbentry, addr, retaddr);
867b3201
RH
296 res = TGT_BE(res);
297 return res;
298 }
299
300 /* Handle slow unaligned access (it spans two pages or IO). */
301 if (DATA_SIZE > 1
302 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
303 >= TARGET_PAGE_SIZE)) {
304 target_ulong addr1, addr2;
305 DATA_TYPE res1, res2;
306 unsigned shift;
307 do_unaligned_access:
dfb36305
RH
308 if ((get_memop(oi) & MO_AMASK) == MO_ALIGN) {
309 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
310 mmu_idx, retaddr);
311 }
867b3201
RH
312 addr1 = addr & ~(DATA_SIZE - 1);
313 addr2 = addr1 + DATA_SIZE;
314 /* Note the adjustment at the beginning of the function.
315 Undo that for the recursion. */
3972ef6f
RH
316 res1 = helper_be_ld_name(env, addr1, oi, retaddr + GETPC_ADJ);
317 res2 = helper_be_ld_name(env, addr2, oi, retaddr + GETPC_ADJ);
867b3201
RH
318 shift = (addr & (DATA_SIZE - 1)) * 8;
319
320 /* Big-endian combine. */
321 res = (res1 << shift) | (res2 >> ((DATA_SIZE * 8) - shift));
aac1fb05
RH
322 return res;
323 }
324
325 /* Handle aligned access or unaligned access in the same page. */
dfb36305
RH
326 if ((addr & (DATA_SIZE - 1)) != 0
327 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
93e22326
PB
328 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
329 mmu_idx, retaddr);
b92e5a22 330 }
aac1fb05
RH
331
332 haddr = addr + env->tlb_table[mmu_idx][index].addend;
867b3201
RH
333 res = glue(glue(ld, LSUFFIX), _be_p)((uint8_t *)haddr);
334 return res;
b92e5a22 335}
867b3201 336#endif /* DATA_SIZE > 1 */
b92e5a22 337
e25c3887
RH
338DATA_TYPE
339glue(glue(helper_ld, SUFFIX), MMUSUFFIX)(CPUArchState *env, target_ulong addr,
340 int mmu_idx)
341{
3972ef6f
RH
342 TCGMemOpIdx oi = make_memop_idx(SHIFT, mmu_idx);
343 return helper_te_ld_name (env, addr, oi, GETRA());
e25c3887
RH
344}
345
b769d8fe
FB
346#ifndef SOFTMMU_CODE_ACCESS
347
c8f94df5
RH
348/* Provide signed versions of the load routines as well. We can of course
349 avoid this for 64-bit data, or for 32-bit data on 32-bit host. */
350#if DATA_SIZE * 8 < TCG_TARGET_REG_BITS
867b3201 351WORD_TYPE helper_le_lds_name(CPUArchState *env, target_ulong addr,
3972ef6f 352 TCGMemOpIdx oi, uintptr_t retaddr)
867b3201 353{
3972ef6f 354 return (SDATA_TYPE)helper_le_ld_name(env, addr, oi, retaddr);
867b3201
RH
355}
356
357# if DATA_SIZE > 1
358WORD_TYPE helper_be_lds_name(CPUArchState *env, target_ulong addr,
3972ef6f 359 TCGMemOpIdx oi, uintptr_t retaddr)
c8f94df5 360{
3972ef6f 361 return (SDATA_TYPE)helper_be_ld_name(env, addr, oi, retaddr);
c8f94df5 362}
867b3201 363# endif
c8f94df5
RH
364#endif
365
89c33337 366static inline void glue(io_write, SUFFIX)(CPUArchState *env,
e469b22f 367 CPUIOTLBEntry *iotlbentry,
b769d8fe 368 DATA_TYPE val,
0f459d16 369 target_ulong addr,
20503968 370 uintptr_t retaddr)
b769d8fe 371{
09daed84 372 CPUState *cpu = ENV_GET_CPU(env);
e469b22f 373 hwaddr physaddr = iotlbentry->addr;
9d82b5a7 374 MemoryRegion *mr = iotlb_to_region(cpu, physaddr);
37ec01d4 375
0f459d16 376 physaddr = (physaddr & TARGET_PAGE_MASK) + addr;
99df7dce 377 if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu_can_do_io(cpu)) {
90b40a69 378 cpu_io_recompile(cpu, retaddr);
2e70f6ef 379 }
b769d8fe 380
93afeade
AF
381 cpu->mem_io_vaddr = addr;
382 cpu->mem_io_pc = retaddr;
3b643495 383 memory_region_dispatch_write(mr, physaddr, val, 1 << SHIFT,
fadc1cbe 384 iotlbentry->attrs);
b769d8fe 385}
b92e5a22 386
867b3201 387void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
3972ef6f 388 TCGMemOpIdx oi, uintptr_t retaddr)
b92e5a22 389{
3972ef6f 390 unsigned mmu_idx = get_mmuidx(oi);
aac1fb05
RH
391 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
392 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
393 uintptr_t haddr;
3b46e624 394
0f842f8a
RH
395 /* Adjust the given return address. */
396 retaddr -= GETPC_ADJ;
397
aac1fb05
RH
398 /* If the TLB entry is for a different page, reload and try again. */
399 if ((addr & TARGET_PAGE_MASK)
400 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
dfb36305
RH
401 if ((addr & (DATA_SIZE - 1)) != 0
402 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
55e94093
LA
403 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
404 mmu_idx, retaddr);
aac1fb05 405 }
88e89a57 406 if (!VICTIM_TLB_HIT(addr_write)) {
55e94093 407 tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_STORE, mmu_idx, retaddr);
88e89a57 408 }
aac1fb05
RH
409 tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
410 }
411
412 /* Handle an IO access. */
413 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
e469b22f 414 CPUIOTLBEntry *iotlbentry;
aac1fb05
RH
415 if ((addr & (DATA_SIZE - 1)) != 0) {
416 goto do_unaligned_access;
417 }
e469b22f 418 iotlbentry = &env->iotlb[mmu_idx][index];
867b3201
RH
419
420 /* ??? Note that the io helpers always read data in the target
421 byte ordering. We should push the LE/BE request down into io. */
422 val = TGT_LE(val);
e469b22f 423 glue(io_write, SUFFIX)(env, iotlbentry, val, addr, retaddr);
aac1fb05
RH
424 return;
425 }
426
427 /* Handle slow unaligned access (it spans two pages or IO). */
428 if (DATA_SIZE > 1
429 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
430 >= TARGET_PAGE_SIZE)) {
431 int i;
432 do_unaligned_access:
dfb36305
RH
433 if ((get_memop(oi) & MO_AMASK) == MO_ALIGN) {
434 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
435 mmu_idx, retaddr);
436 }
aac1fb05
RH
437 /* XXX: not efficient, but simple */
438 /* Note: relies on the fact that tlb_fill() does not remove the
439 * previous page from the TLB cache. */
440 for (i = DATA_SIZE - 1; i >= 0; i--) {
867b3201 441 /* Little-endian extract. */
aac1fb05 442 uint8_t val8 = val >> (i * 8);
867b3201
RH
443 /* Note the adjustment at the beginning of the function.
444 Undo that for the recursion. */
445 glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8,
3972ef6f 446 oi, retaddr + GETPC_ADJ);
867b3201
RH
447 }
448 return;
449 }
450
451 /* Handle aligned access or unaligned access in the same page. */
dfb36305
RH
452 if ((addr & (DATA_SIZE - 1)) != 0
453 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
55e94093
LA
454 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
455 mmu_idx, retaddr);
867b3201 456 }
867b3201
RH
457
458 haddr = addr + env->tlb_table[mmu_idx][index].addend;
459#if DATA_SIZE == 1
460 glue(glue(st, SUFFIX), _p)((uint8_t *)haddr, val);
461#else
462 glue(glue(st, SUFFIX), _le_p)((uint8_t *)haddr, val);
a64d4718 463#endif
867b3201
RH
464}
465
466#if DATA_SIZE > 1
467void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
3972ef6f 468 TCGMemOpIdx oi, uintptr_t retaddr)
867b3201 469{
3972ef6f 470 unsigned mmu_idx = get_mmuidx(oi);
867b3201
RH
471 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
472 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
473 uintptr_t haddr;
474
475 /* Adjust the given return address. */
476 retaddr -= GETPC_ADJ;
477
478 /* If the TLB entry is for a different page, reload and try again. */
479 if ((addr & TARGET_PAGE_MASK)
480 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
dfb36305
RH
481 if ((addr & (DATA_SIZE - 1)) != 0
482 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
55e94093
LA
483 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
484 mmu_idx, retaddr);
867b3201 485 }
88e89a57 486 if (!VICTIM_TLB_HIT(addr_write)) {
55e94093 487 tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_STORE, mmu_idx, retaddr);
88e89a57 488 }
867b3201
RH
489 tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
490 }
491
492 /* Handle an IO access. */
493 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
e469b22f 494 CPUIOTLBEntry *iotlbentry;
867b3201
RH
495 if ((addr & (DATA_SIZE - 1)) != 0) {
496 goto do_unaligned_access;
497 }
e469b22f 498 iotlbentry = &env->iotlb[mmu_idx][index];
867b3201
RH
499
500 /* ??? Note that the io helpers always read data in the target
501 byte ordering. We should push the LE/BE request down into io. */
502 val = TGT_BE(val);
e469b22f 503 glue(io_write, SUFFIX)(env, iotlbentry, val, addr, retaddr);
867b3201
RH
504 return;
505 }
506
507 /* Handle slow unaligned access (it spans two pages or IO). */
508 if (DATA_SIZE > 1
509 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
510 >= TARGET_PAGE_SIZE)) {
511 int i;
512 do_unaligned_access:
dfb36305
RH
513 if ((get_memop(oi) & MO_AMASK) == MO_ALIGN) {
514 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
515 mmu_idx, retaddr);
516 }
867b3201
RH
517 /* XXX: not efficient, but simple */
518 /* Note: relies on the fact that tlb_fill() does not remove the
519 * previous page from the TLB cache. */
520 for (i = DATA_SIZE - 1; i >= 0; i--) {
521 /* Big-endian extract. */
522 uint8_t val8 = val >> (((DATA_SIZE - 1) * 8) - (i * 8));
0f842f8a
RH
523 /* Note the adjustment at the beginning of the function.
524 Undo that for the recursion. */
aac1fb05 525 glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8,
3972ef6f 526 oi, retaddr + GETPC_ADJ);
b92e5a22 527 }
aac1fb05
RH
528 return;
529 }
530
531 /* Handle aligned access or unaligned access in the same page. */
dfb36305
RH
532 if ((addr & (DATA_SIZE - 1)) != 0
533 && (get_memop(oi) & MO_AMASK) == MO_ALIGN) {
55e94093
LA
534 cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE,
535 mmu_idx, retaddr);
b92e5a22 536 }
aac1fb05
RH
537
538 haddr = addr + env->tlb_table[mmu_idx][index].addend;
867b3201 539 glue(glue(st, SUFFIX), _be_p)((uint8_t *)haddr, val);
b92e5a22 540}
867b3201 541#endif /* DATA_SIZE > 1 */
b92e5a22 542
e25c3887
RH
543void
544glue(glue(helper_st, SUFFIX), MMUSUFFIX)(CPUArchState *env, target_ulong addr,
545 DATA_TYPE val, int mmu_idx)
546{
3972ef6f
RH
547 TCGMemOpIdx oi = make_memop_idx(SHIFT, mmu_idx);
548 helper_te_st_name(env, addr, val, oi, GETRA());
e25c3887
RH
549}
550
b769d8fe
FB
551#endif /* !defined(SOFTMMU_CODE_ACCESS) */
552
553#undef READ_ACCESS_TYPE
b92e5a22
FB
554#undef SHIFT
555#undef DATA_TYPE
556#undef SUFFIX
701e3a5c 557#undef LSUFFIX
b92e5a22 558#undef DATA_SIZE
84b7b8e7 559#undef ADDR_READ
c8f94df5
RH
560#undef WORD_TYPE
561#undef SDATA_TYPE
562#undef USUFFIX
563#undef SSUFFIX
867b3201
RH
564#undef BSWAP
565#undef TGT_BE
566#undef TGT_LE
567#undef CPU_BE
568#undef CPU_LE
569#undef helper_le_ld_name
570#undef helper_be_ld_name
571#undef helper_le_lds_name
572#undef helper_be_lds_name
573#undef helper_le_st_name
574#undef helper_be_st_name
575#undef helper_te_ld_name
576#undef helper_te_st_name