]>
Commit | Line | Data |
---|---|---|
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; \ | |
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 | 145 | static 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 | 167 | static __attribute__((unused)) |
e25c3887 | 168 | #endif |
867b3201 RH |
169 | WORD_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 | |
255 | static __attribute__((unused)) | |
256 | #endif | |
257 | WORD_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 |
338 | DATA_TYPE |
339 | glue(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 |
350 | WORD_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 | |
357 | WORD_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 | 365 | static 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 |
384 | void 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) { |
55e94093 LA |
399 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
400 | mmu_idx, retaddr); | |
aac1fb05 | 401 | } |
a64d4718 | 402 | #endif |
88e89a57 | 403 | if (!VICTIM_TLB_HIT(addr_write)) { |
55e94093 | 404 | tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_STORE, mmu_idx, retaddr); |
88e89a57 | 405 | } |
aac1fb05 RH |
406 | tlb_addr = env->tlb_table[mmu_idx][index].addr_write; |
407 | } | |
408 | ||
409 | /* Handle an IO access. */ | |
410 | if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { | |
411 | hwaddr ioaddr; | |
412 | if ((addr & (DATA_SIZE - 1)) != 0) { | |
413 | goto do_unaligned_access; | |
414 | } | |
415 | ioaddr = env->iotlb[mmu_idx][index]; | |
867b3201 RH |
416 | |
417 | /* ??? Note that the io helpers always read data in the target | |
418 | byte ordering. We should push the LE/BE request down into io. */ | |
419 | val = TGT_LE(val); | |
aac1fb05 RH |
420 | glue(io_write, SUFFIX)(env, ioaddr, val, addr, retaddr); |
421 | return; | |
422 | } | |
423 | ||
424 | /* Handle slow unaligned access (it spans two pages or IO). */ | |
425 | if (DATA_SIZE > 1 | |
426 | && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1 | |
427 | >= TARGET_PAGE_SIZE)) { | |
428 | int i; | |
429 | do_unaligned_access: | |
a64d4718 | 430 | #ifdef ALIGNED_ONLY |
55e94093 LA |
431 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
432 | mmu_idx, retaddr); | |
aac1fb05 RH |
433 | #endif |
434 | /* XXX: not efficient, but simple */ | |
435 | /* Note: relies on the fact that tlb_fill() does not remove the | |
436 | * previous page from the TLB cache. */ | |
437 | for (i = DATA_SIZE - 1; i >= 0; i--) { | |
867b3201 | 438 | /* Little-endian extract. */ |
aac1fb05 | 439 | uint8_t val8 = val >> (i * 8); |
867b3201 RH |
440 | /* Note the adjustment at the beginning of the function. |
441 | Undo that for the recursion. */ | |
442 | glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8, | |
443 | mmu_idx, retaddr + GETPC_ADJ); | |
444 | } | |
445 | return; | |
446 | } | |
447 | ||
448 | /* Handle aligned access or unaligned access in the same page. */ | |
449 | #ifdef ALIGNED_ONLY | |
450 | if ((addr & (DATA_SIZE - 1)) != 0) { | |
55e94093 LA |
451 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
452 | mmu_idx, retaddr); | |
867b3201 RH |
453 | } |
454 | #endif | |
455 | ||
456 | haddr = addr + env->tlb_table[mmu_idx][index].addend; | |
457 | #if DATA_SIZE == 1 | |
458 | glue(glue(st, SUFFIX), _p)((uint8_t *)haddr, val); | |
459 | #else | |
460 | glue(glue(st, SUFFIX), _le_p)((uint8_t *)haddr, val); | |
a64d4718 | 461 | #endif |
867b3201 RH |
462 | } |
463 | ||
464 | #if DATA_SIZE > 1 | |
465 | void helper_be_st_name(CPUArchState *env, target_ulong addr, DATA_TYPE val, | |
466 | int mmu_idx, uintptr_t retaddr) | |
467 | { | |
468 | int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); | |
469 | target_ulong tlb_addr = env->tlb_table[mmu_idx][index].addr_write; | |
470 | uintptr_t haddr; | |
471 | ||
472 | /* Adjust the given return address. */ | |
473 | retaddr -= GETPC_ADJ; | |
474 | ||
475 | /* If the TLB entry is for a different page, reload and try again. */ | |
476 | if ((addr & TARGET_PAGE_MASK) | |
477 | != (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { | |
478 | #ifdef ALIGNED_ONLY | |
479 | if ((addr & (DATA_SIZE - 1)) != 0) { | |
55e94093 LA |
480 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
481 | mmu_idx, retaddr); | |
867b3201 RH |
482 | } |
483 | #endif | |
88e89a57 | 484 | if (!VICTIM_TLB_HIT(addr_write)) { |
55e94093 | 485 | tlb_fill(ENV_GET_CPU(env), addr, MMU_DATA_STORE, mmu_idx, retaddr); |
88e89a57 | 486 | } |
867b3201 RH |
487 | tlb_addr = env->tlb_table[mmu_idx][index].addr_write; |
488 | } | |
489 | ||
490 | /* Handle an IO access. */ | |
491 | if (unlikely(tlb_addr & ~TARGET_PAGE_MASK)) { | |
492 | hwaddr ioaddr; | |
493 | if ((addr & (DATA_SIZE - 1)) != 0) { | |
494 | goto do_unaligned_access; | |
495 | } | |
496 | ioaddr = env->iotlb[mmu_idx][index]; | |
497 | ||
498 | /* ??? Note that the io helpers always read data in the target | |
499 | byte ordering. We should push the LE/BE request down into io. */ | |
500 | val = TGT_BE(val); | |
501 | glue(io_write, SUFFIX)(env, ioaddr, val, addr, retaddr); | |
502 | return; | |
503 | } | |
504 | ||
505 | /* Handle slow unaligned access (it spans two pages or IO). */ | |
506 | if (DATA_SIZE > 1 | |
507 | && unlikely((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1 | |
508 | >= TARGET_PAGE_SIZE)) { | |
509 | int i; | |
510 | do_unaligned_access: | |
511 | #ifdef ALIGNED_ONLY | |
55e94093 LA |
512 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
513 | mmu_idx, retaddr); | |
867b3201 RH |
514 | #endif |
515 | /* XXX: not efficient, but simple */ | |
516 | /* Note: relies on the fact that tlb_fill() does not remove the | |
517 | * previous page from the TLB cache. */ | |
518 | for (i = DATA_SIZE - 1; i >= 0; i--) { | |
519 | /* Big-endian extract. */ | |
520 | uint8_t val8 = val >> (((DATA_SIZE - 1) * 8) - (i * 8)); | |
0f842f8a RH |
521 | /* Note the adjustment at the beginning of the function. |
522 | Undo that for the recursion. */ | |
aac1fb05 | 523 | glue(helper_ret_stb, MMUSUFFIX)(env, addr + i, val8, |
0f842f8a | 524 | mmu_idx, retaddr + GETPC_ADJ); |
b92e5a22 | 525 | } |
aac1fb05 RH |
526 | return; |
527 | } | |
528 | ||
529 | /* Handle aligned access or unaligned access in the same page. */ | |
a64d4718 | 530 | #ifdef ALIGNED_ONLY |
aac1fb05 | 531 | if ((addr & (DATA_SIZE - 1)) != 0) { |
55e94093 LA |
532 | cpu_unaligned_access(ENV_GET_CPU(env), addr, MMU_DATA_STORE, |
533 | mmu_idx, retaddr); | |
b92e5a22 | 534 | } |
aac1fb05 RH |
535 | #endif |
536 | ||
537 | haddr = addr + env->tlb_table[mmu_idx][index].addend; | |
867b3201 | 538 | glue(glue(st, SUFFIX), _be_p)((uint8_t *)haddr, val); |
b92e5a22 | 539 | } |
867b3201 | 540 | #endif /* DATA_SIZE > 1 */ |
b92e5a22 | 541 | |
e25c3887 RH |
542 | void |
543 | glue(glue(helper_st, SUFFIX), MMUSUFFIX)(CPUArchState *env, target_ulong addr, | |
544 | DATA_TYPE val, int mmu_idx) | |
545 | { | |
867b3201 | 546 | helper_te_st_name(env, addr, val, mmu_idx, GETRA()); |
e25c3887 RH |
547 | } |
548 | ||
b769d8fe FB |
549 | #endif /* !defined(SOFTMMU_CODE_ACCESS) */ |
550 | ||
551 | #undef READ_ACCESS_TYPE | |
b92e5a22 FB |
552 | #undef SHIFT |
553 | #undef DATA_TYPE | |
554 | #undef SUFFIX | |
701e3a5c | 555 | #undef LSUFFIX |
b92e5a22 | 556 | #undef DATA_SIZE |
84b7b8e7 | 557 | #undef ADDR_READ |
c8f94df5 RH |
558 | #undef WORD_TYPE |
559 | #undef SDATA_TYPE | |
560 | #undef USUFFIX | |
561 | #undef SSUFFIX | |
867b3201 RH |
562 | #undef BSWAP |
563 | #undef TGT_BE | |
564 | #undef TGT_LE | |
565 | #undef CPU_BE | |
566 | #undef CPU_LE | |
567 | #undef helper_le_ld_name | |
568 | #undef helper_be_ld_name | |
569 | #undef helper_le_lds_name | |
570 | #undef helper_be_lds_name | |
571 | #undef helper_le_st_name | |
572 | #undef helper_be_st_name | |
573 | #undef helper_te_ld_name | |
574 | #undef helper_te_st_name |