]>
Commit | Line | Data |
---|---|---|
b92e5a22 FB |
1 | /* |
2 | * Software MMU support | |
3 | * | |
4 | * Copyright (c) 2003 Fabrice Bellard | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | */ | |
20 | #define DATA_SIZE (1 << SHIFT) | |
21 | ||
22 | #if DATA_SIZE == 8 | |
23 | #define SUFFIX q | |
61382a50 | 24 | #define USUFFIX q |
b92e5a22 FB |
25 | #define DATA_TYPE uint64_t |
26 | #elif DATA_SIZE == 4 | |
27 | #define SUFFIX l | |
61382a50 | 28 | #define USUFFIX l |
b92e5a22 FB |
29 | #define DATA_TYPE uint32_t |
30 | #elif DATA_SIZE == 2 | |
31 | #define SUFFIX w | |
61382a50 | 32 | #define USUFFIX uw |
b92e5a22 FB |
33 | #define DATA_TYPE uint16_t |
34 | #elif DATA_SIZE == 1 | |
35 | #define SUFFIX b | |
61382a50 | 36 | #define USUFFIX ub |
b92e5a22 FB |
37 | #define DATA_TYPE uint8_t |
38 | #else | |
39 | #error unsupported data size | |
40 | #endif | |
41 | ||
b769d8fe FB |
42 | #ifdef SOFTMMU_CODE_ACCESS |
43 | #define READ_ACCESS_TYPE 2 | |
84b7b8e7 | 44 | #define ADDR_READ addr_code |
b769d8fe FB |
45 | #else |
46 | #define READ_ACCESS_TYPE 0 | |
84b7b8e7 | 47 | #define ADDR_READ addr_read |
b769d8fe FB |
48 | #endif |
49 | ||
c27004ec | 50 | static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr, |
61382a50 FB |
51 | int is_user, |
52 | void *retaddr); | |
108c49b8 | 53 | static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, |
c27004ec | 54 | target_ulong tlb_addr) |
b92e5a22 FB |
55 | { |
56 | DATA_TYPE res; | |
57 | int index; | |
58 | ||
59 | index = (tlb_addr >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); | |
60 | #if SHIFT <= 2 | |
a4193c8a | 61 | res = io_mem_read[index][SHIFT](io_mem_opaque[index], physaddr); |
b92e5a22 FB |
62 | #else |
63 | #ifdef TARGET_WORDS_BIGENDIAN | |
a4193c8a FB |
64 | res = (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr) << 32; |
65 | res |= io_mem_read[index][2](io_mem_opaque[index], physaddr + 4); | |
b92e5a22 | 66 | #else |
a4193c8a FB |
67 | res = io_mem_read[index][2](io_mem_opaque[index], physaddr); |
68 | res |= (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr + 4) << 32; | |
b92e5a22 FB |
69 | #endif |
70 | #endif /* SHIFT > 2 */ | |
71 | return res; | |
72 | } | |
73 | ||
b92e5a22 | 74 | /* handle all cases except unaligned access which span two pages */ |
c27004ec | 75 | DATA_TYPE REGPARM(1) glue(glue(__ld, SUFFIX), MMUSUFFIX)(target_ulong addr, |
61382a50 | 76 | int is_user) |
b92e5a22 FB |
77 | { |
78 | DATA_TYPE res; | |
61382a50 | 79 | int index; |
c27004ec | 80 | target_ulong tlb_addr; |
108c49b8 | 81 | target_phys_addr_t physaddr; |
b92e5a22 FB |
82 | void *retaddr; |
83 | ||
84 | /* test if there is match for unaligned or IO access */ | |
85 | /* XXX: could done more in memory macro in a non portable way */ | |
b92e5a22 FB |
86 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
87 | redo: | |
84b7b8e7 | 88 | tlb_addr = env->tlb_table[is_user][index].ADDR_READ; |
b92e5a22 | 89 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
84b7b8e7 | 90 | physaddr = addr + env->tlb_table[is_user][index].addend; |
b92e5a22 FB |
91 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
92 | /* IO access */ | |
93 | if ((addr & (DATA_SIZE - 1)) != 0) | |
94 | goto do_unaligned_access; | |
95 | res = glue(io_read, SUFFIX)(physaddr, tlb_addr); | |
98699967 | 96 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
b92e5a22 FB |
97 | /* slow unaligned access (it spans two pages or IO) */ |
98 | do_unaligned_access: | |
61382a50 FB |
99 | retaddr = GETPC(); |
100 | res = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(addr, | |
101 | is_user, retaddr); | |
b92e5a22 FB |
102 | } else { |
103 | /* unaligned access in the same page */ | |
108c49b8 | 104 | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)(long)physaddr); |
b92e5a22 FB |
105 | } |
106 | } else { | |
107 | /* the page is not in the TLB : fill it */ | |
61382a50 | 108 | retaddr = GETPC(); |
b769d8fe | 109 | tlb_fill(addr, READ_ACCESS_TYPE, is_user, retaddr); |
b92e5a22 FB |
110 | goto redo; |
111 | } | |
112 | return res; | |
113 | } | |
114 | ||
115 | /* handle all unaligned cases */ | |
c27004ec | 116 | static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr, |
61382a50 FB |
117 | int is_user, |
118 | void *retaddr) | |
b92e5a22 FB |
119 | { |
120 | DATA_TYPE res, res1, res2; | |
61382a50 | 121 | int index, shift; |
108c49b8 | 122 | target_phys_addr_t physaddr; |
c27004ec | 123 | target_ulong tlb_addr, addr1, addr2; |
b92e5a22 | 124 | |
b92e5a22 FB |
125 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
126 | redo: | |
84b7b8e7 | 127 | tlb_addr = env->tlb_table[is_user][index].ADDR_READ; |
b92e5a22 | 128 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
84b7b8e7 | 129 | physaddr = addr + env->tlb_table[is_user][index].addend; |
b92e5a22 FB |
130 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
131 | /* IO access */ | |
132 | if ((addr & (DATA_SIZE - 1)) != 0) | |
133 | goto do_unaligned_access; | |
134 | res = glue(io_read, SUFFIX)(physaddr, tlb_addr); | |
98699967 | 135 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
b92e5a22 FB |
136 | do_unaligned_access: |
137 | /* slow unaligned access (it spans two pages) */ | |
138 | addr1 = addr & ~(DATA_SIZE - 1); | |
139 | addr2 = addr1 + DATA_SIZE; | |
61382a50 FB |
140 | res1 = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(addr1, |
141 | is_user, retaddr); | |
142 | res2 = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(addr2, | |
143 | is_user, retaddr); | |
b92e5a22 FB |
144 | shift = (addr & (DATA_SIZE - 1)) * 8; |
145 | #ifdef TARGET_WORDS_BIGENDIAN | |
146 | res = (res1 << shift) | (res2 >> ((DATA_SIZE * 8) - shift)); | |
147 | #else | |
148 | res = (res1 >> shift) | (res2 << ((DATA_SIZE * 8) - shift)); | |
149 | #endif | |
6986f88c | 150 | res = (DATA_TYPE)res; |
b92e5a22 FB |
151 | } else { |
152 | /* unaligned/aligned access in the same page */ | |
108c49b8 | 153 | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)(long)physaddr); |
b92e5a22 FB |
154 | } |
155 | } else { | |
156 | /* the page is not in the TLB : fill it */ | |
b769d8fe | 157 | tlb_fill(addr, READ_ACCESS_TYPE, is_user, retaddr); |
b92e5a22 FB |
158 | goto redo; |
159 | } | |
160 | return res; | |
161 | } | |
162 | ||
b769d8fe FB |
163 | #ifndef SOFTMMU_CODE_ACCESS |
164 | ||
c27004ec | 165 | static void glue(glue(slow_st, SUFFIX), MMUSUFFIX)(target_ulong addr, |
b769d8fe FB |
166 | DATA_TYPE val, |
167 | int is_user, | |
168 | void *retaddr); | |
169 | ||
108c49b8 | 170 | static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, |
b769d8fe | 171 | DATA_TYPE val, |
c27004ec | 172 | target_ulong tlb_addr, |
b769d8fe FB |
173 | void *retaddr) |
174 | { | |
175 | int index; | |
176 | ||
177 | index = (tlb_addr >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); | |
178 | env->mem_write_vaddr = tlb_addr; | |
179 | env->mem_write_pc = (unsigned long)retaddr; | |
180 | #if SHIFT <= 2 | |
181 | io_mem_write[index][SHIFT](io_mem_opaque[index], physaddr, val); | |
182 | #else | |
183 | #ifdef TARGET_WORDS_BIGENDIAN | |
184 | io_mem_write[index][2](io_mem_opaque[index], physaddr, val >> 32); | |
185 | io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val); | |
186 | #else | |
187 | io_mem_write[index][2](io_mem_opaque[index], physaddr, val); | |
188 | io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val >> 32); | |
189 | #endif | |
190 | #endif /* SHIFT > 2 */ | |
191 | } | |
b92e5a22 | 192 | |
c27004ec | 193 | void REGPARM(2) glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr, |
61382a50 FB |
194 | DATA_TYPE val, |
195 | int is_user) | |
b92e5a22 | 196 | { |
108c49b8 | 197 | target_phys_addr_t physaddr; |
c27004ec | 198 | target_ulong tlb_addr; |
b92e5a22 | 199 | void *retaddr; |
61382a50 | 200 | int index; |
b92e5a22 | 201 | |
b92e5a22 FB |
202 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
203 | redo: | |
84b7b8e7 | 204 | tlb_addr = env->tlb_table[is_user][index].addr_write; |
b92e5a22 | 205 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
84b7b8e7 | 206 | physaddr = addr + env->tlb_table[is_user][index].addend; |
b92e5a22 FB |
207 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
208 | /* IO access */ | |
209 | if ((addr & (DATA_SIZE - 1)) != 0) | |
210 | goto do_unaligned_access; | |
d720b93d FB |
211 | retaddr = GETPC(); |
212 | glue(io_write, SUFFIX)(physaddr, val, tlb_addr, retaddr); | |
98699967 | 213 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
b92e5a22 | 214 | do_unaligned_access: |
61382a50 FB |
215 | retaddr = GETPC(); |
216 | glue(glue(slow_st, SUFFIX), MMUSUFFIX)(addr, val, | |
217 | is_user, retaddr); | |
b92e5a22 FB |
218 | } else { |
219 | /* aligned/unaligned access in the same page */ | |
108c49b8 | 220 | glue(glue(st, SUFFIX), _raw)((uint8_t *)(long)physaddr, val); |
b92e5a22 FB |
221 | } |
222 | } else { | |
223 | /* the page is not in the TLB : fill it */ | |
61382a50 FB |
224 | retaddr = GETPC(); |
225 | tlb_fill(addr, 1, is_user, retaddr); | |
b92e5a22 FB |
226 | goto redo; |
227 | } | |
228 | } | |
229 | ||
230 | /* handles all unaligned cases */ | |
c27004ec | 231 | static void glue(glue(slow_st, SUFFIX), MMUSUFFIX)(target_ulong addr, |
61382a50 FB |
232 | DATA_TYPE val, |
233 | int is_user, | |
234 | void *retaddr) | |
b92e5a22 | 235 | { |
108c49b8 | 236 | target_phys_addr_t physaddr; |
c27004ec | 237 | target_ulong tlb_addr; |
61382a50 | 238 | int index, i; |
b92e5a22 | 239 | |
b92e5a22 FB |
240 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
241 | redo: | |
84b7b8e7 | 242 | tlb_addr = env->tlb_table[is_user][index].addr_write; |
b92e5a22 | 243 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
84b7b8e7 | 244 | physaddr = addr + env->tlb_table[is_user][index].addend; |
b92e5a22 FB |
245 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
246 | /* IO access */ | |
247 | if ((addr & (DATA_SIZE - 1)) != 0) | |
248 | goto do_unaligned_access; | |
d720b93d | 249 | glue(io_write, SUFFIX)(physaddr, val, tlb_addr, retaddr); |
98699967 | 250 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
b92e5a22 FB |
251 | do_unaligned_access: |
252 | /* XXX: not efficient, but simple */ | |
253 | for(i = 0;i < DATA_SIZE; i++) { | |
254 | #ifdef TARGET_WORDS_BIGENDIAN | |
61382a50 FB |
255 | glue(slow_stb, MMUSUFFIX)(addr + i, val >> (((DATA_SIZE - 1) * 8) - (i * 8)), |
256 | is_user, retaddr); | |
b92e5a22 | 257 | #else |
61382a50 FB |
258 | glue(slow_stb, MMUSUFFIX)(addr + i, val >> (i * 8), |
259 | is_user, retaddr); | |
b92e5a22 FB |
260 | #endif |
261 | } | |
262 | } else { | |
263 | /* aligned/unaligned access in the same page */ | |
108c49b8 | 264 | glue(glue(st, SUFFIX), _raw)((uint8_t *)(long)physaddr, val); |
b92e5a22 FB |
265 | } |
266 | } else { | |
267 | /* the page is not in the TLB : fill it */ | |
61382a50 | 268 | tlb_fill(addr, 1, is_user, retaddr); |
b92e5a22 FB |
269 | goto redo; |
270 | } | |
271 | } | |
272 | ||
b769d8fe FB |
273 | #endif /* !defined(SOFTMMU_CODE_ACCESS) */ |
274 | ||
275 | #undef READ_ACCESS_TYPE | |
b92e5a22 FB |
276 | #undef SHIFT |
277 | #undef DATA_TYPE | |
278 | #undef SUFFIX | |
61382a50 | 279 | #undef USUFFIX |
b92e5a22 | 280 | #undef DATA_SIZE |
84b7b8e7 | 281 | #undef ADDR_READ |