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