bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * i386 emulator main execution loop |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 66321a1 | 2005-04-06 20:47:48 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2005 Fabrice Bellard |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 5 | * |
bellard | 3ef693a | 2003-03-23 20:17:16 +0000 | [diff] [blame] | 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. |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 10 | * |
bellard | 3ef693a | 2003-03-23 20:17:16 +0000 | [diff] [blame] | 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. |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 15 | * |
bellard | 3ef693a | 2003-03-23 20:17:16 +0000 | [diff] [blame] | 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 |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 19 | */ |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 20 | #include "config.h" |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 21 | #include "exec.h" |
bellard | 956034d | 2003-04-29 20:40:53 +0000 | [diff] [blame] | 22 | #include "disas.h" |
ths | 40a2e65 | 2008-01-23 19:01:12 +0000 | [diff] [blame] | 23 | #include <string.h> |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 24 | |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 25 | #if !defined(CONFIG_SOFTMMU) |
| 26 | #undef EAX |
| 27 | #undef ECX |
| 28 | #undef EDX |
| 29 | #undef EBX |
| 30 | #undef ESP |
| 31 | #undef EBP |
| 32 | #undef ESI |
| 33 | #undef EDI |
| 34 | #undef EIP |
| 35 | #include <signal.h> |
| 36 | #include <sys/ucontext.h> |
| 37 | #endif |
| 38 | |
bellard | 36bdbe5 | 2003-11-19 22:12:02 +0000 | [diff] [blame] | 39 | int tb_invalidated_flag; |
| 40 | |
bellard | dc99065 | 2003-03-19 00:00:28 +0000 | [diff] [blame] | 41 | //#define DEBUG_EXEC |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 42 | //#define DEBUG_SIGNAL |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 43 | |
ths | 40a2e65 | 2008-01-23 19:01:12 +0000 | [diff] [blame] | 44 | /* translation settings */ |
| 45 | int translation_settings = 0; |
| 46 | |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 47 | #define SAVE_GLOBALS() |
| 48 | #define RESTORE_GLOBALS() |
| 49 | |
| 50 | #if defined(__sparc__) && !defined(HOST_SOLARIS) |
| 51 | #include <features.h> |
| 52 | #if defined(__GLIBC__) && ((__GLIBC__ < 2) || \ |
| 53 | ((__GLIBC__ == 2) && (__GLIBC_MINOR__ <= 90))) |
| 54 | // Work around ugly bugs in glibc that mangle global register contents |
| 55 | |
| 56 | static volatile void *saved_env; |
| 57 | static volatile unsigned long saved_t0, saved_i7; |
| 58 | #undef SAVE_GLOBALS |
| 59 | #define SAVE_GLOBALS() do { \ |
| 60 | saved_env = env; \ |
| 61 | saved_t0 = T0; \ |
| 62 | asm volatile ("st %%i7, [%0]" : : "r" (&saved_i7)); \ |
| 63 | } while(0) |
| 64 | |
| 65 | #undef RESTORE_GLOBALS |
| 66 | #define RESTORE_GLOBALS() do { \ |
| 67 | env = (void *)saved_env; \ |
| 68 | T0 = saved_t0; \ |
| 69 | asm volatile ("ld [%0], %%i7" : : "r" (&saved_i7)); \ |
| 70 | } while(0) |
| 71 | |
| 72 | static int sparc_setjmp(jmp_buf buf) |
| 73 | { |
| 74 | int ret; |
| 75 | |
| 76 | SAVE_GLOBALS(); |
| 77 | ret = setjmp(buf); |
| 78 | RESTORE_GLOBALS(); |
| 79 | return ret; |
| 80 | } |
| 81 | #undef setjmp |
| 82 | #define setjmp(jmp_buf) sparc_setjmp(jmp_buf) |
| 83 | |
| 84 | static void sparc_longjmp(jmp_buf buf, int val) |
| 85 | { |
| 86 | SAVE_GLOBALS(); |
| 87 | longjmp(buf, val); |
| 88 | } |
| 89 | #define longjmp(jmp_buf, val) sparc_longjmp(jmp_buf, val) |
| 90 | #endif |
| 91 | #endif |
| 92 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 93 | void cpu_loop_exit(void) |
| 94 | { |
ths | bfed01f | 2007-06-03 17:44:37 +0000 | [diff] [blame] | 95 | /* NOTE: the register at this point must be saved by hand because |
| 96 | longjmp restore them */ |
| 97 | regs_to_env(); |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 98 | longjmp(env->jmp_env, 1); |
| 99 | } |
ths | bfed01f | 2007-06-03 17:44:37 +0000 | [diff] [blame] | 100 | |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 101 | #if !(defined(TARGET_SPARC) || defined(TARGET_SH4) || defined(TARGET_M68K)) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 102 | #define reg_T2 |
| 103 | #endif |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 104 | |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 105 | /* exit the current TB from a signal handler. The host registers are |
| 106 | restored in a state compatible with the CPU emulator |
| 107 | */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 108 | void cpu_resume_from_signal(CPUState *env1, void *puc) |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 109 | { |
| 110 | #if !defined(CONFIG_SOFTMMU) |
| 111 | struct ucontext *uc = puc; |
| 112 | #endif |
| 113 | |
| 114 | env = env1; |
| 115 | |
| 116 | /* XXX: restore cpu registers saved in host registers */ |
| 117 | |
| 118 | #if !defined(CONFIG_SOFTMMU) |
| 119 | if (puc) { |
| 120 | /* XXX: use siglongjmp ? */ |
| 121 | sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL); |
| 122 | } |
| 123 | #endif |
| 124 | longjmp(env->jmp_env, 1); |
| 125 | } |
| 126 | |
ths | 40a2e65 | 2008-01-23 19:01:12 +0000 | [diff] [blame] | 127 | CPUTranslationSetting cpu_translation_settings[] = { |
| 128 | { CPU_SETTING_NO_CACHE, "no-cache", |
| 129 | "Do not use translation blocks cache (very slow!)" }, |
| 130 | { 0, NULL, NULL }, |
| 131 | }; |
| 132 | |
| 133 | void cpu_set_translation_settings(int translation_flags) |
| 134 | { |
| 135 | translation_settings = translation_flags; |
| 136 | } |
| 137 | |
| 138 | static int cmp1(const char *s1, int n, const char *s2) |
| 139 | { |
| 140 | if (strlen(s2) != n) |
| 141 | return 0; |
| 142 | return memcmp(s1, s2, n) == 0; |
| 143 | } |
| 144 | |
| 145 | /* takes a comma separated list of translation settings. Return 0 if error. */ |
| 146 | int cpu_str_to_translation_mask(const char *str) |
| 147 | { |
| 148 | CPUTranslationSetting *setting; |
| 149 | int mask; |
| 150 | const char *p, *p1; |
| 151 | |
| 152 | p = str; |
| 153 | mask = 0; |
| 154 | for(;;) { |
| 155 | p1 = strchr(p, ','); |
| 156 | if (!p1) |
| 157 | p1 = p + strlen(p); |
| 158 | if(cmp1(p,p1-p,"all")) { |
| 159 | for(setting = cpu_translation_settings; setting->mask != 0; setting++) { |
| 160 | mask |= setting->mask; |
| 161 | } |
| 162 | } else { |
| 163 | for(setting = cpu_translation_settings; setting->mask != 0; setting++) { |
| 164 | if (cmp1(p, p1 - p, setting->name)) |
| 165 | goto found; |
| 166 | } |
| 167 | return 0; |
| 168 | } |
| 169 | found: |
| 170 | mask |= setting->mask; |
| 171 | if (*p1 != ',') |
| 172 | break; |
| 173 | p = p1 + 1; |
| 174 | } |
| 175 | return mask; |
| 176 | } |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 177 | |
| 178 | static TranslationBlock *tb_find_slow(target_ulong pc, |
| 179 | target_ulong cs_base, |
j_mayer | c068688 | 2007-09-20 22:47:42 +0000 | [diff] [blame] | 180 | uint64_t flags) |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 181 | { |
| 182 | TranslationBlock *tb, **ptb1; |
| 183 | int code_gen_size; |
| 184 | unsigned int h; |
| 185 | target_ulong phys_pc, phys_page1, phys_page2, virt_page2; |
| 186 | uint8_t *tc_ptr; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 187 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 188 | spin_lock(&tb_lock); |
| 189 | |
| 190 | tb_invalidated_flag = 0; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 191 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 192 | regs_to_env(); /* XXX: do it just before cpu_gen_code() */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 193 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 194 | /* find translated block using physical mappings */ |
| 195 | phys_pc = get_phys_addr_code(env, pc); |
| 196 | phys_page1 = phys_pc & TARGET_PAGE_MASK; |
| 197 | phys_page2 = -1; |
ths | 40a2e65 | 2008-01-23 19:01:12 +0000 | [diff] [blame] | 198 | if (translation_settings & CPU_SETTING_NO_CACHE) |
| 199 | goto not_found; |
| 200 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 201 | h = tb_phys_hash_func(phys_pc); |
| 202 | ptb1 = &tb_phys_hash[h]; |
| 203 | for(;;) { |
| 204 | tb = *ptb1; |
| 205 | if (!tb) |
| 206 | goto not_found; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 207 | if (tb->pc == pc && |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 208 | tb->page_addr[0] == phys_page1 && |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 209 | tb->cs_base == cs_base && |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 210 | tb->flags == flags) { |
| 211 | /* check next page if needed */ |
| 212 | if (tb->page_addr[1] != -1) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 213 | virt_page2 = (pc & TARGET_PAGE_MASK) + |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 214 | TARGET_PAGE_SIZE; |
| 215 | phys_page2 = get_phys_addr_code(env, virt_page2); |
| 216 | if (tb->page_addr[1] == phys_page2) |
| 217 | goto found; |
| 218 | } else { |
| 219 | goto found; |
| 220 | } |
| 221 | } |
| 222 | ptb1 = &tb->phys_hash_next; |
| 223 | } |
| 224 | not_found: |
| 225 | /* if no translated code available, then translate it now */ |
| 226 | tb = tb_alloc(pc); |
| 227 | if (!tb) { |
| 228 | /* flush must be done */ |
| 229 | tb_flush(env); |
| 230 | /* cannot fail at this point */ |
| 231 | tb = tb_alloc(pc); |
| 232 | /* don't forget to invalidate previous TB info */ |
bellard | 1538800 | 2005-12-19 01:42:32 +0000 | [diff] [blame] | 233 | tb_invalidated_flag = 1; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 234 | } |
| 235 | tc_ptr = code_gen_ptr; |
| 236 | tb->tc_ptr = tc_ptr; |
| 237 | tb->cs_base = cs_base; |
| 238 | tb->flags = flags; |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 239 | SAVE_GLOBALS(); |
blueswir1 | d07bde8 | 2007-12-11 19:35:45 +0000 | [diff] [blame] | 240 | cpu_gen_code(env, tb, &code_gen_size); |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 241 | RESTORE_GLOBALS(); |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 242 | code_gen_ptr = (void *)(((unsigned long)code_gen_ptr + code_gen_size + CODE_GEN_ALIGN - 1) & ~(CODE_GEN_ALIGN - 1)); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 243 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 244 | /* check next page if needed */ |
| 245 | virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; |
| 246 | phys_page2 = -1; |
| 247 | if ((pc & TARGET_PAGE_MASK) != virt_page2) { |
| 248 | phys_page2 = get_phys_addr_code(env, virt_page2); |
| 249 | } |
| 250 | tb_link_phys(tb, phys_pc, phys_page2); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 251 | |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 252 | found: |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 253 | /* we add the TB in the virtual pc hash table */ |
| 254 | env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)] = tb; |
| 255 | spin_unlock(&tb_lock); |
| 256 | return tb; |
| 257 | } |
| 258 | |
| 259 | static inline TranslationBlock *tb_find_fast(void) |
| 260 | { |
| 261 | TranslationBlock *tb; |
| 262 | target_ulong cs_base, pc; |
j_mayer | c068688 | 2007-09-20 22:47:42 +0000 | [diff] [blame] | 263 | uint64_t flags; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 264 | |
| 265 | /* we record a subset of the CPU state. It will |
| 266 | always be the same before a given translated block |
| 267 | is executed. */ |
| 268 | #if defined(TARGET_I386) |
| 269 | flags = env->hflags; |
| 270 | flags |= (env->eflags & (IOPL_MASK | TF_MASK | VM_MASK)); |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 271 | flags |= env->intercept; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 272 | cs_base = env->segs[R_CS].base; |
| 273 | pc = cs_base + env->eip; |
| 274 | #elif defined(TARGET_ARM) |
| 275 | flags = env->thumb | (env->vfp.vec_len << 1) |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 276 | | (env->vfp.vec_stride << 4); |
| 277 | if ((env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) |
| 278 | flags |= (1 << 6); |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 279 | if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)) |
| 280 | flags |= (1 << 7); |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 281 | flags |= (env->condexec_bits << 8); |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 282 | cs_base = 0; |
| 283 | pc = env->regs[15]; |
| 284 | #elif defined(TARGET_SPARC) |
| 285 | #ifdef TARGET_SPARC64 |
bellard | a80dde0 | 2006-06-26 19:53:29 +0000 | [diff] [blame] | 286 | // Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled |
| 287 | flags = (((env->pstate & PS_PEF) >> 1) | ((env->fprs & FPRS_FEF) << 2)) |
| 288 | | (env->pstate & PS_PRIV) | ((env->lsu & (DMMU_E | IMMU_E)) >> 2); |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 289 | #else |
blueswir1 | 6d5f237 | 2007-11-07 17:03:37 +0000 | [diff] [blame] | 290 | // FPU enable . Supervisor |
| 291 | flags = (env->psref << 4) | env->psrs; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 292 | #endif |
| 293 | cs_base = env->npc; |
| 294 | pc = env->pc; |
| 295 | #elif defined(TARGET_PPC) |
j_mayer | 1527c87 | 2007-09-19 05:37:56 +0000 | [diff] [blame] | 296 | flags = env->hflags; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 297 | cs_base = 0; |
| 298 | pc = env->nip; |
| 299 | #elif defined(TARGET_MIPS) |
pbrook | 56b1940 | 2006-03-11 16:23:39 +0000 | [diff] [blame] | 300 | flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK); |
bellard | cc9442b | 2005-11-26 18:43:28 +0000 | [diff] [blame] | 301 | cs_base = 0; |
ths | ead9360 | 2007-09-06 00:18:15 +0000 | [diff] [blame] | 302 | pc = env->PC[env->current_tc]; |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 303 | #elif defined(TARGET_M68K) |
pbrook | acf930a | 2007-05-29 14:57:59 +0000 | [diff] [blame] | 304 | flags = (env->fpcr & M68K_FPCR_PREC) /* Bit 6 */ |
| 305 | | (env->sr & SR_S) /* Bit 13 */ |
| 306 | | ((env->macsr >> 4) & 0xf); /* Bits 0-3 */ |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 307 | cs_base = 0; |
| 308 | pc = env->pc; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 309 | #elif defined(TARGET_SH4) |
ths | 823029f | 2007-12-02 06:10:04 +0000 | [diff] [blame] | 310 | flags = env->flags; |
| 311 | cs_base = 0; |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 312 | pc = env->pc; |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 313 | #elif defined(TARGET_ALPHA) |
| 314 | flags = env->ps; |
| 315 | cs_base = 0; |
| 316 | pc = env->pc; |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 317 | #elif defined(TARGET_CRIS) |
| 318 | flags = 0; |
| 319 | cs_base = 0; |
| 320 | pc = env->pc; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 321 | #else |
| 322 | #error unsupported CPU |
| 323 | #endif |
ths | 40a2e65 | 2008-01-23 19:01:12 +0000 | [diff] [blame] | 324 | if (translation_settings & CPU_SETTING_NO_CACHE) |
| 325 | tb = NULL; |
| 326 | else |
| 327 | tb = env->tb_jmp_cache[tb_jmp_cache_hash_func(pc)]; |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 328 | if (__builtin_expect(!tb || tb->pc != pc || tb->cs_base != cs_base || |
| 329 | tb->flags != flags, 0)) { |
| 330 | tb = tb_find_slow(pc, cs_base, flags); |
bellard | 1538800 | 2005-12-19 01:42:32 +0000 | [diff] [blame] | 331 | /* Note: we do it here to avoid a gcc bug on Mac OS X when |
| 332 | doing it in tb_find_slow */ |
| 333 | if (tb_invalidated_flag) { |
| 334 | /* as some TB could have been invalidated because |
| 335 | of memory exceptions while generating the code, we |
| 336 | must recompute the hash index here */ |
| 337 | T0 = 0; |
| 338 | } |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 339 | } |
| 340 | return tb; |
| 341 | } |
| 342 | |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 343 | #define BREAK_CHAIN T0 = 0 |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 344 | |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 345 | /* main execution loop */ |
| 346 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 347 | int cpu_exec(CPUState *env1) |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 348 | { |
pbrook | 1057eaa | 2007-02-04 13:37:44 +0000 | [diff] [blame] | 349 | #define DECLARE_HOST_REGS 1 |
| 350 | #include "hostregs_helper.h" |
| 351 | #if defined(TARGET_SPARC) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 352 | #if defined(reg_REGWPTR) |
| 353 | uint32_t *saved_regwptr; |
| 354 | #endif |
| 355 | #endif |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 356 | int ret, interrupt_request; |
bellard | 57fec1f | 2008-02-01 10:50:11 +0000 | [diff] [blame^] | 357 | long (*gen_func)(void); |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 358 | TranslationBlock *tb; |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 359 | uint8_t *tc_ptr; |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 360 | |
ths | bfed01f | 2007-06-03 17:44:37 +0000 | [diff] [blame] | 361 | if (cpu_halted(env1) == EXCP_HALTED) |
| 362 | return EXCP_HALTED; |
bellard | 5a1e3cf | 2005-11-23 21:02:53 +0000 | [diff] [blame] | 363 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 364 | cpu_single_env = env1; |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 365 | |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 366 | /* first we save global registers */ |
pbrook | 1057eaa | 2007-02-04 13:37:44 +0000 | [diff] [blame] | 367 | #define SAVE_HOST_REGS 1 |
| 368 | #include "hostregs_helper.h" |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 369 | env = env1; |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 370 | SAVE_GLOBALS(); |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 371 | |
bellard | 0d1a29f | 2004-10-12 22:01:28 +0000 | [diff] [blame] | 372 | env_to_regs(); |
ths | ecb644f | 2007-06-03 18:45:53 +0000 | [diff] [blame] | 373 | #if defined(TARGET_I386) |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 374 | /* put eflags in CPU temporary format */ |
bellard | fc2b4c4 | 2003-03-29 16:52:44 +0000 | [diff] [blame] | 375 | CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
| 376 | DF = 1 - (2 * ((env->eflags >> 10) & 1)); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 377 | CC_OP = CC_OP_EFLAGS; |
bellard | fc2b4c4 | 2003-03-29 16:52:44 +0000 | [diff] [blame] | 378 | env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 379 | #elif defined(TARGET_SPARC) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 380 | #if defined(reg_REGWPTR) |
| 381 | saved_regwptr = REGWPTR; |
| 382 | #endif |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 383 | #elif defined(TARGET_M68K) |
| 384 | env->cc_op = CC_OP_FLAGS; |
| 385 | env->cc_dest = env->sr & 0xf; |
| 386 | env->cc_x = (env->sr >> 4) & 1; |
ths | ecb644f | 2007-06-03 18:45:53 +0000 | [diff] [blame] | 387 | #elif defined(TARGET_ALPHA) |
| 388 | #elif defined(TARGET_ARM) |
| 389 | #elif defined(TARGET_PPC) |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 390 | #elif defined(TARGET_MIPS) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 391 | #elif defined(TARGET_SH4) |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 392 | #elif defined(TARGET_CRIS) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 393 | /* XXXXX */ |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 394 | #else |
| 395 | #error unsupported target CPU |
| 396 | #endif |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 397 | env->exception_index = -1; |
bellard | 9d27abd | 2003-05-10 13:13:54 +0000 | [diff] [blame] | 398 | |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 399 | /* prepare setjmp context for exception handling */ |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 400 | for(;;) { |
| 401 | if (setjmp(env->jmp_env) == 0) { |
bellard | ee8b702 | 2004-02-03 23:35:10 +0000 | [diff] [blame] | 402 | env->current_tb = NULL; |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 403 | /* if an exception is pending, we execute it here */ |
| 404 | if (env->exception_index >= 0) { |
| 405 | if (env->exception_index >= EXCP_INTERRUPT) { |
| 406 | /* exit request from the cpu execution loop */ |
| 407 | ret = env->exception_index; |
| 408 | break; |
| 409 | } else if (env->user_mode_only) { |
| 410 | /* if user mode only, we simulate a fake exception |
ths | 9f08349 | 2006-12-07 18:28:42 +0000 | [diff] [blame] | 411 | which will be handled outside the cpu execution |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 412 | loop */ |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 413 | #if defined(TARGET_I386) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 414 | do_interrupt_user(env->exception_index, |
| 415 | env->exception_is_int, |
| 416 | env->error_code, |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 417 | env->exception_next_eip); |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 418 | #endif |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 419 | ret = env->exception_index; |
| 420 | break; |
| 421 | } else { |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 422 | #if defined(TARGET_I386) |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 423 | /* simulate a real cpu exception. On i386, it can |
| 424 | trigger new exceptions, but we do not handle |
| 425 | double or triple faults yet. */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 426 | do_interrupt(env->exception_index, |
| 427 | env->exception_is_int, |
| 428 | env->error_code, |
bellard | d05e66d | 2003-08-20 21:34:35 +0000 | [diff] [blame] | 429 | env->exception_next_eip, 0); |
ths | 678dde1 | 2007-03-31 20:28:52 +0000 | [diff] [blame] | 430 | /* successfully delivered */ |
| 431 | env->old_exception = -1; |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 432 | #elif defined(TARGET_PPC) |
| 433 | do_interrupt(env); |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 434 | #elif defined(TARGET_MIPS) |
| 435 | do_interrupt(env); |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 436 | #elif defined(TARGET_SPARC) |
bellard | 1a0c329 | 2005-02-13 19:02:07 +0000 | [diff] [blame] | 437 | do_interrupt(env->exception_index); |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 438 | #elif defined(TARGET_ARM) |
| 439 | do_interrupt(env); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 440 | #elif defined(TARGET_SH4) |
| 441 | do_interrupt(env); |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 442 | #elif defined(TARGET_ALPHA) |
| 443 | do_interrupt(env); |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 444 | #elif defined(TARGET_CRIS) |
| 445 | do_interrupt(env); |
pbrook | 0633879 | 2007-05-23 19:58:11 +0000 | [diff] [blame] | 446 | #elif defined(TARGET_M68K) |
| 447 | do_interrupt(0); |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 448 | #endif |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 449 | } |
| 450 | env->exception_index = -1; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 451 | } |
bellard | 9df217a | 2005-02-10 22:05:51 +0000 | [diff] [blame] | 452 | #ifdef USE_KQEMU |
| 453 | if (kqemu_is_ok(env) && env->interrupt_request == 0) { |
| 454 | int ret; |
| 455 | env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK); |
| 456 | ret = kqemu_cpu_exec(env); |
| 457 | /* put eflags in CPU temporary format */ |
| 458 | CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
| 459 | DF = 1 - (2 * ((env->eflags >> 10) & 1)); |
| 460 | CC_OP = CC_OP_EFLAGS; |
| 461 | env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
| 462 | if (ret == 1) { |
| 463 | /* exception */ |
| 464 | longjmp(env->jmp_env, 1); |
| 465 | } else if (ret == 2) { |
| 466 | /* softmmu execution needed */ |
| 467 | } else { |
| 468 | if (env->interrupt_request != 0) { |
| 469 | /* hardware interrupt will be executed just after */ |
| 470 | } else { |
| 471 | /* otherwise, we restart */ |
| 472 | longjmp(env->jmp_env, 1); |
| 473 | } |
| 474 | } |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 475 | } |
bellard | 9df217a | 2005-02-10 22:05:51 +0000 | [diff] [blame] | 476 | #endif |
| 477 | |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 478 | T0 = 0; /* force lookup of first TB */ |
| 479 | for(;;) { |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 480 | SAVE_GLOBALS(); |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 481 | interrupt_request = env->interrupt_request; |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 482 | if (__builtin_expect(interrupt_request, 0) |
| 483 | #if defined(TARGET_I386) |
| 484 | && env->hflags & HF_GIF_MASK |
| 485 | #endif |
| 486 | ) { |
pbrook | 6658ffb | 2007-03-16 23:58:11 +0000 | [diff] [blame] | 487 | if (interrupt_request & CPU_INTERRUPT_DEBUG) { |
| 488 | env->interrupt_request &= ~CPU_INTERRUPT_DEBUG; |
| 489 | env->exception_index = EXCP_DEBUG; |
| 490 | cpu_loop_exit(); |
| 491 | } |
balrog | a90b731 | 2007-05-01 01:28:01 +0000 | [diff] [blame] | 492 | #if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS) || \ |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 493 | defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS) |
balrog | a90b731 | 2007-05-01 01:28:01 +0000 | [diff] [blame] | 494 | if (interrupt_request & CPU_INTERRUPT_HALT) { |
| 495 | env->interrupt_request &= ~CPU_INTERRUPT_HALT; |
| 496 | env->halted = 1; |
| 497 | env->exception_index = EXCP_HLT; |
| 498 | cpu_loop_exit(); |
| 499 | } |
| 500 | #endif |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 501 | #if defined(TARGET_I386) |
bellard | 3b21e03 | 2006-09-24 18:41:56 +0000 | [diff] [blame] | 502 | if ((interrupt_request & CPU_INTERRUPT_SMI) && |
| 503 | !(env->hflags & HF_SMM_MASK)) { |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 504 | svm_check_intercept(SVM_EXIT_SMI); |
bellard | 3b21e03 | 2006-09-24 18:41:56 +0000 | [diff] [blame] | 505 | env->interrupt_request &= ~CPU_INTERRUPT_SMI; |
| 506 | do_smm_enter(); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 507 | BREAK_CHAIN; |
bellard | 3b21e03 | 2006-09-24 18:41:56 +0000 | [diff] [blame] | 508 | } else if ((interrupt_request & CPU_INTERRUPT_HARD) && |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 509 | (env->eflags & IF_MASK || env->hflags & HF_HIF_MASK) && |
bellard | 3f33731 | 2003-08-20 23:02:09 +0000 | [diff] [blame] | 510 | !(env->hflags & HF_INHIBIT_IRQ_MASK)) { |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 511 | int intno; |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 512 | svm_check_intercept(SVM_EXIT_INTR); |
ths | 5262168 | 2007-09-27 01:52:00 +0000 | [diff] [blame] | 513 | env->interrupt_request &= ~(CPU_INTERRUPT_HARD | CPU_INTERRUPT_VIRQ); |
bellard | a541f29 | 2004-04-12 20:39:29 +0000 | [diff] [blame] | 514 | intno = cpu_get_pic_interrupt(env); |
bellard | f193c79 | 2004-03-21 17:06:25 +0000 | [diff] [blame] | 515 | if (loglevel & CPU_LOG_TB_IN_ASM) { |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 516 | fprintf(logfile, "Servicing hardware INT=0x%02x\n", intno); |
| 517 | } |
bellard | d05e66d | 2003-08-20 21:34:35 +0000 | [diff] [blame] | 518 | do_interrupt(intno, 0, 0, 0, 1); |
bellard | 907a5b2 | 2003-06-30 23:18:22 +0000 | [diff] [blame] | 519 | /* ensure that no TB jump will be modified as |
| 520 | the program flow was changed */ |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 521 | BREAK_CHAIN; |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 522 | #if !defined(CONFIG_USER_ONLY) |
| 523 | } else if ((interrupt_request & CPU_INTERRUPT_VIRQ) && |
| 524 | (env->eflags & IF_MASK) && !(env->hflags & HF_INHIBIT_IRQ_MASK)) { |
| 525 | int intno; |
| 526 | /* FIXME: this should respect TPR */ |
| 527 | env->interrupt_request &= ~CPU_INTERRUPT_VIRQ; |
ths | 5262168 | 2007-09-27 01:52:00 +0000 | [diff] [blame] | 528 | svm_check_intercept(SVM_EXIT_VINTR); |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 529 | intno = ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_vector)); |
| 530 | if (loglevel & CPU_LOG_TB_IN_ASM) |
| 531 | fprintf(logfile, "Servicing virtual hardware INT=0x%02x\n", intno); |
| 532 | do_interrupt(intno, 0, 0, -1, 1); |
ths | 5262168 | 2007-09-27 01:52:00 +0000 | [diff] [blame] | 533 | stl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl), |
| 534 | ldl_phys(env->vm_vmcb + offsetof(struct vmcb, control.int_ctl)) & ~V_IRQ_MASK); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 535 | BREAK_CHAIN; |
ths | 0573fbf | 2007-09-23 15:28:04 +0000 | [diff] [blame] | 536 | #endif |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 537 | } |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 538 | #elif defined(TARGET_PPC) |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 539 | #if 0 |
| 540 | if ((interrupt_request & CPU_INTERRUPT_RESET)) { |
| 541 | cpu_ppc_reset(env); |
| 542 | } |
| 543 | #endif |
j_mayer | 4710357 | 2007-03-30 09:38:04 +0000 | [diff] [blame] | 544 | if (interrupt_request & CPU_INTERRUPT_HARD) { |
j_mayer | e9df014 | 2007-04-09 22:45:36 +0000 | [diff] [blame] | 545 | ppc_hw_interrupt(env); |
| 546 | if (env->pending_interrupts == 0) |
| 547 | env->interrupt_request &= ~CPU_INTERRUPT_HARD; |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 548 | BREAK_CHAIN; |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 549 | } |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 550 | #elif defined(TARGET_MIPS) |
| 551 | if ((interrupt_request & CPU_INTERRUPT_HARD) && |
ths | 24c7b0e | 2007-03-30 16:44:54 +0000 | [diff] [blame] | 552 | (env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask) && |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 553 | (env->CP0_Status & (1 << CP0St_IE)) && |
ths | 24c7b0e | 2007-03-30 16:44:54 +0000 | [diff] [blame] | 554 | !(env->CP0_Status & (1 << CP0St_EXL)) && |
| 555 | !(env->CP0_Status & (1 << CP0St_ERL)) && |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 556 | !(env->hflags & MIPS_HFLAG_DM)) { |
| 557 | /* Raise it */ |
| 558 | env->exception_index = EXCP_EXT_INTERRUPT; |
| 559 | env->error_code = 0; |
| 560 | do_interrupt(env); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 561 | BREAK_CHAIN; |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 562 | } |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 563 | #elif defined(TARGET_SPARC) |
bellard | 66321a1 | 2005-04-06 20:47:48 +0000 | [diff] [blame] | 564 | if ((interrupt_request & CPU_INTERRUPT_HARD) && |
| 565 | (env->psret != 0)) { |
| 566 | int pil = env->interrupt_index & 15; |
| 567 | int type = env->interrupt_index & 0xf0; |
| 568 | |
| 569 | if (((type == TT_EXTINT) && |
| 570 | (pil == 15 || pil > env->psrpil)) || |
| 571 | type != TT_EXTINT) { |
| 572 | env->interrupt_request &= ~CPU_INTERRUPT_HARD; |
| 573 | do_interrupt(env->interrupt_index); |
| 574 | env->interrupt_index = 0; |
blueswir1 | 327ac2e | 2007-08-04 10:50:30 +0000 | [diff] [blame] | 575 | #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) |
| 576 | cpu_check_irqs(env); |
| 577 | #endif |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 578 | BREAK_CHAIN; |
bellard | 66321a1 | 2005-04-06 20:47:48 +0000 | [diff] [blame] | 579 | } |
bellard | e95c8d5 | 2004-09-30 22:22:08 +0000 | [diff] [blame] | 580 | } else if (interrupt_request & CPU_INTERRUPT_TIMER) { |
| 581 | //do_interrupt(0, 0, 0, 0, 0); |
| 582 | env->interrupt_request &= ~CPU_INTERRUPT_TIMER; |
balrog | a90b731 | 2007-05-01 01:28:01 +0000 | [diff] [blame] | 583 | } |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 584 | #elif defined(TARGET_ARM) |
| 585 | if (interrupt_request & CPU_INTERRUPT_FIQ |
| 586 | && !(env->uncached_cpsr & CPSR_F)) { |
| 587 | env->exception_index = EXCP_FIQ; |
| 588 | do_interrupt(env); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 589 | BREAK_CHAIN; |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 590 | } |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 591 | /* ARMv7-M interrupt return works by loading a magic value |
| 592 | into the PC. On real hardware the load causes the |
| 593 | return to occur. The qemu implementation performs the |
| 594 | jump normally, then does the exception return when the |
| 595 | CPU tries to execute code at the magic address. |
| 596 | This will cause the magic PC value to be pushed to |
| 597 | the stack if an interrupt occured at the wrong time. |
| 598 | We avoid this by disabling interrupts when |
| 599 | pc contains a magic address. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 600 | if (interrupt_request & CPU_INTERRUPT_HARD |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 601 | && ((IS_M(env) && env->regs[15] < 0xfffffff0) |
| 602 | || !(env->uncached_cpsr & CPSR_I))) { |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 603 | env->exception_index = EXCP_IRQ; |
| 604 | do_interrupt(env); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 605 | BREAK_CHAIN; |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 606 | } |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 607 | #elif defined(TARGET_SH4) |
ths | e96e204 | 2007-12-02 06:18:24 +0000 | [diff] [blame] | 608 | if (interrupt_request & CPU_INTERRUPT_HARD) { |
| 609 | do_interrupt(env); |
| 610 | BREAK_CHAIN; |
| 611 | } |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 612 | #elif defined(TARGET_ALPHA) |
| 613 | if (interrupt_request & CPU_INTERRUPT_HARD) { |
| 614 | do_interrupt(env); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 615 | BREAK_CHAIN; |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 616 | } |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 617 | #elif defined(TARGET_CRIS) |
| 618 | if (interrupt_request & CPU_INTERRUPT_HARD) { |
| 619 | do_interrupt(env); |
| 620 | env->interrupt_request &= ~CPU_INTERRUPT_HARD; |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 621 | BREAK_CHAIN; |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 622 | } |
pbrook | 0633879 | 2007-05-23 19:58:11 +0000 | [diff] [blame] | 623 | #elif defined(TARGET_M68K) |
| 624 | if (interrupt_request & CPU_INTERRUPT_HARD |
| 625 | && ((env->sr & SR_I) >> SR_I_SHIFT) |
| 626 | < env->pending_level) { |
| 627 | /* Real hardware gets the interrupt vector via an |
| 628 | IACK cycle at this point. Current emulated |
| 629 | hardware doesn't rely on this, so we |
| 630 | provide/save the vector when the interrupt is |
| 631 | first signalled. */ |
| 632 | env->exception_index = env->pending_vector; |
| 633 | do_interrupt(1); |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 634 | BREAK_CHAIN; |
pbrook | 0633879 | 2007-05-23 19:58:11 +0000 | [diff] [blame] | 635 | } |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 636 | #endif |
bellard | 9d05095 | 2006-05-22 22:03:52 +0000 | [diff] [blame] | 637 | /* Don't use the cached interupt_request value, |
| 638 | do_interrupt may have updated the EXITTB flag. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 639 | if (env->interrupt_request & CPU_INTERRUPT_EXITTB) { |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 640 | env->interrupt_request &= ~CPU_INTERRUPT_EXITTB; |
| 641 | /* ensure that no TB jump will be modified as |
| 642 | the program flow was changed */ |
pbrook | 497ad68 | 2007-11-23 02:11:10 +0000 | [diff] [blame] | 643 | BREAK_CHAIN; |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 644 | } |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 645 | if (interrupt_request & CPU_INTERRUPT_EXIT) { |
| 646 | env->interrupt_request &= ~CPU_INTERRUPT_EXIT; |
| 647 | env->exception_index = EXCP_INTERRUPT; |
| 648 | cpu_loop_exit(); |
| 649 | } |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 650 | } |
| 651 | #ifdef DEBUG_EXEC |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 652 | if ((loglevel & CPU_LOG_TB_CPU)) { |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 653 | /* restore flags in standard format */ |
ths | ecb644f | 2007-06-03 18:45:53 +0000 | [diff] [blame] | 654 | regs_to_env(); |
| 655 | #if defined(TARGET_I386) |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 656 | env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK); |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 657 | cpu_dump_state(env, logfile, fprintf, X86_DUMP_CCOP); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 658 | env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C); |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 659 | #elif defined(TARGET_ARM) |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 660 | cpu_dump_state(env, logfile, fprintf, 0); |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 661 | #elif defined(TARGET_SPARC) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 662 | REGWPTR = env->regbase + (env->cwp * 16); |
| 663 | env->regwptr = REGWPTR; |
| 664 | cpu_dump_state(env, logfile, fprintf, 0); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 665 | #elif defined(TARGET_PPC) |
bellard | 7fe4848 | 2004-10-09 18:08:01 +0000 | [diff] [blame] | 666 | cpu_dump_state(env, logfile, fprintf, 0); |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 667 | #elif defined(TARGET_M68K) |
| 668 | cpu_m68k_flush_flags(env, env->cc_op); |
| 669 | env->cc_op = CC_OP_FLAGS; |
| 670 | env->sr = (env->sr & 0xffe0) |
| 671 | | env->cc_dest | (env->cc_x << 4); |
| 672 | cpu_dump_state(env, logfile, fprintf, 0); |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 673 | #elif defined(TARGET_MIPS) |
| 674 | cpu_dump_state(env, logfile, fprintf, 0); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 675 | #elif defined(TARGET_SH4) |
| 676 | cpu_dump_state(env, logfile, fprintf, 0); |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 677 | #elif defined(TARGET_ALPHA) |
| 678 | cpu_dump_state(env, logfile, fprintf, 0); |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 679 | #elif defined(TARGET_CRIS) |
| 680 | cpu_dump_state(env, logfile, fprintf, 0); |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 681 | #else |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 682 | #error unsupported target CPU |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 683 | #endif |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 684 | } |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 685 | #endif |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 686 | tb = tb_find_fast(); |
bellard | 9d27abd | 2003-05-10 13:13:54 +0000 | [diff] [blame] | 687 | #ifdef DEBUG_EXEC |
bellard | c1135f6 | 2005-01-30 22:41:54 +0000 | [diff] [blame] | 688 | if ((loglevel & CPU_LOG_EXEC)) { |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 689 | fprintf(logfile, "Trace 0x%08lx [" TARGET_FMT_lx "] %s\n", |
| 690 | (long)tb->tc_ptr, tb->pc, |
| 691 | lookup_symbol(tb->pc)); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 692 | } |
bellard | 9d27abd | 2003-05-10 13:13:54 +0000 | [diff] [blame] | 693 | #endif |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 694 | RESTORE_GLOBALS(); |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 695 | /* see if we can patch the calling TB. When the TB |
| 696 | spans two pages, we cannot safely do a direct |
| 697 | jump. */ |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 698 | { |
bellard | 8a40a18 | 2005-11-20 10:35:40 +0000 | [diff] [blame] | 699 | if (T0 != 0 && |
bellard | f32fc64 | 2006-02-08 22:43:39 +0000 | [diff] [blame] | 700 | #if USE_KQEMU |
| 701 | (env->kqemu_enabled != 2) && |
| 702 | #endif |
bellard | ec6338b | 2007-11-08 14:25:03 +0000 | [diff] [blame] | 703 | tb->page_addr[1] == -1) { |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 704 | spin_lock(&tb_lock); |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 705 | tb_add_jump((TranslationBlock *)(long)(T0 & ~3), T0 & 3, tb); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 706 | spin_unlock(&tb_lock); |
| 707 | } |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 708 | } |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 709 | tc_ptr = tb->tc_ptr; |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 710 | env->current_tb = tb; |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 711 | /* execute the generated code */ |
| 712 | gen_func = (void *)tc_ptr; |
| 713 | #if defined(__sparc__) |
| 714 | __asm__ __volatile__("call %0\n\t" |
| 715 | "mov %%o7,%%i0" |
| 716 | : /* no outputs */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 717 | : "r" (gen_func) |
bellard | fdbb469 | 2006-06-14 17:32:25 +0000 | [diff] [blame] | 718 | : "i0", "i1", "i2", "i3", "i4", "i5", |
ths | faab759 | 2007-03-19 20:39:49 +0000 | [diff] [blame] | 719 | "o0", "o1", "o2", "o3", "o4", "o5", |
bellard | fdbb469 | 2006-06-14 17:32:25 +0000 | [diff] [blame] | 720 | "l0", "l1", "l2", "l3", "l4", "l5", |
| 721 | "l6", "l7"); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 722 | #elif defined(__arm__) |
| 723 | asm volatile ("mov pc, %0\n\t" |
| 724 | ".global exec_loop\n\t" |
| 725 | "exec_loop:\n\t" |
| 726 | : /* no outputs */ |
| 727 | : "r" (gen_func) |
| 728 | : "r1", "r2", "r3", "r8", "r9", "r10", "r12", "r14"); |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 729 | #elif defined(__ia64) |
| 730 | struct fptr { |
| 731 | void *ip; |
| 732 | void *gp; |
| 733 | } fp; |
| 734 | |
| 735 | fp.ip = tc_ptr; |
| 736 | fp.gp = code_gen_buffer + 2 * (1 << 20); |
| 737 | (*(void (*)(void)) &fp)(); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 738 | #else |
bellard | 57fec1f | 2008-02-01 10:50:11 +0000 | [diff] [blame^] | 739 | T0 = gen_func(); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 740 | #endif |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 741 | env->current_tb = NULL; |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 742 | /* reset soft MMU for next block (it can currently |
| 743 | only be set by a memory fault) */ |
| 744 | #if defined(TARGET_I386) && !defined(CONFIG_SOFTMMU) |
bellard | 3f33731 | 2003-08-20 23:02:09 +0000 | [diff] [blame] | 745 | if (env->hflags & HF_SOFTMMU_MASK) { |
| 746 | env->hflags &= ~HF_SOFTMMU_MASK; |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 747 | /* do not allow linking to another block */ |
| 748 | T0 = 0; |
| 749 | } |
| 750 | #endif |
bellard | f32fc64 | 2006-02-08 22:43:39 +0000 | [diff] [blame] | 751 | #if defined(USE_KQEMU) |
| 752 | #define MIN_CYCLE_BEFORE_SWITCH (100 * 1000) |
| 753 | if (kqemu_is_ok(env) && |
| 754 | (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) { |
| 755 | cpu_loop_exit(); |
| 756 | } |
| 757 | #endif |
ths | 50a518e | 2007-06-03 18:52:15 +0000 | [diff] [blame] | 758 | } /* for(;;) */ |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 759 | } else { |
bellard | 0d1a29f | 2004-10-12 22:01:28 +0000 | [diff] [blame] | 760 | env_to_regs(); |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 761 | } |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 762 | } /* for(;;) */ |
| 763 | |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 764 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 765 | #if defined(TARGET_I386) |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 766 | /* restore flags in standard format */ |
bellard | fc2b4c4 | 2003-03-29 16:52:44 +0000 | [diff] [blame] | 767 | env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK); |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 768 | #elif defined(TARGET_ARM) |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 769 | /* XXX: Save/restore host fpu exception state?. */ |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 770 | #elif defined(TARGET_SPARC) |
bellard | 3475187 | 2005-07-02 14:31:34 +0000 | [diff] [blame] | 771 | #if defined(reg_REGWPTR) |
| 772 | REGWPTR = saved_regwptr; |
| 773 | #endif |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 774 | #elif defined(TARGET_PPC) |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 775 | #elif defined(TARGET_M68K) |
| 776 | cpu_m68k_flush_flags(env, env->cc_op); |
| 777 | env->cc_op = CC_OP_FLAGS; |
| 778 | env->sr = (env->sr & 0xffe0) |
| 779 | | env->cc_dest | (env->cc_x << 4); |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 780 | #elif defined(TARGET_MIPS) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 781 | #elif defined(TARGET_SH4) |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 782 | #elif defined(TARGET_ALPHA) |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 783 | #elif defined(TARGET_CRIS) |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 784 | /* XXXXX */ |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 785 | #else |
| 786 | #error unsupported target CPU |
| 787 | #endif |
pbrook | 1057eaa | 2007-02-04 13:37:44 +0000 | [diff] [blame] | 788 | |
| 789 | /* restore global registers */ |
blueswir1 | 66f1cdb | 2007-12-11 19:39:25 +0000 | [diff] [blame] | 790 | RESTORE_GLOBALS(); |
pbrook | 1057eaa | 2007-02-04 13:37:44 +0000 | [diff] [blame] | 791 | #include "hostregs_helper.h" |
| 792 | |
bellard | 6a00d60 | 2005-11-21 23:25:50 +0000 | [diff] [blame] | 793 | /* fail safe : never use cpu_single_env outside cpu_exec() */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 794 | cpu_single_env = NULL; |
bellard | 7d13299 | 2003-03-06 23:23:54 +0000 | [diff] [blame] | 795 | return ret; |
| 796 | } |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 797 | |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 798 | /* must only be called from the generated code as an exception can be |
| 799 | generated */ |
| 800 | void tb_invalidate_page_range(target_ulong start, target_ulong end) |
| 801 | { |
bellard | dc5d0b3 | 2004-06-22 18:43:30 +0000 | [diff] [blame] | 802 | /* XXX: cannot enable it yet because it yields to MMU exception |
| 803 | where NIP != read address on PowerPC */ |
| 804 | #if 0 |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 805 | target_ulong phys_addr; |
| 806 | phys_addr = get_phys_addr_code(env, start); |
| 807 | tb_invalidate_phys_page_range(phys_addr, phys_addr + end - start, 0); |
bellard | dc5d0b3 | 2004-06-22 18:43:30 +0000 | [diff] [blame] | 808 | #endif |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 809 | } |
| 810 | |
bellard | 1a18c71 | 2003-10-30 01:07:51 +0000 | [diff] [blame] | 811 | #if defined(TARGET_I386) && defined(CONFIG_USER_ONLY) |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 812 | |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 813 | void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector) |
| 814 | { |
| 815 | CPUX86State *saved_env; |
| 816 | |
| 817 | saved_env = env; |
| 818 | env = s; |
bellard | a412ac5 | 2003-07-26 18:01:40 +0000 | [diff] [blame] | 819 | if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 820 | selector &= 0xffff; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 821 | cpu_x86_load_seg_cache(env, seg_reg, selector, |
bellard | c27004e | 2005-01-03 23:35:10 +0000 | [diff] [blame] | 822 | (selector << 4), 0xffff, 0); |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 823 | } else { |
bellard | b453b70 | 2004-01-04 15:45:21 +0000 | [diff] [blame] | 824 | load_seg(seg_reg, selector); |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 825 | } |
bellard | 6dbad63 | 2003-03-16 18:05:05 +0000 | [diff] [blame] | 826 | env = saved_env; |
| 827 | } |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 828 | |
bellard | 6f12a2a | 2007-11-11 22:16:56 +0000 | [diff] [blame] | 829 | void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32) |
bellard | d0a1ffc | 2003-05-29 20:04:28 +0000 | [diff] [blame] | 830 | { |
| 831 | CPUX86State *saved_env; |
| 832 | |
| 833 | saved_env = env; |
| 834 | env = s; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 835 | |
bellard | 6f12a2a | 2007-11-11 22:16:56 +0000 | [diff] [blame] | 836 | helper_fsave(ptr, data32); |
bellard | d0a1ffc | 2003-05-29 20:04:28 +0000 | [diff] [blame] | 837 | |
| 838 | env = saved_env; |
| 839 | } |
| 840 | |
bellard | 6f12a2a | 2007-11-11 22:16:56 +0000 | [diff] [blame] | 841 | void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32) |
bellard | d0a1ffc | 2003-05-29 20:04:28 +0000 | [diff] [blame] | 842 | { |
| 843 | CPUX86State *saved_env; |
| 844 | |
| 845 | saved_env = env; |
| 846 | env = s; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 847 | |
bellard | 6f12a2a | 2007-11-11 22:16:56 +0000 | [diff] [blame] | 848 | helper_frstor(ptr, data32); |
bellard | d0a1ffc | 2003-05-29 20:04:28 +0000 | [diff] [blame] | 849 | |
| 850 | env = saved_env; |
| 851 | } |
| 852 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 853 | #endif /* TARGET_I386 */ |
| 854 | |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 855 | #if !defined(CONFIG_SOFTMMU) |
| 856 | |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 857 | #if defined(TARGET_I386) |
| 858 | |
bellard | b56dad1 | 2003-05-08 15:38:04 +0000 | [diff] [blame] | 859 | /* 'pc' is the host PC at which the exception was raised. 'address' is |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 860 | the effective address of the memory exception. 'is_write' is 1 if a |
| 861 | write caused the exception and otherwise 0'. 'old_set' is the |
| 862 | signal set which should be restored */ |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 863 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 864 | int is_write, sigset_t *old_set, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 865 | void *puc) |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 866 | { |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 867 | TranslationBlock *tb; |
| 868 | int ret; |
bellard | 68a7931 | 2003-06-30 13:12:32 +0000 | [diff] [blame] | 869 | |
bellard | 83479e7 | 2003-06-25 16:12:37 +0000 | [diff] [blame] | 870 | if (cpu_single_env) |
| 871 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 872 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 873 | qemu_printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 874 | pc, address, is_write, *(unsigned long *)old_set); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 875 | #endif |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 876 | /* XXX: locking issue */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 877 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 878 | return 1; |
| 879 | } |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 880 | |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 881 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 882 | ret = cpu_x86_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 883 | if (ret < 0) |
| 884 | return 0; /* not an MMU fault */ |
| 885 | if (ret == 0) |
| 886 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 887 | /* now we have a real cpu fault */ |
bellard | a513fe1 | 2003-05-27 23:29:48 +0000 | [diff] [blame] | 888 | tb = tb_find_pc(pc); |
| 889 | if (tb) { |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 890 | /* the PC is inside the translated code. It means that we have |
| 891 | a virtual CPU fault */ |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 892 | cpu_restore_state(tb, env, pc, puc); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 893 | } |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 894 | if (ret == 1) { |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 895 | #if 0 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 896 | printf("PF exception: EIP=0x%08x CR2=0x%08x error=0x%x\n", |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 897 | env->eip, env->cr[2], env->error_code); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 898 | #endif |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 899 | /* we restore the process signal mask as the sigreturn should |
| 900 | do it (XXX: use sigsetjmp) */ |
| 901 | sigprocmask(SIG_SETMASK, old_set, NULL); |
bellard | 54ca909 | 2005-12-04 18:46:06 +0000 | [diff] [blame] | 902 | raise_exception_err(env->exception_index, env->error_code); |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 903 | } else { |
| 904 | /* activate soft MMU for this block */ |
bellard | 3f33731 | 2003-08-20 23:02:09 +0000 | [diff] [blame] | 905 | env->hflags |= HF_SOFTMMU_MASK; |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 906 | cpu_resume_from_signal(env, puc); |
bellard | 4cbf74b | 2003-08-10 21:48:43 +0000 | [diff] [blame] | 907 | } |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 908 | /* never comes here */ |
| 909 | return 1; |
| 910 | } |
| 911 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 912 | #elif defined(TARGET_ARM) |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 913 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 914 | int is_write, sigset_t *old_set, |
| 915 | void *puc) |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 916 | { |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 917 | TranslationBlock *tb; |
| 918 | int ret; |
| 919 | |
| 920 | if (cpu_single_env) |
| 921 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 922 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 923 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 924 | pc, address, is_write, *(unsigned long *)old_set); |
| 925 | #endif |
bellard | 9f0777e | 2005-02-02 20:42:01 +0000 | [diff] [blame] | 926 | /* XXX: locking issue */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 927 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
bellard | 9f0777e | 2005-02-02 20:42:01 +0000 | [diff] [blame] | 928 | return 1; |
| 929 | } |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 930 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 931 | ret = cpu_arm_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 932 | if (ret < 0) |
| 933 | return 0; /* not an MMU fault */ |
| 934 | if (ret == 0) |
| 935 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 936 | /* now we have a real cpu fault */ |
| 937 | tb = tb_find_pc(pc); |
| 938 | if (tb) { |
| 939 | /* the PC is inside the translated code. It means that we have |
| 940 | a virtual CPU fault */ |
| 941 | cpu_restore_state(tb, env, pc, puc); |
| 942 | } |
| 943 | /* we restore the process signal mask as the sigreturn should |
| 944 | do it (XXX: use sigsetjmp) */ |
| 945 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 946 | cpu_loop_exit(); |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 947 | } |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 948 | #elif defined(TARGET_SPARC) |
| 949 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 950 | int is_write, sigset_t *old_set, |
| 951 | void *puc) |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 952 | { |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 953 | TranslationBlock *tb; |
| 954 | int ret; |
| 955 | |
| 956 | if (cpu_single_env) |
| 957 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 958 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 959 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 960 | pc, address, is_write, *(unsigned long *)old_set); |
| 961 | #endif |
bellard | b453b70 | 2004-01-04 15:45:21 +0000 | [diff] [blame] | 962 | /* XXX: locking issue */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 963 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
bellard | b453b70 | 2004-01-04 15:45:21 +0000 | [diff] [blame] | 964 | return 1; |
| 965 | } |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 966 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 967 | ret = cpu_sparc_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | 68016c6 | 2005-02-07 23:12:27 +0000 | [diff] [blame] | 968 | if (ret < 0) |
| 969 | return 0; /* not an MMU fault */ |
| 970 | if (ret == 0) |
| 971 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 972 | /* now we have a real cpu fault */ |
| 973 | tb = tb_find_pc(pc); |
| 974 | if (tb) { |
| 975 | /* the PC is inside the translated code. It means that we have |
| 976 | a virtual CPU fault */ |
| 977 | cpu_restore_state(tb, env, pc, puc); |
| 978 | } |
| 979 | /* we restore the process signal mask as the sigreturn should |
| 980 | do it (XXX: use sigsetjmp) */ |
| 981 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 982 | cpu_loop_exit(); |
bellard | 93ac68b | 2003-09-30 20:57:29 +0000 | [diff] [blame] | 983 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 984 | #elif defined (TARGET_PPC) |
| 985 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 986 | int is_write, sigset_t *old_set, |
| 987 | void *puc) |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 988 | { |
| 989 | TranslationBlock *tb; |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 990 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 991 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 992 | if (cpu_single_env) |
| 993 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 994 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 995 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 996 | pc, address, is_write, *(unsigned long *)old_set); |
| 997 | #endif |
| 998 | /* XXX: locking issue */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 999 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1000 | return 1; |
| 1001 | } |
| 1002 | |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1003 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1004 | ret = cpu_ppc_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1005 | if (ret < 0) |
| 1006 | return 0; /* not an MMU fault */ |
| 1007 | if (ret == 0) |
| 1008 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1009 | |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1010 | /* now we have a real cpu fault */ |
| 1011 | tb = tb_find_pc(pc); |
| 1012 | if (tb) { |
| 1013 | /* the PC is inside the translated code. It means that we have |
| 1014 | a virtual CPU fault */ |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1015 | cpu_restore_state(tb, env, pc, puc); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1016 | } |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1017 | if (ret == 1) { |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1018 | #if 0 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1019 | printf("PF exception: NIP=0x%08x error=0x%x %p\n", |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1020 | env->nip, env->error_code, tb); |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1021 | #endif |
| 1022 | /* we restore the process signal mask as the sigreturn should |
| 1023 | do it (XXX: use sigsetjmp) */ |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1024 | sigprocmask(SIG_SETMASK, old_set, NULL); |
bellard | 9fddaa0 | 2004-05-21 12:59:32 +0000 | [diff] [blame] | 1025 | do_raise_exception_err(env->exception_index, env->error_code); |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1026 | } else { |
| 1027 | /* activate soft MMU for this block */ |
bellard | fbf9eeb | 2004-04-25 21:21:33 +0000 | [diff] [blame] | 1028 | cpu_resume_from_signal(env, puc); |
bellard | ce09776 | 2004-01-04 23:53:18 +0000 | [diff] [blame] | 1029 | } |
bellard | 6786730 | 2003-11-23 17:05:30 +0000 | [diff] [blame] | 1030 | /* never comes here */ |
| 1031 | return 1; |
| 1032 | } |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1033 | |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 1034 | #elif defined(TARGET_M68K) |
| 1035 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
| 1036 | int is_write, sigset_t *old_set, |
| 1037 | void *puc) |
| 1038 | { |
| 1039 | TranslationBlock *tb; |
| 1040 | int ret; |
| 1041 | |
| 1042 | if (cpu_single_env) |
| 1043 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 1044 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1045 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 1046 | pc, address, is_write, *(unsigned long *)old_set); |
| 1047 | #endif |
| 1048 | /* XXX: locking issue */ |
| 1049 | if (is_write && page_unprotect(address, pc, puc)) { |
| 1050 | return 1; |
| 1051 | } |
| 1052 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1053 | ret = cpu_m68k_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
pbrook | e6e5906 | 2006-10-22 00:18:54 +0000 | [diff] [blame] | 1054 | if (ret < 0) |
| 1055 | return 0; /* not an MMU fault */ |
| 1056 | if (ret == 0) |
| 1057 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1058 | /* now we have a real cpu fault */ |
| 1059 | tb = tb_find_pc(pc); |
| 1060 | if (tb) { |
| 1061 | /* the PC is inside the translated code. It means that we have |
| 1062 | a virtual CPU fault */ |
| 1063 | cpu_restore_state(tb, env, pc, puc); |
| 1064 | } |
| 1065 | /* we restore the process signal mask as the sigreturn should |
| 1066 | do it (XXX: use sigsetjmp) */ |
| 1067 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 1068 | cpu_loop_exit(); |
| 1069 | /* never comes here */ |
| 1070 | return 1; |
| 1071 | } |
| 1072 | |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1073 | #elif defined (TARGET_MIPS) |
| 1074 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
| 1075 | int is_write, sigset_t *old_set, |
| 1076 | void *puc) |
| 1077 | { |
| 1078 | TranslationBlock *tb; |
| 1079 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1080 | |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1081 | if (cpu_single_env) |
| 1082 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 1083 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1084 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1085 | pc, address, is_write, *(unsigned long *)old_set); |
| 1086 | #endif |
| 1087 | /* XXX: locking issue */ |
pbrook | 53a5960 | 2006-03-25 19:31:22 +0000 | [diff] [blame] | 1088 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1089 | return 1; |
| 1090 | } |
| 1091 | |
| 1092 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1093 | ret = cpu_mips_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1094 | if (ret < 0) |
| 1095 | return 0; /* not an MMU fault */ |
| 1096 | if (ret == 0) |
| 1097 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1098 | |
| 1099 | /* now we have a real cpu fault */ |
| 1100 | tb = tb_find_pc(pc); |
| 1101 | if (tb) { |
| 1102 | /* the PC is inside the translated code. It means that we have |
| 1103 | a virtual CPU fault */ |
| 1104 | cpu_restore_state(tb, env, pc, puc); |
| 1105 | } |
| 1106 | if (ret == 1) { |
| 1107 | #if 0 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1108 | printf("PF exception: PC=0x" TARGET_FMT_lx " error=0x%x %p\n", |
ths | 1eb5207 | 2007-05-12 16:57:42 +0000 | [diff] [blame] | 1109 | env->PC, env->error_code, tb); |
bellard | 6af0bf9 | 2005-07-02 14:58:51 +0000 | [diff] [blame] | 1110 | #endif |
| 1111 | /* we restore the process signal mask as the sigreturn should |
| 1112 | do it (XXX: use sigsetjmp) */ |
| 1113 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 1114 | do_raise_exception_err(env->exception_index, env->error_code); |
| 1115 | } else { |
| 1116 | /* activate soft MMU for this block */ |
| 1117 | cpu_resume_from_signal(env, puc); |
| 1118 | } |
| 1119 | /* never comes here */ |
| 1120 | return 1; |
| 1121 | } |
| 1122 | |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1123 | #elif defined (TARGET_SH4) |
| 1124 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
| 1125 | int is_write, sigset_t *old_set, |
| 1126 | void *puc) |
| 1127 | { |
| 1128 | TranslationBlock *tb; |
| 1129 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1130 | |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1131 | if (cpu_single_env) |
| 1132 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 1133 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1134 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1135 | pc, address, is_write, *(unsigned long *)old_set); |
| 1136 | #endif |
| 1137 | /* XXX: locking issue */ |
| 1138 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
| 1139 | return 1; |
| 1140 | } |
| 1141 | |
| 1142 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1143 | ret = cpu_sh4_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1144 | if (ret < 0) |
| 1145 | return 0; /* not an MMU fault */ |
| 1146 | if (ret == 0) |
| 1147 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1148 | |
| 1149 | /* now we have a real cpu fault */ |
| 1150 | tb = tb_find_pc(pc); |
| 1151 | if (tb) { |
| 1152 | /* the PC is inside the translated code. It means that we have |
| 1153 | a virtual CPU fault */ |
| 1154 | cpu_restore_state(tb, env, pc, puc); |
| 1155 | } |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1156 | #if 0 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1157 | printf("PF exception: NIP=0x%08x error=0x%x %p\n", |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1158 | env->nip, env->error_code, tb); |
| 1159 | #endif |
| 1160 | /* we restore the process signal mask as the sigreturn should |
| 1161 | do it (XXX: use sigsetjmp) */ |
pbrook | 355fb23 | 2006-06-17 19:58:25 +0000 | [diff] [blame] | 1162 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 1163 | cpu_loop_exit(); |
bellard | fdf9b3e | 2006-04-27 21:07:38 +0000 | [diff] [blame] | 1164 | /* never comes here */ |
| 1165 | return 1; |
| 1166 | } |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 1167 | |
| 1168 | #elif defined (TARGET_ALPHA) |
| 1169 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
| 1170 | int is_write, sigset_t *old_set, |
| 1171 | void *puc) |
| 1172 | { |
| 1173 | TranslationBlock *tb; |
| 1174 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1175 | |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 1176 | if (cpu_single_env) |
| 1177 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 1178 | #if defined(DEBUG_SIGNAL) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1179 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 1180 | pc, address, is_write, *(unsigned long *)old_set); |
| 1181 | #endif |
| 1182 | /* XXX: locking issue */ |
| 1183 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
| 1184 | return 1; |
| 1185 | } |
| 1186 | |
| 1187 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1188 | ret = cpu_alpha_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 1189 | if (ret < 0) |
| 1190 | return 0; /* not an MMU fault */ |
| 1191 | if (ret == 0) |
| 1192 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1193 | |
| 1194 | /* now we have a real cpu fault */ |
| 1195 | tb = tb_find_pc(pc); |
| 1196 | if (tb) { |
| 1197 | /* the PC is inside the translated code. It means that we have |
| 1198 | a virtual CPU fault */ |
| 1199 | cpu_restore_state(tb, env, pc, puc); |
| 1200 | } |
| 1201 | #if 0 |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1202 | printf("PF exception: NIP=0x%08x error=0x%x %p\n", |
j_mayer | eddf68a | 2007-04-05 07:22:49 +0000 | [diff] [blame] | 1203 | env->nip, env->error_code, tb); |
| 1204 | #endif |
| 1205 | /* we restore the process signal mask as the sigreturn should |
| 1206 | do it (XXX: use sigsetjmp) */ |
| 1207 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 1208 | cpu_loop_exit(); |
| 1209 | /* never comes here */ |
| 1210 | return 1; |
| 1211 | } |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 1212 | #elif defined (TARGET_CRIS) |
| 1213 | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
| 1214 | int is_write, sigset_t *old_set, |
| 1215 | void *puc) |
| 1216 | { |
| 1217 | TranslationBlock *tb; |
| 1218 | int ret; |
| 1219 | |
| 1220 | if (cpu_single_env) |
| 1221 | env = cpu_single_env; /* XXX: find a correct solution for multithread */ |
| 1222 | #if defined(DEBUG_SIGNAL) |
| 1223 | printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", |
| 1224 | pc, address, is_write, *(unsigned long *)old_set); |
| 1225 | #endif |
| 1226 | /* XXX: locking issue */ |
| 1227 | if (is_write && page_unprotect(h2g(address), pc, puc)) { |
| 1228 | return 1; |
| 1229 | } |
| 1230 | |
| 1231 | /* see if it is an MMU fault */ |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 1232 | ret = cpu_cris_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); |
ths | f1ccf90 | 2007-10-08 13:16:14 +0000 | [diff] [blame] | 1233 | if (ret < 0) |
| 1234 | return 0; /* not an MMU fault */ |
| 1235 | if (ret == 0) |
| 1236 | return 1; /* the MMU fault was handled without causing real CPU fault */ |
| 1237 | |
| 1238 | /* now we have a real cpu fault */ |
| 1239 | tb = tb_find_pc(pc); |
| 1240 | if (tb) { |
| 1241 | /* the PC is inside the translated code. It means that we have |
| 1242 | a virtual CPU fault */ |
| 1243 | cpu_restore_state(tb, env, pc, puc); |
| 1244 | } |
| 1245 | #if 0 |
| 1246 | printf("PF exception: NIP=0x%08x error=0x%x %p\n", |
| 1247 | env->nip, env->error_code, tb); |
| 1248 | #endif |
| 1249 | /* we restore the process signal mask as the sigreturn should |
| 1250 | do it (XXX: use sigsetjmp) */ |
| 1251 | sigprocmask(SIG_SETMASK, old_set, NULL); |
| 1252 | cpu_loop_exit(); |
| 1253 | /* never comes here */ |
| 1254 | return 1; |
| 1255 | } |
| 1256 | |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 1257 | #else |
| 1258 | #error unsupported target CPU |
| 1259 | #endif |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 1260 | |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1261 | #if defined(__i386__) |
| 1262 | |
bellard | d8ecc0b | 2007-02-05 21:41:46 +0000 | [diff] [blame] | 1263 | #if defined(__APPLE__) |
| 1264 | # include <sys/ucontext.h> |
| 1265 | |
| 1266 | # define EIP_sig(context) (*((unsigned long*)&(context)->uc_mcontext->ss.eip)) |
| 1267 | # define TRAP_sig(context) ((context)->uc_mcontext->es.trapno) |
| 1268 | # define ERROR_sig(context) ((context)->uc_mcontext->es.err) |
| 1269 | #else |
| 1270 | # define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP]) |
| 1271 | # define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO]) |
| 1272 | # define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR]) |
| 1273 | #endif |
| 1274 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1275 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 1276 | void *puc) |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 1277 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1278 | siginfo_t *info = pinfo; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 1279 | struct ucontext *uc = puc; |
| 1280 | unsigned long pc; |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1281 | int trapno; |
bellard | 97eb5b1 | 2004-02-25 23:19:55 +0000 | [diff] [blame] | 1282 | |
bellard | d691f66 | 2003-03-24 21:58:34 +0000 | [diff] [blame] | 1283 | #ifndef REG_EIP |
| 1284 | /* for glibc 2.1 */ |
bellard | fd6ce8f | 2003-05-14 19:00:11 +0000 | [diff] [blame] | 1285 | #define REG_EIP EIP |
| 1286 | #define REG_ERR ERR |
| 1287 | #define REG_TRAPNO TRAPNO |
bellard | d691f66 | 2003-03-24 21:58:34 +0000 | [diff] [blame] | 1288 | #endif |
bellard | d8ecc0b | 2007-02-05 21:41:46 +0000 | [diff] [blame] | 1289 | pc = EIP_sig(uc); |
| 1290 | trapno = TRAP_sig(uc); |
bellard | ec6338b | 2007-11-08 14:25:03 +0000 | [diff] [blame] | 1291 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
| 1292 | trapno == 0xe ? |
| 1293 | (ERROR_sig(uc) >> 1) & 1 : 0, |
| 1294 | &uc->uc_sigmask, puc); |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 1297 | #elif defined(__x86_64__) |
| 1298 | |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1299 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 1300 | void *puc) |
| 1301 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1302 | siginfo_t *info = pinfo; |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 1303 | struct ucontext *uc = puc; |
| 1304 | unsigned long pc; |
| 1305 | |
| 1306 | pc = uc->uc_mcontext.gregs[REG_RIP]; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1307 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
| 1308 | uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe ? |
bellard | bc51c5c | 2004-03-17 23:46:04 +0000 | [diff] [blame] | 1309 | (uc->uc_mcontext.gregs[REG_ERR] >> 1) & 1 : 0, |
| 1310 | &uc->uc_sigmask, puc); |
| 1311 | } |
| 1312 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1313 | #elif defined(__powerpc__) |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1314 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1315 | /*********************************************************************** |
| 1316 | * signal context platform-specific definitions |
| 1317 | * From Wine |
| 1318 | */ |
| 1319 | #ifdef linux |
| 1320 | /* All Registers access - only for local access */ |
| 1321 | # define REG_sig(reg_name, context) ((context)->uc_mcontext.regs->reg_name) |
| 1322 | /* Gpr Registers access */ |
| 1323 | # define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context) |
| 1324 | # define IAR_sig(context) REG_sig(nip, context) /* Program counter */ |
| 1325 | # define MSR_sig(context) REG_sig(msr, context) /* Machine State Register (Supervisor) */ |
| 1326 | # define CTR_sig(context) REG_sig(ctr, context) /* Count register */ |
| 1327 | # define XER_sig(context) REG_sig(xer, context) /* User's integer exception register */ |
| 1328 | # define LR_sig(context) REG_sig(link, context) /* Link register */ |
| 1329 | # define CR_sig(context) REG_sig(ccr, context) /* Condition register */ |
| 1330 | /* Float Registers access */ |
| 1331 | # define FLOAT_sig(reg_num, context) (((double*)((char*)((context)->uc_mcontext.regs+48*4)))[reg_num]) |
| 1332 | # define FPSCR_sig(context) (*(int*)((char*)((context)->uc_mcontext.regs+(48+32*2)*4))) |
| 1333 | /* Exception Registers access */ |
| 1334 | # define DAR_sig(context) REG_sig(dar, context) |
| 1335 | # define DSISR_sig(context) REG_sig(dsisr, context) |
| 1336 | # define TRAP_sig(context) REG_sig(trap, context) |
| 1337 | #endif /* linux */ |
| 1338 | |
| 1339 | #ifdef __APPLE__ |
| 1340 | # include <sys/ucontext.h> |
| 1341 | typedef struct ucontext SIGCONTEXT; |
| 1342 | /* All Registers access - only for local access */ |
| 1343 | # define REG_sig(reg_name, context) ((context)->uc_mcontext->ss.reg_name) |
| 1344 | # define FLOATREG_sig(reg_name, context) ((context)->uc_mcontext->fs.reg_name) |
| 1345 | # define EXCEPREG_sig(reg_name, context) ((context)->uc_mcontext->es.reg_name) |
| 1346 | # define VECREG_sig(reg_name, context) ((context)->uc_mcontext->vs.reg_name) |
| 1347 | /* Gpr Registers access */ |
| 1348 | # define GPR_sig(reg_num, context) REG_sig(r##reg_num, context) |
| 1349 | # define IAR_sig(context) REG_sig(srr0, context) /* Program counter */ |
| 1350 | # define MSR_sig(context) REG_sig(srr1, context) /* Machine State Register (Supervisor) */ |
| 1351 | # define CTR_sig(context) REG_sig(ctr, context) |
| 1352 | # define XER_sig(context) REG_sig(xer, context) /* Link register */ |
| 1353 | # define LR_sig(context) REG_sig(lr, context) /* User's integer exception register */ |
| 1354 | # define CR_sig(context) REG_sig(cr, context) /* Condition register */ |
| 1355 | /* Float Registers access */ |
| 1356 | # define FLOAT_sig(reg_num, context) FLOATREG_sig(fpregs[reg_num], context) |
| 1357 | # define FPSCR_sig(context) ((double)FLOATREG_sig(fpscr, context)) |
| 1358 | /* Exception Registers access */ |
| 1359 | # define DAR_sig(context) EXCEPREG_sig(dar, context) /* Fault registers for coredump */ |
| 1360 | # define DSISR_sig(context) EXCEPREG_sig(dsisr, context) |
| 1361 | # define TRAP_sig(context) EXCEPREG_sig(exception, context) /* number of powerpc exception taken */ |
| 1362 | #endif /* __APPLE__ */ |
| 1363 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1364 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 1365 | void *puc) |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1366 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1367 | siginfo_t *info = pinfo; |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1368 | struct ucontext *uc = puc; |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1369 | unsigned long pc; |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1370 | int is_write; |
| 1371 | |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1372 | pc = IAR_sig(uc); |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1373 | is_write = 0; |
| 1374 | #if 0 |
| 1375 | /* ppc 4xx case */ |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1376 | if (DSISR_sig(uc) & 0x00800000) |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1377 | is_write = 1; |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 1378 | #else |
bellard | 83fb7ad | 2004-07-05 21:25:26 +0000 | [diff] [blame] | 1379 | if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) |
bellard | 25eb448 | 2003-05-14 21:50:54 +0000 | [diff] [blame] | 1380 | is_write = 1; |
| 1381 | #endif |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1382 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1383 | is_write, &uc->uc_sigmask, puc); |
bellard | 9de5e44 | 2003-03-23 16:49:39 +0000 | [diff] [blame] | 1384 | } |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1385 | |
bellard | 2f87c60 | 2003-06-02 20:38:09 +0000 | [diff] [blame] | 1386 | #elif defined(__alpha__) |
| 1387 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1388 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | 2f87c60 | 2003-06-02 20:38:09 +0000 | [diff] [blame] | 1389 | void *puc) |
| 1390 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1391 | siginfo_t *info = pinfo; |
bellard | 2f87c60 | 2003-06-02 20:38:09 +0000 | [diff] [blame] | 1392 | struct ucontext *uc = puc; |
| 1393 | uint32_t *pc = uc->uc_mcontext.sc_pc; |
| 1394 | uint32_t insn = *pc; |
| 1395 | int is_write = 0; |
| 1396 | |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1397 | /* XXX: need kernel patch to get write flag faster */ |
bellard | 2f87c60 | 2003-06-02 20:38:09 +0000 | [diff] [blame] | 1398 | switch (insn >> 26) { |
| 1399 | case 0x0d: // stw |
| 1400 | case 0x0e: // stb |
| 1401 | case 0x0f: // stq_u |
| 1402 | case 0x24: // stf |
| 1403 | case 0x25: // stg |
| 1404 | case 0x26: // sts |
| 1405 | case 0x27: // stt |
| 1406 | case 0x2c: // stl |
| 1407 | case 0x2d: // stq |
| 1408 | case 0x2e: // stl_c |
| 1409 | case 0x2f: // stq_c |
| 1410 | is_write = 1; |
| 1411 | } |
| 1412 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1413 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1414 | is_write, &uc->uc_sigmask, puc); |
bellard | 2f87c60 | 2003-06-02 20:38:09 +0000 | [diff] [blame] | 1415 | } |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1416 | #elif defined(__sparc__) |
| 1417 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1418 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 1419 | void *puc) |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1420 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1421 | siginfo_t *info = pinfo; |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1422 | uint32_t *regs = (uint32_t *)(info + 1); |
| 1423 | void *sigmask = (regs + 20); |
| 1424 | unsigned long pc; |
| 1425 | int is_write; |
| 1426 | uint32_t insn; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1427 | |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1428 | /* XXX: is there a standard glibc define ? */ |
| 1429 | pc = regs[1]; |
| 1430 | /* XXX: need kernel patch to get write flag faster */ |
| 1431 | is_write = 0; |
| 1432 | insn = *(uint32_t *)pc; |
| 1433 | if ((insn >> 30) == 3) { |
| 1434 | switch((insn >> 19) & 0x3f) { |
| 1435 | case 0x05: // stb |
| 1436 | case 0x06: // sth |
| 1437 | case 0x04: // st |
| 1438 | case 0x07: // std |
| 1439 | case 0x24: // stf |
| 1440 | case 0x27: // stdf |
| 1441 | case 0x25: // stfsr |
| 1442 | is_write = 1; |
| 1443 | break; |
| 1444 | } |
| 1445 | } |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1446 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1447 | is_write, sigmask, NULL); |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | #elif defined(__arm__) |
| 1451 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1452 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | e4533c7 | 2003-06-15 19:51:39 +0000 | [diff] [blame] | 1453 | void *puc) |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1454 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1455 | siginfo_t *info = pinfo; |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1456 | struct ucontext *uc = puc; |
| 1457 | unsigned long pc; |
| 1458 | int is_write; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1459 | |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1460 | pc = uc->uc_mcontext.gregs[R15]; |
| 1461 | /* XXX: compute is_write */ |
| 1462 | is_write = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1463 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1464 | is_write, |
pbrook | f3a9676 | 2006-07-29 19:09:31 +0000 | [diff] [blame] | 1465 | &uc->uc_sigmask, puc); |
bellard | 8c6939c | 2003-06-09 15:28:00 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1468 | #elif defined(__mc68000) |
| 1469 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1470 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1471 | void *puc) |
| 1472 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1473 | siginfo_t *info = pinfo; |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1474 | struct ucontext *uc = puc; |
| 1475 | unsigned long pc; |
| 1476 | int is_write; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1477 | |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1478 | pc = uc->uc_mcontext.gregs[16]; |
| 1479 | /* XXX: compute is_write */ |
| 1480 | is_write = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1481 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1482 | is_write, |
bellard | bf3e8bf | 2004-02-16 21:58:54 +0000 | [diff] [blame] | 1483 | &uc->uc_sigmask, puc); |
bellard | 38e584a | 2003-08-10 22:14:22 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 1486 | #elif defined(__ia64) |
| 1487 | |
| 1488 | #ifndef __ISR_VALID |
| 1489 | /* This ought to be in <bits/siginfo.h>... */ |
| 1490 | # define __ISR_VALID 1 |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 1491 | #endif |
| 1492 | |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1493 | int cpu_signal_handler(int host_signum, void *pinfo, void *puc) |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 1494 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1495 | siginfo_t *info = pinfo; |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 1496 | struct ucontext *uc = puc; |
| 1497 | unsigned long ip; |
| 1498 | int is_write = 0; |
| 1499 | |
| 1500 | ip = uc->uc_mcontext.sc_ip; |
| 1501 | switch (host_signum) { |
| 1502 | case SIGILL: |
| 1503 | case SIGFPE: |
| 1504 | case SIGSEGV: |
| 1505 | case SIGBUS: |
| 1506 | case SIGTRAP: |
bellard | fd4a43e | 2006-04-24 20:32:17 +0000 | [diff] [blame] | 1507 | if (info->si_code && (info->si_segvflags & __ISR_VALID)) |
bellard | b8076a7 | 2005-04-07 22:20:31 +0000 | [diff] [blame] | 1508 | /* ISR.W (write-access) is bit 33: */ |
| 1509 | is_write = (info->si_isr >> 33) & 1; |
| 1510 | break; |
| 1511 | |
| 1512 | default: |
| 1513 | break; |
| 1514 | } |
| 1515 | return handle_cpu_signal(ip, (unsigned long)info->si_addr, |
| 1516 | is_write, |
| 1517 | &uc->uc_sigmask, puc); |
| 1518 | } |
| 1519 | |
bellard | 90cb949 | 2005-07-24 15:11:38 +0000 | [diff] [blame] | 1520 | #elif defined(__s390__) |
| 1521 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1522 | int cpu_signal_handler(int host_signum, void *pinfo, |
bellard | 90cb949 | 2005-07-24 15:11:38 +0000 | [diff] [blame] | 1523 | void *puc) |
| 1524 | { |
ths | 5a7b542 | 2007-01-31 12:16:51 +0000 | [diff] [blame] | 1525 | siginfo_t *info = pinfo; |
bellard | 90cb949 | 2005-07-24 15:11:38 +0000 | [diff] [blame] | 1526 | struct ucontext *uc = puc; |
| 1527 | unsigned long pc; |
| 1528 | int is_write; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1529 | |
bellard | 90cb949 | 2005-07-24 15:11:38 +0000 | [diff] [blame] | 1530 | pc = uc->uc_mcontext.psw.addr; |
| 1531 | /* XXX: compute is_write */ |
| 1532 | is_write = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1533 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 1534 | is_write, &uc->uc_sigmask, puc); |
| 1535 | } |
| 1536 | |
| 1537 | #elif defined(__mips__) |
| 1538 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1539 | int cpu_signal_handler(int host_signum, void *pinfo, |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 1540 | void *puc) |
| 1541 | { |
ths | 9617efe | 2007-05-08 21:05:55 +0000 | [diff] [blame] | 1542 | siginfo_t *info = pinfo; |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 1543 | struct ucontext *uc = puc; |
| 1544 | greg_t pc = uc->uc_mcontext.pc; |
| 1545 | int is_write; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1546 | |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 1547 | /* XXX: compute is_write */ |
| 1548 | is_write = 0; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1549 | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
ths | c4b89d1 | 2007-05-05 19:23:11 +0000 | [diff] [blame] | 1550 | is_write, &uc->uc_sigmask, puc); |
bellard | 90cb949 | 2005-07-24 15:11:38 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1553 | #else |
| 1554 | |
bellard | 3fb2ded | 2003-06-24 13:22:59 +0000 | [diff] [blame] | 1555 | #error host CPU specific signal handler needed |
bellard | 2b41314 | 2003-05-14 23:01:10 +0000 | [diff] [blame] | 1556 | |
| 1557 | #endif |
bellard | 67b915a | 2004-03-31 23:37:16 +0000 | [diff] [blame] | 1558 | |
| 1559 | #endif /* !defined(CONFIG_SOFTMMU) */ |