bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 1 | /* |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 2 | * virtual page mapping and translated block handling |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 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 | */ |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 20 | #include "config.h" |
bellard | d5a8f07 | 2004-09-29 21:15:28 +0000 | [diff] [blame] | 21 | #ifdef _WIN32 |
| 22 | #include <windows.h> |
| 23 | #else |
bellard | a98d49b | 2004-11-14 16:22:05 +0000 | [diff] [blame] | 24 | #include <sys/types.h> |
bellard | d5a8f07 | 2004-09-29 21:15:28 +0000 | [diff] [blame] | 25 | #include <sys/mman.h> |
| 26 | #endif |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include <stdio.h> |
| 29 | #include <stdarg.h> |
| 30 | #include <string.h> |
| 31 | #include <errno.h> |
| 32 | #include <unistd.h> |
| 33 | #include <inttypes.h> |
| 34 | |
bellard | 6180a18 | 2003-09-30 21:04:53 +0000 | [diff] [blame] | 35 | #include "cpu.h" |
| 36 | #include "exec-all.h" |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 37 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 38 | //#define DEBUG_TB_INVALIDATE |
bellard | 66e85a2 | 2003-06-24 13:28:12 +0000 | [diff] [blame] | 39 | //#define DEBUG_FLUSH |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 40 | //#define DEBUG_TLB |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 41 | |
| 42 | /* make various TB consistency checks */ |
| 43 | //#define DEBUG_TB_CHECK |
bellard | 9885788 | 2004-01-18 21:52:14 +0000 | [diff] [blame] | 44 | //#define DEBUG_TLB_CHECK |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 45 | |
| 46 | /* threshold to flush the translated code buffer */ |
| 47 | #define CODE_GEN_BUFFER_MAX_SIZE (CODE_GEN_BUFFER_SIZE - CODE_GEN_MAX_SIZE) |
| 48 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 49 | #define SMC_BITMAP_USE_THRESHOLD 10 |
| 50 | |
| 51 | #define MMAP_AREA_START 0x00000000 |
| 52 | #define MMAP_AREA_END 0xa8000000 |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 53 | |
| 54 | TranslationBlock tbs[CODE_GEN_MAX_BLOCKS]; |
| 55 | TranslationBlock *tb_hash[CODE_GEN_HASH_SIZE]; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 56 | TranslationBlock *tb_phys_hash[CODE_GEN_PHYS_HASH_SIZE]; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 57 | int nb_tbs; |
bellard | eb51d10 | 2003-05-14 21:51:13 +0000 | [diff] [blame] | 58 | /* any access to the tbs or the page table must use this lock */ |
| 59 | spinlock_t tb_lock = SPIN_LOCK_UNLOCKED; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 60 | |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 61 | uint8_t code_gen_buffer[CODE_GEN_BUFFER_SIZE] __attribute__((aligned (32))); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 62 | uint8_t *code_gen_ptr; |
| 63 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 64 | int phys_ram_size; |
| 65 | int phys_ram_fd; |
| 66 | uint8_t *phys_ram_base; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 67 | uint8_t *phys_ram_dirty; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 68 | |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 69 | typedef struct PageDesc { |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 70 | /* list of TBs intersecting this ram page */ |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 71 | TranslationBlock *first_tb; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 72 | /* in order to optimize self modifying code, we count the number |
| 73 | of lookups we do to a given page to use a bitmap */ |
| 74 | unsigned int code_write_count; |
| 75 | uint8_t *code_bitmap; |
| 76 | #if defined(CONFIG_USER_ONLY) |
| 77 | unsigned long flags; |
| 78 | #endif |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 79 | } PageDesc; |
| 80 | |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 81 | typedef struct PhysPageDesc { |
| 82 | /* offset in host memory of the page + io_index in the low 12 bits */ |
bellard | e04f40b | 2005-04-24 18:02:38 +0000 | [diff] [blame] | 83 | uint32_t phys_offset; |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 84 | } PhysPageDesc; |
| 85 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 86 | /* Note: the VirtPage handling is absolete and will be suppressed |
| 87 | ASAP */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 88 | typedef struct VirtPageDesc { |
| 89 | /* physical address of code page. It is valid only if 'valid_tag' |
| 90 | matches 'virt_valid_tag' */ |
| 91 | target_ulong phys_addr; |
| 92 | unsigned int valid_tag; |
| 93 | #if !defined(CONFIG_SOFTMMU) |
| 94 | /* original page access rights. It is valid only if 'valid_tag' |
| 95 | matches 'virt_valid_tag' */ |
| 96 | unsigned int prot; |
| 97 | #endif |
| 98 | } VirtPageDesc; |
| 99 | |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 100 | #define L2_BITS 10 |
| 101 | #define L1_BITS (32 - L2_BITS - TARGET_PAGE_BITS) |
| 102 | |
| 103 | #define L1_SIZE (1 << L1_BITS) |
| 104 | #define L2_SIZE (1 << L2_BITS) |
| 105 | |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 106 | static void io_mem_init(void); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 107 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 108 | unsigned long qemu_real_host_page_size; |
| 109 | unsigned long qemu_host_page_bits; |
| 110 | unsigned long qemu_host_page_size; |
| 111 | unsigned long qemu_host_page_mask; |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 112 | |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 113 | /* XXX: for system emulation, it could just be an array */ |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 114 | static PageDesc *l1_map[L1_SIZE]; |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 115 | PhysPageDesc **l1_phys_map; |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 116 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 117 | #if !defined(CONFIG_USER_ONLY) |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 118 | #if TARGET_LONG_BITS > 32 |
| 119 | #define VIRT_L_BITS 9 |
| 120 | #define VIRT_L_SIZE (1 << VIRT_L_BITS) |
| 121 | static void *l1_virt_map[VIRT_L_SIZE]; |
| 122 | #else |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 123 | static VirtPageDesc *l1_virt_map[L1_SIZE]; |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 124 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 125 | static unsigned int virt_valid_tag; |
| 126 | #endif |
| 127 | |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 128 | /* io memory support */ |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 129 | CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; |
| 130 | CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 131 | void *io_mem_opaque[IO_MEM_NB_ENTRIES]; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 132 | static int io_mem_nb; |
| 133 | |
bellard | 3486513 | 2003-10-05 14:28:56 +0000 | [diff] [blame] | 134 | /* log support */ |
| 135 | char *logfilename = "/tmp/qemu.log"; |
| 136 | FILE *logfile; |
| 137 | int loglevel; |
| 138 | |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 139 | /* statistics */ |
| 140 | static int tlb_flush_count; |
| 141 | static int tb_flush_count; |
| 142 | static int tb_phys_invalidate_count; |
| 143 | |
bellard | b346ff4 | 2003-06-15 20:05:50 +0000 | [diff] [blame] | 144 | static void page_init(void) |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 145 | { |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 146 | /* NOTE: we can always suppose that qemu_host_page_size >= |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 147 | TARGET_PAGE_SIZE */ |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 148 | #ifdef _WIN32 |
bellard | d5a8f07 | 2004-09-29 21:15:28 +0000 | [diff] [blame] | 149 | { |
| 150 | SYSTEM_INFO system_info; |
| 151 | DWORD old_protect; |
| 152 | |
| 153 | GetSystemInfo(&system_info); |
| 154 | qemu_real_host_page_size = system_info.dwPageSize; |
| 155 | |
| 156 | VirtualProtect(code_gen_buffer, sizeof(code_gen_buffer), |
| 157 | PAGE_EXECUTE_READWRITE, &old_protect); |
| 158 | } |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 159 | #else |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 160 | qemu_real_host_page_size = getpagesize(); |
bellard | d5a8f07 | 2004-09-29 21:15:28 +0000 | [diff] [blame] | 161 | { |
| 162 | unsigned long start, end; |
| 163 | |
| 164 | start = (unsigned long)code_gen_buffer; |
| 165 | start &= ~(qemu_real_host_page_size - 1); |
| 166 | |
| 167 | end = (unsigned long)code_gen_buffer + sizeof(code_gen_buffer); |
| 168 | end += qemu_real_host_page_size - 1; |
| 169 | end &= ~(qemu_real_host_page_size - 1); |
| 170 | |
| 171 | mprotect((void *)start, end - start, |
| 172 | PROT_READ | PROT_WRITE | PROT_EXEC); |
| 173 | } |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 174 | #endif |
bellard | d5a8f07 | 2004-09-29 21:15:28 +0000 | [diff] [blame] | 175 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 176 | if (qemu_host_page_size == 0) |
| 177 | qemu_host_page_size = qemu_real_host_page_size; |
| 178 | if (qemu_host_page_size < TARGET_PAGE_SIZE) |
| 179 | qemu_host_page_size = TARGET_PAGE_SIZE; |
| 180 | qemu_host_page_bits = 0; |
| 181 | while ((1 << qemu_host_page_bits) < qemu_host_page_size) |
| 182 | qemu_host_page_bits++; |
| 183 | qemu_host_page_mask = ~(qemu_host_page_size - 1); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 184 | #if !defined(CONFIG_USER_ONLY) |
| 185 | virt_valid_tag = 1; |
| 186 | #endif |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 187 | l1_phys_map = qemu_vmalloc(L1_SIZE * sizeof(PhysPageDesc *)); |
| 188 | memset(l1_phys_map, 0, L1_SIZE * sizeof(PhysPageDesc *)); |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 189 | } |
| 190 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 191 | static inline PageDesc *page_find_alloc(unsigned int index) |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 192 | { |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 193 | PageDesc **lp, *p; |
| 194 | |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 195 | lp = &l1_map[index >> L2_BITS]; |
| 196 | p = *lp; |
| 197 | if (!p) { |
| 198 | /* allocate if not found */ |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 199 | p = qemu_malloc(sizeof(PageDesc) * L2_SIZE); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 200 | memset(p, 0, sizeof(PageDesc) * L2_SIZE); |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 201 | *lp = p; |
| 202 | } |
| 203 | return p + (index & (L2_SIZE - 1)); |
| 204 | } |
| 205 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 206 | static inline PageDesc *page_find(unsigned int index) |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 207 | { |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 208 | PageDesc *p; |
| 209 | |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 210 | p = l1_map[index >> L2_BITS]; |
| 211 | if (!p) |
| 212 | return 0; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 213 | return p + (index & (L2_SIZE - 1)); |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 214 | } |
| 215 | |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 216 | static inline PhysPageDesc *phys_page_find_alloc(unsigned int index) |
| 217 | { |
| 218 | PhysPageDesc **lp, *p; |
| 219 | |
| 220 | lp = &l1_phys_map[index >> L2_BITS]; |
| 221 | p = *lp; |
| 222 | if (!p) { |
| 223 | /* allocate if not found */ |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 224 | p = qemu_vmalloc(sizeof(PhysPageDesc) * L2_SIZE); |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 225 | memset(p, 0, sizeof(PhysPageDesc) * L2_SIZE); |
| 226 | *lp = p; |
| 227 | } |
| 228 | return p + (index & (L2_SIZE - 1)); |
| 229 | } |
| 230 | |
| 231 | static inline PhysPageDesc *phys_page_find(unsigned int index) |
| 232 | { |
| 233 | PhysPageDesc *p; |
| 234 | |
| 235 | p = l1_phys_map[index >> L2_BITS]; |
| 236 | if (!p) |
| 237 | return 0; |
| 238 | return p + (index & (L2_SIZE - 1)); |
| 239 | } |
| 240 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 241 | #if !defined(CONFIG_USER_ONLY) |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 242 | static void tlb_protect_code(CPUState *env, target_ulong addr); |
| 243 | static void tlb_unprotect_code_phys(CPUState *env, unsigned long phys_addr, target_ulong vaddr); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 244 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 245 | static VirtPageDesc *virt_page_find_alloc(target_ulong index, int alloc) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 246 | { |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 247 | #if TARGET_LONG_BITS > 32 |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 248 | void **p, **lp; |
| 249 | |
| 250 | p = l1_virt_map; |
| 251 | lp = p + ((index >> (5 * VIRT_L_BITS)) & (VIRT_L_SIZE - 1)); |
| 252 | p = *lp; |
| 253 | if (!p) { |
| 254 | if (!alloc) |
| 255 | return NULL; |
| 256 | p = qemu_mallocz(sizeof(void *) * VIRT_L_SIZE); |
| 257 | *lp = p; |
| 258 | } |
| 259 | lp = p + ((index >> (4 * VIRT_L_BITS)) & (VIRT_L_SIZE - 1)); |
| 260 | p = *lp; |
| 261 | if (!p) { |
| 262 | if (!alloc) |
| 263 | return NULL; |
| 264 | p = qemu_mallocz(sizeof(void *) * VIRT_L_SIZE); |
| 265 | *lp = p; |
| 266 | } |
| 267 | lp = p + ((index >> (3 * VIRT_L_BITS)) & (VIRT_L_SIZE - 1)); |
| 268 | p = *lp; |
| 269 | if (!p) { |
| 270 | if (!alloc) |
| 271 | return NULL; |
| 272 | p = qemu_mallocz(sizeof(void *) * VIRT_L_SIZE); |
| 273 | *lp = p; |
| 274 | } |
| 275 | lp = p + ((index >> (2 * VIRT_L_BITS)) & (VIRT_L_SIZE - 1)); |
| 276 | p = *lp; |
| 277 | if (!p) { |
| 278 | if (!alloc) |
| 279 | return NULL; |
| 280 | p = qemu_mallocz(sizeof(void *) * VIRT_L_SIZE); |
| 281 | *lp = p; |
| 282 | } |
| 283 | lp = p + ((index >> (1 * VIRT_L_BITS)) & (VIRT_L_SIZE - 1)); |
| 284 | p = *lp; |
| 285 | if (!p) { |
| 286 | if (!alloc) |
| 287 | return NULL; |
| 288 | p = qemu_mallocz(sizeof(VirtPageDesc) * VIRT_L_SIZE); |
| 289 | *lp = p; |
| 290 | } |
| 291 | return ((VirtPageDesc *)p) + (index & (VIRT_L_SIZE - 1)); |
| 292 | #else |
| 293 | VirtPageDesc *p, **lp; |
| 294 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 295 | lp = &l1_virt_map[index >> L2_BITS]; |
| 296 | p = *lp; |
| 297 | if (!p) { |
| 298 | /* allocate if not found */ |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 299 | if (!alloc) |
| 300 | return NULL; |
| 301 | p = qemu_mallocz(sizeof(VirtPageDesc) * L2_SIZE); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 302 | *lp = p; |
| 303 | } |
| 304 | return p + (index & (L2_SIZE - 1)); |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 305 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 306 | } |
| 307 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 308 | static inline VirtPageDesc *virt_page_find(target_ulong index) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 309 | { |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 310 | return virt_page_find_alloc(index, 0); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 311 | } |
| 312 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 313 | #if TARGET_LONG_BITS > 32 |
| 314 | static void virt_page_flush_internal(void **p, int level) |
| 315 | { |
| 316 | int i; |
| 317 | if (level == 0) { |
| 318 | VirtPageDesc *q = (VirtPageDesc *)p; |
| 319 | for(i = 0; i < VIRT_L_SIZE; i++) |
| 320 | q[i].valid_tag = 0; |
| 321 | } else { |
| 322 | level--; |
| 323 | for(i = 0; i < VIRT_L_SIZE; i++) { |
| 324 | if (p[i]) |
| 325 | virt_page_flush_internal(p[i], level); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | #endif |
| 330 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 331 | static void virt_page_flush(void) |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 332 | { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 333 | virt_valid_tag++; |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 334 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 335 | if (virt_valid_tag == 0) { |
| 336 | virt_valid_tag = 1; |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 337 | #if TARGET_LONG_BITS > 32 |
| 338 | virt_page_flush_internal(l1_virt_map, 5); |
| 339 | #else |
| 340 | { |
| 341 | int i, j; |
| 342 | VirtPageDesc *p; |
| 343 | for(i = 0; i < L1_SIZE; i++) { |
| 344 | p = l1_virt_map[i]; |
| 345 | if (p) { |
| 346 | for(j = 0; j < L2_SIZE; j++) |
| 347 | p[j].valid_tag = 0; |
| 348 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 349 | } |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 350 | } |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 351 | #endif |
bellard | 5493600 | 2003-05-13 00:25:15 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 354 | #else |
| 355 | static void virt_page_flush(void) |
| 356 | { |
| 357 | } |
| 358 | #endif |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 359 | |
bellard | b346ff4 | 2003-06-15 20:05:50 +0000 | [diff] [blame] | 360 | void cpu_exec_init(void) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 361 | { |
| 362 | if (!code_gen_ptr) { |
| 363 | code_gen_ptr = code_gen_buffer; |
bellard | b346ff4 | 2003-06-15 20:05:50 +0000 | [diff] [blame] | 364 | page_init(); |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 365 | io_mem_init(); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 369 | static inline void invalidate_page_bitmap(PageDesc *p) |
| 370 | { |
| 371 | if (p->code_bitmap) { |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 372 | qemu_free(p->code_bitmap); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 373 | p->code_bitmap = NULL; |
| 374 | } |
| 375 | p->code_write_count = 0; |
| 376 | } |
| 377 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 378 | /* set to NULL all the 'first_tb' fields in all PageDescs */ |
| 379 | static void page_flush_tb(void) |
| 380 | { |
| 381 | int i, j; |
| 382 | PageDesc *p; |
| 383 | |
| 384 | for(i = 0; i < L1_SIZE; i++) { |
| 385 | p = l1_map[i]; |
| 386 | if (p) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 387 | for(j = 0; j < L2_SIZE; j++) { |
| 388 | p->first_tb = NULL; |
| 389 | invalidate_page_bitmap(p); |
| 390 | p++; |
| 391 | } |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /* flush all the translation blocks */ |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 397 | /* XXX: tb_flush is currently not thread safe */ |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 398 | void tb_flush(CPUState *env) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 399 | { |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 400 | #if defined(DEBUG_FLUSH) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 401 | printf("qemu: flush code_size=%d nb_tbs=%d avg_tb_size=%d\n", |
| 402 | code_gen_ptr - code_gen_buffer, |
| 403 | nb_tbs, |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 404 | nb_tbs > 0 ? (code_gen_ptr - code_gen_buffer) / nb_tbs : 0); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 405 | #endif |
| 406 | nb_tbs = 0; |
bellard | 8a8a608 | 2004-10-03 13:36:49 +0000 | [diff] [blame] | 407 | memset (tb_hash, 0, CODE_GEN_HASH_SIZE * sizeof (void *)); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 408 | virt_page_flush(); |
| 409 | |
bellard | 8a8a608 | 2004-10-03 13:36:49 +0000 | [diff] [blame] | 410 | memset (tb_phys_hash, 0, CODE_GEN_PHYS_HASH_SIZE * sizeof (void *)); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 411 | page_flush_tb(); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 412 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 413 | code_gen_ptr = code_gen_buffer; |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 414 | /* XXX: flush processor icache at this point if cache flush is |
| 415 | expensive */ |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 416 | tb_flush_count++; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | #ifdef DEBUG_TB_CHECK |
| 420 | |
| 421 | static void tb_invalidate_check(unsigned long address) |
| 422 | { |
| 423 | TranslationBlock *tb; |
| 424 | int i; |
| 425 | address &= TARGET_PAGE_MASK; |
| 426 | for(i = 0;i < CODE_GEN_HASH_SIZE; i++) { |
| 427 | for(tb = tb_hash[i]; tb != NULL; tb = tb->hash_next) { |
| 428 | if (!(address + TARGET_PAGE_SIZE <= tb->pc || |
| 429 | address >= tb->pc + tb->size)) { |
| 430 | printf("ERROR invalidate: address=%08lx PC=%08lx size=%04x\n", |
| 431 | address, tb->pc, tb->size); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /* verify that all the pages have correct rights for code */ |
| 438 | static void tb_page_check(void) |
| 439 | { |
| 440 | TranslationBlock *tb; |
| 441 | int i, flags1, flags2; |
| 442 | |
| 443 | for(i = 0;i < CODE_GEN_HASH_SIZE; i++) { |
| 444 | for(tb = tb_hash[i]; tb != NULL; tb = tb->hash_next) { |
| 445 | flags1 = page_get_flags(tb->pc); |
| 446 | flags2 = page_get_flags(tb->pc + tb->size - 1); |
| 447 | if ((flags1 & PAGE_WRITE) || (flags2 & PAGE_WRITE)) { |
| 448 | printf("ERROR page flags: PC=%08lx size=%04x f1=%x f2=%x\n", |
| 449 | tb->pc, tb->size, flags1, flags2); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 455 | void tb_jmp_check(TranslationBlock *tb) |
| 456 | { |
| 457 | TranslationBlock *tb1; |
| 458 | unsigned int n1; |
| 459 | |
| 460 | /* suppress any remaining jumps to this TB */ |
| 461 | tb1 = tb->jmp_first; |
| 462 | for(;;) { |
| 463 | n1 = (long)tb1 & 3; |
| 464 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 465 | if (n1 == 2) |
| 466 | break; |
| 467 | tb1 = tb1->jmp_next[n1]; |
| 468 | } |
| 469 | /* check end of list */ |
| 470 | if (tb1 != tb) { |
| 471 | printf("ERROR: jmp_list from 0x%08lx\n", (long)tb); |
| 472 | } |
| 473 | } |
| 474 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 475 | #endif |
| 476 | |
| 477 | /* invalidate one TB */ |
| 478 | static inline void tb_remove(TranslationBlock **ptb, TranslationBlock *tb, |
| 479 | int next_offset) |
| 480 | { |
| 481 | TranslationBlock *tb1; |
| 482 | for(;;) { |
| 483 | tb1 = *ptb; |
| 484 | if (tb1 == tb) { |
| 485 | *ptb = *(TranslationBlock **)((char *)tb1 + next_offset); |
| 486 | break; |
| 487 | } |
| 488 | ptb = (TranslationBlock **)((char *)tb1 + next_offset); |
| 489 | } |
| 490 | } |
| 491 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 492 | static inline void tb_page_remove(TranslationBlock **ptb, TranslationBlock *tb) |
| 493 | { |
| 494 | TranslationBlock *tb1; |
| 495 | unsigned int n1; |
| 496 | |
| 497 | for(;;) { |
| 498 | tb1 = *ptb; |
| 499 | n1 = (long)tb1 & 3; |
| 500 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 501 | if (tb1 == tb) { |
| 502 | *ptb = tb1->page_next[n1]; |
| 503 | break; |
| 504 | } |
| 505 | ptb = &tb1->page_next[n1]; |
| 506 | } |
| 507 | } |
| 508 | |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 509 | static inline void tb_jmp_remove(TranslationBlock *tb, int n) |
| 510 | { |
| 511 | TranslationBlock *tb1, **ptb; |
| 512 | unsigned int n1; |
| 513 | |
| 514 | ptb = &tb->jmp_next[n]; |
| 515 | tb1 = *ptb; |
| 516 | if (tb1) { |
| 517 | /* find tb(n) in circular list */ |
| 518 | for(;;) { |
| 519 | tb1 = *ptb; |
| 520 | n1 = (long)tb1 & 3; |
| 521 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 522 | if (n1 == n && tb1 == tb) |
| 523 | break; |
| 524 | if (n1 == 2) { |
| 525 | ptb = &tb1->jmp_first; |
| 526 | } else { |
| 527 | ptb = &tb1->jmp_next[n1]; |
| 528 | } |
| 529 | } |
| 530 | /* now we can suppress tb(n) from the list */ |
| 531 | *ptb = tb->jmp_next[n]; |
| 532 | |
| 533 | tb->jmp_next[n] = NULL; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | /* reset the jump entry 'n' of a TB so that it is not chained to |
| 538 | another TB */ |
| 539 | static inline void tb_reset_jump(TranslationBlock *tb, int n) |
| 540 | { |
| 541 | tb_set_jmp_target(tb, n, (unsigned long)(tb->tc_ptr + tb->tb_next_offset[n])); |
| 542 | } |
| 543 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 544 | static inline void tb_invalidate(TranslationBlock *tb) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 545 | { |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 546 | unsigned int h, n1; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 547 | TranslationBlock *tb1, *tb2, **ptb; |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 548 | |
bellard | 36bdbe5 | 2003-11-19 22:12:02 +0000 | [diff] [blame] | 549 | tb_invalidated_flag = 1; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 550 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 551 | /* remove the TB from the hash list */ |
| 552 | h = tb_hash_func(tb->pc); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 553 | ptb = &tb_hash[h]; |
| 554 | for(;;) { |
| 555 | tb1 = *ptb; |
| 556 | /* NOTE: the TB is not necessarily linked in the hash. It |
| 557 | indicates that it is not currently used */ |
| 558 | if (tb1 == NULL) |
| 559 | return; |
| 560 | if (tb1 == tb) { |
| 561 | *ptb = tb1->hash_next; |
| 562 | break; |
| 563 | } |
| 564 | ptb = &tb1->hash_next; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 565 | } |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 566 | |
| 567 | /* suppress this TB from the two jump lists */ |
| 568 | tb_jmp_remove(tb, 0); |
| 569 | tb_jmp_remove(tb, 1); |
| 570 | |
| 571 | /* suppress any remaining jumps to this TB */ |
| 572 | tb1 = tb->jmp_first; |
| 573 | for(;;) { |
| 574 | n1 = (long)tb1 & 3; |
| 575 | if (n1 == 2) |
| 576 | break; |
| 577 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 578 | tb2 = tb1->jmp_next[n1]; |
| 579 | tb_reset_jump(tb1, n1); |
| 580 | tb1->jmp_next[n1] = NULL; |
| 581 | tb1 = tb2; |
| 582 | } |
| 583 | tb->jmp_first = (TranslationBlock *)((long)tb | 2); /* fail safe */ |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 584 | } |
| 585 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 586 | static inline void tb_phys_invalidate(TranslationBlock *tb, unsigned int page_addr) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 587 | { |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 588 | PageDesc *p; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 589 | unsigned int h; |
| 590 | target_ulong phys_pc; |
| 591 | |
| 592 | /* remove the TB from the hash list */ |
| 593 | phys_pc = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); |
| 594 | h = tb_phys_hash_func(phys_pc); |
| 595 | tb_remove(&tb_phys_hash[h], tb, |
| 596 | offsetof(TranslationBlock, phys_hash_next)); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 597 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 598 | /* remove the TB from the page list */ |
| 599 | if (tb->page_addr[0] != page_addr) { |
| 600 | p = page_find(tb->page_addr[0] >> TARGET_PAGE_BITS); |
| 601 | tb_page_remove(&p->first_tb, tb); |
| 602 | invalidate_page_bitmap(p); |
| 603 | } |
| 604 | if (tb->page_addr[1] != -1 && tb->page_addr[1] != page_addr) { |
| 605 | p = page_find(tb->page_addr[1] >> TARGET_PAGE_BITS); |
| 606 | tb_page_remove(&p->first_tb, tb); |
| 607 | invalidate_page_bitmap(p); |
| 608 | } |
| 609 | |
| 610 | tb_invalidate(tb); |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 611 | tb_phys_invalidate_count++; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static inline void set_bits(uint8_t *tab, int start, int len) |
| 615 | { |
| 616 | int end, mask, end1; |
| 617 | |
| 618 | end = start + len; |
| 619 | tab += start >> 3; |
| 620 | mask = 0xff << (start & 7); |
| 621 | if ((start & ~7) == (end & ~7)) { |
| 622 | if (start < end) { |
| 623 | mask &= ~(0xff << (end & 7)); |
| 624 | *tab |= mask; |
| 625 | } |
| 626 | } else { |
| 627 | *tab++ |= mask; |
| 628 | start = (start + 8) & ~7; |
| 629 | end1 = end & ~7; |
| 630 | while (start < end1) { |
| 631 | *tab++ = 0xff; |
| 632 | start += 8; |
| 633 | } |
| 634 | if (start < end) { |
| 635 | mask = ~(0xff << (end & 7)); |
| 636 | *tab |= mask; |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | static void build_page_bitmap(PageDesc *p) |
| 642 | { |
| 643 | int n, tb_start, tb_end; |
| 644 | TranslationBlock *tb; |
| 645 | |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 646 | p->code_bitmap = qemu_malloc(TARGET_PAGE_SIZE / 8); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 647 | if (!p->code_bitmap) |
| 648 | return; |
| 649 | memset(p->code_bitmap, 0, TARGET_PAGE_SIZE / 8); |
| 650 | |
| 651 | tb = p->first_tb; |
| 652 | while (tb != NULL) { |
| 653 | n = (long)tb & 3; |
| 654 | tb = (TranslationBlock *)((long)tb & ~3); |
| 655 | /* NOTE: this is subtle as a TB may span two physical pages */ |
| 656 | if (n == 0) { |
| 657 | /* NOTE: tb_end may be after the end of the page, but |
| 658 | it is not a problem */ |
| 659 | tb_start = tb->pc & ~TARGET_PAGE_MASK; |
| 660 | tb_end = tb_start + tb->size; |
| 661 | if (tb_end > TARGET_PAGE_SIZE) |
| 662 | tb_end = TARGET_PAGE_SIZE; |
| 663 | } else { |
| 664 | tb_start = 0; |
| 665 | tb_end = ((tb->pc + tb->size) & ~TARGET_PAGE_MASK); |
| 666 | } |
| 667 | set_bits(p->code_bitmap, tb_start, tb_end - tb_start); |
| 668 | tb = tb->page_next[n]; |
| 669 | } |
| 670 | } |
| 671 | |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 672 | #ifdef TARGET_HAS_PRECISE_SMC |
| 673 | |
| 674 | static void tb_gen_code(CPUState *env, |
| 675 | target_ulong pc, target_ulong cs_base, int flags, |
| 676 | int cflags) |
| 677 | { |
| 678 | TranslationBlock *tb; |
| 679 | uint8_t *tc_ptr; |
| 680 | target_ulong phys_pc, phys_page2, virt_page2; |
| 681 | int code_gen_size; |
| 682 | |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 683 | phys_pc = get_phys_addr_code(env, pc); |
| 684 | tb = tb_alloc(pc); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 685 | if (!tb) { |
| 686 | /* flush must be done */ |
| 687 | tb_flush(env); |
| 688 | /* cannot fail at this point */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 689 | tb = tb_alloc(pc); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 690 | } |
| 691 | tc_ptr = code_gen_ptr; |
| 692 | tb->tc_ptr = tc_ptr; |
| 693 | tb->cs_base = cs_base; |
| 694 | tb->flags = flags; |
| 695 | tb->cflags = cflags; |
| 696 | cpu_gen_code(env, tb, CODE_GEN_MAX_SIZE, &code_gen_size); |
| 697 | code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1)); |
| 698 | |
| 699 | /* check next page if needed */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 700 | virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 701 | phys_page2 = -1; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 702 | if ((pc & TARGET_PAGE_MASK) != virt_page2) { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 703 | phys_page2 = get_phys_addr_code(env, virt_page2); |
| 704 | } |
| 705 | tb_link_phys(tb, phys_pc, phys_page2); |
| 706 | } |
| 707 | #endif |
| 708 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 709 | /* invalidate all TBs which intersect with the target physical page |
| 710 | starting in range [start;end[. NOTE: start and end must refer to |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 711 | the same physical page. 'is_cpu_write_access' should be true if called |
| 712 | from a real cpu write access: the virtual CPU will exit the current |
| 713 | TB if code is modified inside this TB. */ |
| 714 | void tb_invalidate_phys_page_range(target_ulong start, target_ulong end, |
| 715 | int is_cpu_write_access) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 716 | { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 717 | int n, current_tb_modified, current_tb_not_found, current_flags; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 718 | CPUState *env = cpu_single_env; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 719 | PageDesc *p; |
bellard | ea1c180 | 2004-06-14 18:56:36 +0000 | [diff] [blame] | 720 | TranslationBlock *tb, *tb_next, *current_tb, *saved_tb; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 721 | target_ulong tb_start, tb_end; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 722 | target_ulong current_pc, current_cs_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 723 | |
| 724 | p = page_find(start >> TARGET_PAGE_BITS); |
| 725 | if (!p) |
| 726 | return; |
| 727 | if (!p->code_bitmap && |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 728 | ++p->code_write_count >= SMC_BITMAP_USE_THRESHOLD && |
| 729 | is_cpu_write_access) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 730 | /* build code bitmap */ |
| 731 | build_page_bitmap(p); |
| 732 | } |
| 733 | |
| 734 | /* we remove all the TBs in the range [start, end[ */ |
| 735 | /* XXX: see if in some cases it could be faster to invalidate all the code */ |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 736 | current_tb_not_found = is_cpu_write_access; |
| 737 | current_tb_modified = 0; |
| 738 | current_tb = NULL; /* avoid warning */ |
| 739 | current_pc = 0; /* avoid warning */ |
| 740 | current_cs_base = 0; /* avoid warning */ |
| 741 | current_flags = 0; /* avoid warning */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 742 | tb = p->first_tb; |
| 743 | while (tb != NULL) { |
| 744 | n = (long)tb & 3; |
| 745 | tb = (TranslationBlock *)((long)tb & ~3); |
| 746 | tb_next = tb->page_next[n]; |
| 747 | /* NOTE: this is subtle as a TB may span two physical pages */ |
| 748 | if (n == 0) { |
| 749 | /* NOTE: tb_end may be after the end of the page, but |
| 750 | it is not a problem */ |
| 751 | tb_start = tb->page_addr[0] + (tb->pc & ~TARGET_PAGE_MASK); |
| 752 | tb_end = tb_start + tb->size; |
| 753 | } else { |
| 754 | tb_start = tb->page_addr[1]; |
| 755 | tb_end = tb_start + ((tb->pc + tb->size) & ~TARGET_PAGE_MASK); |
| 756 | } |
| 757 | if (!(tb_end <= start || tb_start >= end)) { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 758 | #ifdef TARGET_HAS_PRECISE_SMC |
| 759 | if (current_tb_not_found) { |
| 760 | current_tb_not_found = 0; |
| 761 | current_tb = NULL; |
| 762 | if (env->mem_write_pc) { |
| 763 | /* now we have a real cpu fault */ |
| 764 | current_tb = tb_find_pc(env->mem_write_pc); |
| 765 | } |
| 766 | } |
| 767 | if (current_tb == tb && |
| 768 | !(current_tb->cflags & CF_SINGLE_INSN)) { |
| 769 | /* If we are modifying the current TB, we must stop |
| 770 | its execution. We could be more precise by checking |
| 771 | that the modification is after the current PC, but it |
| 772 | would require a specialized function to partially |
| 773 | restore the CPU state */ |
| 774 | |
| 775 | current_tb_modified = 1; |
| 776 | cpu_restore_state(current_tb, env, |
| 777 | env->mem_write_pc, NULL); |
| 778 | #if defined(TARGET_I386) |
| 779 | current_flags = env->hflags; |
| 780 | current_flags |= (env->eflags & (IOPL_MASK | TF_MASK | VM_MASK)); |
| 781 | current_cs_base = (target_ulong)env->segs[R_CS].base; |
| 782 | current_pc = current_cs_base + env->eip; |
| 783 | #else |
| 784 | #error unsupported CPU |
| 785 | #endif |
| 786 | } |
| 787 | #endif /* TARGET_HAS_PRECISE_SMC */ |
bellard | ea1c180 | 2004-06-14 18:56:36 +0000 | [diff] [blame] | 788 | saved_tb = env->current_tb; |
| 789 | env->current_tb = NULL; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 790 | tb_phys_invalidate(tb, -1); |
bellard | ea1c180 | 2004-06-14 18:56:36 +0000 | [diff] [blame] | 791 | env->current_tb = saved_tb; |
| 792 | if (env->interrupt_request && env->current_tb) |
| 793 | cpu_interrupt(env, env->interrupt_request); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 794 | } |
| 795 | tb = tb_next; |
| 796 | } |
| 797 | #if !defined(CONFIG_USER_ONLY) |
| 798 | /* if no code remaining, no need to continue to use slow writes */ |
| 799 | if (!p->first_tb) { |
| 800 | invalidate_page_bitmap(p); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 801 | if (is_cpu_write_access) { |
| 802 | tlb_unprotect_code_phys(env, start, env->mem_write_vaddr); |
| 803 | } |
| 804 | } |
| 805 | #endif |
| 806 | #ifdef TARGET_HAS_PRECISE_SMC |
| 807 | if (current_tb_modified) { |
| 808 | /* we generate a block containing just the instruction |
| 809 | modifying the memory. It will ensure that it cannot modify |
| 810 | itself */ |
bellard | ea1c180 | 2004-06-14 18:56:36 +0000 | [diff] [blame] | 811 | env->current_tb = NULL; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 812 | tb_gen_code(env, current_pc, current_cs_base, current_flags, |
| 813 | CF_SINGLE_INSN); |
| 814 | cpu_resume_from_signal(env, NULL); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 815 | } |
| 816 | #endif |
| 817 | } |
| 818 | |
| 819 | /* len must be <= 8 and start must be a multiple of len */ |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 820 | static inline void tb_invalidate_phys_page_fast(target_ulong start, int len) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 821 | { |
| 822 | PageDesc *p; |
| 823 | int offset, b; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 824 | #if 0 |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 825 | if (1) { |
| 826 | if (loglevel) { |
| 827 | fprintf(logfile, "modifying code at 0x%x size=%d EIP=%x PC=%08x\n", |
| 828 | cpu_single_env->mem_write_vaddr, len, |
| 829 | cpu_single_env->eip, |
| 830 | cpu_single_env->eip + (long)cpu_single_env->segs[R_CS].base); |
| 831 | } |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 832 | } |
| 833 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 834 | p = page_find(start >> TARGET_PAGE_BITS); |
| 835 | if (!p) |
| 836 | return; |
| 837 | if (p->code_bitmap) { |
| 838 | offset = start & ~TARGET_PAGE_MASK; |
| 839 | b = p->code_bitmap[offset >> 3] >> (offset & 7); |
| 840 | if (b & ((1 << len) - 1)) |
| 841 | goto do_invalidate; |
| 842 | } else { |
| 843 | do_invalidate: |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 844 | tb_invalidate_phys_page_range(start, start + len, 1); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 848 | #if !defined(CONFIG_SOFTMMU) |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 849 | static void tb_invalidate_phys_page(target_ulong addr, |
| 850 | unsigned long pc, void *puc) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 851 | { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 852 | int n, current_flags, current_tb_modified; |
| 853 | target_ulong current_pc, current_cs_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 854 | PageDesc *p; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 855 | TranslationBlock *tb, *current_tb; |
| 856 | #ifdef TARGET_HAS_PRECISE_SMC |
| 857 | CPUState *env = cpu_single_env; |
| 858 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 859 | |
| 860 | addr &= TARGET_PAGE_MASK; |
| 861 | p = page_find(addr >> TARGET_PAGE_BITS); |
| 862 | if (!p) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 863 | return; |
| 864 | tb = p->first_tb; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 865 | current_tb_modified = 0; |
| 866 | current_tb = NULL; |
| 867 | current_pc = 0; /* avoid warning */ |
| 868 | current_cs_base = 0; /* avoid warning */ |
| 869 | current_flags = 0; /* avoid warning */ |
| 870 | #ifdef TARGET_HAS_PRECISE_SMC |
| 871 | if (tb && pc != 0) { |
| 872 | current_tb = tb_find_pc(pc); |
| 873 | } |
| 874 | #endif |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 875 | while (tb != NULL) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 876 | n = (long)tb & 3; |
| 877 | tb = (TranslationBlock *)((long)tb & ~3); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 878 | #ifdef TARGET_HAS_PRECISE_SMC |
| 879 | if (current_tb == tb && |
| 880 | !(current_tb->cflags & CF_SINGLE_INSN)) { |
| 881 | /* If we are modifying the current TB, we must stop |
| 882 | its execution. We could be more precise by checking |
| 883 | that the modification is after the current PC, but it |
| 884 | would require a specialized function to partially |
| 885 | restore the CPU state */ |
| 886 | |
| 887 | current_tb_modified = 1; |
| 888 | cpu_restore_state(current_tb, env, pc, puc); |
| 889 | #if defined(TARGET_I386) |
| 890 | current_flags = env->hflags; |
| 891 | current_flags |= (env->eflags & (IOPL_MASK | TF_MASK | VM_MASK)); |
| 892 | current_cs_base = (target_ulong)env->segs[R_CS].base; |
| 893 | current_pc = current_cs_base + env->eip; |
| 894 | #else |
| 895 | #error unsupported CPU |
| 896 | #endif |
| 897 | } |
| 898 | #endif /* TARGET_HAS_PRECISE_SMC */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 899 | tb_phys_invalidate(tb, addr); |
| 900 | tb = tb->page_next[n]; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 901 | } |
| 902 | p->first_tb = NULL; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 903 | #ifdef TARGET_HAS_PRECISE_SMC |
| 904 | if (current_tb_modified) { |
| 905 | /* we generate a block containing just the instruction |
| 906 | modifying the memory. It will ensure that it cannot modify |
| 907 | itself */ |
bellard | ea1c180 | 2004-06-14 18:56:36 +0000 | [diff] [blame] | 908 | env->current_tb = NULL; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 909 | tb_gen_code(env, current_pc, current_cs_base, current_flags, |
| 910 | CF_SINGLE_INSN); |
| 911 | cpu_resume_from_signal(env, puc); |
| 912 | } |
| 913 | #endif |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 914 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 915 | #endif |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 916 | |
| 917 | /* add the tb in the target page and protect it if necessary */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 918 | static inline void tb_alloc_page(TranslationBlock *tb, |
| 919 | unsigned int n, unsigned int page_addr) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 920 | { |
| 921 | PageDesc *p; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 922 | TranslationBlock *last_first_tb; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 923 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 924 | tb->page_addr[n] = page_addr; |
| 925 | p = page_find(page_addr >> TARGET_PAGE_BITS); |
| 926 | tb->page_next[n] = p->first_tb; |
| 927 | last_first_tb = p->first_tb; |
| 928 | p->first_tb = (TranslationBlock *)((long)tb | n); |
| 929 | invalidate_page_bitmap(p); |
| 930 | |
bellard | 107db44 | 2004-06-22 18:48:46 +0000 | [diff] [blame] | 931 | #if defined(TARGET_HAS_SMC) || 1 |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 932 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 933 | #if defined(CONFIG_USER_ONLY) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 934 | if (p->flags & PAGE_WRITE) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 935 | unsigned long host_start, host_end, addr; |
| 936 | int prot; |
| 937 | |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 938 | /* force the host page as non writable (writes will have a |
| 939 | page fault + mprotect overhead) */ |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 940 | host_start = page_addr & qemu_host_page_mask; |
| 941 | host_end = host_start + qemu_host_page_size; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 942 | prot = 0; |
| 943 | for(addr = host_start; addr < host_end; addr += TARGET_PAGE_SIZE) |
| 944 | prot |= page_get_flags(addr); |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 945 | mprotect((void *)host_start, qemu_host_page_size, |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 946 | (prot & PAGE_BITS) & ~PAGE_WRITE); |
| 947 | #ifdef DEBUG_TB_INVALIDATE |
| 948 | printf("protecting code page: 0x%08lx\n", |
| 949 | host_start); |
| 950 | #endif |
| 951 | p->flags &= ~PAGE_WRITE; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 952 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 953 | #else |
| 954 | /* if some code is already present, then the pages are already |
| 955 | protected. So we handle the case where only the first TB is |
| 956 | allocated in a physical page */ |
| 957 | if (!last_first_tb) { |
| 958 | target_ulong virt_addr; |
| 959 | |
| 960 | virt_addr = (tb->pc & TARGET_PAGE_MASK) + (n << TARGET_PAGE_BITS); |
| 961 | tlb_protect_code(cpu_single_env, virt_addr); |
| 962 | } |
| 963 | #endif |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 964 | |
| 965 | #endif /* TARGET_HAS_SMC */ |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /* Allocate a new translation block. Flush the translation buffer if |
| 969 | too many translation blocks or too much generated code. */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 970 | TranslationBlock *tb_alloc(target_ulong pc) |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 971 | { |
| 972 | TranslationBlock *tb; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 973 | |
| 974 | if (nb_tbs >= CODE_GEN_MAX_BLOCKS || |
| 975 | (code_gen_ptr - code_gen_buffer) >= CODE_GEN_BUFFER_MAX_SIZE) |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 976 | return NULL; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 977 | tb = &tbs[nb_tbs++]; |
| 978 | tb->pc = pc; |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 979 | tb->cflags = 0; |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 980 | return tb; |
| 981 | } |
| 982 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 983 | /* add a new TB and link it to the physical page tables. phys_page2 is |
| 984 | (-1) to indicate that only one page contains the TB. */ |
| 985 | void tb_link_phys(TranslationBlock *tb, |
| 986 | target_ulong phys_pc, target_ulong phys_page2) |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 987 | { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 988 | unsigned int h; |
| 989 | TranslationBlock **ptb; |
| 990 | |
| 991 | /* add in the physical hash table */ |
| 992 | h = tb_phys_hash_func(phys_pc); |
| 993 | ptb = &tb_phys_hash[h]; |
| 994 | tb->phys_hash_next = *ptb; |
| 995 | *ptb = tb; |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 996 | |
| 997 | /* add in the page list */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 998 | tb_alloc_page(tb, 0, phys_pc & TARGET_PAGE_MASK); |
| 999 | if (phys_page2 != -1) |
| 1000 | tb_alloc_page(tb, 1, phys_page2); |
| 1001 | else |
| 1002 | tb->page_addr[1] = -1; |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1003 | #ifdef DEBUG_TB_CHECK |
| 1004 | tb_page_check(); |
| 1005 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* link the tb with the other TBs */ |
| 1009 | void tb_link(TranslationBlock *tb) |
| 1010 | { |
| 1011 | #if !defined(CONFIG_USER_ONLY) |
| 1012 | { |
| 1013 | VirtPageDesc *vp; |
| 1014 | target_ulong addr; |
| 1015 | |
| 1016 | /* save the code memory mappings (needed to invalidate the code) */ |
| 1017 | addr = tb->pc & TARGET_PAGE_MASK; |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 1018 | vp = virt_page_find_alloc(addr >> TARGET_PAGE_BITS, 1); |
bellard | 9885788 | 2004-01-18 21:52:14 +0000 | [diff] [blame] | 1019 | #ifdef DEBUG_TLB_CHECK |
| 1020 | if (vp->valid_tag == virt_valid_tag && |
| 1021 | vp->phys_addr != tb->page_addr[0]) { |
| 1022 | printf("Error tb addr=0x%x phys=0x%x vp->phys_addr=0x%x\n", |
| 1023 | addr, tb->page_addr[0], vp->phys_addr); |
| 1024 | } |
| 1025 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1026 | vp->phys_addr = tb->page_addr[0]; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1027 | if (vp->valid_tag != virt_valid_tag) { |
| 1028 | vp->valid_tag = virt_valid_tag; |
| 1029 | #if !defined(CONFIG_SOFTMMU) |
| 1030 | vp->prot = 0; |
| 1031 | #endif |
| 1032 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1033 | |
| 1034 | if (tb->page_addr[1] != -1) { |
| 1035 | addr += TARGET_PAGE_SIZE; |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 1036 | vp = virt_page_find_alloc(addr >> TARGET_PAGE_BITS, 1); |
bellard | 9885788 | 2004-01-18 21:52:14 +0000 | [diff] [blame] | 1037 | #ifdef DEBUG_TLB_CHECK |
| 1038 | if (vp->valid_tag == virt_valid_tag && |
| 1039 | vp->phys_addr != tb->page_addr[1]) { |
| 1040 | printf("Error tb addr=0x%x phys=0x%x vp->phys_addr=0x%x\n", |
| 1041 | addr, tb->page_addr[1], vp->phys_addr); |
| 1042 | } |
| 1043 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1044 | vp->phys_addr = tb->page_addr[1]; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1045 | if (vp->valid_tag != virt_valid_tag) { |
| 1046 | vp->valid_tag = virt_valid_tag; |
| 1047 | #if !defined(CONFIG_SOFTMMU) |
| 1048 | vp->prot = 0; |
| 1049 | #endif |
| 1050 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | #endif |
| 1054 | |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 1055 | tb->jmp_first = (TranslationBlock *)((long)tb | 2); |
| 1056 | tb->jmp_next[0] = NULL; |
| 1057 | tb->jmp_next[1] = NULL; |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 1058 | #ifdef USE_CODE_COPY |
| 1059 | tb->cflags &= ~CF_FP_USED; |
| 1060 | if (tb->cflags & CF_TB_FP_USED) |
| 1061 | tb->cflags |= CF_FP_USED; |
| 1062 | #endif |
bellard | d4e8164 | 2003-05-25 16:46:15 +0000 | [diff] [blame] | 1063 | |
| 1064 | /* init original jump addresses */ |
| 1065 | if (tb->tb_next_offset[0] != 0xffff) |
| 1066 | tb_reset_jump(tb, 0); |
| 1067 | if (tb->tb_next_offset[1] != 0xffff) |
| 1068 | tb_reset_jump(tb, 1); |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 1071 | /* find the TB 'tb' such that tb[0].tc_ptr <= tc_ptr < |
| 1072 | tb[1].tc_ptr. Return NULL if not found */ |
| 1073 | TranslationBlock *tb_find_pc(unsigned long tc_ptr) |
| 1074 | { |
| 1075 | int m_min, m_max, m; |
| 1076 | unsigned long v; |
| 1077 | TranslationBlock *tb; |
| 1078 | |
| 1079 | if (nb_tbs <= 0) |
| 1080 | return NULL; |
| 1081 | if (tc_ptr < (unsigned long)code_gen_buffer || |
| 1082 | tc_ptr >= (unsigned long)code_gen_ptr) |
| 1083 | return NULL; |
| 1084 | /* binary search (cf Knuth) */ |
| 1085 | m_min = 0; |
| 1086 | m_max = nb_tbs - 1; |
| 1087 | while (m_min <= m_max) { |
| 1088 | m = (m_min + m_max) >> 1; |
| 1089 | tb = &tbs[m]; |
| 1090 | v = (unsigned long)tb->tc_ptr; |
| 1091 | if (v == tc_ptr) |
| 1092 | return tb; |
| 1093 | else if (tc_ptr < v) { |
| 1094 | m_max = m - 1; |
| 1095 | } else { |
| 1096 | m_min = m + 1; |
| 1097 | } |
| 1098 | } |
| 1099 | return &tbs[m_max]; |
| 1100 | } |
bellard | 7501267 | 2003-06-21 13:11:07 +0000 | [diff] [blame] | 1101 | |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1102 | static void tb_reset_jump_recursive(TranslationBlock *tb); |
| 1103 | |
| 1104 | static inline void tb_reset_jump_recursive2(TranslationBlock *tb, int n) |
| 1105 | { |
| 1106 | TranslationBlock *tb1, *tb_next, **ptb; |
| 1107 | unsigned int n1; |
| 1108 | |
| 1109 | tb1 = tb->jmp_next[n]; |
| 1110 | if (tb1 != NULL) { |
| 1111 | /* find head of list */ |
| 1112 | for(;;) { |
| 1113 | n1 = (long)tb1 & 3; |
| 1114 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 1115 | if (n1 == 2) |
| 1116 | break; |
| 1117 | tb1 = tb1->jmp_next[n1]; |
| 1118 | } |
| 1119 | /* we are now sure now that tb jumps to tb1 */ |
| 1120 | tb_next = tb1; |
| 1121 | |
| 1122 | /* remove tb from the jmp_first list */ |
| 1123 | ptb = &tb_next->jmp_first; |
| 1124 | for(;;) { |
| 1125 | tb1 = *ptb; |
| 1126 | n1 = (long)tb1 & 3; |
| 1127 | tb1 = (TranslationBlock *)((long)tb1 & ~3); |
| 1128 | if (n1 == n && tb1 == tb) |
| 1129 | break; |
| 1130 | ptb = &tb1->jmp_next[n1]; |
| 1131 | } |
| 1132 | *ptb = tb->jmp_next[n]; |
| 1133 | tb->jmp_next[n] = NULL; |
| 1134 | |
| 1135 | /* suppress the jump to next tb in generated code */ |
| 1136 | tb_reset_jump(tb, n); |
| 1137 | |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1138 | /* suppress jumps in the tb on which we could have jumped */ |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1139 | tb_reset_jump_recursive(tb_next); |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | static void tb_reset_jump_recursive(TranslationBlock *tb) |
| 1144 | { |
| 1145 | tb_reset_jump_recursive2(tb, 0); |
| 1146 | tb_reset_jump_recursive2(tb, 1); |
| 1147 | } |
| 1148 | |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 1149 | #if defined(TARGET_HAS_ICE) |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1150 | static void breakpoint_invalidate(CPUState *env, target_ulong pc) |
| 1151 | { |
| 1152 | target_ulong phys_addr; |
| 1153 | |
| 1154 | phys_addr = cpu_get_phys_page_debug(env, pc); |
| 1155 | tb_invalidate_phys_page_range(phys_addr, phys_addr + 1, 0); |
| 1156 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 1157 | #endif |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1158 | |
bellard | c33a346 | 2003-07-29 20:50:33 +0000 | [diff] [blame] | 1159 | /* add a breakpoint. EXCP_DEBUG is returned by the CPU loop if a |
| 1160 | breakpoint is reached */ |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1161 | int cpu_breakpoint_insert(CPUState *env, target_ulong pc) |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1162 | { |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 1163 | #if defined(TARGET_HAS_ICE) |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1164 | int i; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1165 | |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1166 | for(i = 0; i < env->nb_breakpoints; i++) { |
| 1167 | if (env->breakpoints[i] == pc) |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | if (env->nb_breakpoints >= MAX_BREAKPOINTS) |
| 1172 | return -1; |
| 1173 | env->breakpoints[env->nb_breakpoints++] = pc; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1174 | |
| 1175 | breakpoint_invalidate(env, pc); |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1176 | return 0; |
| 1177 | #else |
| 1178 | return -1; |
| 1179 | #endif |
| 1180 | } |
| 1181 | |
| 1182 | /* remove a breakpoint */ |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1183 | int cpu_breakpoint_remove(CPUState *env, target_ulong pc) |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1184 | { |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 1185 | #if defined(TARGET_HAS_ICE) |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1186 | int i; |
| 1187 | for(i = 0; i < env->nb_breakpoints; i++) { |
| 1188 | if (env->breakpoints[i] == pc) |
| 1189 | goto found; |
| 1190 | } |
| 1191 | return -1; |
| 1192 | found: |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1193 | env->nb_breakpoints--; |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 1194 | if (i < env->nb_breakpoints) |
| 1195 | env->breakpoints[i] = env->breakpoints[env->nb_breakpoints]; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1196 | |
| 1197 | breakpoint_invalidate(env, pc); |
bellard | 4c3a88a | 2003-07-26 12:06:08 +0000 | [diff] [blame] | 1198 | return 0; |
| 1199 | #else |
| 1200 | return -1; |
| 1201 | #endif |
| 1202 | } |
| 1203 | |
bellard | c33a346 | 2003-07-29 20:50:33 +0000 | [diff] [blame] | 1204 | /* enable or disable single step mode. EXCP_DEBUG is returned by the |
| 1205 | CPU loop after each instruction */ |
| 1206 | void cpu_single_step(CPUState *env, int enabled) |
| 1207 | { |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 1208 | #if defined(TARGET_HAS_ICE) |
bellard | c33a346 | 2003-07-29 20:50:33 +0000 | [diff] [blame] | 1209 | if (env->singlestep_enabled != enabled) { |
| 1210 | env->singlestep_enabled = enabled; |
| 1211 | /* must flush all the translated code to avoid inconsistancies */ |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1212 | /* XXX: only flush what is necessary */ |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1213 | tb_flush(env); |
bellard | c33a346 | 2003-07-29 20:50:33 +0000 | [diff] [blame] | 1214 | } |
| 1215 | #endif |
| 1216 | } |
| 1217 | |
bellard | 3486513 | 2003-10-05 14:28:56 +0000 | [diff] [blame] | 1218 | /* enable or disable low levels log */ |
| 1219 | void cpu_set_log(int log_flags) |
| 1220 | { |
| 1221 | loglevel = log_flags; |
| 1222 | if (loglevel && !logfile) { |
| 1223 | logfile = fopen(logfilename, "w"); |
| 1224 | if (!logfile) { |
| 1225 | perror(logfilename); |
| 1226 | _exit(1); |
| 1227 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1228 | #if !defined(CONFIG_SOFTMMU) |
| 1229 | /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ |
| 1230 | { |
| 1231 | static uint8_t logfile_buf[4096]; |
| 1232 | setvbuf(logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); |
| 1233 | } |
| 1234 | #else |
bellard | 3486513 | 2003-10-05 14:28:56 +0000 | [diff] [blame] | 1235 | setvbuf(logfile, NULL, _IOLBF, 0); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1236 | #endif |
bellard | 3486513 | 2003-10-05 14:28:56 +0000 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | void cpu_set_log_filename(const char *filename) |
| 1241 | { |
| 1242 | logfilename = strdup(filename); |
| 1243 | } |
bellard | c33a346 | 2003-07-29 20:50:33 +0000 | [diff] [blame] | 1244 | |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1245 | /* mask must never be zero, except for A20 change call */ |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 1246 | void cpu_interrupt(CPUState *env, int mask) |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1247 | { |
| 1248 | TranslationBlock *tb; |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 1249 | static int interrupt_lock; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1250 | |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 1251 | env->interrupt_request |= mask; |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1252 | /* if the cpu is currently executing code, we must unlink it and |
| 1253 | all the potentially executing TB */ |
| 1254 | tb = env->current_tb; |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 1255 | if (tb && !testandset(&interrupt_lock)) { |
| 1256 | env->current_tb = NULL; |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1257 | tb_reset_jump_recursive(tb); |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 1258 | interrupt_lock = 0; |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1259 | } |
| 1260 | } |
| 1261 | |
bellard | b54ad04 | 2004-05-20 13:42:52 +0000 | [diff] [blame] | 1262 | void cpu_reset_interrupt(CPUState *env, int mask) |
| 1263 | { |
| 1264 | env->interrupt_request &= ~mask; |
| 1265 | } |
| 1266 | |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1267 | CPULogItem cpu_log_items[] = { |
| 1268 | { CPU_LOG_TB_OUT_ASM, "out_asm", |
| 1269 | "show generated host assembly code for each compiled TB" }, |
| 1270 | { CPU_LOG_TB_IN_ASM, "in_asm", |
| 1271 | "show target assembly code for each compiled TB" }, |
| 1272 | { CPU_LOG_TB_OP, "op", |
| 1273 | "show micro ops for each compiled TB (only usable if 'in_asm' used)" }, |
| 1274 | #ifdef TARGET_I386 |
| 1275 | { CPU_LOG_TB_OP_OPT, "op_opt", |
| 1276 | "show micro ops after optimization for each compiled TB" }, |
| 1277 | #endif |
| 1278 | { CPU_LOG_INT, "int", |
| 1279 | "show interrupts/exceptions in short format" }, |
| 1280 | { CPU_LOG_EXEC, "exec", |
| 1281 | "show trace before each executed TB (lots of logs)" }, |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 1282 | { CPU_LOG_TB_CPU, "cpu", |
| 1283 | "show CPU state before bloc translation" }, |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1284 | #ifdef TARGET_I386 |
| 1285 | { CPU_LOG_PCALL, "pcall", |
| 1286 | "show protected mode far calls/returns/exceptions" }, |
| 1287 | #endif |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 1288 | #ifdef DEBUG_IOPORT |
bellard | fd87259 | 2004-05-12 19:11:15 +0000 | [diff] [blame] | 1289 | { CPU_LOG_IOPORT, "ioport", |
| 1290 | "show all i/o ports accesses" }, |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 1291 | #endif |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1292 | { 0, NULL, NULL }, |
| 1293 | }; |
| 1294 | |
| 1295 | static int cmp1(const char *s1, int n, const char *s2) |
| 1296 | { |
| 1297 | if (strlen(s2) != n) |
| 1298 | return 0; |
| 1299 | return memcmp(s1, s2, n) == 0; |
| 1300 | } |
| 1301 | |
| 1302 | /* takes a comma separated list of log masks. Return 0 if error. */ |
| 1303 | int cpu_str_to_log_mask(const char *str) |
| 1304 | { |
| 1305 | CPULogItem *item; |
| 1306 | int mask; |
| 1307 | const char *p, *p1; |
| 1308 | |
| 1309 | p = str; |
| 1310 | mask = 0; |
| 1311 | for(;;) { |
| 1312 | p1 = strchr(p, ','); |
| 1313 | if (!p1) |
| 1314 | p1 = p + strlen(p); |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 1315 | if(cmp1(p,p1-p,"all")) { |
| 1316 | for(item = cpu_log_items; item->mask != 0; item++) { |
| 1317 | mask |= item->mask; |
| 1318 | } |
| 1319 | } else { |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1320 | for(item = cpu_log_items; item->mask != 0; item++) { |
| 1321 | if (cmp1(p, p1 - p, item->name)) |
| 1322 | goto found; |
| 1323 | } |
| 1324 | return 0; |
bellard | 8e3a9fd | 2004-10-09 17:32:58 +0000 | [diff] [blame] | 1325 | } |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 1326 | found: |
| 1327 | mask |= item->mask; |
| 1328 | if (*p1 != ',') |
| 1329 | break; |
| 1330 | p = p1 + 1; |
| 1331 | } |
| 1332 | return mask; |
| 1333 | } |
bellard | ea041c0 | 2003-06-25 16:16:50 +0000 | [diff] [blame] | 1334 | |
bellard | 7501267 | 2003-06-21 13:11:07 +0000 | [diff] [blame] | 1335 | void cpu_abort(CPUState *env, const char *fmt, ...) |
| 1336 | { |
| 1337 | va_list ap; |
| 1338 | |
| 1339 | va_start(ap, fmt); |
| 1340 | fprintf(stderr, "qemu: fatal: "); |
| 1341 | vfprintf(stderr, fmt, ap); |
| 1342 | fprintf(stderr, "\n"); |
| 1343 | #ifdef TARGET_I386 |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 1344 | cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP); |
| 1345 | #else |
| 1346 | cpu_dump_state(env, stderr, fprintf, 0); |
bellard | 7501267 | 2003-06-21 13:11:07 +0000 | [diff] [blame] | 1347 | #endif |
| 1348 | va_end(ap); |
| 1349 | abort(); |
| 1350 | } |
| 1351 | |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1352 | #if !defined(CONFIG_USER_ONLY) |
| 1353 | |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 1354 | /* NOTE: if flush_global is true, also flush global entries (not |
| 1355 | implemented yet) */ |
| 1356 | void tlb_flush(CPUState *env, int flush_global) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1357 | { |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1358 | int i; |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1359 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1360 | #if defined(DEBUG_TLB) |
| 1361 | printf("tlb_flush:\n"); |
| 1362 | #endif |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1363 | /* must reset current TB so that interrupts cannot modify the |
| 1364 | links while we are modifying them */ |
| 1365 | env->current_tb = NULL; |
| 1366 | |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1367 | for(i = 0; i < CPU_TLB_SIZE; i++) { |
| 1368 | env->tlb_read[0][i].address = -1; |
| 1369 | env->tlb_write[0][i].address = -1; |
| 1370 | env->tlb_read[1][i].address = -1; |
| 1371 | env->tlb_write[1][i].address = -1; |
| 1372 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1373 | |
| 1374 | virt_page_flush(); |
bellard | 8a8a608 | 2004-10-03 13:36:49 +0000 | [diff] [blame] | 1375 | memset (tb_hash, 0, CODE_GEN_HASH_SIZE * sizeof (void *)); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1376 | |
| 1377 | #if !defined(CONFIG_SOFTMMU) |
| 1378 | munmap((void *)MMAP_AREA_START, MMAP_AREA_END - MMAP_AREA_START); |
| 1379 | #endif |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1380 | #ifdef USE_KQEMU |
| 1381 | if (env->kqemu_enabled) { |
| 1382 | kqemu_flush(env, flush_global); |
| 1383 | } |
| 1384 | #endif |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 1385 | tlb_flush_count++; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
bellard | 274da6b | 2004-05-20 21:56:27 +0000 | [diff] [blame] | 1388 | static inline void tlb_flush_entry(CPUTLBEntry *tlb_entry, target_ulong addr) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1389 | { |
| 1390 | if (addr == (tlb_entry->address & |
| 1391 | (TARGET_PAGE_MASK | TLB_INVALID_MASK))) |
| 1392 | tlb_entry->address = -1; |
| 1393 | } |
| 1394 | |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1395 | void tlb_flush_page(CPUState *env, target_ulong addr) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1396 | { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1397 | int i, n; |
| 1398 | VirtPageDesc *vp; |
| 1399 | PageDesc *p; |
| 1400 | TranslationBlock *tb; |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1401 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1402 | #if defined(DEBUG_TLB) |
| 1403 | printf("tlb_flush_page: 0x%08x\n", addr); |
| 1404 | #endif |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1405 | /* must reset current TB so that interrupts cannot modify the |
| 1406 | links while we are modifying them */ |
| 1407 | env->current_tb = NULL; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1408 | |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1409 | addr &= TARGET_PAGE_MASK; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1410 | i = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1411 | tlb_flush_entry(&env->tlb_read[0][i], addr); |
| 1412 | tlb_flush_entry(&env->tlb_write[0][i], addr); |
| 1413 | tlb_flush_entry(&env->tlb_read[1][i], addr); |
| 1414 | tlb_flush_entry(&env->tlb_write[1][i], addr); |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1415 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1416 | /* remove from the virtual pc hash table all the TB at this |
| 1417 | virtual address */ |
| 1418 | |
| 1419 | vp = virt_page_find(addr >> TARGET_PAGE_BITS); |
| 1420 | if (vp && vp->valid_tag == virt_valid_tag) { |
| 1421 | p = page_find(vp->phys_addr >> TARGET_PAGE_BITS); |
| 1422 | if (p) { |
| 1423 | /* we remove all the links to the TBs in this virtual page */ |
| 1424 | tb = p->first_tb; |
| 1425 | while (tb != NULL) { |
| 1426 | n = (long)tb & 3; |
| 1427 | tb = (TranslationBlock *)((long)tb & ~3); |
| 1428 | if ((tb->pc & TARGET_PAGE_MASK) == addr || |
| 1429 | ((tb->pc + tb->size - 1) & TARGET_PAGE_MASK) == addr) { |
| 1430 | tb_invalidate(tb); |
| 1431 | } |
| 1432 | tb = tb->page_next[n]; |
| 1433 | } |
| 1434 | } |
bellard | 9885788 | 2004-01-18 21:52:14 +0000 | [diff] [blame] | 1435 | vp->valid_tag = 0; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1438 | #if !defined(CONFIG_SOFTMMU) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1439 | if (addr < MMAP_AREA_END) |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1440 | munmap((void *)addr, TARGET_PAGE_SIZE); |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1441 | #endif |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1442 | #ifdef USE_KQEMU |
| 1443 | if (env->kqemu_enabled) { |
| 1444 | kqemu_flush_page(env, addr); |
| 1445 | } |
| 1446 | #endif |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1449 | static inline void tlb_protect_code1(CPUTLBEntry *tlb_entry, target_ulong addr) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1450 | { |
| 1451 | if (addr == (tlb_entry->address & |
| 1452 | (TARGET_PAGE_MASK | TLB_INVALID_MASK)) && |
bellard | 9885788 | 2004-01-18 21:52:14 +0000 | [diff] [blame] | 1453 | (tlb_entry->address & ~TARGET_PAGE_MASK) != IO_MEM_CODE && |
| 1454 | (tlb_entry->address & ~TARGET_PAGE_MASK) != IO_MEM_ROM) { |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1455 | tlb_entry->address = (tlb_entry->address & TARGET_PAGE_MASK) | IO_MEM_CODE; |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1456 | } |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1459 | /* update the TLBs so that writes to code in the virtual page 'addr' |
| 1460 | can be detected */ |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1461 | static void tlb_protect_code(CPUState *env, target_ulong addr) |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1462 | { |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 1463 | int i; |
| 1464 | |
| 1465 | addr &= TARGET_PAGE_MASK; |
| 1466 | i = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1467 | tlb_protect_code1(&env->tlb_write[0][i], addr); |
| 1468 | tlb_protect_code1(&env->tlb_write[1][i], addr); |
| 1469 | #if !defined(CONFIG_SOFTMMU) |
| 1470 | /* NOTE: as we generated the code for this page, it is already at |
| 1471 | least readable */ |
| 1472 | if (addr < MMAP_AREA_END) |
| 1473 | mprotect((void *)addr, TARGET_PAGE_SIZE, PROT_READ); |
| 1474 | #endif |
| 1475 | } |
| 1476 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1477 | static inline void tlb_unprotect_code2(CPUTLBEntry *tlb_entry, |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1478 | unsigned long phys_addr) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1479 | { |
| 1480 | if ((tlb_entry->address & ~TARGET_PAGE_MASK) == IO_MEM_CODE && |
| 1481 | ((tlb_entry->address & TARGET_PAGE_MASK) + tlb_entry->addend) == phys_addr) { |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1482 | tlb_entry->address = (tlb_entry->address & TARGET_PAGE_MASK) | IO_MEM_NOTDIRTY; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* update the TLB so that writes in physical page 'phys_addr' are no longer |
| 1487 | tested self modifying code */ |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1488 | static void tlb_unprotect_code_phys(CPUState *env, unsigned long phys_addr, target_ulong vaddr) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1489 | { |
| 1490 | int i; |
| 1491 | |
| 1492 | phys_addr &= TARGET_PAGE_MASK; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1493 | phys_addr += (long)phys_ram_base; |
| 1494 | i = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 1495 | tlb_unprotect_code2(&env->tlb_write[0][i], phys_addr); |
| 1496 | tlb_unprotect_code2(&env->tlb_write[1][i], phys_addr); |
| 1497 | } |
| 1498 | |
| 1499 | static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry, |
| 1500 | unsigned long start, unsigned long length) |
| 1501 | { |
| 1502 | unsigned long addr; |
| 1503 | if ((tlb_entry->address & ~TARGET_PAGE_MASK) == IO_MEM_RAM) { |
| 1504 | addr = (tlb_entry->address & TARGET_PAGE_MASK) + tlb_entry->addend; |
| 1505 | if ((addr - start) < length) { |
| 1506 | tlb_entry->address = (tlb_entry->address & TARGET_PAGE_MASK) | IO_MEM_NOTDIRTY; |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1511 | void cpu_physical_memory_reset_dirty(target_ulong start, target_ulong end, |
| 1512 | int dirty_flags) |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1513 | { |
| 1514 | CPUState *env; |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1515 | unsigned long length, start1; |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1516 | int i, mask, len; |
| 1517 | uint8_t *p; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1518 | |
| 1519 | start &= TARGET_PAGE_MASK; |
| 1520 | end = TARGET_PAGE_ALIGN(end); |
| 1521 | |
| 1522 | length = end - start; |
| 1523 | if (length == 0) |
| 1524 | return; |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1525 | mask = ~dirty_flags; |
| 1526 | p = phys_ram_dirty + (start >> TARGET_PAGE_BITS); |
| 1527 | len = length >> TARGET_PAGE_BITS; |
| 1528 | for(i = 0; i < len; i++) |
| 1529 | p[i] &= mask; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1530 | |
| 1531 | env = cpu_single_env; |
| 1532 | /* we modify the TLB cache so that the dirty bit will be set again |
| 1533 | when accessing the range */ |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1534 | start1 = start + (unsigned long)phys_ram_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1535 | for(i = 0; i < CPU_TLB_SIZE; i++) |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1536 | tlb_reset_dirty_range(&env->tlb_write[0][i], start1, length); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1537 | for(i = 0; i < CPU_TLB_SIZE; i++) |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1538 | tlb_reset_dirty_range(&env->tlb_write[1][i], start1, length); |
| 1539 | |
| 1540 | #if !defined(CONFIG_SOFTMMU) |
| 1541 | /* XXX: this is expensive */ |
| 1542 | { |
| 1543 | VirtPageDesc *p; |
| 1544 | int j; |
| 1545 | target_ulong addr; |
| 1546 | |
| 1547 | for(i = 0; i < L1_SIZE; i++) { |
| 1548 | p = l1_virt_map[i]; |
| 1549 | if (p) { |
| 1550 | addr = i << (TARGET_PAGE_BITS + L2_BITS); |
| 1551 | for(j = 0; j < L2_SIZE; j++) { |
| 1552 | if (p->valid_tag == virt_valid_tag && |
| 1553 | p->phys_addr >= start && p->phys_addr < end && |
| 1554 | (p->prot & PROT_WRITE)) { |
| 1555 | if (addr < MMAP_AREA_END) { |
| 1556 | mprotect((void *)addr, TARGET_PAGE_SIZE, |
| 1557 | p->prot & ~PROT_WRITE); |
| 1558 | } |
| 1559 | } |
| 1560 | addr += TARGET_PAGE_SIZE; |
| 1561 | p++; |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | #endif |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | static inline void tlb_set_dirty1(CPUTLBEntry *tlb_entry, |
| 1570 | unsigned long start) |
| 1571 | { |
| 1572 | unsigned long addr; |
| 1573 | if ((tlb_entry->address & ~TARGET_PAGE_MASK) == IO_MEM_NOTDIRTY) { |
| 1574 | addr = (tlb_entry->address & TARGET_PAGE_MASK) + tlb_entry->addend; |
| 1575 | if (addr == start) { |
| 1576 | tlb_entry->address = (tlb_entry->address & TARGET_PAGE_MASK) | IO_MEM_RAM; |
| 1577 | } |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | /* update the TLB corresponding to virtual page vaddr and phys addr |
| 1582 | addr so that it is no longer dirty */ |
| 1583 | static inline void tlb_set_dirty(unsigned long addr, target_ulong vaddr) |
| 1584 | { |
| 1585 | CPUState *env = cpu_single_env; |
| 1586 | int i; |
| 1587 | |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1588 | phys_ram_dirty[(addr - (unsigned long)phys_ram_base) >> TARGET_PAGE_BITS] = 0xff; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1589 | |
| 1590 | addr &= TARGET_PAGE_MASK; |
| 1591 | i = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
| 1592 | tlb_set_dirty1(&env->tlb_write[0][i], addr); |
| 1593 | tlb_set_dirty1(&env->tlb_write[1][i], addr); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1596 | /* add a new TLB entry. At most one entry for a given virtual address |
| 1597 | is permitted. Return 0 if OK or 2 if the page could not be mapped |
| 1598 | (can only happen in non SOFTMMU mode for I/O pages or pages |
| 1599 | conflicting with the host address space). */ |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1600 | int tlb_set_page(CPUState *env, target_ulong vaddr, |
| 1601 | target_phys_addr_t paddr, int prot, |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1602 | int is_user, int is_softmmu) |
| 1603 | { |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1604 | PhysPageDesc *p; |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1605 | unsigned long pd; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1606 | TranslationBlock *first_tb; |
| 1607 | unsigned int index; |
bellard | 4f2ac23 | 2004-04-26 19:44:02 +0000 | [diff] [blame] | 1608 | target_ulong address; |
| 1609 | unsigned long addend; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1610 | int ret; |
| 1611 | |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1612 | p = phys_page_find(paddr >> TARGET_PAGE_BITS); |
| 1613 | first_tb = NULL; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1614 | if (!p) { |
| 1615 | pd = IO_MEM_UNASSIGNED; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1616 | } else { |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1617 | PageDesc *p1; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1618 | pd = p->phys_offset; |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1619 | if ((pd & ~TARGET_PAGE_MASK) <= IO_MEM_ROM) { |
| 1620 | /* NOTE: we also allocate the page at this stage */ |
| 1621 | p1 = page_find_alloc(pd >> TARGET_PAGE_BITS); |
| 1622 | first_tb = p1->first_tb; |
| 1623 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1624 | } |
| 1625 | #if defined(DEBUG_TLB) |
| 1626 | printf("tlb_set_page: vaddr=0x%08x paddr=0x%08x prot=%x u=%d c=%d smmu=%d pd=0x%08x\n", |
| 1627 | vaddr, paddr, prot, is_user, (first_tb != NULL), is_softmmu, pd); |
| 1628 | #endif |
| 1629 | |
| 1630 | ret = 0; |
| 1631 | #if !defined(CONFIG_SOFTMMU) |
| 1632 | if (is_softmmu) |
| 1633 | #endif |
| 1634 | { |
| 1635 | if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) { |
| 1636 | /* IO memory case */ |
| 1637 | address = vaddr | pd; |
| 1638 | addend = paddr; |
| 1639 | } else { |
| 1640 | /* standard memory */ |
| 1641 | address = vaddr; |
| 1642 | addend = (unsigned long)phys_ram_base + (pd & TARGET_PAGE_MASK); |
| 1643 | } |
| 1644 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 1645 | index = (vaddr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1646 | addend -= vaddr; |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 1647 | if (prot & PAGE_READ) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1648 | env->tlb_read[is_user][index].address = address; |
| 1649 | env->tlb_read[is_user][index].addend = addend; |
| 1650 | } else { |
| 1651 | env->tlb_read[is_user][index].address = -1; |
| 1652 | env->tlb_read[is_user][index].addend = -1; |
| 1653 | } |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 1654 | if (prot & PAGE_WRITE) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1655 | if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM) { |
| 1656 | /* ROM: access is ignored (same as unassigned) */ |
| 1657 | env->tlb_write[is_user][index].address = vaddr | IO_MEM_ROM; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1658 | env->tlb_write[is_user][index].addend = addend; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1659 | } else |
| 1660 | /* XXX: the PowerPC code seems not ready to handle |
| 1661 | self modifying code with DCBI */ |
| 1662 | #if defined(TARGET_HAS_SMC) || 1 |
| 1663 | if (first_tb) { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1664 | /* if code is present, we use a specific memory |
| 1665 | handler. It works only for physical memory access */ |
| 1666 | env->tlb_write[is_user][index].address = vaddr | IO_MEM_CODE; |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1667 | env->tlb_write[is_user][index].addend = addend; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1668 | } else |
| 1669 | #endif |
| 1670 | if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM && |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1671 | !cpu_physical_memory_is_dirty(pd)) { |
| 1672 | env->tlb_write[is_user][index].address = vaddr | IO_MEM_NOTDIRTY; |
| 1673 | env->tlb_write[is_user][index].addend = addend; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1674 | } else { |
| 1675 | env->tlb_write[is_user][index].address = address; |
| 1676 | env->tlb_write[is_user][index].addend = addend; |
| 1677 | } |
| 1678 | } else { |
| 1679 | env->tlb_write[is_user][index].address = -1; |
| 1680 | env->tlb_write[is_user][index].addend = -1; |
| 1681 | } |
| 1682 | } |
| 1683 | #if !defined(CONFIG_SOFTMMU) |
| 1684 | else { |
| 1685 | if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) { |
| 1686 | /* IO access: no mapping is done as it will be handled by the |
| 1687 | soft MMU */ |
| 1688 | if (!(env->hflags & HF_SOFTMMU_MASK)) |
| 1689 | ret = 2; |
| 1690 | } else { |
| 1691 | void *map_addr; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1692 | |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1693 | if (vaddr >= MMAP_AREA_END) { |
| 1694 | ret = 2; |
| 1695 | } else { |
| 1696 | if (prot & PROT_WRITE) { |
| 1697 | if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM || |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1698 | #if defined(TARGET_HAS_SMC) || 1 |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1699 | first_tb || |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1700 | #endif |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1701 | ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM && |
| 1702 | !cpu_physical_memory_is_dirty(pd))) { |
| 1703 | /* ROM: we do as if code was inside */ |
| 1704 | /* if code is present, we only map as read only and save the |
| 1705 | original mapping */ |
| 1706 | VirtPageDesc *vp; |
| 1707 | |
bellard | 90f1842 | 2005-07-24 10:17:31 +0000 | [diff] [blame^] | 1708 | vp = virt_page_find_alloc(vaddr >> TARGET_PAGE_BITS, 1); |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1709 | vp->phys_addr = pd; |
| 1710 | vp->prot = prot; |
| 1711 | vp->valid_tag = virt_valid_tag; |
| 1712 | prot &= ~PAGE_WRITE; |
| 1713 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1714 | } |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1715 | map_addr = mmap((void *)vaddr, TARGET_PAGE_SIZE, prot, |
| 1716 | MAP_SHARED | MAP_FIXED, phys_ram_fd, (pd & TARGET_PAGE_MASK)); |
| 1717 | if (map_addr == MAP_FAILED) { |
| 1718 | cpu_abort(env, "mmap failed when mapped physical address 0x%08x to virtual address 0x%08x\n", |
| 1719 | paddr, vaddr); |
| 1720 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | #endif |
| 1725 | return ret; |
| 1726 | } |
| 1727 | |
| 1728 | /* called from signal handler: invalidate the code and unprotect the |
| 1729 | page. Return TRUE if the fault was succesfully handled. */ |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1730 | int page_unprotect(unsigned long addr, unsigned long pc, void *puc) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1731 | { |
| 1732 | #if !defined(CONFIG_SOFTMMU) |
| 1733 | VirtPageDesc *vp; |
| 1734 | |
| 1735 | #if defined(DEBUG_TLB) |
| 1736 | printf("page_unprotect: addr=0x%08x\n", addr); |
| 1737 | #endif |
| 1738 | addr &= TARGET_PAGE_MASK; |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1739 | |
| 1740 | /* if it is not mapped, no need to worry here */ |
| 1741 | if (addr >= MMAP_AREA_END) |
| 1742 | return 0; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1743 | vp = virt_page_find(addr >> TARGET_PAGE_BITS); |
| 1744 | if (!vp) |
| 1745 | return 0; |
| 1746 | /* NOTE: in this case, validate_tag is _not_ tested as it |
| 1747 | validates only the code TLB */ |
| 1748 | if (vp->valid_tag != virt_valid_tag) |
| 1749 | return 0; |
| 1750 | if (!(vp->prot & PAGE_WRITE)) |
| 1751 | return 0; |
| 1752 | #if defined(DEBUG_TLB) |
| 1753 | printf("page_unprotect: addr=0x%08x phys_addr=0x%08x prot=%x\n", |
| 1754 | addr, vp->phys_addr, vp->prot); |
| 1755 | #endif |
bellard | 59817cc | 2004-02-16 22:01:13 +0000 | [diff] [blame] | 1756 | if (mprotect((void *)addr, TARGET_PAGE_SIZE, vp->prot) < 0) |
| 1757 | cpu_abort(cpu_single_env, "error mprotect addr=0x%lx prot=%d\n", |
| 1758 | (unsigned long)addr, vp->prot); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1759 | /* set the dirty bit */ |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1760 | phys_ram_dirty[vp->phys_addr >> TARGET_PAGE_BITS] = 0xff; |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1761 | /* flush the code inside */ |
| 1762 | tb_invalidate_phys_page(vp->phys_addr, pc, puc); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1763 | return 1; |
| 1764 | #else |
| 1765 | return 0; |
| 1766 | #endif |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1767 | } |
| 1768 | |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1769 | #else |
| 1770 | |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 1771 | void tlb_flush(CPUState *env, int flush_global) |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1772 | { |
| 1773 | } |
| 1774 | |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1775 | void tlb_flush_page(CPUState *env, target_ulong addr) |
bellard | 0124311 | 2004-01-04 15:48:17 +0000 | [diff] [blame] | 1776 | { |
| 1777 | } |
| 1778 | |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1779 | int tlb_set_page(CPUState *env, target_ulong vaddr, |
| 1780 | target_phys_addr_t paddr, int prot, |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1781 | int is_user, int is_softmmu) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1782 | { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1783 | return 0; |
| 1784 | } |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1785 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1786 | /* dump memory mappings */ |
| 1787 | void page_dump(FILE *f) |
| 1788 | { |
| 1789 | unsigned long start, end; |
| 1790 | int i, j, prot, prot1; |
| 1791 | PageDesc *p; |
| 1792 | |
| 1793 | fprintf(f, "%-8s %-8s %-8s %s\n", |
| 1794 | "start", "end", "size", "prot"); |
| 1795 | start = -1; |
| 1796 | end = -1; |
| 1797 | prot = 0; |
| 1798 | for(i = 0; i <= L1_SIZE; i++) { |
| 1799 | if (i < L1_SIZE) |
| 1800 | p = l1_map[i]; |
| 1801 | else |
| 1802 | p = NULL; |
| 1803 | for(j = 0;j < L2_SIZE; j++) { |
| 1804 | if (!p) |
| 1805 | prot1 = 0; |
| 1806 | else |
| 1807 | prot1 = p[j].flags; |
| 1808 | if (prot1 != prot) { |
| 1809 | end = (i << (32 - L1_BITS)) | (j << TARGET_PAGE_BITS); |
| 1810 | if (start != -1) { |
| 1811 | fprintf(f, "%08lx-%08lx %08lx %c%c%c\n", |
| 1812 | start, end, end - start, |
| 1813 | prot & PAGE_READ ? 'r' : '-', |
| 1814 | prot & PAGE_WRITE ? 'w' : '-', |
| 1815 | prot & PAGE_EXEC ? 'x' : '-'); |
| 1816 | } |
| 1817 | if (prot1 != 0) |
| 1818 | start = end; |
| 1819 | else |
| 1820 | start = -1; |
| 1821 | prot = prot1; |
| 1822 | } |
| 1823 | if (!p) |
| 1824 | break; |
| 1825 | } |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1826 | } |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1829 | int page_get_flags(unsigned long address) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1830 | { |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1831 | PageDesc *p; |
| 1832 | |
| 1833 | p = page_find(address >> TARGET_PAGE_BITS); |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1834 | if (!p) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1835 | return 0; |
| 1836 | return p->flags; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1839 | /* modify the flags of a page and invalidate the code if |
| 1840 | necessary. The flag PAGE_WRITE_ORG is positionned automatically |
| 1841 | depending on PAGE_WRITE */ |
| 1842 | void page_set_flags(unsigned long start, unsigned long end, int flags) |
| 1843 | { |
| 1844 | PageDesc *p; |
| 1845 | unsigned long addr; |
| 1846 | |
| 1847 | start = start & TARGET_PAGE_MASK; |
| 1848 | end = TARGET_PAGE_ALIGN(end); |
| 1849 | if (flags & PAGE_WRITE) |
| 1850 | flags |= PAGE_WRITE_ORG; |
| 1851 | spin_lock(&tb_lock); |
| 1852 | for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) { |
| 1853 | p = page_find_alloc(addr >> TARGET_PAGE_BITS); |
| 1854 | /* if the write protection is set, then we invalidate the code |
| 1855 | inside */ |
| 1856 | if (!(p->flags & PAGE_WRITE) && |
| 1857 | (flags & PAGE_WRITE) && |
| 1858 | p->first_tb) { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1859 | tb_invalidate_phys_page(addr, 0, NULL); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1860 | } |
| 1861 | p->flags = flags; |
| 1862 | } |
| 1863 | spin_unlock(&tb_lock); |
| 1864 | } |
| 1865 | |
| 1866 | /* called from signal handler: invalidate the code and unprotect the |
| 1867 | page. Return TRUE if the fault was succesfully handled. */ |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1868 | int page_unprotect(unsigned long address, unsigned long pc, void *puc) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1869 | { |
| 1870 | unsigned int page_index, prot, pindex; |
| 1871 | PageDesc *p, *p1; |
| 1872 | unsigned long host_start, host_end, addr; |
| 1873 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1874 | host_start = address & qemu_host_page_mask; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1875 | page_index = host_start >> TARGET_PAGE_BITS; |
| 1876 | p1 = page_find(page_index); |
| 1877 | if (!p1) |
| 1878 | return 0; |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1879 | host_end = host_start + qemu_host_page_size; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1880 | p = p1; |
| 1881 | prot = 0; |
| 1882 | for(addr = host_start;addr < host_end; addr += TARGET_PAGE_SIZE) { |
| 1883 | prot |= p->flags; |
| 1884 | p++; |
| 1885 | } |
| 1886 | /* if the page was really writable, then we change its |
| 1887 | protection back to writable */ |
| 1888 | if (prot & PAGE_WRITE_ORG) { |
| 1889 | pindex = (address - host_start) >> TARGET_PAGE_BITS; |
| 1890 | if (!(p1[pindex].flags & PAGE_WRITE)) { |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1891 | mprotect((void *)host_start, qemu_host_page_size, |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1892 | (prot & PAGE_BITS) | PAGE_WRITE); |
| 1893 | p1[pindex].flags |= PAGE_WRITE; |
| 1894 | /* and since the content will be modified, we must invalidate |
| 1895 | the corresponding translated code. */ |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1896 | tb_invalidate_phys_page(address, pc, puc); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1897 | #ifdef DEBUG_TB_CHECK |
| 1898 | tb_invalidate_check(address); |
| 1899 | #endif |
| 1900 | return 1; |
| 1901 | } |
| 1902 | } |
| 1903 | return 0; |
| 1904 | } |
| 1905 | |
| 1906 | /* call this function when system calls directly modify a memory area */ |
| 1907 | void page_unprotect_range(uint8_t *data, unsigned long data_size) |
| 1908 | { |
| 1909 | unsigned long start, end, addr; |
| 1910 | |
| 1911 | start = (unsigned long)data; |
| 1912 | end = start + data_size; |
| 1913 | start &= TARGET_PAGE_MASK; |
| 1914 | end = TARGET_PAGE_ALIGN(end); |
| 1915 | for(addr = start; addr < end; addr += TARGET_PAGE_SIZE) { |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1916 | page_unprotect(addr, 0, NULL); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1917 | } |
| 1918 | } |
| 1919 | |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1920 | static inline void tlb_set_dirty(unsigned long addr, target_ulong vaddr) |
| 1921 | { |
| 1922 | } |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1923 | #endif /* defined(CONFIG_USER_ONLY) */ |
| 1924 | |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1925 | /* register physical memory. 'size' must be a multiple of the target |
| 1926 | page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an |
| 1927 | io memory page */ |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 1928 | void cpu_register_physical_memory(target_phys_addr_t start_addr, |
| 1929 | unsigned long size, |
| 1930 | unsigned long phys_offset) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1931 | { |
| 1932 | unsigned long addr, end_addr; |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1933 | PhysPageDesc *p; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1934 | |
bellard | 5fd386f | 2004-05-23 21:11:22 +0000 | [diff] [blame] | 1935 | size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1936 | end_addr = start_addr + size; |
bellard | 5fd386f | 2004-05-23 21:11:22 +0000 | [diff] [blame] | 1937 | for(addr = start_addr; addr != end_addr; addr += TARGET_PAGE_SIZE) { |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 1938 | p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1939 | p->phys_offset = phys_offset; |
| 1940 | if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1941 | phys_offset += TARGET_PAGE_SIZE; |
| 1942 | } |
| 1943 | } |
| 1944 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 1945 | static uint32_t unassigned_mem_readb(void *opaque, target_phys_addr_t addr) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1946 | { |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 1950 | static void unassigned_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 1951 | { |
| 1952 | } |
| 1953 | |
| 1954 | static CPUReadMemoryFunc *unassigned_mem_read[3] = { |
| 1955 | unassigned_mem_readb, |
| 1956 | unassigned_mem_readb, |
| 1957 | unassigned_mem_readb, |
| 1958 | }; |
| 1959 | |
| 1960 | static CPUWriteMemoryFunc *unassigned_mem_write[3] = { |
| 1961 | unassigned_mem_writeb, |
| 1962 | unassigned_mem_writeb, |
| 1963 | unassigned_mem_writeb, |
| 1964 | }; |
| 1965 | |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1966 | /* self modifying code support in soft mmu mode : writing to a page |
| 1967 | containing code comes to these functions */ |
| 1968 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 1969 | static void code_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1970 | { |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1971 | unsigned long phys_addr; |
| 1972 | |
bellard | 274da6b | 2004-05-20 21:56:27 +0000 | [diff] [blame] | 1973 | phys_addr = addr - (unsigned long)phys_ram_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1974 | #if !defined(CONFIG_USER_ONLY) |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1975 | tb_invalidate_phys_page_fast(phys_addr, 1); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1976 | #endif |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 1977 | stb_p((uint8_t *)(long)addr, val); |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1978 | phys_ram_dirty[phys_addr >> TARGET_PAGE_BITS] = 0xff; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 1981 | static void code_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1982 | { |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1983 | unsigned long phys_addr; |
| 1984 | |
bellard | 274da6b | 2004-05-20 21:56:27 +0000 | [diff] [blame] | 1985 | phys_addr = addr - (unsigned long)phys_ram_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1986 | #if !defined(CONFIG_USER_ONLY) |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1987 | tb_invalidate_phys_page_fast(phys_addr, 2); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1988 | #endif |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 1989 | stw_p((uint8_t *)(long)addr, val); |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 1990 | phys_ram_dirty[phys_addr >> TARGET_PAGE_BITS] = 0xff; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 1993 | static void code_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1994 | { |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 1995 | unsigned long phys_addr; |
| 1996 | |
bellard | 274da6b | 2004-05-20 21:56:27 +0000 | [diff] [blame] | 1997 | phys_addr = addr - (unsigned long)phys_ram_base; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 1998 | #if !defined(CONFIG_USER_ONLY) |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 1999 | tb_invalidate_phys_page_fast(phys_addr, 4); |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 2000 | #endif |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2001 | stl_p((uint8_t *)(long)addr, val); |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 2002 | phys_ram_dirty[phys_addr >> TARGET_PAGE_BITS] = 0xff; |
bellard | 9fa3e85 | 2004-01-04 18:06:42 +0000 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | static CPUReadMemoryFunc *code_mem_read[3] = { |
| 2006 | NULL, /* never used */ |
| 2007 | NULL, /* never used */ |
| 2008 | NULL, /* never used */ |
| 2009 | }; |
| 2010 | |
| 2011 | static CPUWriteMemoryFunc *code_mem_write[3] = { |
| 2012 | code_mem_writeb, |
| 2013 | code_mem_writew, |
| 2014 | code_mem_writel, |
| 2015 | }; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 2016 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2017 | static void notdirty_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2018 | { |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2019 | stb_p((uint8_t *)(long)addr, val); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 2020 | tlb_set_dirty(addr, cpu_single_env->mem_write_vaddr); |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2023 | static void notdirty_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2024 | { |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2025 | stw_p((uint8_t *)(long)addr, val); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 2026 | tlb_set_dirty(addr, cpu_single_env->mem_write_vaddr); |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2029 | static void notdirty_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2030 | { |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2031 | stl_p((uint8_t *)(long)addr, val); |
bellard | d720b93 | 2004-04-25 17:57:43 +0000 | [diff] [blame] | 2032 | tlb_set_dirty(addr, cpu_single_env->mem_write_vaddr); |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | static CPUWriteMemoryFunc *notdirty_mem_write[3] = { |
| 2036 | notdirty_mem_writeb, |
| 2037 | notdirty_mem_writew, |
| 2038 | notdirty_mem_writel, |
| 2039 | }; |
| 2040 | |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 2041 | static void io_mem_init(void) |
| 2042 | { |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2043 | cpu_register_io_memory(IO_MEM_ROM >> IO_MEM_SHIFT, code_mem_read, unassigned_mem_write, NULL); |
| 2044 | cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); |
| 2045 | cpu_register_io_memory(IO_MEM_CODE >> IO_MEM_SHIFT, code_mem_read, code_mem_write, NULL); |
| 2046 | cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, code_mem_read, notdirty_mem_write, NULL); |
bellard | 1ccde1c | 2004-02-06 19:46:14 +0000 | [diff] [blame] | 2047 | io_mem_nb = 5; |
| 2048 | |
| 2049 | /* alloc dirty bits array */ |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 2050 | phys_ram_dirty = qemu_vmalloc(phys_ram_size >> TARGET_PAGE_BITS); |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /* mem_read and mem_write are arrays of functions containing the |
| 2054 | function to access byte (index 0), word (index 1) and dword (index |
| 2055 | 2). All functions must be supplied. If io_index is non zero, the |
| 2056 | corresponding io zone is modified. If it is zero, a new io zone is |
| 2057 | allocated. The return value can be used with |
| 2058 | cpu_register_physical_memory(). (-1) is returned if error. */ |
| 2059 | int cpu_register_io_memory(int io_index, |
| 2060 | CPUReadMemoryFunc **mem_read, |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2061 | CPUWriteMemoryFunc **mem_write, |
| 2062 | void *opaque) |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 2063 | { |
| 2064 | int i; |
| 2065 | |
| 2066 | if (io_index <= 0) { |
| 2067 | if (io_index >= IO_MEM_NB_ENTRIES) |
| 2068 | return -1; |
| 2069 | io_index = io_mem_nb++; |
| 2070 | } else { |
| 2071 | if (io_index >= IO_MEM_NB_ENTRIES) |
| 2072 | return -1; |
| 2073 | } |
| 2074 | |
| 2075 | for(i = 0;i < 3; i++) { |
| 2076 | io_mem_read[io_index][i] = mem_read[i]; |
| 2077 | io_mem_write[io_index][i] = mem_write[i]; |
| 2078 | } |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2079 | io_mem_opaque[io_index] = opaque; |
bellard | 33417e7 | 2003-08-10 21:47:01 +0000 | [diff] [blame] | 2080 | return io_index << IO_MEM_SHIFT; |
| 2081 | } |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 2082 | |
bellard | 8926b51 | 2004-10-10 15:14:20 +0000 | [diff] [blame] | 2083 | CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index) |
| 2084 | { |
| 2085 | return io_mem_write[io_index >> IO_MEM_SHIFT]; |
| 2086 | } |
| 2087 | |
| 2088 | CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index) |
| 2089 | { |
| 2090 | return io_mem_read[io_index >> IO_MEM_SHIFT]; |
| 2091 | } |
| 2092 | |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2093 | /* physical memory access (slow version, mainly for debug) */ |
| 2094 | #if defined(CONFIG_USER_ONLY) |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 2095 | void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2096 | int len, int is_write) |
| 2097 | { |
| 2098 | int l, flags; |
| 2099 | target_ulong page; |
| 2100 | |
| 2101 | while (len > 0) { |
| 2102 | page = addr & TARGET_PAGE_MASK; |
| 2103 | l = (page + TARGET_PAGE_SIZE) - addr; |
| 2104 | if (l > len) |
| 2105 | l = len; |
| 2106 | flags = page_get_flags(page); |
| 2107 | if (!(flags & PAGE_VALID)) |
| 2108 | return; |
| 2109 | if (is_write) { |
| 2110 | if (!(flags & PAGE_WRITE)) |
| 2111 | return; |
| 2112 | memcpy((uint8_t *)addr, buf, len); |
| 2113 | } else { |
| 2114 | if (!(flags & PAGE_READ)) |
| 2115 | return; |
| 2116 | memcpy(buf, (uint8_t *)addr, len); |
| 2117 | } |
| 2118 | len -= l; |
| 2119 | buf += l; |
| 2120 | addr += l; |
| 2121 | } |
| 2122 | } |
bellard | 8df1cd0 | 2005-01-28 22:37:22 +0000 | [diff] [blame] | 2123 | |
| 2124 | /* never used */ |
| 2125 | uint32_t ldl_phys(target_phys_addr_t addr) |
| 2126 | { |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) |
| 2131 | { |
| 2132 | } |
| 2133 | |
| 2134 | void stl_phys(target_phys_addr_t addr, uint32_t val) |
| 2135 | { |
| 2136 | } |
| 2137 | |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2138 | #else |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 2139 | void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2140 | int len, int is_write) |
| 2141 | { |
| 2142 | int l, io_index; |
| 2143 | uint8_t *ptr; |
| 2144 | uint32_t val; |
bellard | 2e12669 | 2004-04-25 21:28:44 +0000 | [diff] [blame] | 2145 | target_phys_addr_t page; |
| 2146 | unsigned long pd; |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 2147 | PhysPageDesc *p; |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2148 | |
| 2149 | while (len > 0) { |
| 2150 | page = addr & TARGET_PAGE_MASK; |
| 2151 | l = (page + TARGET_PAGE_SIZE) - addr; |
| 2152 | if (l > len) |
| 2153 | l = len; |
bellard | 92e873b | 2004-05-21 14:52:29 +0000 | [diff] [blame] | 2154 | p = phys_page_find(page >> TARGET_PAGE_BITS); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2155 | if (!p) { |
| 2156 | pd = IO_MEM_UNASSIGNED; |
| 2157 | } else { |
| 2158 | pd = p->phys_offset; |
| 2159 | } |
| 2160 | |
| 2161 | if (is_write) { |
| 2162 | if ((pd & ~TARGET_PAGE_MASK) != 0) { |
| 2163 | io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); |
| 2164 | if (l >= 4 && ((addr & 3) == 0)) { |
| 2165 | /* 32 bit read access */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2166 | val = ldl_p(buf); |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2167 | io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2168 | l = 4; |
| 2169 | } else if (l >= 2 && ((addr & 1) == 0)) { |
| 2170 | /* 16 bit read access */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2171 | val = lduw_p(buf); |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2172 | io_mem_write[io_index][1](io_mem_opaque[io_index], addr, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2173 | l = 2; |
| 2174 | } else { |
| 2175 | /* 8 bit access */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2176 | val = ldub_p(buf); |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2177 | io_mem_write[io_index][0](io_mem_opaque[io_index], addr, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2178 | l = 1; |
| 2179 | } |
| 2180 | } else { |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 2181 | unsigned long addr1; |
| 2182 | addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2183 | /* RAM case */ |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 2184 | ptr = phys_ram_base + addr1; |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2185 | memcpy(ptr, buf, l); |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 2186 | /* invalidate code */ |
| 2187 | tb_invalidate_phys_page_range(addr1, addr1 + l, 0); |
| 2188 | /* set dirty bit */ |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 2189 | phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] = 0xff; |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2190 | } |
| 2191 | } else { |
| 2192 | if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && |
| 2193 | (pd & ~TARGET_PAGE_MASK) != IO_MEM_CODE) { |
| 2194 | /* I/O case */ |
| 2195 | io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); |
| 2196 | if (l >= 4 && ((addr & 3) == 0)) { |
| 2197 | /* 32 bit read access */ |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2198 | val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2199 | stl_p(buf, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2200 | l = 4; |
| 2201 | } else if (l >= 2 && ((addr & 1) == 0)) { |
| 2202 | /* 16 bit read access */ |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2203 | val = io_mem_read[io_index][1](io_mem_opaque[io_index], addr); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2204 | stw_p(buf, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2205 | l = 2; |
| 2206 | } else { |
| 2207 | /* 8 bit access */ |
bellard | a4193c8 | 2004-06-03 14:01:43 +0000 | [diff] [blame] | 2208 | val = io_mem_read[io_index][0](io_mem_opaque[io_index], addr); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 2209 | stb_p(buf, val); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2210 | l = 1; |
| 2211 | } |
| 2212 | } else { |
| 2213 | /* RAM case */ |
| 2214 | ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + |
| 2215 | (addr & ~TARGET_PAGE_MASK); |
| 2216 | memcpy(buf, ptr, l); |
| 2217 | } |
| 2218 | } |
| 2219 | len -= l; |
| 2220 | buf += l; |
| 2221 | addr += l; |
| 2222 | } |
| 2223 | } |
bellard | 8df1cd0 | 2005-01-28 22:37:22 +0000 | [diff] [blame] | 2224 | |
| 2225 | /* warning: addr must be aligned */ |
| 2226 | uint32_t ldl_phys(target_phys_addr_t addr) |
| 2227 | { |
| 2228 | int io_index; |
| 2229 | uint8_t *ptr; |
| 2230 | uint32_t val; |
| 2231 | unsigned long pd; |
| 2232 | PhysPageDesc *p; |
| 2233 | |
| 2234 | p = phys_page_find(addr >> TARGET_PAGE_BITS); |
| 2235 | if (!p) { |
| 2236 | pd = IO_MEM_UNASSIGNED; |
| 2237 | } else { |
| 2238 | pd = p->phys_offset; |
| 2239 | } |
| 2240 | |
| 2241 | if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && |
| 2242 | (pd & ~TARGET_PAGE_MASK) != IO_MEM_CODE) { |
| 2243 | /* I/O case */ |
| 2244 | io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); |
| 2245 | val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr); |
| 2246 | } else { |
| 2247 | /* RAM case */ |
| 2248 | ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + |
| 2249 | (addr & ~TARGET_PAGE_MASK); |
| 2250 | val = ldl_p(ptr); |
| 2251 | } |
| 2252 | return val; |
| 2253 | } |
| 2254 | |
| 2255 | /* warning: addr must be aligned. The ram page is not masked as dirty |
| 2256 | and the code inside is not invalidated. It is useful if the dirty |
| 2257 | bits are used to track modified PTEs */ |
| 2258 | void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) |
| 2259 | { |
| 2260 | int io_index; |
| 2261 | uint8_t *ptr; |
| 2262 | unsigned long pd; |
| 2263 | PhysPageDesc *p; |
| 2264 | |
| 2265 | p = phys_page_find(addr >> TARGET_PAGE_BITS); |
| 2266 | if (!p) { |
| 2267 | pd = IO_MEM_UNASSIGNED; |
| 2268 | } else { |
| 2269 | pd = p->phys_offset; |
| 2270 | } |
| 2271 | |
| 2272 | if ((pd & ~TARGET_PAGE_MASK) != 0) { |
| 2273 | io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); |
| 2274 | io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val); |
| 2275 | } else { |
| 2276 | ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) + |
| 2277 | (addr & ~TARGET_PAGE_MASK); |
| 2278 | stl_p(ptr, val); |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | /* warning: addr must be aligned */ |
| 2283 | /* XXX: optimize code invalidation test */ |
| 2284 | void stl_phys(target_phys_addr_t addr, uint32_t val) |
| 2285 | { |
| 2286 | int io_index; |
| 2287 | uint8_t *ptr; |
| 2288 | unsigned long pd; |
| 2289 | PhysPageDesc *p; |
| 2290 | |
| 2291 | p = phys_page_find(addr >> TARGET_PAGE_BITS); |
| 2292 | if (!p) { |
| 2293 | pd = IO_MEM_UNASSIGNED; |
| 2294 | } else { |
| 2295 | pd = p->phys_offset; |
| 2296 | } |
| 2297 | |
| 2298 | if ((pd & ~TARGET_PAGE_MASK) != 0) { |
| 2299 | io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); |
| 2300 | io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val); |
| 2301 | } else { |
| 2302 | unsigned long addr1; |
| 2303 | addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK); |
| 2304 | /* RAM case */ |
| 2305 | ptr = phys_ram_base + addr1; |
| 2306 | stl_p(ptr, val); |
| 2307 | /* invalidate code */ |
| 2308 | tb_invalidate_phys_page_range(addr1, addr1 + 4, 0); |
| 2309 | /* set dirty bit */ |
bellard | 0a962c0 | 2005-02-10 22:00:27 +0000 | [diff] [blame] | 2310 | phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] = 0xff; |
bellard | 8df1cd0 | 2005-01-28 22:37:22 +0000 | [diff] [blame] | 2311 | } |
| 2312 | } |
| 2313 | |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2314 | #endif |
| 2315 | |
| 2316 | /* virtual memory access for debug */ |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 2317 | int cpu_memory_rw_debug(CPUState *env, target_ulong addr, |
| 2318 | uint8_t *buf, int len, int is_write) |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2319 | { |
| 2320 | int l; |
| 2321 | target_ulong page, phys_addr; |
| 2322 | |
| 2323 | while (len > 0) { |
| 2324 | page = addr & TARGET_PAGE_MASK; |
| 2325 | phys_addr = cpu_get_phys_page_debug(env, page); |
| 2326 | /* if no physical page mapped, return an error */ |
| 2327 | if (phys_addr == -1) |
| 2328 | return -1; |
| 2329 | l = (page + TARGET_PAGE_SIZE) - addr; |
| 2330 | if (l > len) |
| 2331 | l = len; |
bellard | b448f2f | 2004-02-25 23:24:04 +0000 | [diff] [blame] | 2332 | cpu_physical_memory_rw(phys_addr + (addr & ~TARGET_PAGE_MASK), |
| 2333 | buf, l, is_write); |
bellard | 13eb76e | 2004-01-24 15:23:36 +0000 | [diff] [blame] | 2334 | len -= l; |
| 2335 | buf += l; |
| 2336 | addr += l; |
| 2337 | } |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
bellard | e3db722 | 2005-01-26 22:00:47 +0000 | [diff] [blame] | 2341 | void dump_exec_info(FILE *f, |
| 2342 | int (*cpu_fprintf)(FILE *f, const char *fmt, ...)) |
| 2343 | { |
| 2344 | int i, target_code_size, max_target_code_size; |
| 2345 | int direct_jmp_count, direct_jmp2_count, cross_page; |
| 2346 | TranslationBlock *tb; |
| 2347 | |
| 2348 | target_code_size = 0; |
| 2349 | max_target_code_size = 0; |
| 2350 | cross_page = 0; |
| 2351 | direct_jmp_count = 0; |
| 2352 | direct_jmp2_count = 0; |
| 2353 | for(i = 0; i < nb_tbs; i++) { |
| 2354 | tb = &tbs[i]; |
| 2355 | target_code_size += tb->size; |
| 2356 | if (tb->size > max_target_code_size) |
| 2357 | max_target_code_size = tb->size; |
| 2358 | if (tb->page_addr[1] != -1) |
| 2359 | cross_page++; |
| 2360 | if (tb->tb_next_offset[0] != 0xffff) { |
| 2361 | direct_jmp_count++; |
| 2362 | if (tb->tb_next_offset[1] != 0xffff) { |
| 2363 | direct_jmp2_count++; |
| 2364 | } |
| 2365 | } |
| 2366 | } |
| 2367 | /* XXX: avoid using doubles ? */ |
| 2368 | cpu_fprintf(f, "TB count %d\n", nb_tbs); |
| 2369 | cpu_fprintf(f, "TB avg target size %d max=%d bytes\n", |
| 2370 | nb_tbs ? target_code_size / nb_tbs : 0, |
| 2371 | max_target_code_size); |
| 2372 | cpu_fprintf(f, "TB avg host size %d bytes (expansion ratio: %0.1f)\n", |
| 2373 | nb_tbs ? (code_gen_ptr - code_gen_buffer) / nb_tbs : 0, |
| 2374 | target_code_size ? (double) (code_gen_ptr - code_gen_buffer) / target_code_size : 0); |
| 2375 | cpu_fprintf(f, "cross page TB count %d (%d%%)\n", |
| 2376 | cross_page, |
| 2377 | nb_tbs ? (cross_page * 100) / nb_tbs : 0); |
| 2378 | cpu_fprintf(f, "direct jump count %d (%d%%) (2 jumps=%d %d%%)\n", |
| 2379 | direct_jmp_count, |
| 2380 | nb_tbs ? (direct_jmp_count * 100) / nb_tbs : 0, |
| 2381 | direct_jmp2_count, |
| 2382 | nb_tbs ? (direct_jmp2_count * 100) / nb_tbs : 0); |
| 2383 | cpu_fprintf(f, "TB flush count %d\n", tb_flush_count); |
| 2384 | cpu_fprintf(f, "TB invalidate count %d\n", tb_phys_invalidate_count); |
| 2385 | cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count); |
| 2386 | } |
| 2387 | |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 2388 | #if !defined(CONFIG_USER_ONLY) |
| 2389 | |
| 2390 | #define MMUSUFFIX _cmmu |
| 2391 | #define GETPC() NULL |
| 2392 | #define env cpu_single_env |
bellard | b769d8f | 2004-10-03 15:07:13 +0000 | [diff] [blame] | 2393 | #define SOFTMMU_CODE_ACCESS |
bellard | 61382a5 | 2003-10-27 21:22:23 +0000 | [diff] [blame] | 2394 | |
| 2395 | #define SHIFT 0 |
| 2396 | #include "softmmu_template.h" |
| 2397 | |
| 2398 | #define SHIFT 1 |
| 2399 | #include "softmmu_template.h" |
| 2400 | |
| 2401 | #define SHIFT 2 |
| 2402 | #include "softmmu_template.h" |
| 2403 | |
| 2404 | #define SHIFT 3 |
| 2405 | #include "softmmu_template.h" |
| 2406 | |
| 2407 | #undef env |
| 2408 | |
| 2409 | #endif |