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