]> git.proxmox.com Git - mirror_qemu.git/blame - softmmu_template.h
spapr: Refactor spapr_populate_memory() to allow memoryless nodes
[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
FB
69#ifdef SOFTMMU_CODE_ACCESS
70#define READ_ACCESS_TYPE 2
84b7b8e7 71#define ADDR_READ addr_code
b769d8fe
FB
72#else
73#define READ_ACCESS_TYPE 0
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; \
126 hwaddr tmpiotlb; \
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,
a8170e5e 146 hwaddr physaddr,
2e70f6ef 147 target_ulong addr,
20503968 148 uintptr_t retaddr)
b92e5a22 149{
791af8c8 150 uint64_t val;
09daed84
EI
151 CPUState *cpu = ENV_GET_CPU(env);
152 MemoryRegion *mr = iotlb_to_region(cpu->as, physaddr);
37ec01d4 153
0f459d16 154 physaddr = (physaddr & TARGET_PAGE_MASK) + addr;
93afeade 155 cpu->mem_io_pc = retaddr;
99df7dce 156 if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu_can_do_io(cpu)) {
90b40a69 157 cpu_io_recompile(cpu, retaddr);
2e70f6ef 158 }
b92e5a22 159
93afeade 160 cpu->mem_io_vaddr = addr;
791af8c8
PB
161 io_mem_read(mr, physaddr, &val, 1 << SHIFT);
162 return val;
b92e5a22 163}
0f590e74 164#endif
b92e5a22 165
e25c3887 166#ifdef SOFTMMU_CODE_ACCESS
867b3201 167static __attribute__((unused))
e25c3887 168#endif
867b3201
RH
169WORD_TYPE helper_le_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
170 uintptr_t retaddr)
b92e5a22 171{
aac1fb05
RH
172 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
173 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
174 uintptr_t haddr;
867b3201 175 DATA_TYPE res;
3b46e624 176
0f842f8a
RH
177 /* Adjust the given return address. */
178 retaddr -= GETPC_ADJ;
179
aac1fb05
RH
180 /* If the TLB entry is for a different page, reload and try again. */
181 if ((addr & TARGET_PAGE_MASK)
182 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
a64d4718 183#ifdef ALIGNED_ONLY
aac1fb05 184 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326
PB
185 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
186 mmu_idx, retaddr);
aac1fb05 187 }
a64d4718 188#endif
88e89a57
XT
189 if (!VICTIM_TLB_HIT(ADDR_READ)) {
190 tlb_fill(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
191 mmu_idx, retaddr);
192 }
aac1fb05
RH
193 tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
194 }
195
196 /* Handle an IO access. */
197 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
198 hwaddr ioaddr;
199 if ((addr & (DATA_SIZE - 1)) != 0) {
200 goto do_unaligned_access;
b92e5a22 201 }
aac1fb05 202 ioaddr = env->iotlb[mmu_idx][index];
867b3201
RH
203
204 /* ??? Note that the io helpers always read data in the target
205 byte ordering. We should push the LE/BE request down into io. */
206 res = glue(io_read, SUFFIX)(env, ioaddr, addr, retaddr);
207 res = TGT_LE(res);
208 return res;
aac1fb05
RH
209 }
210
211 /* Handle slow unaligned access (it spans two pages or IO). */
212 if (DATA_SIZE > 1
213 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
214 >= TARGET_PAGE_SIZE)) {
215 target_ulong addr1, addr2;
867b3201 216 DATA_TYPE res1, res2;
aac1fb05
RH
217 unsigned shift;
218 do_unaligned_access:
a64d4718 219#ifdef ALIGNED_ONLY
93e22326
PB
220 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
221 mmu_idx, retaddr);
a64d4718 222#endif
aac1fb05
RH
223 addr1 = addr & ~(DATA_SIZE - 1);
224 addr2 = addr1 + DATA_SIZE;
0f842f8a
RH
225 /* Note the adjustment at the beginning of the function.
226 Undo that for the recursion. */
867b3201
RH
227 res1 = helper_le_ld_name(env, addr1, mmu_idx, retaddr + GETPC_ADJ);
228 res2 = helper_le_ld_name(env, addr2, mmu_idx, retaddr + GETPC_ADJ);
aac1fb05 229 shift = (addr & (DATA_SIZE - 1)) * 8;
867b3201
RH
230
231 /* Little-endian combine. */
aac1fb05 232 res = (res1 >> shift) | (res2 << ((DATA_SIZE * 8) - shift));
867b3201
RH
233 return res;
234 }
235
236 /* Handle aligned access or unaligned access in the same page. */
237#ifdef ALIGNED_ONLY
238 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326
PB
239 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
240 mmu_idx, retaddr);
867b3201
RH
241 }
242#endif
243
244 haddr = addr + env->tlb_table[mmu_idx][index].addend;
245#if DATA_SIZE == 1
246 res = glue(glue(ld, LSUFFIX), _p)((uint8_t *)haddr);
247#else
248 res = glue(glue(ld, LSUFFIX), _le_p)((uint8_t *)haddr);
249#endif
250 return res;
251}
252
253#if DATA_SIZE > 1
254#ifdef SOFTMMU_CODE_ACCESS
255static __attribute__((unused))
256#endif
257WORD_TYPE helper_be_ld_name(CPUArchState *env, target_ulong addr, int mmu_idx,
258 uintptr_t retaddr)
259{
260 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
261 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
262 uintptr_t haddr;
263 DATA_TYPE res;
264
265 /* Adjust the given return address. */
266 retaddr -= GETPC_ADJ;
267
268 /* If the TLB entry is for a different page, reload and try again. */
269 if ((addr & TARGET_PAGE_MASK)
270 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
271#ifdef ALIGNED_ONLY
272 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326
PB
273 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
274 mmu_idx, retaddr);
867b3201
RH
275 }
276#endif
88e89a57
XT
277 if (!VICTIM_TLB_HIT(ADDR_READ)) {
278 tlb_fill(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
279 mmu_idx, retaddr);
280 }
867b3201
RH
281 tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ;
282 }
283
284 /* Handle an IO access. */
285 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
286 hwaddr ioaddr;
287 if ((addr & (DATA_SIZE - 1)) != 0) {
288 goto do_unaligned_access;
289 }
290 ioaddr = env->iotlb[mmu_idx][index];
291
292 /* ??? Note that the io helpers always read data in the target
293 byte ordering. We should push the LE/BE request down into io. */
294 res = glue(io_read, SUFFIX)(env, ioaddr, addr, retaddr);
295 res = TGT_BE(res);
296 return res;
297 }
298
299 /* Handle slow unaligned access (it spans two pages or IO). */
300 if (DATA_SIZE > 1
301 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
302 >= TARGET_PAGE_SIZE)) {
303 target_ulong addr1, addr2;
304 DATA_TYPE res1, res2;
305 unsigned shift;
306 do_unaligned_access:
307#ifdef ALIGNED_ONLY
93e22326
PB
308 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
309 mmu_idx, retaddr);
aac1fb05 310#endif
867b3201
RH
311 addr1 = addr & ~(DATA_SIZE - 1);
312 addr2 = addr1 + DATA_SIZE;
313 /* Note the adjustment at the beginning of the function.
314 Undo that for the recursion. */
315 res1 = helper_be_ld_name(env, addr1, mmu_idx, retaddr + GETPC_ADJ);
316 res2 = helper_be_ld_name(env, addr2, mmu_idx, retaddr + GETPC_ADJ);
317 shift = (addr & (DATA_SIZE - 1)) * 8;
318
319 /* Big-endian combine. */
320 res = (res1 << shift) | (res2 >> ((DATA_SIZE * 8) - shift));
aac1fb05
RH
321 return res;
322 }
323
324 /* Handle aligned access or unaligned access in the same page. */
325#ifdef ALIGNED_ONLY
326 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326
PB
327 cpu_unaligned_access(ENV_GET_CPU(env), addr, READ_ACCESS_TYPE,
328 mmu_idx, retaddr);
b92e5a22 329 }
aac1fb05
RH
330#endif
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{
867b3201 342 return helper_te_ld_name (env, addr, mmu_idx, GETRA());
e25c3887
RH
343}
344
b769d8fe
FB
345#ifndef SOFTMMU_CODE_ACCESS
346
c8f94df5
RH
347/* Provide signed versions of the load routines as well. We can of course
348 avoid this for 64-bit data, or for 32-bit data on 32-bit host. */
349#if DATA_SIZE * 8 < TCG_TARGET_REG_BITS
867b3201
RH
350WORD_TYPE helper_le_lds_name(CPUArchState *env, target_ulong addr,
351 int mmu_idx, uintptr_t retaddr)
352{
353 return (SDATA_TYPE)helper_le_ld_name(env, addr, mmu_idx, retaddr);
354}
355
356# if DATA_SIZE > 1
357WORD_TYPE helper_be_lds_name(CPUArchState *env, target_ulong addr,
358 int mmu_idx, uintptr_t retaddr)
c8f94df5 359{
867b3201 360 return (SDATA_TYPE)helper_be_ld_name(env, addr, mmu_idx, retaddr);
c8f94df5 361}
867b3201 362# endif
c8f94df5
RH
363#endif
364
89c33337 365static inline void glue(io_write, SUFFIX)(CPUArchState *env,
a8170e5e 366 hwaddr physaddr,
b769d8fe 367 DATA_TYPE val,
0f459d16 368 target_ulong addr,
20503968 369 uintptr_t retaddr)
b769d8fe 370{
09daed84
EI
371 CPUState *cpu = ENV_GET_CPU(env);
372 MemoryRegion *mr = iotlb_to_region(cpu->as, physaddr);
37ec01d4 373
0f459d16 374 physaddr = (physaddr & TARGET_PAGE_MASK) + addr;
99df7dce 375 if (mr != &io_mem_rom && mr != &io_mem_notdirty && !cpu_can_do_io(cpu)) {
90b40a69 376 cpu_io_recompile(cpu, retaddr);
2e70f6ef 377 }
b769d8fe 378
93afeade
AF
379 cpu->mem_io_vaddr = addr;
380 cpu->mem_io_pc = retaddr;
37ec01d4 381 io_mem_write(mr, physaddr, val, 1 << SHIFT);
b769d8fe 382}
b92e5a22 383
867b3201
RH
384void helper_le_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
385 int mmu_idx, uintptr_t retaddr)
b92e5a22 386{
aac1fb05
RH
387 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
388 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
389 uintptr_t haddr;
3b46e624 390
0f842f8a
RH
391 /* Adjust the given return address. */
392 retaddr -= GETPC_ADJ;
393
aac1fb05
RH
394 /* If the TLB entry is for a different page, reload and try again. */
395 if ((addr & TARGET_PAGE_MASK)
396 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
a64d4718 397#ifdef ALIGNED_ONLY
aac1fb05 398 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326 399 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
aac1fb05 400 }
a64d4718 401#endif
88e89a57
XT
402 if (!VICTIM_TLB_HIT(addr_write)) {
403 tlb_fill(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
404 }
aac1fb05
RH
405 tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
406 }
407
408 /* Handle an IO access. */
409 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
410 hwaddr ioaddr;
411 if ((addr & (DATA_SIZE - 1)) != 0) {
412 goto do_unaligned_access;
413 }
414 ioaddr = env->iotlb[mmu_idx][index];
867b3201
RH
415
416 /* ??? Note that the io helpers always read data in the target
417 byte ordering. We should push the LE/BE request down into io. */
418 val = TGT_LE(val);
aac1fb05
RH
419 glue(io_write, SUFFIX)(env, ioaddr, val, addr, retaddr);
420 return;
421 }
422
423 /* Handle slow unaligned access (it spans two pages or IO). */
424 if (DATA_SIZE > 1
425 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
426 >= TARGET_PAGE_SIZE)) {
427 int i;
428 do_unaligned_access:
a64d4718 429#ifdef ALIGNED_ONLY
93e22326 430 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
aac1fb05
RH
431#endif
432 /* XXX: not efficient, but simple */
433 /* Note: relies on the fact that tlb_fill() does not remove the
434 * previous page from the TLB cache. */
435 for (i = DATA_SIZE - 1; i >= 0; i--) {
867b3201 436 /* Little-endian extract. */
aac1fb05 437 uint8_t val8 = val >> (i * 8);
867b3201
RH
438 /* Note the adjustment at the beginning of the function.
439 Undo that for the recursion. */
440 glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8,
441 mmu_idx, retaddr + GETPC_ADJ);
442 }
443 return;
444 }
445
446 /* Handle aligned access or unaligned access in the same page. */
447#ifdef ALIGNED_ONLY
448 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326 449 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
867b3201
RH
450 }
451#endif
452
453 haddr = addr + env->tlb_table[mmu_idx][index].addend;
454#if DATA_SIZE == 1
455 glue(glue(st, SUFFIX), _p)((uint8_t *)haddr, val);
456#else
457 glue(glue(st, SUFFIX), _le_p)((uint8_t *)haddr, val);
a64d4718 458#endif
867b3201
RH
459}
460
461#if DATA_SIZE > 1
462void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val,
463 int mmu_idx, uintptr_t retaddr)
464{
465 int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
466 target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
467 uintptr_t haddr;
468
469 /* Adjust the given return address. */
470 retaddr -= GETPC_ADJ;
471
472 /* If the TLB entry is for a different page, reload and try again. */
473 if ((addr & TARGET_PAGE_MASK)
474 != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
475#ifdef ALIGNED_ONLY
476 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326 477 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
867b3201
RH
478 }
479#endif
88e89a57
XT
480 if (!VICTIM_TLB_HIT(addr_write)) {
481 tlb_fill(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
482 }
867b3201
RH
483 tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
484 }
485
486 /* Handle an IO access. */
487 if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) {
488 hwaddr ioaddr;
489 if ((addr & (DATA_SIZE - 1)) != 0) {
490 goto do_unaligned_access;
491 }
492 ioaddr = env->iotlb[mmu_idx][index];
493
494 /* ??? Note that the io helpers always read data in the target
495 byte ordering. We should push the LE/BE request down into io. */
496 val = TGT_BE(val);
497 glue(io_write, SUFFIX)(env, ioaddr, val, addr, retaddr);
498 return;
499 }
500
501 /* Handle slow unaligned access (it spans two pages or IO). */
502 if (DATA_SIZE > 1
503 && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1
504 >= TARGET_PAGE_SIZE)) {
505 int i;
506 do_unaligned_access:
507#ifdef ALIGNED_ONLY
93e22326 508 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
867b3201
RH
509#endif
510 /* XXX: not efficient, but simple */
511 /* Note: relies on the fact that tlb_fill() does not remove the
512 * previous page from the TLB cache. */
513 for (i = DATA_SIZE - 1; i >= 0; i--) {
514 /* Big-endian extract. */
515 uint8_t val8 = val >> (((DATA_SIZE - 1) * 8) - (i * 8));
0f842f8a
RH
516 /* Note the adjustment at the beginning of the function.
517 Undo that for the recursion. */
aac1fb05 518 glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8,
0f842f8a 519 mmu_idx, retaddr + GETPC_ADJ);
b92e5a22 520 }
aac1fb05
RH
521 return;
522 }
523
524 /* Handle aligned access or unaligned access in the same page. */
a64d4718 525#ifdef ALIGNED_ONLY
aac1fb05 526 if ((addr & (DATA_SIZE - 1)) != 0) {
93e22326 527 cpu_unaligned_access(ENV_GET_CPU(env), addr, 1, mmu_idx, retaddr);
b92e5a22 528 }
aac1fb05
RH
529#endif
530
531 haddr = addr + env->tlb_table[mmu_idx][index].addend;
867b3201 532 glue(glue(st, SUFFIX), _be_p)((uint8_t *)haddr, val);
b92e5a22 533}
867b3201 534#endif /* DATA_SIZE > 1 */
b92e5a22 535
e25c3887
RH
536void
537glue(glue(helper_st, SUFFIX), MMUSUFFIX)(CPUArchState *env, target_ulong addr,
538 DATA_TYPE val, int mmu_idx)
539{
867b3201 540 helper_te_st_name(env, addr, val, mmu_idx, GETRA());
e25c3887
RH
541}
542
b769d8fe
FB
543#endif /* !defined(SOFTMMU_CODE_ACCESS) */
544
545#undef READ_ACCESS_TYPE
b92e5a22
FB
546#undef SHIFT
547#undef DATA_TYPE
548#undef SUFFIX
701e3a5c 549#undef LSUFFIX
b92e5a22 550#undef DATA_SIZE
84b7b8e7 551#undef ADDR_READ
c8f94df5
RH
552#undef WORD_TYPE
553#undef SDATA_TYPE
554#undef USUFFIX
555#undef SSUFFIX
867b3201
RH
556#undef BSWAP
557#undef TGT_BE
558#undef TGT_LE
559#undef CPU_BE
560#undef CPU_LE
561#undef helper_le_ld_name
562#undef helper_be_ld_name
563#undef helper_le_lds_name
564#undef helper_be_lds_name
565#undef helper_le_st_name
566#undef helper_be_st_name
567#undef helper_te_ld_name
568#undef helper_te_st_name