]>
git.proxmox.com Git - mirror_qemu.git/blob - include/exec/softmmu_template.h
4 * Generate helpers used by TCG for qemu_ld/st ops and code load
7 * Included from target op helpers and exec.c.
9 * Copyright (c) 2003 Fabrice Bellard
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.
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.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 #include "qemu/timer.h"
25 #include "exec/memory.h"
27 #define DATA_SIZE (1 << SHIFT)
32 #define DATA_TYPE uint64_t
36 #define DATA_TYPE uint32_t
40 #define DATA_TYPE uint16_t
44 #define DATA_TYPE uint8_t
46 #error unsupported data size
49 #ifdef SOFTMMU_CODE_ACCESS
50 #define READ_ACCESS_TYPE 2
51 #define ADDR_READ addr_code
53 #define READ_ACCESS_TYPE 0
54 #define ADDR_READ addr_read
57 static DATA_TYPE
glue(glue(slow_ld
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
61 static inline DATA_TYPE
glue(io_read
, SUFFIX
)(CPUArchState
*env
,
67 MemoryRegion
*mr
= iotlb_to_region(physaddr
);
69 physaddr
= (physaddr
& TARGET_PAGE_MASK
) + addr
;
70 env
->mem_io_pc
= retaddr
;
71 if (mr
!= &io_mem_rom
&& mr
!= &io_mem_notdirty
&& !can_do_io(env
)) {
72 cpu_io_recompile(env
, retaddr
);
75 env
->mem_io_vaddr
= addr
;
76 io_mem_read(mr
, physaddr
, &val
, 1 << SHIFT
);
80 /* handle all cases except unaligned access which span two pages */
81 #ifdef SOFTMMU_CODE_ACCESS
85 glue(glue(helper_ret_ld
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
86 target_ulong addr
, int mmu_idx
,
91 target_ulong tlb_addr
;
94 /* test if there is match for unaligned or IO access */
95 /* XXX: could done more in memory macro in a non portable way */
96 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
98 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].ADDR_READ
;
99 if ((addr
& TARGET_PAGE_MASK
) == (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
100 if (tlb_addr
& ~TARGET_PAGE_MASK
) {
102 if ((addr
& (DATA_SIZE
- 1)) != 0)
103 goto do_unaligned_access
;
104 ioaddr
= env
->iotlb
[mmu_idx
][index
];
105 res
= glue(io_read
, SUFFIX
)(env
, ioaddr
, addr
, retaddr
);
106 } else if (((addr
& ~TARGET_PAGE_MASK
) + DATA_SIZE
- 1) >= TARGET_PAGE_SIZE
) {
107 /* slow unaligned access (it spans two pages or IO) */
110 do_unaligned_access(env
, addr
, READ_ACCESS_TYPE
, mmu_idx
, retaddr
);
112 res
= glue(glue(slow_ld
, SUFFIX
), MMUSUFFIX
)(env
, addr
,
115 /* unaligned/aligned access in the same page */
118 if ((addr
& (DATA_SIZE
- 1)) != 0) {
119 do_unaligned_access(env
, addr
, READ_ACCESS_TYPE
, mmu_idx
, retaddr
);
122 addend
= env
->tlb_table
[mmu_idx
][index
].addend
;
123 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)(intptr_t)
128 if ((addr
& (DATA_SIZE
- 1)) != 0)
129 do_unaligned_access(env
, addr
, READ_ACCESS_TYPE
, mmu_idx
, retaddr
);
131 tlb_fill(env
, addr
, READ_ACCESS_TYPE
, mmu_idx
, retaddr
);
138 glue(glue(helper_ld
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
, target_ulong addr
,
141 return glue(glue(helper_ret_ld
, SUFFIX
), MMUSUFFIX
)(env
, addr
, mmu_idx
,
145 /* handle all unaligned cases */
147 glue(glue(slow_ld
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
152 DATA_TYPE res
, res1
, res2
;
155 target_ulong tlb_addr
, addr1
, addr2
;
157 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
159 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].ADDR_READ
;
160 if ((addr
& TARGET_PAGE_MASK
) == (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
161 if (tlb_addr
& ~TARGET_PAGE_MASK
) {
163 if ((addr
& (DATA_SIZE
- 1)) != 0)
164 goto do_unaligned_access
;
165 ioaddr
= env
->iotlb
[mmu_idx
][index
];
166 res
= glue(io_read
, SUFFIX
)(env
, ioaddr
, addr
, retaddr
);
167 } else if (((addr
& ~TARGET_PAGE_MASK
) + DATA_SIZE
- 1) >= TARGET_PAGE_SIZE
) {
169 /* slow unaligned access (it spans two pages) */
170 addr1
= addr
& ~(DATA_SIZE
- 1);
171 addr2
= addr1
+ DATA_SIZE
;
172 res1
= glue(glue(slow_ld
, SUFFIX
), MMUSUFFIX
)(env
, addr1
,
174 res2
= glue(glue(slow_ld
, SUFFIX
), MMUSUFFIX
)(env
, addr2
,
176 shift
= (addr
& (DATA_SIZE
- 1)) * 8;
177 #ifdef TARGET_WORDS_BIGENDIAN
178 res
= (res1
<< shift
) | (res2
>> ((DATA_SIZE
* 8) - shift
));
180 res
= (res1
>> shift
) | (res2
<< ((DATA_SIZE
* 8) - shift
));
182 res
= (DATA_TYPE
)res
;
184 /* unaligned/aligned access in the same page */
185 uintptr_t addend
= env
->tlb_table
[mmu_idx
][index
].addend
;
186 res
= glue(glue(ld
, USUFFIX
), _raw
)((uint8_t *)(intptr_t)
190 /* the page is not in the TLB : fill it */
191 tlb_fill(env
, addr
, READ_ACCESS_TYPE
, mmu_idx
, retaddr
);
197 #ifndef SOFTMMU_CODE_ACCESS
199 static void glue(glue(slow_st
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
205 static inline void glue(io_write
, SUFFIX
)(CPUArchState
*env
,
211 MemoryRegion
*mr
= iotlb_to_region(physaddr
);
213 physaddr
= (physaddr
& TARGET_PAGE_MASK
) + addr
;
214 if (mr
!= &io_mem_rom
&& mr
!= &io_mem_notdirty
&& !can_do_io(env
)) {
215 cpu_io_recompile(env
, retaddr
);
218 env
->mem_io_vaddr
= addr
;
219 env
->mem_io_pc
= retaddr
;
220 io_mem_write(mr
, physaddr
, val
, 1 << SHIFT
);
224 glue(glue(helper_ret_st
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
225 target_ulong addr
, DATA_TYPE val
,
226 int mmu_idx
, uintptr_t retaddr
)
229 target_ulong tlb_addr
;
232 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
234 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
235 if ((addr
& TARGET_PAGE_MASK
) == (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
236 if (tlb_addr
& ~TARGET_PAGE_MASK
) {
238 if ((addr
& (DATA_SIZE
- 1)) != 0)
239 goto do_unaligned_access
;
240 ioaddr
= env
->iotlb
[mmu_idx
][index
];
241 glue(io_write
, SUFFIX
)(env
, ioaddr
, val
, addr
, retaddr
);
242 } else if (((addr
& ~TARGET_PAGE_MASK
) + DATA_SIZE
- 1) >= TARGET_PAGE_SIZE
) {
245 do_unaligned_access(env
, addr
, 1, mmu_idx
, retaddr
);
247 glue(glue(slow_st
, SUFFIX
), MMUSUFFIX
)(env
, addr
, val
,
250 /* aligned/unaligned access in the same page */
253 if ((addr
& (DATA_SIZE
- 1)) != 0) {
254 do_unaligned_access(env
, addr
, 1, mmu_idx
, retaddr
);
257 addend
= env
->tlb_table
[mmu_idx
][index
].addend
;
258 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)(intptr_t)
259 (addr
+ addend
), val
);
262 /* the page is not in the TLB : fill it */
264 if ((addr
& (DATA_SIZE
- 1)) != 0)
265 do_unaligned_access(env
, addr
, 1, mmu_idx
, retaddr
);
267 tlb_fill(env
, addr
, 1, mmu_idx
, retaddr
);
273 glue(glue(helper_st
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
, target_ulong addr
,
274 DATA_TYPE val
, int mmu_idx
)
276 glue(glue(helper_ret_st
, SUFFIX
), MMUSUFFIX
)(env
, addr
, val
, mmu_idx
,
280 /* handles all unaligned cases */
281 static void glue(glue(slow_st
, SUFFIX
), MMUSUFFIX
)(CPUArchState
*env
,
288 target_ulong tlb_addr
;
291 index
= (addr
>> TARGET_PAGE_BITS
) & (CPU_TLB_SIZE
- 1);
293 tlb_addr
= env
->tlb_table
[mmu_idx
][index
].addr_write
;
294 if ((addr
& TARGET_PAGE_MASK
) == (tlb_addr
& (TARGET_PAGE_MASK
| TLB_INVALID_MASK
))) {
295 if (tlb_addr
& ~TARGET_PAGE_MASK
) {
297 if ((addr
& (DATA_SIZE
- 1)) != 0)
298 goto do_unaligned_access
;
299 ioaddr
= env
->iotlb
[mmu_idx
][index
];
300 glue(io_write
, SUFFIX
)(env
, ioaddr
, val
, addr
, retaddr
);
301 } else if (((addr
& ~TARGET_PAGE_MASK
) + DATA_SIZE
- 1) >= TARGET_PAGE_SIZE
) {
303 /* XXX: not efficient, but simple */
304 /* Note: relies on the fact that tlb_fill() does not remove the
305 * previous page from the TLB cache. */
306 for(i
= DATA_SIZE
- 1; i
>= 0; i
--) {
307 #ifdef TARGET_WORDS_BIGENDIAN
308 glue(slow_stb
, MMUSUFFIX
)(env
, addr
+ i
,
309 val
>> (((DATA_SIZE
- 1) * 8) - (i
* 8)),
312 glue(slow_stb
, MMUSUFFIX
)(env
, addr
+ i
,
318 /* aligned/unaligned access in the same page */
319 uintptr_t addend
= env
->tlb_table
[mmu_idx
][index
].addend
;
320 glue(glue(st
, SUFFIX
), _raw
)((uint8_t *)(intptr_t)
321 (addr
+ addend
), val
);
324 /* the page is not in the TLB : fill it */
325 tlb_fill(env
, addr
, 1, mmu_idx
, retaddr
);
330 #endif /* !defined(SOFTMMU_CODE_ACCESS) */
332 #undef READ_ACCESS_TYPE