root / user-exec.c @ 43642b38
History | View | Annotate | Download (20.2 kB)
1 | 42a623c7 | Blue Swirl | /*
|
---|---|---|---|
2 | 42a623c7 | Blue Swirl | * User emulator execution
|
3 | 42a623c7 | Blue Swirl | *
|
4 | 42a623c7 | Blue Swirl | * Copyright (c) 2003-2005 Fabrice Bellard
|
5 | 42a623c7 | Blue Swirl | *
|
6 | 42a623c7 | Blue Swirl | * This library is free software; you can redistribute it and/or
|
7 | 42a623c7 | Blue Swirl | * modify it under the terms of the GNU Lesser General Public
|
8 | 42a623c7 | Blue Swirl | * License as published by the Free Software Foundation; either
|
9 | 42a623c7 | Blue Swirl | * version 2 of the License, or (at your option) any later version.
|
10 | 42a623c7 | Blue Swirl | *
|
11 | 42a623c7 | Blue Swirl | * This library is distributed in the hope that it will be useful,
|
12 | 42a623c7 | Blue Swirl | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 42a623c7 | Blue Swirl | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 42a623c7 | Blue Swirl | * Lesser General Public License for more details.
|
15 | 42a623c7 | Blue Swirl | *
|
16 | 42a623c7 | Blue Swirl | * You should have received a copy of the GNU Lesser General Public
|
17 | 42a623c7 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | 42a623c7 | Blue Swirl | */
|
19 | 42a623c7 | Blue Swirl | #include "config.h" |
20 | 42a623c7 | Blue Swirl | #include "exec.h" |
21 | 42a623c7 | Blue Swirl | #include "disas.h" |
22 | 42a623c7 | Blue Swirl | #include "tcg.h" |
23 | 42a623c7 | Blue Swirl | |
24 | 42a623c7 | Blue Swirl | #undef EAX
|
25 | 42a623c7 | Blue Swirl | #undef ECX
|
26 | 42a623c7 | Blue Swirl | #undef EDX
|
27 | 42a623c7 | Blue Swirl | #undef EBX
|
28 | 42a623c7 | Blue Swirl | #undef ESP
|
29 | 42a623c7 | Blue Swirl | #undef EBP
|
30 | 42a623c7 | Blue Swirl | #undef ESI
|
31 | 42a623c7 | Blue Swirl | #undef EDI
|
32 | 42a623c7 | Blue Swirl | #undef EIP
|
33 | 42a623c7 | Blue Swirl | #include <signal.h> |
34 | 42a623c7 | Blue Swirl | #ifdef __linux__
|
35 | 42a623c7 | Blue Swirl | #include <sys/ucontext.h> |
36 | 42a623c7 | Blue Swirl | #endif
|
37 | 42a623c7 | Blue Swirl | |
38 | 42a623c7 | Blue Swirl | //#define DEBUG_SIGNAL
|
39 | 42a623c7 | Blue Swirl | |
40 | 1162c041 | Blue Swirl | static void exception_action(CPUState *env1) |
41 | 1162c041 | Blue Swirl | { |
42 | 42a623c7 | Blue Swirl | #if defined(TARGET_I386)
|
43 | 1162c041 | Blue Swirl | raise_exception_err(env1->exception_index, env1->error_code); |
44 | 42a623c7 | Blue Swirl | #else
|
45 | 1162c041 | Blue Swirl | cpu_loop_exit(env1); |
46 | 42a623c7 | Blue Swirl | #endif
|
47 | 1162c041 | Blue Swirl | } |
48 | 42a623c7 | Blue Swirl | |
49 | 42a623c7 | Blue Swirl | /* exit the current TB from a signal handler. The host registers are
|
50 | 42a623c7 | Blue Swirl | restored in a state compatible with the CPU emulator
|
51 | 42a623c7 | Blue Swirl | */
|
52 | 42a623c7 | Blue Swirl | void cpu_resume_from_signal(CPUState *env1, void *puc) |
53 | 42a623c7 | Blue Swirl | { |
54 | 42a623c7 | Blue Swirl | #ifdef __linux__
|
55 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
56 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
57 | 42a623c7 | Blue Swirl | struct sigcontext *uc = puc;
|
58 | 42a623c7 | Blue Swirl | #endif
|
59 | 42a623c7 | Blue Swirl | |
60 | 42a623c7 | Blue Swirl | env = env1; |
61 | 42a623c7 | Blue Swirl | |
62 | 42a623c7 | Blue Swirl | /* XXX: restore cpu registers saved in host registers */
|
63 | 42a623c7 | Blue Swirl | |
64 | 42a623c7 | Blue Swirl | if (puc) {
|
65 | 42a623c7 | Blue Swirl | /* XXX: use siglongjmp ? */
|
66 | 42a623c7 | Blue Swirl | #ifdef __linux__
|
67 | 42a623c7 | Blue Swirl | #ifdef __ia64
|
68 | 42a623c7 | Blue Swirl | sigprocmask(SIG_SETMASK, (sigset_t *)&uc->uc_sigmask, NULL);
|
69 | 42a623c7 | Blue Swirl | #else
|
70 | 42a623c7 | Blue Swirl | sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
|
71 | 42a623c7 | Blue Swirl | #endif
|
72 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
73 | 42a623c7 | Blue Swirl | sigprocmask(SIG_SETMASK, &uc->sc_mask, NULL);
|
74 | 42a623c7 | Blue Swirl | #endif
|
75 | 42a623c7 | Blue Swirl | } |
76 | 42a623c7 | Blue Swirl | env->exception_index = -1;
|
77 | 42a623c7 | Blue Swirl | longjmp(env->jmp_env, 1);
|
78 | 42a623c7 | Blue Swirl | } |
79 | 42a623c7 | Blue Swirl | |
80 | 42a623c7 | Blue Swirl | /* 'pc' is the host PC at which the exception was raised. 'address' is
|
81 | 42a623c7 | Blue Swirl | the effective address of the memory exception. 'is_write' is 1 if a
|
82 | 42a623c7 | Blue Swirl | write caused the exception and otherwise 0'. 'old_set' is the
|
83 | 42a623c7 | Blue Swirl | signal set which should be restored */
|
84 | 42a623c7 | Blue Swirl | static inline int handle_cpu_signal(unsigned long pc, unsigned long address, |
85 | 42a623c7 | Blue Swirl | int is_write, sigset_t *old_set,
|
86 | 42a623c7 | Blue Swirl | void *puc)
|
87 | 42a623c7 | Blue Swirl | { |
88 | 42a623c7 | Blue Swirl | TranslationBlock *tb; |
89 | 42a623c7 | Blue Swirl | int ret;
|
90 | 42a623c7 | Blue Swirl | |
91 | 42a623c7 | Blue Swirl | if (cpu_single_env) {
|
92 | 42a623c7 | Blue Swirl | env = cpu_single_env; /* XXX: find a correct solution for multithread */
|
93 | 42a623c7 | Blue Swirl | } |
94 | 42a623c7 | Blue Swirl | #if defined(DEBUG_SIGNAL)
|
95 | 42a623c7 | Blue Swirl | qemu_printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
|
96 | 42a623c7 | Blue Swirl | pc, address, is_write, *(unsigned long *)old_set); |
97 | 42a623c7 | Blue Swirl | #endif
|
98 | 42a623c7 | Blue Swirl | /* XXX: locking issue */
|
99 | 42a623c7 | Blue Swirl | if (is_write && page_unprotect(h2g(address), pc, puc)) {
|
100 | 42a623c7 | Blue Swirl | return 1; |
101 | 42a623c7 | Blue Swirl | } |
102 | 42a623c7 | Blue Swirl | |
103 | 42a623c7 | Blue Swirl | /* see if it is an MMU fault */
|
104 | 42a623c7 | Blue Swirl | ret = cpu_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0);
|
105 | 42a623c7 | Blue Swirl | if (ret < 0) { |
106 | 42a623c7 | Blue Swirl | return 0; /* not an MMU fault */ |
107 | 42a623c7 | Blue Swirl | } |
108 | 42a623c7 | Blue Swirl | if (ret == 0) { |
109 | 42a623c7 | Blue Swirl | return 1; /* the MMU fault was handled without causing real CPU fault */ |
110 | 42a623c7 | Blue Swirl | } |
111 | 42a623c7 | Blue Swirl | /* now we have a real cpu fault */
|
112 | 42a623c7 | Blue Swirl | tb = tb_find_pc(pc); |
113 | 42a623c7 | Blue Swirl | if (tb) {
|
114 | 42a623c7 | Blue Swirl | /* the PC is inside the translated code. It means that we have
|
115 | 42a623c7 | Blue Swirl | a virtual CPU fault */
|
116 | 42a623c7 | Blue Swirl | cpu_restore_state(tb, env, pc); |
117 | 42a623c7 | Blue Swirl | } |
118 | 42a623c7 | Blue Swirl | |
119 | 42a623c7 | Blue Swirl | /* we restore the process signal mask as the sigreturn should
|
120 | 42a623c7 | Blue Swirl | do it (XXX: use sigsetjmp) */
|
121 | 42a623c7 | Blue Swirl | sigprocmask(SIG_SETMASK, old_set, NULL);
|
122 | 1162c041 | Blue Swirl | exception_action(env); |
123 | 42a623c7 | Blue Swirl | |
124 | 42a623c7 | Blue Swirl | /* never comes here */
|
125 | 42a623c7 | Blue Swirl | return 1; |
126 | 42a623c7 | Blue Swirl | } |
127 | 42a623c7 | Blue Swirl | |
128 | 42a623c7 | Blue Swirl | #if defined(__i386__)
|
129 | 42a623c7 | Blue Swirl | |
130 | 42a623c7 | Blue Swirl | #if defined(__APPLE__)
|
131 | 42a623c7 | Blue Swirl | #include <sys/ucontext.h> |
132 | 42a623c7 | Blue Swirl | |
133 | 42a623c7 | Blue Swirl | #define EIP_sig(context) (*((unsigned long *)&(context)->uc_mcontext->ss.eip)) |
134 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext->es.trapno)
|
135 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext->es.err)
|
136 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
137 | 42a623c7 | Blue Swirl | #elif defined(__NetBSD__)
|
138 | 42a623c7 | Blue Swirl | #include <ucontext.h> |
139 | 42a623c7 | Blue Swirl | |
140 | 42a623c7 | Blue Swirl | #define EIP_sig(context) ((context)->uc_mcontext.__gregs[_REG_EIP])
|
141 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
|
142 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR])
|
143 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
144 | 42a623c7 | Blue Swirl | #elif defined(__FreeBSD__) || defined(__DragonFly__)
|
145 | 42a623c7 | Blue Swirl | #include <ucontext.h> |
146 | 42a623c7 | Blue Swirl | |
147 | 42a623c7 | Blue Swirl | #define EIP_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_eip)) |
148 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno)
|
149 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.mc_err)
|
150 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
151 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
152 | 42a623c7 | Blue Swirl | #define EIP_sig(context) ((context)->sc_eip)
|
153 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->sc_trapno)
|
154 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->sc_err)
|
155 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->sc_mask)
|
156 | 42a623c7 | Blue Swirl | #else
|
157 | 42a623c7 | Blue Swirl | #define EIP_sig(context) ((context)->uc_mcontext.gregs[REG_EIP])
|
158 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
|
159 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
|
160 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
161 | 42a623c7 | Blue Swirl | #endif
|
162 | 42a623c7 | Blue Swirl | |
163 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
164 | 42a623c7 | Blue Swirl | void *puc)
|
165 | 42a623c7 | Blue Swirl | { |
166 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
167 | 42a623c7 | Blue Swirl | #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
168 | 42a623c7 | Blue Swirl | ucontext_t *uc = puc; |
169 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
170 | 42a623c7 | Blue Swirl | struct sigcontext *uc = puc;
|
171 | 42a623c7 | Blue Swirl | #else
|
172 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
173 | 42a623c7 | Blue Swirl | #endif
|
174 | 42a623c7 | Blue Swirl | unsigned long pc; |
175 | 42a623c7 | Blue Swirl | int trapno;
|
176 | 42a623c7 | Blue Swirl | |
177 | 42a623c7 | Blue Swirl | #ifndef REG_EIP
|
178 | 42a623c7 | Blue Swirl | /* for glibc 2.1 */
|
179 | 42a623c7 | Blue Swirl | #define REG_EIP EIP
|
180 | 42a623c7 | Blue Swirl | #define REG_ERR ERR
|
181 | 42a623c7 | Blue Swirl | #define REG_TRAPNO TRAPNO
|
182 | 42a623c7 | Blue Swirl | #endif
|
183 | 42a623c7 | Blue Swirl | pc = EIP_sig(uc); |
184 | 42a623c7 | Blue Swirl | trapno = TRAP_sig(uc); |
185 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
186 | 42a623c7 | Blue Swirl | trapno == 0xe ?
|
187 | 42a623c7 | Blue Swirl | (ERROR_sig(uc) >> 1) & 1 : 0, |
188 | 42a623c7 | Blue Swirl | &MASK_sig(uc), puc); |
189 | 42a623c7 | Blue Swirl | } |
190 | 42a623c7 | Blue Swirl | |
191 | 42a623c7 | Blue Swirl | #elif defined(__x86_64__)
|
192 | 42a623c7 | Blue Swirl | |
193 | 42a623c7 | Blue Swirl | #ifdef __NetBSD__
|
194 | 42a623c7 | Blue Swirl | #define PC_sig(context) _UC_MACHINE_PC(context)
|
195 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
|
196 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.__gregs[_REG_ERR])
|
197 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
198 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
199 | 42a623c7 | Blue Swirl | #define PC_sig(context) ((context)->sc_rip)
|
200 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->sc_trapno)
|
201 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->sc_err)
|
202 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->sc_mask)
|
203 | 42a623c7 | Blue Swirl | #elif defined(__FreeBSD__) || defined(__DragonFly__)
|
204 | 42a623c7 | Blue Swirl | #include <ucontext.h> |
205 | 42a623c7 | Blue Swirl | |
206 | 42a623c7 | Blue Swirl | #define PC_sig(context) (*((unsigned long *)&(context)->uc_mcontext.mc_rip)) |
207 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.mc_trapno)
|
208 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.mc_err)
|
209 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
210 | 42a623c7 | Blue Swirl | #else
|
211 | 42a623c7 | Blue Swirl | #define PC_sig(context) ((context)->uc_mcontext.gregs[REG_RIP])
|
212 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.gregs[REG_TRAPNO])
|
213 | 42a623c7 | Blue Swirl | #define ERROR_sig(context) ((context)->uc_mcontext.gregs[REG_ERR])
|
214 | 42a623c7 | Blue Swirl | #define MASK_sig(context) ((context)->uc_sigmask)
|
215 | 42a623c7 | Blue Swirl | #endif
|
216 | 42a623c7 | Blue Swirl | |
217 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
218 | 42a623c7 | Blue Swirl | void *puc)
|
219 | 42a623c7 | Blue Swirl | { |
220 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
221 | 42a623c7 | Blue Swirl | unsigned long pc; |
222 | 42a623c7 | Blue Swirl | #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
223 | 42a623c7 | Blue Swirl | ucontext_t *uc = puc; |
224 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
225 | 42a623c7 | Blue Swirl | struct sigcontext *uc = puc;
|
226 | 42a623c7 | Blue Swirl | #else
|
227 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
228 | 42a623c7 | Blue Swirl | #endif
|
229 | 42a623c7 | Blue Swirl | |
230 | 42a623c7 | Blue Swirl | pc = PC_sig(uc); |
231 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
232 | 42a623c7 | Blue Swirl | TRAP_sig(uc) == 0xe ?
|
233 | 42a623c7 | Blue Swirl | (ERROR_sig(uc) >> 1) & 1 : 0, |
234 | 42a623c7 | Blue Swirl | &MASK_sig(uc), puc); |
235 | 42a623c7 | Blue Swirl | } |
236 | 42a623c7 | Blue Swirl | |
237 | 42a623c7 | Blue Swirl | #elif defined(_ARCH_PPC)
|
238 | 42a623c7 | Blue Swirl | |
239 | 42a623c7 | Blue Swirl | /***********************************************************************
|
240 | 42a623c7 | Blue Swirl | * signal context platform-specific definitions
|
241 | 42a623c7 | Blue Swirl | * From Wine
|
242 | 42a623c7 | Blue Swirl | */
|
243 | 42a623c7 | Blue Swirl | #ifdef linux
|
244 | 42a623c7 | Blue Swirl | /* All Registers access - only for local access */
|
245 | 42a623c7 | Blue Swirl | #define REG_sig(reg_name, context) \
|
246 | 42a623c7 | Blue Swirl | ((context)->uc_mcontext.regs->reg_name) |
247 | 42a623c7 | Blue Swirl | /* Gpr Registers access */
|
248 | 42a623c7 | Blue Swirl | #define GPR_sig(reg_num, context) REG_sig(gpr[reg_num], context)
|
249 | 42a623c7 | Blue Swirl | /* Program counter */
|
250 | 42a623c7 | Blue Swirl | #define IAR_sig(context) REG_sig(nip, context)
|
251 | 42a623c7 | Blue Swirl | /* Machine State Register (Supervisor) */
|
252 | 42a623c7 | Blue Swirl | #define MSR_sig(context) REG_sig(msr, context)
|
253 | 42a623c7 | Blue Swirl | /* Count register */
|
254 | 42a623c7 | Blue Swirl | #define CTR_sig(context) REG_sig(ctr, context)
|
255 | 42a623c7 | Blue Swirl | /* User's integer exception register */
|
256 | 42a623c7 | Blue Swirl | #define XER_sig(context) REG_sig(xer, context)
|
257 | 42a623c7 | Blue Swirl | /* Link register */
|
258 | 42a623c7 | Blue Swirl | #define LR_sig(context) REG_sig(link, context)
|
259 | 42a623c7 | Blue Swirl | /* Condition register */
|
260 | 42a623c7 | Blue Swirl | #define CR_sig(context) REG_sig(ccr, context)
|
261 | 42a623c7 | Blue Swirl | |
262 | 42a623c7 | Blue Swirl | /* Float Registers access */
|
263 | 42a623c7 | Blue Swirl | #define FLOAT_sig(reg_num, context) \
|
264 | 42a623c7 | Blue Swirl | (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num]) |
265 | 42a623c7 | Blue Swirl | #define FPSCR_sig(context) \
|
266 | 42a623c7 | Blue Swirl | (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4))) |
267 | 42a623c7 | Blue Swirl | /* Exception Registers access */
|
268 | 42a623c7 | Blue Swirl | #define DAR_sig(context) REG_sig(dar, context)
|
269 | 42a623c7 | Blue Swirl | #define DSISR_sig(context) REG_sig(dsisr, context)
|
270 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) REG_sig(trap, context)
|
271 | 42a623c7 | Blue Swirl | #endif /* linux */ |
272 | 42a623c7 | Blue Swirl | |
273 | 42a623c7 | Blue Swirl | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
274 | 42a623c7 | Blue Swirl | #include <ucontext.h> |
275 | 42a623c7 | Blue Swirl | #define IAR_sig(context) ((context)->uc_mcontext.mc_srr0)
|
276 | 42a623c7 | Blue Swirl | #define MSR_sig(context) ((context)->uc_mcontext.mc_srr1)
|
277 | 42a623c7 | Blue Swirl | #define CTR_sig(context) ((context)->uc_mcontext.mc_ctr)
|
278 | 42a623c7 | Blue Swirl | #define XER_sig(context) ((context)->uc_mcontext.mc_xer)
|
279 | 42a623c7 | Blue Swirl | #define LR_sig(context) ((context)->uc_mcontext.mc_lr)
|
280 | 42a623c7 | Blue Swirl | #define CR_sig(context) ((context)->uc_mcontext.mc_cr)
|
281 | 42a623c7 | Blue Swirl | /* Exception Registers access */
|
282 | 42a623c7 | Blue Swirl | #define DAR_sig(context) ((context)->uc_mcontext.mc_dar)
|
283 | 42a623c7 | Blue Swirl | #define DSISR_sig(context) ((context)->uc_mcontext.mc_dsisr)
|
284 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) ((context)->uc_mcontext.mc_exc)
|
285 | 42a623c7 | Blue Swirl | #endif /* __FreeBSD__|| __FreeBSD_kernel__ */ |
286 | 42a623c7 | Blue Swirl | |
287 | 42a623c7 | Blue Swirl | #ifdef __APPLE__
|
288 | 42a623c7 | Blue Swirl | #include <sys/ucontext.h> |
289 | 42a623c7 | Blue Swirl | typedef struct ucontext SIGCONTEXT; |
290 | 42a623c7 | Blue Swirl | /* All Registers access - only for local access */
|
291 | 42a623c7 | Blue Swirl | #define REG_sig(reg_name, context) \
|
292 | 42a623c7 | Blue Swirl | ((context)->uc_mcontext->ss.reg_name) |
293 | 42a623c7 | Blue Swirl | #define FLOATREG_sig(reg_name, context) \
|
294 | 42a623c7 | Blue Swirl | ((context)->uc_mcontext->fs.reg_name) |
295 | 42a623c7 | Blue Swirl | #define EXCEPREG_sig(reg_name, context) \
|
296 | 42a623c7 | Blue Swirl | ((context)->uc_mcontext->es.reg_name) |
297 | 42a623c7 | Blue Swirl | #define VECREG_sig(reg_name, context) \
|
298 | 42a623c7 | Blue Swirl | ((context)->uc_mcontext->vs.reg_name) |
299 | 42a623c7 | Blue Swirl | /* Gpr Registers access */
|
300 | 42a623c7 | Blue Swirl | #define GPR_sig(reg_num, context) REG_sig(r##reg_num, context) |
301 | 42a623c7 | Blue Swirl | /* Program counter */
|
302 | 42a623c7 | Blue Swirl | #define IAR_sig(context) REG_sig(srr0, context)
|
303 | 42a623c7 | Blue Swirl | /* Machine State Register (Supervisor) */
|
304 | 42a623c7 | Blue Swirl | #define MSR_sig(context) REG_sig(srr1, context)
|
305 | 42a623c7 | Blue Swirl | #define CTR_sig(context) REG_sig(ctr, context)
|
306 | 42a623c7 | Blue Swirl | /* Link register */
|
307 | 42a623c7 | Blue Swirl | #define XER_sig(context) REG_sig(xer, context)
|
308 | 42a623c7 | Blue Swirl | /* User's integer exception register */
|
309 | 42a623c7 | Blue Swirl | #define LR_sig(context) REG_sig(lr, context)
|
310 | 42a623c7 | Blue Swirl | /* Condition register */
|
311 | 42a623c7 | Blue Swirl | #define CR_sig(context) REG_sig(cr, context)
|
312 | 42a623c7 | Blue Swirl | /* Float Registers access */
|
313 | 42a623c7 | Blue Swirl | #define FLOAT_sig(reg_num, context) \
|
314 | 42a623c7 | Blue Swirl | FLOATREG_sig(fpregs[reg_num], context) |
315 | 42a623c7 | Blue Swirl | #define FPSCR_sig(context) \
|
316 | 42a623c7 | Blue Swirl | ((double)FLOATREG_sig(fpscr, context))
|
317 | 42a623c7 | Blue Swirl | /* Exception Registers access */
|
318 | 42a623c7 | Blue Swirl | /* Fault registers for coredump */
|
319 | 42a623c7 | Blue Swirl | #define DAR_sig(context) EXCEPREG_sig(dar, context)
|
320 | 42a623c7 | Blue Swirl | #define DSISR_sig(context) EXCEPREG_sig(dsisr, context)
|
321 | 42a623c7 | Blue Swirl | /* number of powerpc exception taken */
|
322 | 42a623c7 | Blue Swirl | #define TRAP_sig(context) EXCEPREG_sig(exception, context)
|
323 | 42a623c7 | Blue Swirl | #endif /* __APPLE__ */ |
324 | 42a623c7 | Blue Swirl | |
325 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
326 | 42a623c7 | Blue Swirl | void *puc)
|
327 | 42a623c7 | Blue Swirl | { |
328 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
329 | 42a623c7 | Blue Swirl | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
330 | 42a623c7 | Blue Swirl | ucontext_t *uc = puc; |
331 | 42a623c7 | Blue Swirl | #else
|
332 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
333 | 42a623c7 | Blue Swirl | #endif
|
334 | 42a623c7 | Blue Swirl | unsigned long pc; |
335 | 42a623c7 | Blue Swirl | int is_write;
|
336 | 42a623c7 | Blue Swirl | |
337 | 42a623c7 | Blue Swirl | pc = IAR_sig(uc); |
338 | 42a623c7 | Blue Swirl | is_write = 0;
|
339 | 42a623c7 | Blue Swirl | #if 0
|
340 | 42a623c7 | Blue Swirl | /* ppc 4xx case */
|
341 | 42a623c7 | Blue Swirl | if (DSISR_sig(uc) & 0x00800000) {
|
342 | 42a623c7 | Blue Swirl | is_write = 1;
|
343 | 42a623c7 | Blue Swirl | }
|
344 | 42a623c7 | Blue Swirl | #else
|
345 | 42a623c7 | Blue Swirl | if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) { |
346 | 42a623c7 | Blue Swirl | is_write = 1;
|
347 | 42a623c7 | Blue Swirl | } |
348 | 42a623c7 | Blue Swirl | #endif
|
349 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
350 | 42a623c7 | Blue Swirl | is_write, &uc->uc_sigmask, puc); |
351 | 42a623c7 | Blue Swirl | } |
352 | 42a623c7 | Blue Swirl | |
353 | 42a623c7 | Blue Swirl | #elif defined(__alpha__)
|
354 | 42a623c7 | Blue Swirl | |
355 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
356 | 42a623c7 | Blue Swirl | void *puc)
|
357 | 42a623c7 | Blue Swirl | { |
358 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
359 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
360 | 42a623c7 | Blue Swirl | uint32_t *pc = uc->uc_mcontext.sc_pc; |
361 | 42a623c7 | Blue Swirl | uint32_t insn = *pc; |
362 | 42a623c7 | Blue Swirl | int is_write = 0; |
363 | 42a623c7 | Blue Swirl | |
364 | 42a623c7 | Blue Swirl | /* XXX: need kernel patch to get write flag faster */
|
365 | 42a623c7 | Blue Swirl | switch (insn >> 26) { |
366 | 42a623c7 | Blue Swirl | case 0x0d: /* stw */ |
367 | 42a623c7 | Blue Swirl | case 0x0e: /* stb */ |
368 | 42a623c7 | Blue Swirl | case 0x0f: /* stq_u */ |
369 | 42a623c7 | Blue Swirl | case 0x24: /* stf */ |
370 | 42a623c7 | Blue Swirl | case 0x25: /* stg */ |
371 | 42a623c7 | Blue Swirl | case 0x26: /* sts */ |
372 | 42a623c7 | Blue Swirl | case 0x27: /* stt */ |
373 | 42a623c7 | Blue Swirl | case 0x2c: /* stl */ |
374 | 42a623c7 | Blue Swirl | case 0x2d: /* stq */ |
375 | 42a623c7 | Blue Swirl | case 0x2e: /* stl_c */ |
376 | 42a623c7 | Blue Swirl | case 0x2f: /* stq_c */ |
377 | 42a623c7 | Blue Swirl | is_write = 1;
|
378 | 42a623c7 | Blue Swirl | } |
379 | 42a623c7 | Blue Swirl | |
380 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
381 | 42a623c7 | Blue Swirl | is_write, &uc->uc_sigmask, puc); |
382 | 42a623c7 | Blue Swirl | } |
383 | 42a623c7 | Blue Swirl | #elif defined(__sparc__)
|
384 | 42a623c7 | Blue Swirl | |
385 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
386 | 42a623c7 | Blue Swirl | void *puc)
|
387 | 42a623c7 | Blue Swirl | { |
388 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
389 | 42a623c7 | Blue Swirl | int is_write;
|
390 | 42a623c7 | Blue Swirl | uint32_t insn; |
391 | 42a623c7 | Blue Swirl | #if !defined(__arch64__) || defined(CONFIG_SOLARIS)
|
392 | 42a623c7 | Blue Swirl | uint32_t *regs = (uint32_t *)(info + 1);
|
393 | 42a623c7 | Blue Swirl | void *sigmask = (regs + 20); |
394 | 42a623c7 | Blue Swirl | /* XXX: is there a standard glibc define ? */
|
395 | 42a623c7 | Blue Swirl | unsigned long pc = regs[1]; |
396 | 42a623c7 | Blue Swirl | #else
|
397 | 42a623c7 | Blue Swirl | #ifdef __linux__
|
398 | 42a623c7 | Blue Swirl | struct sigcontext *sc = puc;
|
399 | 42a623c7 | Blue Swirl | unsigned long pc = sc->sigc_regs.tpc; |
400 | 42a623c7 | Blue Swirl | void *sigmask = (void *)sc->sigc_mask; |
401 | 42a623c7 | Blue Swirl | #elif defined(__OpenBSD__)
|
402 | 42a623c7 | Blue Swirl | struct sigcontext *uc = puc;
|
403 | 42a623c7 | Blue Swirl | unsigned long pc = uc->sc_pc; |
404 | 42a623c7 | Blue Swirl | void *sigmask = (void *)(long)uc->sc_mask; |
405 | 42a623c7 | Blue Swirl | #endif
|
406 | 42a623c7 | Blue Swirl | #endif
|
407 | 42a623c7 | Blue Swirl | |
408 | 42a623c7 | Blue Swirl | /* XXX: need kernel patch to get write flag faster */
|
409 | 42a623c7 | Blue Swirl | is_write = 0;
|
410 | 42a623c7 | Blue Swirl | insn = *(uint32_t *)pc; |
411 | 42a623c7 | Blue Swirl | if ((insn >> 30) == 3) { |
412 | 42a623c7 | Blue Swirl | switch ((insn >> 19) & 0x3f) { |
413 | 42a623c7 | Blue Swirl | case 0x05: /* stb */ |
414 | 42a623c7 | Blue Swirl | case 0x15: /* stba */ |
415 | 42a623c7 | Blue Swirl | case 0x06: /* sth */ |
416 | 42a623c7 | Blue Swirl | case 0x16: /* stha */ |
417 | 42a623c7 | Blue Swirl | case 0x04: /* st */ |
418 | 42a623c7 | Blue Swirl | case 0x14: /* sta */ |
419 | 42a623c7 | Blue Swirl | case 0x07: /* std */ |
420 | 42a623c7 | Blue Swirl | case 0x17: /* stda */ |
421 | 42a623c7 | Blue Swirl | case 0x0e: /* stx */ |
422 | 42a623c7 | Blue Swirl | case 0x1e: /* stxa */ |
423 | 42a623c7 | Blue Swirl | case 0x24: /* stf */ |
424 | 42a623c7 | Blue Swirl | case 0x34: /* stfa */ |
425 | 42a623c7 | Blue Swirl | case 0x27: /* stdf */ |
426 | 42a623c7 | Blue Swirl | case 0x37: /* stdfa */ |
427 | 42a623c7 | Blue Swirl | case 0x26: /* stqf */ |
428 | 42a623c7 | Blue Swirl | case 0x36: /* stqfa */ |
429 | 42a623c7 | Blue Swirl | case 0x25: /* stfsr */ |
430 | 42a623c7 | Blue Swirl | case 0x3c: /* casa */ |
431 | 42a623c7 | Blue Swirl | case 0x3e: /* casxa */ |
432 | 42a623c7 | Blue Swirl | is_write = 1;
|
433 | 42a623c7 | Blue Swirl | break;
|
434 | 42a623c7 | Blue Swirl | } |
435 | 42a623c7 | Blue Swirl | } |
436 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
437 | 42a623c7 | Blue Swirl | is_write, sigmask, NULL);
|
438 | 42a623c7 | Blue Swirl | } |
439 | 42a623c7 | Blue Swirl | |
440 | 42a623c7 | Blue Swirl | #elif defined(__arm__)
|
441 | 42a623c7 | Blue Swirl | |
442 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
443 | 42a623c7 | Blue Swirl | void *puc)
|
444 | 42a623c7 | Blue Swirl | { |
445 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
446 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
447 | 42a623c7 | Blue Swirl | unsigned long pc; |
448 | 42a623c7 | Blue Swirl | int is_write;
|
449 | 42a623c7 | Blue Swirl | |
450 | 42a623c7 | Blue Swirl | #if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3)) |
451 | 42a623c7 | Blue Swirl | pc = uc->uc_mcontext.gregs[R15]; |
452 | 42a623c7 | Blue Swirl | #else
|
453 | 42a623c7 | Blue Swirl | pc = uc->uc_mcontext.arm_pc; |
454 | 42a623c7 | Blue Swirl | #endif
|
455 | 42a623c7 | Blue Swirl | /* XXX: compute is_write */
|
456 | 42a623c7 | Blue Swirl | is_write = 0;
|
457 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
458 | 42a623c7 | Blue Swirl | is_write, |
459 | 42a623c7 | Blue Swirl | &uc->uc_sigmask, puc); |
460 | 42a623c7 | Blue Swirl | } |
461 | 42a623c7 | Blue Swirl | |
462 | 42a623c7 | Blue Swirl | #elif defined(__mc68000)
|
463 | 42a623c7 | Blue Swirl | |
464 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
465 | 42a623c7 | Blue Swirl | void *puc)
|
466 | 42a623c7 | Blue Swirl | { |
467 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
468 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
469 | 42a623c7 | Blue Swirl | unsigned long pc; |
470 | 42a623c7 | Blue Swirl | int is_write;
|
471 | 42a623c7 | Blue Swirl | |
472 | 42a623c7 | Blue Swirl | pc = uc->uc_mcontext.gregs[16];
|
473 | 42a623c7 | Blue Swirl | /* XXX: compute is_write */
|
474 | 42a623c7 | Blue Swirl | is_write = 0;
|
475 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
476 | 42a623c7 | Blue Swirl | is_write, |
477 | 42a623c7 | Blue Swirl | &uc->uc_sigmask, puc); |
478 | 42a623c7 | Blue Swirl | } |
479 | 42a623c7 | Blue Swirl | |
480 | 42a623c7 | Blue Swirl | #elif defined(__ia64)
|
481 | 42a623c7 | Blue Swirl | |
482 | 42a623c7 | Blue Swirl | #ifndef __ISR_VALID
|
483 | 42a623c7 | Blue Swirl | /* This ought to be in <bits/siginfo.h>... */
|
484 | 42a623c7 | Blue Swirl | # define __ISR_VALID 1 |
485 | 42a623c7 | Blue Swirl | #endif
|
486 | 42a623c7 | Blue Swirl | |
487 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, void *puc) |
488 | 42a623c7 | Blue Swirl | { |
489 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
490 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
491 | 42a623c7 | Blue Swirl | unsigned long ip; |
492 | 42a623c7 | Blue Swirl | int is_write = 0; |
493 | 42a623c7 | Blue Swirl | |
494 | 42a623c7 | Blue Swirl | ip = uc->uc_mcontext.sc_ip; |
495 | 42a623c7 | Blue Swirl | switch (host_signum) {
|
496 | 42a623c7 | Blue Swirl | case SIGILL:
|
497 | 42a623c7 | Blue Swirl | case SIGFPE:
|
498 | 42a623c7 | Blue Swirl | case SIGSEGV:
|
499 | 42a623c7 | Blue Swirl | case SIGBUS:
|
500 | 42a623c7 | Blue Swirl | case SIGTRAP:
|
501 | 42a623c7 | Blue Swirl | if (info->si_code && (info->si_segvflags & __ISR_VALID)) {
|
502 | 42a623c7 | Blue Swirl | /* ISR.W (write-access) is bit 33: */
|
503 | 42a623c7 | Blue Swirl | is_write = (info->si_isr >> 33) & 1; |
504 | 42a623c7 | Blue Swirl | } |
505 | 42a623c7 | Blue Swirl | break;
|
506 | 42a623c7 | Blue Swirl | |
507 | 42a623c7 | Blue Swirl | default:
|
508 | 42a623c7 | Blue Swirl | break;
|
509 | 42a623c7 | Blue Swirl | } |
510 | 42a623c7 | Blue Swirl | return handle_cpu_signal(ip, (unsigned long)info->si_addr, |
511 | 42a623c7 | Blue Swirl | is_write, |
512 | 42a623c7 | Blue Swirl | (sigset_t *)&uc->uc_sigmask, puc); |
513 | 42a623c7 | Blue Swirl | } |
514 | 42a623c7 | Blue Swirl | |
515 | 42a623c7 | Blue Swirl | #elif defined(__s390__)
|
516 | 42a623c7 | Blue Swirl | |
517 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
518 | 42a623c7 | Blue Swirl | void *puc)
|
519 | 42a623c7 | Blue Swirl | { |
520 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
521 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
522 | 42a623c7 | Blue Swirl | unsigned long pc; |
523 | 42a623c7 | Blue Swirl | uint16_t *pinsn; |
524 | 42a623c7 | Blue Swirl | int is_write = 0; |
525 | 42a623c7 | Blue Swirl | |
526 | 42a623c7 | Blue Swirl | pc = uc->uc_mcontext.psw.addr; |
527 | 42a623c7 | Blue Swirl | |
528 | 42a623c7 | Blue Swirl | /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead
|
529 | 42a623c7 | Blue Swirl | of the normal 2 arguments. The 3rd argument contains the "int_code"
|
530 | 42a623c7 | Blue Swirl | from the hardware which does in fact contain the is_write value.
|
531 | 42a623c7 | Blue Swirl | The rt signal handler, as far as I can tell, does not give this value
|
532 | 42a623c7 | Blue Swirl | at all. Not that we could get to it from here even if it were. */
|
533 | 42a623c7 | Blue Swirl | /* ??? This is not even close to complete, since it ignores all
|
534 | 42a623c7 | Blue Swirl | of the read-modify-write instructions. */
|
535 | 42a623c7 | Blue Swirl | pinsn = (uint16_t *)pc; |
536 | 42a623c7 | Blue Swirl | switch (pinsn[0] >> 8) { |
537 | 42a623c7 | Blue Swirl | case 0x50: /* ST */ |
538 | 42a623c7 | Blue Swirl | case 0x42: /* STC */ |
539 | 42a623c7 | Blue Swirl | case 0x40: /* STH */ |
540 | 42a623c7 | Blue Swirl | is_write = 1;
|
541 | 42a623c7 | Blue Swirl | break;
|
542 | 42a623c7 | Blue Swirl | case 0xc4: /* RIL format insns */ |
543 | 42a623c7 | Blue Swirl | switch (pinsn[0] & 0xf) { |
544 | 42a623c7 | Blue Swirl | case 0xf: /* STRL */ |
545 | 42a623c7 | Blue Swirl | case 0xb: /* STGRL */ |
546 | 42a623c7 | Blue Swirl | case 0x7: /* STHRL */ |
547 | 42a623c7 | Blue Swirl | is_write = 1;
|
548 | 42a623c7 | Blue Swirl | } |
549 | 42a623c7 | Blue Swirl | break;
|
550 | 42a623c7 | Blue Swirl | case 0xe3: /* RXY format insns */ |
551 | 42a623c7 | Blue Swirl | switch (pinsn[2] & 0xff) { |
552 | 42a623c7 | Blue Swirl | case 0x50: /* STY */ |
553 | 42a623c7 | Blue Swirl | case 0x24: /* STG */ |
554 | 42a623c7 | Blue Swirl | case 0x72: /* STCY */ |
555 | 42a623c7 | Blue Swirl | case 0x70: /* STHY */ |
556 | 42a623c7 | Blue Swirl | case 0x8e: /* STPQ */ |
557 | 42a623c7 | Blue Swirl | case 0x3f: /* STRVH */ |
558 | 42a623c7 | Blue Swirl | case 0x3e: /* STRV */ |
559 | 42a623c7 | Blue Swirl | case 0x2f: /* STRVG */ |
560 | 42a623c7 | Blue Swirl | is_write = 1;
|
561 | 42a623c7 | Blue Swirl | } |
562 | 42a623c7 | Blue Swirl | break;
|
563 | 42a623c7 | Blue Swirl | } |
564 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
565 | 42a623c7 | Blue Swirl | is_write, &uc->uc_sigmask, puc); |
566 | 42a623c7 | Blue Swirl | } |
567 | 42a623c7 | Blue Swirl | |
568 | 42a623c7 | Blue Swirl | #elif defined(__mips__)
|
569 | 42a623c7 | Blue Swirl | |
570 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
571 | 42a623c7 | Blue Swirl | void *puc)
|
572 | 42a623c7 | Blue Swirl | { |
573 | 42a623c7 | Blue Swirl | siginfo_t *info = pinfo; |
574 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
575 | 42a623c7 | Blue Swirl | greg_t pc = uc->uc_mcontext.pc; |
576 | 42a623c7 | Blue Swirl | int is_write;
|
577 | 42a623c7 | Blue Swirl | |
578 | 42a623c7 | Blue Swirl | /* XXX: compute is_write */
|
579 | 42a623c7 | Blue Swirl | is_write = 0;
|
580 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
581 | 42a623c7 | Blue Swirl | is_write, &uc->uc_sigmask, puc); |
582 | 42a623c7 | Blue Swirl | } |
583 | 42a623c7 | Blue Swirl | |
584 | 42a623c7 | Blue Swirl | #elif defined(__hppa__)
|
585 | 42a623c7 | Blue Swirl | |
586 | 42a623c7 | Blue Swirl | int cpu_signal_handler(int host_signum, void *pinfo, |
587 | 42a623c7 | Blue Swirl | void *puc)
|
588 | 42a623c7 | Blue Swirl | { |
589 | 42a623c7 | Blue Swirl | struct siginfo *info = pinfo;
|
590 | 42a623c7 | Blue Swirl | struct ucontext *uc = puc;
|
591 | 42a623c7 | Blue Swirl | unsigned long pc = uc->uc_mcontext.sc_iaoq[0]; |
592 | 42a623c7 | Blue Swirl | uint32_t insn = *(uint32_t *)pc; |
593 | 42a623c7 | Blue Swirl | int is_write = 0; |
594 | 42a623c7 | Blue Swirl | |
595 | 42a623c7 | Blue Swirl | /* XXX: need kernel patch to get write flag faster. */
|
596 | 42a623c7 | Blue Swirl | switch (insn >> 26) { |
597 | 42a623c7 | Blue Swirl | case 0x1a: /* STW */ |
598 | 42a623c7 | Blue Swirl | case 0x19: /* STH */ |
599 | 42a623c7 | Blue Swirl | case 0x18: /* STB */ |
600 | 42a623c7 | Blue Swirl | case 0x1b: /* STWM */ |
601 | 42a623c7 | Blue Swirl | is_write = 1;
|
602 | 42a623c7 | Blue Swirl | break;
|
603 | 42a623c7 | Blue Swirl | |
604 | 42a623c7 | Blue Swirl | case 0x09: /* CSTWX, FSTWX, FSTWS */ |
605 | 42a623c7 | Blue Swirl | case 0x0b: /* CSTDX, FSTDX, FSTDS */ |
606 | 42a623c7 | Blue Swirl | /* Distinguish from coprocessor load ... */
|
607 | 42a623c7 | Blue Swirl | is_write = (insn >> 9) & 1; |
608 | 42a623c7 | Blue Swirl | break;
|
609 | 42a623c7 | Blue Swirl | |
610 | 42a623c7 | Blue Swirl | case 0x03: |
611 | 42a623c7 | Blue Swirl | switch ((insn >> 6) & 15) { |
612 | 42a623c7 | Blue Swirl | case 0xa: /* STWS */ |
613 | 42a623c7 | Blue Swirl | case 0x9: /* STHS */ |
614 | 42a623c7 | Blue Swirl | case 0x8: /* STBS */ |
615 | 42a623c7 | Blue Swirl | case 0xe: /* STWAS */ |
616 | 42a623c7 | Blue Swirl | case 0xc: /* STBYS */ |
617 | 42a623c7 | Blue Swirl | is_write = 1;
|
618 | 42a623c7 | Blue Swirl | } |
619 | 42a623c7 | Blue Swirl | break;
|
620 | 42a623c7 | Blue Swirl | } |
621 | 42a623c7 | Blue Swirl | |
622 | 42a623c7 | Blue Swirl | return handle_cpu_signal(pc, (unsigned long)info->si_addr, |
623 | 42a623c7 | Blue Swirl | is_write, &uc->uc_sigmask, puc); |
624 | 42a623c7 | Blue Swirl | } |
625 | 42a623c7 | Blue Swirl | |
626 | 42a623c7 | Blue Swirl | #else
|
627 | 42a623c7 | Blue Swirl | |
628 | 42a623c7 | Blue Swirl | #error host CPU specific signal handler needed
|
629 | 42a623c7 | Blue Swirl | |
630 | 42a623c7 | Blue Swirl | #endif
|
631 | 42a623c7 | Blue Swirl | |
632 | 42a623c7 | Blue Swirl | #if defined(TARGET_I386)
|
633 | 42a623c7 | Blue Swirl | |
634 | 42a623c7 | Blue Swirl | void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector) |
635 | 42a623c7 | Blue Swirl | { |
636 | 42a623c7 | Blue Swirl | CPUX86State *saved_env; |
637 | 42a623c7 | Blue Swirl | |
638 | 42a623c7 | Blue Swirl | saved_env = env; |
639 | 42a623c7 | Blue Swirl | env = s; |
640 | 42a623c7 | Blue Swirl | if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { |
641 | 42a623c7 | Blue Swirl | selector &= 0xffff;
|
642 | 42a623c7 | Blue Swirl | cpu_x86_load_seg_cache(env, seg_reg, selector, |
643 | 42a623c7 | Blue Swirl | (selector << 4), 0xffff, 0); |
644 | 42a623c7 | Blue Swirl | } else {
|
645 | 42a623c7 | Blue Swirl | helper_load_seg(seg_reg, selector); |
646 | 42a623c7 | Blue Swirl | } |
647 | 42a623c7 | Blue Swirl | env = saved_env; |
648 | 42a623c7 | Blue Swirl | } |
649 | 42a623c7 | Blue Swirl | |
650 | 42a623c7 | Blue Swirl | void cpu_x86_fsave(CPUX86State *s, target_ulong ptr, int data32) |
651 | 42a623c7 | Blue Swirl | { |
652 | 42a623c7 | Blue Swirl | CPUX86State *saved_env; |
653 | 42a623c7 | Blue Swirl | |
654 | 42a623c7 | Blue Swirl | saved_env = env; |
655 | 42a623c7 | Blue Swirl | env = s; |
656 | 42a623c7 | Blue Swirl | |
657 | 42a623c7 | Blue Swirl | helper_fsave(ptr, data32); |
658 | 42a623c7 | Blue Swirl | |
659 | 42a623c7 | Blue Swirl | env = saved_env; |
660 | 42a623c7 | Blue Swirl | } |
661 | 42a623c7 | Blue Swirl | |
662 | 42a623c7 | Blue Swirl | void cpu_x86_frstor(CPUX86State *s, target_ulong ptr, int data32) |
663 | 42a623c7 | Blue Swirl | { |
664 | 42a623c7 | Blue Swirl | CPUX86State *saved_env; |
665 | 42a623c7 | Blue Swirl | |
666 | 42a623c7 | Blue Swirl | saved_env = env; |
667 | 42a623c7 | Blue Swirl | env = s; |
668 | 42a623c7 | Blue Swirl | |
669 | 42a623c7 | Blue Swirl | helper_frstor(ptr, data32); |
670 | 42a623c7 | Blue Swirl | |
671 | 42a623c7 | Blue Swirl | env = saved_env; |
672 | 42a623c7 | Blue Swirl | } |
673 | 42a623c7 | Blue Swirl | |
674 | 42a623c7 | Blue Swirl | #endif /* TARGET_I386 */ |