bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Software MMU support |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
Blue Swirl | efbf29b | 2011-09-21 20:00:18 +0000 | [diff] [blame] | 4 | * Generate inline load/store functions for one MMU mode and data |
| 5 | * size. |
| 6 | * |
| 7 | * Generate a store function as well as signed and unsigned loads. For |
| 8 | * 32 and 64 bit cases, also generate floating point functions with |
| 9 | * the same size. |
| 10 | * |
| 11 | * Not used directly but included from softmmu_exec.h and exec-all.h. |
| 12 | * |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 13 | * Copyright (c) 2003 Fabrice Bellard |
| 14 | * |
| 15 | * This library is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU Lesser General Public |
| 17 | * License as published by the Free Software Foundation; either |
| 18 | * version 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | * This library is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | * Lesser General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU Lesser General Public |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 26 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 27 | */ |
| 28 | #if DATA_SIZE == 8 |
| 29 | #define SUFFIX q |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 30 | #define USUFFIX q |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 31 | #define DATA_TYPE uint64_t |
| 32 | #elif DATA_SIZE == 4 |
| 33 | #define SUFFIX l |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 34 | #define USUFFIX l |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 35 | #define DATA_TYPE uint32_t |
| 36 | #elif DATA_SIZE == 2 |
| 37 | #define SUFFIX w |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 38 | #define USUFFIX uw |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 39 | #define DATA_TYPE uint16_t |
| 40 | #define DATA_STYPE int16_t |
| 41 | #elif DATA_SIZE == 1 |
| 42 | #define SUFFIX b |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 43 | #define USUFFIX ub |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 44 | #define DATA_TYPE uint8_t |
| 45 | #define DATA_STYPE int8_t |
| 46 | #else |
| 47 | #error unsupported data size |
| 48 | #endif |
| 49 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 50 | #if ACCESS_TYPE < (NB_MMU_MODES) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 51 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 52 | #define CPU_MMU_INDEX ACCESS_TYPE |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 53 | #define MMUSUFFIX _mmu |
| 54 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 55 | #elif ACCESS_TYPE == (NB_MMU_MODES) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 56 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 57 | #define CPU_MMU_INDEX (cpu_mmu_index(env)) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 58 | #define MMUSUFFIX _mmu |
| 59 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 60 | #elif ACCESS_TYPE == (NB_MMU_MODES + 1) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 61 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 62 | #define CPU_MMU_INDEX (cpu_mmu_index(env)) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 63 | #define MMUSUFFIX _cmmu |
| 64 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 65 | #else |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 66 | #error invalid ACCESS_TYPE |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | #if DATA_SIZE == 8 |
| 70 | #define RES_TYPE uint64_t |
| 71 | #else |
Igor V. Kovalenko | c086b78 | 2010-06-02 00:12:32 +0400 | [diff] [blame] | 72 | #define RES_TYPE uint32_t |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 75 | #if ACCESS_TYPE == (NB_MMU_MODES + 1) |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 76 | #define ADDR_READ addr_code |
| 77 | #else |
| 78 | #define ADDR_READ addr_read |
| 79 | #endif |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 80 | |
bellard | e16c53f | 2004-01-04 18:15:29 +0000 | [diff] [blame] | 81 | /* generic load/store macros */ |
| 82 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 83 | static inline RES_TYPE |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 84 | glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 85 | { |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 86 | int page_index; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 87 | RES_TYPE res; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 88 | target_ulong addr; |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 89 | int mmu_idx; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 90 | |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 91 | addr = ptr; |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 92 | page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 93 | mmu_idx = CPU_MMU_INDEX; |
ths | 551bd27 | 2008-07-03 17:57:36 +0000 | [diff] [blame] | 94 | if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ != |
| 95 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 96 | res = glue(glue(helper_ld, SUFFIX), MMUSUFFIX)(env, addr, mmu_idx); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 97 | } else { |
Stefan Weil | 23ddbf0 | 2012-04-15 21:02:09 +0200 | [diff] [blame] | 98 | uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend; |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 99 | res = glue(glue(ld, USUFFIX), _raw)(hostaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 100 | } |
| 101 | return res; |
| 102 | } |
| 103 | |
| 104 | #if DATA_SIZE <= 2 |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 105 | static inline int |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 106 | glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 107 | { |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 108 | int res, page_index; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 109 | target_ulong addr; |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 110 | int mmu_idx; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 111 | |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 112 | addr = ptr; |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 113 | page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 114 | mmu_idx = CPU_MMU_INDEX; |
ths | 551bd27 | 2008-07-03 17:57:36 +0000 | [diff] [blame] | 115 | if (unlikely(env->tlb_table[mmu_idx][page_index].ADDR_READ != |
| 116 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 117 | res = (DATA_STYPE)glue(glue(helper_ld, SUFFIX), |
| 118 | MMUSUFFIX)(env, addr, mmu_idx); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 119 | } else { |
Stefan Weil | 23ddbf0 | 2012-04-15 21:02:09 +0200 | [diff] [blame] | 120 | uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend; |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 121 | res = glue(glue(lds, SUFFIX), _raw)(hostaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 122 | } |
| 123 | return res; |
| 124 | } |
| 125 | #endif |
| 126 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 127 | #if ACCESS_TYPE != (NB_MMU_MODES + 1) |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 128 | |
bellard | e16c53f | 2004-01-04 18:15:29 +0000 | [diff] [blame] | 129 | /* generic store macro */ |
| 130 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 131 | static inline void |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 132 | glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr, |
| 133 | RES_TYPE v) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 134 | { |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 135 | int page_index; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 136 | target_ulong addr; |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 137 | int mmu_idx; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 138 | |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 139 | addr = ptr; |
blueswir1 | 4d7a088 | 2008-05-10 10:14:22 +0000 | [diff] [blame] | 140 | page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 141 | mmu_idx = CPU_MMU_INDEX; |
ths | 551bd27 | 2008-07-03 17:57:36 +0000 | [diff] [blame] | 142 | if (unlikely(env->tlb_table[mmu_idx][page_index].addr_write != |
| 143 | (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 144 | glue(glue(helper_st, SUFFIX), MMUSUFFIX)(env, addr, v, mmu_idx); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 145 | } else { |
Stefan Weil | 23ddbf0 | 2012-04-15 21:02:09 +0200 | [diff] [blame] | 146 | uintptr_t hostaddr = addr + env->tlb_table[mmu_idx][page_index].addend; |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 147 | glue(glue(st, SUFFIX), _raw)(hostaddr, v); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 151 | #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */ |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 152 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 153 | #if ACCESS_TYPE != (NB_MMU_MODES + 1) |
bellard | e16c53f | 2004-01-04 18:15:29 +0000 | [diff] [blame] | 154 | |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 155 | #if DATA_SIZE == 8 |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 156 | static inline float64 glue(cpu_ldfq, MEMSUFFIX)(CPUArchState *env, |
| 157 | target_ulong ptr) |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 158 | { |
| 159 | union { |
bellard | 3f87bf6 | 2005-11-06 19:56:23 +0000 | [diff] [blame] | 160 | float64 d; |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 161 | uint64_t i; |
| 162 | } u; |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 163 | u.i = glue(cpu_ldq, MEMSUFFIX)(env, ptr); |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 164 | return u.d; |
| 165 | } |
| 166 | |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 167 | static inline void glue(cpu_stfq, MEMSUFFIX)(CPUArchState *env, |
| 168 | target_ulong ptr, float64 v) |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 169 | { |
| 170 | union { |
bellard | 3f87bf6 | 2005-11-06 19:56:23 +0000 | [diff] [blame] | 171 | float64 d; |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 172 | uint64_t i; |
| 173 | } u; |
| 174 | u.d = v; |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 175 | glue(cpu_stq, MEMSUFFIX)(env, ptr, u.i); |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 176 | } |
| 177 | #endif /* DATA_SIZE == 8 */ |
| 178 | |
| 179 | #if DATA_SIZE == 4 |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 180 | static inline float32 glue(cpu_ldfl, MEMSUFFIX)(CPUArchState *env, |
| 181 | target_ulong ptr) |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 182 | { |
| 183 | union { |
bellard | 3f87bf6 | 2005-11-06 19:56:23 +0000 | [diff] [blame] | 184 | float32 f; |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 185 | uint32_t i; |
| 186 | } u; |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 187 | u.i = glue(cpu_ldl, MEMSUFFIX)(env, ptr); |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 188 | return u.f; |
| 189 | } |
| 190 | |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 191 | static inline void glue(cpu_stfl, MEMSUFFIX)(CPUArchState *env, |
| 192 | target_ulong ptr, float32 v) |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 193 | { |
| 194 | union { |
bellard | 3f87bf6 | 2005-11-06 19:56:23 +0000 | [diff] [blame] | 195 | float32 f; |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 196 | uint32_t i; |
| 197 | } u; |
| 198 | u.f = v; |
Blue Swirl | 89c3333 | 2012-09-02 15:28:56 +0000 | [diff] [blame] | 199 | glue(cpu_stl, MEMSUFFIX)(env, ptr, u.i); |
bellard | 2d603d2 | 2004-01-04 23:56:24 +0000 | [diff] [blame] | 200 | } |
| 201 | #endif /* DATA_SIZE == 4 */ |
| 202 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 203 | #endif /* ACCESS_TYPE != (NB_MMU_MODES + 1) */ |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 204 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 205 | #undef RES_TYPE |
| 206 | #undef DATA_TYPE |
| 207 | #undef DATA_STYPE |
| 208 | #undef SUFFIX |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 209 | #undef USUFFIX |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 210 | #undef DATA_SIZE |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 211 | #undef CPU_MMU_INDEX |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 212 | #undef MMUSUFFIX |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 213 | #undef ADDR_READ |