Paolo Bonzini | f08b617 | 2014-03-28 19:42:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Software MMU support |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * Generate inline load/store functions for all MMU modes (typically |
| 21 | * at least _user and _kernel) as well as _data versions, for all data |
| 22 | * sizes. |
| 23 | * |
| 24 | * Used by target op helpers. |
| 25 | * |
Peter Maydell | db5fd8d | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 26 | * The syntax for the accessors is: |
| 27 | * |
| 28 | * load: cpu_ld{sign}{size}_{mmusuffix}(env, ptr) |
| 29 | * |
| 30 | * store: cpu_st{sign}{size}_{mmusuffix}(env, ptr, val) |
| 31 | * |
| 32 | * sign is: |
| 33 | * (empty): for 32 and 64 bit sizes |
| 34 | * u : unsigned |
| 35 | * s : signed |
| 36 | * |
| 37 | * size is: |
| 38 | * b: 8 bits |
| 39 | * w: 16 bits |
| 40 | * l: 32 bits |
| 41 | * q: 64 bits |
| 42 | * |
| 43 | * mmusuffix is one of the generic suffixes "data" or "code", or |
| 44 | * (for softmmu configs) a target-specific MMU mode suffix as defined |
| 45 | * in target cpu.h. |
Paolo Bonzini | f08b617 | 2014-03-28 19:42:10 +0100 | [diff] [blame] | 46 | */ |
| 47 | #ifndef CPU_LDST_H |
| 48 | #define CPU_LDST_H |
| 49 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 50 | #if defined(CONFIG_USER_ONLY) |
| 51 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
Laurent Vivier | b76f21a | 2015-08-24 14:53:54 +0200 | [diff] [blame] | 52 | #define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + guest_base)) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 53 | |
Max Filippov | ebf9a36 | 2018-03-07 13:50:10 -0800 | [diff] [blame] | 54 | #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
| 55 | #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) |
| 56 | |
| 57 | static inline int guest_range_valid(unsigned long start, unsigned long len) |
| 58 | { |
| 59 | return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
| 60 | } |
Paolo Bonzini | f08b617 | 2014-03-28 19:42:10 +0100 | [diff] [blame] | 61 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 62 | #define h2g_nocheck(x) ({ \ |
Laurent Vivier | b76f21a | 2015-08-24 14:53:54 +0200 | [diff] [blame] | 63 | unsigned long __ret = (unsigned long)(x) - guest_base; \ |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 64 | (abi_ulong)__ret; \ |
| 65 | }) |
| 66 | |
| 67 | #define h2g(x) ({ \ |
| 68 | /* Check if given address fits target address space */ \ |
| 69 | assert(h2g_valid(x)); \ |
| 70 | h2g_nocheck(x); \ |
| 71 | }) |
| 72 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 73 | #endif |
| 74 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 75 | #if defined(CONFIG_USER_ONLY) |
| 76 | |
Richard Henderson | ec603b5 | 2017-11-14 10:34:20 +0100 | [diff] [blame] | 77 | extern __thread uintptr_t helper_retaddr; |
| 78 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 79 | /* In user-only mode we provide only the _code and _data accessors. */ |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 80 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 81 | #define MEMSUFFIX _data |
| 82 | #define DATA_SIZE 1 |
| 83 | #include "exec/cpu_ldst_useronly_template.h" |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 84 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 85 | #define DATA_SIZE 2 |
| 86 | #include "exec/cpu_ldst_useronly_template.h" |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 87 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 88 | #define DATA_SIZE 4 |
| 89 | #include "exec/cpu_ldst_useronly_template.h" |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 90 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 91 | #define DATA_SIZE 8 |
| 92 | #include "exec/cpu_ldst_useronly_template.h" |
| 93 | #undef MEMSUFFIX |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 94 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 95 | #define MEMSUFFIX _code |
| 96 | #define CODE_ACCESS |
| 97 | #define DATA_SIZE 1 |
| 98 | #include "exec/cpu_ldst_useronly_template.h" |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 99 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 100 | #define DATA_SIZE 2 |
| 101 | #include "exec/cpu_ldst_useronly_template.h" |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 102 | |
Peter Maydell | 9220fe5 | 2015-01-20 15:19:34 +0000 | [diff] [blame] | 103 | #define DATA_SIZE 4 |
| 104 | #include "exec/cpu_ldst_useronly_template.h" |
| 105 | |
| 106 | #define DATA_SIZE 8 |
| 107 | #include "exec/cpu_ldst_useronly_template.h" |
| 108 | #undef MEMSUFFIX |
| 109 | #undef CODE_ACCESS |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 110 | |
| 111 | #else |
| 112 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 113 | /* The memory helpers for tcg-generated code need tcg_target_long etc. */ |
| 114 | #include "tcg.h" |
| 115 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 116 | #ifdef MMU_MODE0_SUFFIX |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 117 | #define CPU_MMU_INDEX 0 |
| 118 | #define MEMSUFFIX MMU_MODE0_SUFFIX |
| 119 | #define DATA_SIZE 1 |
| 120 | #include "exec/cpu_ldst_template.h" |
| 121 | |
| 122 | #define DATA_SIZE 2 |
| 123 | #include "exec/cpu_ldst_template.h" |
| 124 | |
| 125 | #define DATA_SIZE 4 |
| 126 | #include "exec/cpu_ldst_template.h" |
| 127 | |
| 128 | #define DATA_SIZE 8 |
| 129 | #include "exec/cpu_ldst_template.h" |
| 130 | #undef CPU_MMU_INDEX |
| 131 | #undef MEMSUFFIX |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 132 | #endif |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 133 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 134 | #if (NB_MMU_MODES >= 2) && defined(MMU_MODE1_SUFFIX) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 135 | #define CPU_MMU_INDEX 1 |
| 136 | #define MEMSUFFIX MMU_MODE1_SUFFIX |
| 137 | #define DATA_SIZE 1 |
| 138 | #include "exec/cpu_ldst_template.h" |
| 139 | |
| 140 | #define DATA_SIZE 2 |
| 141 | #include "exec/cpu_ldst_template.h" |
| 142 | |
| 143 | #define DATA_SIZE 4 |
| 144 | #include "exec/cpu_ldst_template.h" |
| 145 | |
| 146 | #define DATA_SIZE 8 |
| 147 | #include "exec/cpu_ldst_template.h" |
| 148 | #undef CPU_MMU_INDEX |
| 149 | #undef MEMSUFFIX |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 150 | #endif |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 151 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 152 | #if (NB_MMU_MODES >= 3) && defined(MMU_MODE2_SUFFIX) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 153 | |
| 154 | #define CPU_MMU_INDEX 2 |
| 155 | #define MEMSUFFIX MMU_MODE2_SUFFIX |
| 156 | #define DATA_SIZE 1 |
| 157 | #include "exec/cpu_ldst_template.h" |
| 158 | |
| 159 | #define DATA_SIZE 2 |
| 160 | #include "exec/cpu_ldst_template.h" |
| 161 | |
| 162 | #define DATA_SIZE 4 |
| 163 | #include "exec/cpu_ldst_template.h" |
| 164 | |
| 165 | #define DATA_SIZE 8 |
| 166 | #include "exec/cpu_ldst_template.h" |
| 167 | #undef CPU_MMU_INDEX |
| 168 | #undef MEMSUFFIX |
| 169 | #endif /* (NB_MMU_MODES >= 3) */ |
| 170 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 171 | #if (NB_MMU_MODES >= 4) && defined(MMU_MODE3_SUFFIX) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 172 | |
| 173 | #define CPU_MMU_INDEX 3 |
| 174 | #define MEMSUFFIX MMU_MODE3_SUFFIX |
| 175 | #define DATA_SIZE 1 |
| 176 | #include "exec/cpu_ldst_template.h" |
| 177 | |
| 178 | #define DATA_SIZE 2 |
| 179 | #include "exec/cpu_ldst_template.h" |
| 180 | |
| 181 | #define DATA_SIZE 4 |
| 182 | #include "exec/cpu_ldst_template.h" |
| 183 | |
| 184 | #define DATA_SIZE 8 |
| 185 | #include "exec/cpu_ldst_template.h" |
| 186 | #undef CPU_MMU_INDEX |
| 187 | #undef MEMSUFFIX |
| 188 | #endif /* (NB_MMU_MODES >= 4) */ |
| 189 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 190 | #if (NB_MMU_MODES >= 5) && defined(MMU_MODE4_SUFFIX) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 191 | |
| 192 | #define CPU_MMU_INDEX 4 |
| 193 | #define MEMSUFFIX MMU_MODE4_SUFFIX |
| 194 | #define DATA_SIZE 1 |
| 195 | #include "exec/cpu_ldst_template.h" |
| 196 | |
| 197 | #define DATA_SIZE 2 |
| 198 | #include "exec/cpu_ldst_template.h" |
| 199 | |
| 200 | #define DATA_SIZE 4 |
| 201 | #include "exec/cpu_ldst_template.h" |
| 202 | |
| 203 | #define DATA_SIZE 8 |
| 204 | #include "exec/cpu_ldst_template.h" |
| 205 | #undef CPU_MMU_INDEX |
| 206 | #undef MEMSUFFIX |
| 207 | #endif /* (NB_MMU_MODES >= 5) */ |
| 208 | |
Peter Maydell | de5ee4a | 2015-01-20 15:19:35 +0000 | [diff] [blame] | 209 | #if (NB_MMU_MODES >= 6) && defined(MMU_MODE5_SUFFIX) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 210 | |
| 211 | #define CPU_MMU_INDEX 5 |
| 212 | #define MEMSUFFIX MMU_MODE5_SUFFIX |
| 213 | #define DATA_SIZE 1 |
| 214 | #include "exec/cpu_ldst_template.h" |
| 215 | |
| 216 | #define DATA_SIZE 2 |
| 217 | #include "exec/cpu_ldst_template.h" |
| 218 | |
| 219 | #define DATA_SIZE 4 |
| 220 | #include "exec/cpu_ldst_template.h" |
| 221 | |
| 222 | #define DATA_SIZE 8 |
| 223 | #include "exec/cpu_ldst_template.h" |
| 224 | #undef CPU_MMU_INDEX |
| 225 | #undef MEMSUFFIX |
| 226 | #endif /* (NB_MMU_MODES >= 6) */ |
| 227 | |
Peter Maydell | 8f3ae2a | 2015-02-05 13:37:23 +0000 | [diff] [blame] | 228 | #if (NB_MMU_MODES >= 7) && defined(MMU_MODE6_SUFFIX) |
| 229 | |
| 230 | #define CPU_MMU_INDEX 6 |
| 231 | #define MEMSUFFIX MMU_MODE6_SUFFIX |
| 232 | #define DATA_SIZE 1 |
| 233 | #include "exec/cpu_ldst_template.h" |
| 234 | |
| 235 | #define DATA_SIZE 2 |
| 236 | #include "exec/cpu_ldst_template.h" |
| 237 | |
| 238 | #define DATA_SIZE 4 |
| 239 | #include "exec/cpu_ldst_template.h" |
| 240 | |
| 241 | #define DATA_SIZE 8 |
| 242 | #include "exec/cpu_ldst_template.h" |
| 243 | #undef CPU_MMU_INDEX |
| 244 | #undef MEMSUFFIX |
| 245 | #endif /* (NB_MMU_MODES >= 7) */ |
| 246 | |
Paolo Bonzini | 1de29ae | 2015-05-05 09:18:23 +0200 | [diff] [blame] | 247 | #if (NB_MMU_MODES >= 8) && defined(MMU_MODE7_SUFFIX) |
| 248 | |
| 249 | #define CPU_MMU_INDEX 7 |
| 250 | #define MEMSUFFIX MMU_MODE7_SUFFIX |
| 251 | #define DATA_SIZE 1 |
| 252 | #include "exec/cpu_ldst_template.h" |
| 253 | |
| 254 | #define DATA_SIZE 2 |
| 255 | #include "exec/cpu_ldst_template.h" |
| 256 | |
| 257 | #define DATA_SIZE 4 |
| 258 | #include "exec/cpu_ldst_template.h" |
| 259 | |
| 260 | #define DATA_SIZE 8 |
| 261 | #include "exec/cpu_ldst_template.h" |
| 262 | #undef CPU_MMU_INDEX |
| 263 | #undef MEMSUFFIX |
| 264 | #endif /* (NB_MMU_MODES >= 8) */ |
| 265 | |
| 266 | #if (NB_MMU_MODES >= 9) && defined(MMU_MODE8_SUFFIX) |
| 267 | |
| 268 | #define CPU_MMU_INDEX 8 |
| 269 | #define MEMSUFFIX MMU_MODE8_SUFFIX |
| 270 | #define DATA_SIZE 1 |
| 271 | #include "exec/cpu_ldst_template.h" |
| 272 | |
| 273 | #define DATA_SIZE 2 |
| 274 | #include "exec/cpu_ldst_template.h" |
| 275 | |
| 276 | #define DATA_SIZE 4 |
| 277 | #include "exec/cpu_ldst_template.h" |
| 278 | |
| 279 | #define DATA_SIZE 8 |
| 280 | #include "exec/cpu_ldst_template.h" |
| 281 | #undef CPU_MMU_INDEX |
| 282 | #undef MEMSUFFIX |
| 283 | #endif /* (NB_MMU_MODES >= 9) */ |
| 284 | |
| 285 | #if (NB_MMU_MODES >= 10) && defined(MMU_MODE9_SUFFIX) |
| 286 | |
| 287 | #define CPU_MMU_INDEX 9 |
| 288 | #define MEMSUFFIX MMU_MODE9_SUFFIX |
| 289 | #define DATA_SIZE 1 |
| 290 | #include "exec/cpu_ldst_template.h" |
| 291 | |
| 292 | #define DATA_SIZE 2 |
| 293 | #include "exec/cpu_ldst_template.h" |
| 294 | |
| 295 | #define DATA_SIZE 4 |
| 296 | #include "exec/cpu_ldst_template.h" |
| 297 | |
| 298 | #define DATA_SIZE 8 |
| 299 | #include "exec/cpu_ldst_template.h" |
| 300 | #undef CPU_MMU_INDEX |
| 301 | #undef MEMSUFFIX |
| 302 | #endif /* (NB_MMU_MODES >= 10) */ |
| 303 | |
| 304 | #if (NB_MMU_MODES >= 11) && defined(MMU_MODE10_SUFFIX) |
| 305 | |
| 306 | #define CPU_MMU_INDEX 10 |
| 307 | #define MEMSUFFIX MMU_MODE10_SUFFIX |
| 308 | #define DATA_SIZE 1 |
| 309 | #include "exec/cpu_ldst_template.h" |
| 310 | |
| 311 | #define DATA_SIZE 2 |
| 312 | #include "exec/cpu_ldst_template.h" |
| 313 | |
| 314 | #define DATA_SIZE 4 |
| 315 | #include "exec/cpu_ldst_template.h" |
| 316 | |
| 317 | #define DATA_SIZE 8 |
| 318 | #include "exec/cpu_ldst_template.h" |
| 319 | #undef CPU_MMU_INDEX |
| 320 | #undef MEMSUFFIX |
| 321 | #endif /* (NB_MMU_MODES >= 11) */ |
| 322 | |
| 323 | #if (NB_MMU_MODES >= 12) && defined(MMU_MODE11_SUFFIX) |
| 324 | |
| 325 | #define CPU_MMU_INDEX 11 |
| 326 | #define MEMSUFFIX MMU_MODE11_SUFFIX |
| 327 | #define DATA_SIZE 1 |
| 328 | #include "exec/cpu_ldst_template.h" |
| 329 | |
| 330 | #define DATA_SIZE 2 |
| 331 | #include "exec/cpu_ldst_template.h" |
| 332 | |
| 333 | #define DATA_SIZE 4 |
| 334 | #include "exec/cpu_ldst_template.h" |
| 335 | |
| 336 | #define DATA_SIZE 8 |
| 337 | #include "exec/cpu_ldst_template.h" |
| 338 | #undef CPU_MMU_INDEX |
| 339 | #undef MEMSUFFIX |
| 340 | #endif /* (NB_MMU_MODES >= 12) */ |
| 341 | |
| 342 | #if (NB_MMU_MODES > 12) |
| 343 | #error "NB_MMU_MODES > 12 is not supported for now" |
| 344 | #endif /* (NB_MMU_MODES > 12) */ |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 345 | |
| 346 | /* these access are slower, they must be as rare as possible */ |
Benjamin Herrenschmidt | 97ed5cc | 2015-08-17 17:34:10 +1000 | [diff] [blame] | 347 | #define CPU_MMU_INDEX (cpu_mmu_index(env, false)) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 348 | #define MEMSUFFIX _data |
| 349 | #define DATA_SIZE 1 |
| 350 | #include "exec/cpu_ldst_template.h" |
| 351 | |
| 352 | #define DATA_SIZE 2 |
| 353 | #include "exec/cpu_ldst_template.h" |
| 354 | |
| 355 | #define DATA_SIZE 4 |
| 356 | #include "exec/cpu_ldst_template.h" |
| 357 | |
| 358 | #define DATA_SIZE 8 |
| 359 | #include "exec/cpu_ldst_template.h" |
| 360 | #undef CPU_MMU_INDEX |
| 361 | #undef MEMSUFFIX |
| 362 | |
Benjamin Herrenschmidt | 97ed5cc | 2015-08-17 17:34:10 +1000 | [diff] [blame] | 363 | #define CPU_MMU_INDEX (cpu_mmu_index(env, true)) |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 364 | #define MEMSUFFIX _code |
| 365 | #define SOFTMMU_CODE_ACCESS |
| 366 | |
| 367 | #define DATA_SIZE 1 |
| 368 | #include "exec/cpu_ldst_template.h" |
| 369 | |
| 370 | #define DATA_SIZE 2 |
| 371 | #include "exec/cpu_ldst_template.h" |
| 372 | |
| 373 | #define DATA_SIZE 4 |
| 374 | #include "exec/cpu_ldst_template.h" |
| 375 | |
| 376 | #define DATA_SIZE 8 |
| 377 | #include "exec/cpu_ldst_template.h" |
| 378 | |
| 379 | #undef CPU_MMU_INDEX |
| 380 | #undef MEMSUFFIX |
| 381 | #undef SOFTMMU_CODE_ACCESS |
| 382 | |
Aurelien Jarno | 2e83c49 | 2015-06-13 00:45:49 +0200 | [diff] [blame] | 383 | #endif /* defined(CONFIG_USER_ONLY) */ |
| 384 | |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 385 | /** |
| 386 | * tlb_vaddr_to_host: |
| 387 | * @env: CPUArchState |
| 388 | * @addr: guest virtual address to look up |
| 389 | * @access_type: 0 for read, 1 for write, 2 for execute |
| 390 | * @mmu_idx: MMU index to use for lookup |
| 391 | * |
| 392 | * Look up the specified guest virtual index in the TCG softmmu TLB. |
| 393 | * If the TLB contains a host virtual address suitable for direct RAM |
| 394 | * access, then return it. Otherwise (TLB miss, TLB entry is for an |
| 395 | * I/O access, etc) return NULL. |
| 396 | * |
| 397 | * This is the equivalent of the initial fast-path code used by |
| 398 | * TCG backends for guest load and store accesses. |
| 399 | */ |
| 400 | static inline void *tlb_vaddr_to_host(CPUArchState *env, target_ulong addr, |
| 401 | int access_type, int mmu_idx) |
| 402 | { |
Aurelien Jarno | 2e83c49 | 2015-06-13 00:45:49 +0200 | [diff] [blame] | 403 | #if defined(CONFIG_USER_ONLY) |
Bobby Bingham | c2a8531 | 2016-11-12 23:05:23 -0600 | [diff] [blame] | 404 | return g2h(addr); |
Aurelien Jarno | 2e83c49 | 2015-06-13 00:45:49 +0200 | [diff] [blame] | 405 | #else |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 406 | int index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 407 | CPUTLBEntry *tlbentry = &env->tlb_table[mmu_idx][index]; |
| 408 | target_ulong tlb_addr; |
| 409 | uintptr_t haddr; |
| 410 | |
| 411 | switch (access_type) { |
| 412 | case 0: |
| 413 | tlb_addr = tlbentry->addr_read; |
| 414 | break; |
| 415 | case 1: |
| 416 | tlb_addr = tlbentry->addr_write; |
| 417 | break; |
| 418 | case 2: |
| 419 | tlb_addr = tlbentry->addr_code; |
| 420 | break; |
| 421 | default: |
| 422 | g_assert_not_reached(); |
| 423 | } |
| 424 | |
Peter Maydell | 334692b | 2018-06-29 17:21:21 +0100 | [diff] [blame] | 425 | if (!tlb_hit(tlb_addr, addr)) { |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 426 | /* TLB entry is for a different page */ |
| 427 | return NULL; |
| 428 | } |
| 429 | |
| 430 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
| 431 | /* IO access */ |
| 432 | return NULL; |
| 433 | } |
| 434 | |
| 435 | haddr = addr + env->tlb_table[mmu_idx][index].addend; |
| 436 | return (void *)haddr; |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 437 | #endif /* defined(CONFIG_USER_ONLY) */ |
Aurelien Jarno | 2e83c49 | 2015-06-13 00:45:49 +0200 | [diff] [blame] | 438 | } |
Paolo Bonzini | c773828 | 2014-03-28 19:11:26 +0100 | [diff] [blame] | 439 | |
Paolo Bonzini | f08b617 | 2014-03-28 19:42:10 +0100 | [diff] [blame] | 440 | #endif /* CPU_LDST_H */ |