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 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 | * |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 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 |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 22 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 23 | */ |
Blue Swirl | 29e922b | 2010-03-29 19:24:00 +0000 | [diff] [blame] | 24 | #include "qemu-timer.h" |
Avi Kivity | 0e0df1e | 2012-01-02 00:32:15 +0200 | [diff] [blame] | 25 | #include "memory.h" |
Blue Swirl | 29e922b | 2010-03-29 19:24:00 +0000 | [diff] [blame] | 26 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 27 | #define DATA_SIZE (1 << SHIFT) |
| 28 | |
| 29 | #if DATA_SIZE == 8 |
| 30 | #define SUFFIX q |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 31 | #define USUFFIX q |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 32 | #define DATA_TYPE uint64_t |
| 33 | #elif DATA_SIZE == 4 |
| 34 | #define SUFFIX l |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 35 | #define USUFFIX l |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 36 | #define DATA_TYPE uint32_t |
| 37 | #elif DATA_SIZE == 2 |
| 38 | #define SUFFIX w |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 39 | #define USUFFIX uw |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 40 | #define DATA_TYPE uint16_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 | #else |
| 46 | #error unsupported data size |
| 47 | #endif |
| 48 | |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 49 | #ifdef SOFTMMU_CODE_ACCESS |
| 50 | #define READ_ACCESS_TYPE 2 |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 51 | #define ADDR_READ addr_code |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 52 | #else |
| 53 | #define READ_ACCESS_TYPE 0 |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 54 | #define ADDR_READ addr_read |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 57 | #ifndef CONFIG_TCG_PASS_AREG0 |
| 58 | #define ENV_PARAM |
| 59 | #define ENV_VAR |
| 60 | #define CPU_PREFIX |
| 61 | #define HELPER_PREFIX __ |
| 62 | #else |
| 63 | #define ENV_PARAM CPUArchState *env, |
| 64 | #define ENV_VAR env, |
| 65 | #define CPU_PREFIX cpu_ |
| 66 | #define HELPER_PREFIX helper_ |
| 67 | #endif |
| 68 | |
| 69 | static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 70 | target_ulong addr, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 71 | int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 72 | uintptr_t retaddr); |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 73 | static inline DATA_TYPE glue(io_read, SUFFIX)(ENV_PARAM |
| 74 | target_phys_addr_t physaddr, |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 75 | target_ulong addr, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 76 | uintptr_t retaddr) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 77 | { |
| 78 | DATA_TYPE res; |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 79 | MemoryRegion *mr = iotlb_to_region(physaddr); |
| 80 | |
pbrook | 0f459d1 | 2008-06-09 00:20:13 +0000 | [diff] [blame] | 81 | physaddr = (physaddr & TARGET_PAGE_MASK) + addr; |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 82 | env->mem_io_pc = retaddr; |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 83 | if (mr != &io_mem_ram && mr != &io_mem_rom |
| 84 | && mr != &io_mem_unassigned |
| 85 | && mr != &io_mem_notdirty |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 86 | && !can_do_io(env)) { |
| 87 | cpu_io_recompile(env, retaddr); |
| 88 | } |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 89 | |
aliguori | db8886d | 2008-11-18 20:09:43 +0000 | [diff] [blame] | 90 | env->mem_io_vaddr = addr; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 91 | #if SHIFT <= 2 |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 92 | res = io_mem_read(mr, physaddr, 1 << SHIFT); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 93 | #else |
| 94 | #ifdef TARGET_WORDS_BIGENDIAN |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 95 | res = io_mem_read(mr, physaddr, 4) << 32; |
| 96 | res |= io_mem_read(mr, physaddr + 4, 4); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 97 | #else |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 98 | res = io_mem_read(mr, physaddr, 4); |
| 99 | res |= io_mem_read(mr, physaddr + 4, 4) << 32; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 100 | #endif |
| 101 | #endif /* SHIFT > 2 */ |
| 102 | return res; |
| 103 | } |
| 104 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 105 | /* handle all cases except unaligned access which span two pages */ |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 106 | DATA_TYPE |
| 107 | glue(glue(glue(HELPER_PREFIX, ld), SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 108 | target_ulong addr, |
| 109 | int mmu_idx) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 110 | { |
| 111 | DATA_TYPE res; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 112 | int index; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 113 | target_ulong tlb_addr; |
Paul Brook | 355b194 | 2010-04-05 00:28:53 +0100 | [diff] [blame] | 114 | target_phys_addr_t ioaddr; |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 115 | uintptr_t retaddr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 116 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 117 | /* test if there is match for unaligned or IO access */ |
| 118 | /* XXX: could done more in memory macro in a non portable way */ |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 119 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 120 | redo: |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 121 | tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 122 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 123 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
| 124 | /* IO access */ |
| 125 | if ((addr & (DATA_SIZE - 1)) != 0) |
| 126 | goto do_unaligned_access; |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 127 | retaddr = GETPC(); |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 128 | ioaddr = env->iotlb[mmu_idx][index]; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 129 | res = glue(io_read, SUFFIX)(ENV_VAR ioaddr, addr, retaddr); |
bellard | 9869996 | 2005-11-26 10:29:22 +0000 | [diff] [blame] | 130 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 131 | /* slow unaligned access (it spans two pages or IO) */ |
| 132 | do_unaligned_access: |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 133 | retaddr = GETPC(); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 134 | #ifdef ALIGNED_ONLY |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 135 | do_unaligned_access(ENV_VAR addr, READ_ACCESS_TYPE, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 136 | #endif |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 137 | res = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(ENV_VAR addr, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 138 | mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 139 | } else { |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 140 | /* unaligned/aligned access in the same page */ |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 141 | uintptr_t addend; |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 142 | #ifdef ALIGNED_ONLY |
| 143 | if ((addr & (DATA_SIZE - 1)) != 0) { |
| 144 | retaddr = GETPC(); |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 145 | do_unaligned_access(ENV_VAR addr, READ_ACCESS_TYPE, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 146 | } |
| 147 | #endif |
pbrook | 0f459d1 | 2008-06-09 00:20:13 +0000 | [diff] [blame] | 148 | addend = env->tlb_table[mmu_idx][index].addend; |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 149 | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)(intptr_t) |
| 150 | (addr + addend)); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 151 | } |
| 152 | } else { |
| 153 | /* the page is not in the TLB : fill it */ |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 154 | retaddr = GETPC(); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 155 | #ifdef ALIGNED_ONLY |
| 156 | if ((addr & (DATA_SIZE - 1)) != 0) |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 157 | do_unaligned_access(ENV_VAR addr, READ_ACCESS_TYPE, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 158 | #endif |
Blue Swirl | bccd9ec | 2011-07-04 20:57:05 +0000 | [diff] [blame] | 159 | tlb_fill(env, addr, READ_ACCESS_TYPE, mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 160 | goto redo; |
| 161 | } |
| 162 | return res; |
| 163 | } |
| 164 | |
| 165 | /* handle all unaligned cases */ |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 166 | static DATA_TYPE |
| 167 | glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 168 | target_ulong addr, |
| 169 | int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 170 | uintptr_t retaddr) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 171 | { |
| 172 | DATA_TYPE res, res1, res2; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 173 | int index, shift; |
Paul Brook | 355b194 | 2010-04-05 00:28:53 +0100 | [diff] [blame] | 174 | target_phys_addr_t ioaddr; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 175 | target_ulong tlb_addr, addr1, addr2; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 176 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 177 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 178 | redo: |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 179 | tlb_addr = env->tlb_table[mmu_idx][index].ADDR_READ; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 180 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 181 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
| 182 | /* IO access */ |
| 183 | if ((addr & (DATA_SIZE - 1)) != 0) |
| 184 | goto do_unaligned_access; |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 185 | ioaddr = env->iotlb[mmu_idx][index]; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 186 | res = glue(io_read, SUFFIX)(ENV_VAR ioaddr, addr, retaddr); |
bellard | 9869996 | 2005-11-26 10:29:22 +0000 | [diff] [blame] | 187 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 188 | do_unaligned_access: |
| 189 | /* slow unaligned access (it spans two pages) */ |
| 190 | addr1 = addr & ~(DATA_SIZE - 1); |
| 191 | addr2 = addr1 + DATA_SIZE; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 192 | res1 = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(ENV_VAR addr1, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 193 | mmu_idx, retaddr); |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 194 | res2 = glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(ENV_VAR addr2, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 195 | mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 196 | shift = (addr & (DATA_SIZE - 1)) * 8; |
| 197 | #ifdef TARGET_WORDS_BIGENDIAN |
| 198 | res = (res1 << shift) | (res2 >> ((DATA_SIZE * 8) - shift)); |
| 199 | #else |
| 200 | res = (res1 >> shift) | (res2 << ((DATA_SIZE * 8) - shift)); |
| 201 | #endif |
bellard | 6986f88 | 2004-01-18 21:53:18 +0000 | [diff] [blame] | 202 | res = (DATA_TYPE)res; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 203 | } else { |
| 204 | /* unaligned/aligned access in the same page */ |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 205 | uintptr_t addend = env->tlb_table[mmu_idx][index].addend; |
| 206 | res = glue(glue(ld, USUFFIX), _raw)((uint8_t *)(intptr_t) |
| 207 | (addr + addend)); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 208 | } |
| 209 | } else { |
| 210 | /* the page is not in the TLB : fill it */ |
Blue Swirl | bccd9ec | 2011-07-04 20:57:05 +0000 | [diff] [blame] | 211 | tlb_fill(env, addr, READ_ACCESS_TYPE, mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 212 | goto redo; |
| 213 | } |
| 214 | return res; |
| 215 | } |
| 216 | |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 217 | #ifndef SOFTMMU_CODE_ACCESS |
| 218 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 219 | static void glue(glue(slow_st, SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 220 | target_ulong addr, |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 221 | DATA_TYPE val, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 222 | int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 223 | uintptr_t retaddr); |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 224 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 225 | static inline void glue(io_write, SUFFIX)(ENV_PARAM |
| 226 | target_phys_addr_t physaddr, |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 227 | DATA_TYPE val, |
pbrook | 0f459d1 | 2008-06-09 00:20:13 +0000 | [diff] [blame] | 228 | target_ulong addr, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 229 | uintptr_t retaddr) |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 230 | { |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 231 | MemoryRegion *mr = iotlb_to_region(physaddr); |
| 232 | |
pbrook | 0f459d1 | 2008-06-09 00:20:13 +0000 | [diff] [blame] | 233 | physaddr = (physaddr & TARGET_PAGE_MASK) + addr; |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 234 | if (mr != &io_mem_ram && mr != &io_mem_rom |
| 235 | && mr != &io_mem_unassigned |
| 236 | && mr != &io_mem_notdirty |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 237 | && !can_do_io(env)) { |
| 238 | cpu_io_recompile(env, retaddr); |
| 239 | } |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 240 | |
pbrook | 2e70f6e | 2008-06-29 01:03:05 +0000 | [diff] [blame] | 241 | env->mem_io_vaddr = addr; |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 242 | env->mem_io_pc = retaddr; |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 243 | #if SHIFT <= 2 |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 244 | io_mem_write(mr, physaddr, val, 1 << SHIFT); |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 245 | #else |
| 246 | #ifdef TARGET_WORDS_BIGENDIAN |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 247 | io_mem_write(mr, physaddr, (val >> 32), 4); |
| 248 | io_mem_write(mr, physaddr + 4, (uint32_t)val, 4); |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 249 | #else |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 250 | io_mem_write(mr, physaddr, (uint32_t)val, 4); |
| 251 | io_mem_write(mr, physaddr + 4, val >> 32, 4); |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 252 | #endif |
| 253 | #endif /* SHIFT > 2 */ |
| 254 | } |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 255 | |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 256 | void glue(glue(glue(HELPER_PREFIX, st), SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 257 | target_ulong addr, |
| 258 | DATA_TYPE val, |
| 259 | int mmu_idx) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 260 | { |
Paul Brook | 355b194 | 2010-04-05 00:28:53 +0100 | [diff] [blame] | 261 | target_phys_addr_t ioaddr; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 262 | target_ulong tlb_addr; |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 263 | uintptr_t retaddr; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 264 | int index; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 265 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 266 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 267 | redo: |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 268 | tlb_addr = env->tlb_table[mmu_idx][index].addr_write; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 269 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 270 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
| 271 | /* IO access */ |
| 272 | if ((addr & (DATA_SIZE - 1)) != 0) |
| 273 | goto do_unaligned_access; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 274 | retaddr = GETPC(); |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 275 | ioaddr = env->iotlb[mmu_idx][index]; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 276 | glue(io_write, SUFFIX)(ENV_VAR ioaddr, val, addr, retaddr); |
bellard | 9869996 | 2005-11-26 10:29:22 +0000 | [diff] [blame] | 277 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 278 | do_unaligned_access: |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 279 | retaddr = GETPC(); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 280 | #ifdef ALIGNED_ONLY |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 281 | do_unaligned_access(ENV_VAR addr, 1, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 282 | #endif |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 283 | glue(glue(slow_st, SUFFIX), MMUSUFFIX)(ENV_VAR addr, val, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 284 | mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 285 | } else { |
| 286 | /* aligned/unaligned access in the same page */ |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 287 | uintptr_t addend; |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 288 | #ifdef ALIGNED_ONLY |
| 289 | if ((addr & (DATA_SIZE - 1)) != 0) { |
| 290 | retaddr = GETPC(); |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 291 | do_unaligned_access(ENV_VAR addr, 1, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 292 | } |
| 293 | #endif |
pbrook | 0f459d1 | 2008-06-09 00:20:13 +0000 | [diff] [blame] | 294 | addend = env->tlb_table[mmu_idx][index].addend; |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 295 | glue(glue(st, SUFFIX), _raw)((uint8_t *)(intptr_t) |
| 296 | (addr + addend), val); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 297 | } |
| 298 | } else { |
| 299 | /* the page is not in the TLB : fill it */ |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 300 | retaddr = GETPC(); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 301 | #ifdef ALIGNED_ONLY |
| 302 | if ((addr & (DATA_SIZE - 1)) != 0) |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 303 | do_unaligned_access(ENV_VAR addr, 1, mmu_idx, retaddr); |
bellard | a64d471 | 2005-12-05 19:57:57 +0000 | [diff] [blame] | 304 | #endif |
Blue Swirl | bccd9ec | 2011-07-04 20:57:05 +0000 | [diff] [blame] | 305 | tlb_fill(env, addr, 1, mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 306 | goto redo; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* handles all unaligned cases */ |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 311 | static void glue(glue(slow_st, SUFFIX), MMUSUFFIX)(ENV_PARAM |
| 312 | target_ulong addr, |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 313 | DATA_TYPE val, |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 314 | int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 315 | uintptr_t retaddr) |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 316 | { |
Paul Brook | 355b194 | 2010-04-05 00:28:53 +0100 | [diff] [blame] | 317 | target_phys_addr_t ioaddr; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 318 | target_ulong tlb_addr; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 319 | int index, i; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 320 | |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 321 | index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 322 | redo: |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 323 | tlb_addr = env->tlb_table[mmu_idx][index].addr_write; |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 324 | if ((addr & TARGET_PAGE_MASK) == (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 325 | if (tlb_addr & ~TARGET_PAGE_MASK) { |
| 326 | /* IO access */ |
| 327 | if ((addr & (DATA_SIZE - 1)) != 0) |
| 328 | goto do_unaligned_access; |
Avi Kivity | 37ec01d | 2012-03-08 18:08:35 +0200 | [diff] [blame] | 329 | ioaddr = env->iotlb[mmu_idx][index]; |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 330 | glue(io_write, SUFFIX)(ENV_VAR ioaddr, val, addr, retaddr); |
bellard | 9869996 | 2005-11-26 10:29:22 +0000 | [diff] [blame] | 331 | } else if (((addr & ~TARGET_PAGE_MASK) + DATA_SIZE - 1) >= TARGET_PAGE_SIZE) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 332 | do_unaligned_access: |
| 333 | /* XXX: not efficient, but simple */ |
balrog | 6c41b27 | 2007-11-17 12:12:29 +0000 | [diff] [blame] | 334 | /* Note: relies on the fact that tlb_fill() does not remove the |
| 335 | * previous page from the TLB cache. */ |
balrog | 7221fa9 | 2007-11-17 09:53:42 +0000 | [diff] [blame] | 336 | for(i = DATA_SIZE - 1; i >= 0; i--) { |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 337 | #ifdef TARGET_WORDS_BIGENDIAN |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 338 | glue(slow_stb, MMUSUFFIX)(ENV_VAR addr + i, |
| 339 | val >> (((DATA_SIZE - 1) * 8) - (i * 8)), |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 340 | mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 341 | #else |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 342 | glue(slow_stb, MMUSUFFIX)(ENV_VAR addr + i, |
| 343 | val >> (i * 8), |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 344 | mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 345 | #endif |
| 346 | } |
| 347 | } else { |
| 348 | /* aligned/unaligned access in the same page */ |
Stefan Weil | b065927 | 2012-04-12 14:14:51 +0200 | [diff] [blame] | 349 | uintptr_t addend = env->tlb_table[mmu_idx][index].addend; |
| 350 | glue(glue(st, SUFFIX), _raw)((uint8_t *)(intptr_t) |
| 351 | (addr + addend), val); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 352 | } |
| 353 | } else { |
| 354 | /* the page is not in the TLB : fill it */ |
Blue Swirl | bccd9ec | 2011-07-04 20:57:05 +0000 | [diff] [blame] | 355 | tlb_fill(env, addr, 1, mmu_idx, retaddr); |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 356 | goto redo; |
| 357 | } |
| 358 | } |
| 359 | |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 360 | #endif /* !defined(SOFTMMU_CODE_ACCESS) */ |
| 361 | |
| 362 | #undef READ_ACCESS_TYPE |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 363 | #undef SHIFT |
| 364 | #undef DATA_TYPE |
| 365 | #undef SUFFIX |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 366 | #undef USUFFIX |
bellard | b92e5a2 | 2003-08-08 23:58:05 +0000 | [diff] [blame] | 367 | #undef DATA_SIZE |
bellard | 84b7b8e | 2005-11-28 21:19:04 +0000 | [diff] [blame] | 368 | #undef ADDR_READ |
Blue Swirl | e141ab5 | 2011-09-18 14:55:46 +0000 | [diff] [blame] | 369 | #undef ENV_PARAM |
| 370 | #undef ENV_VAR |
| 371 | #undef CPU_PREFIX |
| 372 | #undef HELPER_PREFIX |