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