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