| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: trap.c,v 1.27 2011/09/05 18:50:34 reinoud Exp $ */ | | 1 | /* $NetBSD: trap.c,v 1.28 2011/09/05 21:38:05 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> | | 4 | * Copyright (c) 2011 Reinoud Zandijk <reinoud@netbsd.org> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,47 +17,48 @@ | | | @@ -17,47 +17,48 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.27 2011/09/05 18:50:34 reinoud Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.28 2011/09/05 21:38:05 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include <sys/types.h> | | 32 | #include <sys/types.h> |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/systm.h> | | 34 | #include <sys/systm.h> |
35 | #include <sys/proc.h> | | 35 | #include <sys/proc.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | #include <sys/userret.h> | | 37 | #include <sys/userret.h> |
38 | #include <sys/errno.h> | | 38 | #include <sys/errno.h> |
39 | | | 39 | |
40 | #include <uvm/uvm_extern.h> | | 40 | #include <uvm/uvm_extern.h> |
41 | #include <machine/cpu.h> | | 41 | #include <machine/cpu.h> |
42 | #include <machine/pcb.h> | | 42 | #include <machine/pcb.h> |
43 | #include <machine/pmap.h> | | 43 | #include <machine/pmap.h> |
44 | #include <machine/thunk.h> | | 44 | #include <machine/thunk.h> |
45 | | | 45 | |
46 | //#include <machine/ctlreg.h> | | 46 | //#include <machine/ctlreg.h> |
47 | //#include <machine/trap.h> | | 47 | //#include <machine/trap.h> |
48 | //#include <machine/instr.h> | | 48 | //#include <machine/instr.h> |
49 | //#include <machine/userret.h> | | 49 | //#include <machine/userret.h> |
50 | | | 50 | |
| | | 51 | extern int cpu_lwp_inkernel; |
51 | | | 52 | |
52 | /* forwards and externals */ | | 53 | /* forwards and externals */ |
53 | void setup_signal_handlers(void); | | 54 | void setup_signal_handlers(void); |
54 | static void mem_access_handler(int sig, siginfo_t *info, void *ctx); | | 55 | static void mem_access_handler(int sig, siginfo_t *info, void *ctx); |
55 | static void illegal_instruction_handler(int sig, siginfo_t *info, void *ctx); | | 56 | static void illegal_instruction_handler(int sig, siginfo_t *info, void *ctx); |
56 | extern int errno; | | 57 | extern int errno; |
57 | | | 58 | |
58 | bool pmap_fault(pmap_t pmap, vaddr_t va, vm_prot_t *atype); | | 59 | bool pmap_fault(pmap_t pmap, vaddr_t va, vm_prot_t *atype); |
59 | | | 60 | |
60 | static stack_t sigstk; | | 61 | static stack_t sigstk; |
61 | | | 62 | |
62 | void | | 63 | void |
63 | startlwp(void *arg) | | 64 | startlwp(void *arg) |
| @@ -107,26 +108,28 @@ mem_access_handler(int sig, siginfo_t *i | | | @@ -107,26 +108,28 @@ mem_access_handler(int sig, siginfo_t *i |
107 | static vaddr_t old_va, old_old_va = 0; | | 108 | static vaddr_t old_va, old_old_va = 0; |
108 | | | 109 | |
109 | struct proc *p; | | 110 | struct proc *p; |
110 | struct lwp *l; | | 111 | struct lwp *l; |
111 | struct pcb *pcb; | | 112 | struct pcb *pcb; |
112 | struct vmspace *vm; | | 113 | struct vmspace *vm; |
113 | struct vm_map *vm_map; | | 114 | struct vm_map *vm_map; |
114 | struct trapframe *tf; | | 115 | struct trapframe *tf; |
115 | vm_prot_t atype; | | 116 | vm_prot_t atype; |
116 | vaddr_t va; | | 117 | vaddr_t va; |
117 | void *onfault; | | 118 | void *onfault; |
118 | int kmem, lwp_errno, rv; | | 119 | int kmem, lwp_errno, rv; |
119 | | | 120 | |
| | | 121 | cpu_lwp_inkernel++; |
| | | 122 | |
120 | recurse++; | | 123 | recurse++; |
121 | if (recurse > 1) | | 124 | if (recurse > 1) |
122 | printf("enter trap recursion level %d\n", recurse); | | 125 | printf("enter trap recursion level %d\n", recurse); |
123 | if ((info->si_signo == SIGSEGV) || (info->si_signo == SIGBUS)) { | | 126 | if ((info->si_signo == SIGSEGV) || (info->si_signo == SIGBUS)) { |
124 | l = curlwp; | | 127 | l = curlwp; |
125 | p = l->l_proc; | | 128 | p = l->l_proc; |
126 | pcb = lwp_getpcb(l); | | 129 | pcb = lwp_getpcb(l); |
127 | onfault = pcb->pcb_onfault; | | 130 | onfault = pcb->pcb_onfault; |
128 | vm = p->p_vmspace; | | 131 | vm = p->p_vmspace; |
129 | | | 132 | |
130 | lwp_errno = pcb->pcb_errno = thunk_geterrno(); | | 133 | lwp_errno = pcb->pcb_errno = thunk_geterrno(); |
131 | #if 0 | | 134 | #if 0 |
132 | va = (vaddr_t) info->si_addr; | | 135 | va = (vaddr_t) info->si_addr; |
| @@ -219,37 +222,39 @@ mem_access_handler(int sig, siginfo_t *i | | | @@ -219,37 +222,39 @@ mem_access_handler(int sig, siginfo_t *i |
219 | recurse--; | | 222 | recurse--; |
220 | return; | | 223 | return; |
221 | } | | 224 | } |
222 | panic("should deliver a trap to the process"); | | 225 | panic("should deliver a trap to the process"); |
223 | /* XXX HOWTO see arm/arm/syscall.c illegal instruction signal */ | | 226 | /* XXX HOWTO see arm/arm/syscall.c illegal instruction signal */ |
224 | } | | 227 | } |
225 | | | 228 | |
226 | thunk_seterrno(lwp_errno); | | 229 | thunk_seterrno(lwp_errno); |
227 | pcb->pcb_errno = lwp_errno; | | 230 | pcb->pcb_errno = lwp_errno; |
228 | } | | 231 | } |
229 | if (recurse > 1) | | 232 | if (recurse > 1) |
230 | printf("leaving trap recursion level %d\n", recurse); | | 233 | printf("leaving trap recursion level %d\n", recurse); |
231 | recurse--; | | 234 | recurse--; |
| | | 235 | cpu_lwp_inkernel--; |
232 | } | | 236 | } |
233 | | | 237 | |
234 | static void | | 238 | static void |
235 | illegal_instruction_handler(int sig, siginfo_t *info, void *ctx) | | 239 | illegal_instruction_handler(int sig, siginfo_t *info, void *ctx) |
236 | { | | 240 | { |
237 | static volatile int recurse = 0; | | 241 | static volatile int recurse = 0; |
238 | struct proc *p; | | 242 | struct proc *p; |
239 | struct lwp *l; | | 243 | struct lwp *l; |
240 | struct pcb *pcb; | | 244 | struct pcb *pcb; |
241 | vaddr_t va; | | 245 | vaddr_t va; |
242 | | | 246 | |
| | | 247 | cpu_lwp_inkernel++; |
243 | recurse++; | | 248 | recurse++; |
244 | if (recurse > 1) | | 249 | if (recurse > 1) |
245 | printf("enter trap recursion level %d\n", recurse); | | 250 | printf("enter trap recursion level %d\n", recurse); |
246 | if (info->si_signo == SIGILL) { | | 251 | if (info->si_signo == SIGILL) { |
247 | l = curlwp; | | 252 | l = curlwp; |
248 | p = l->l_proc; | | 253 | p = l->l_proc; |
249 | pcb = lwp_getpcb(l); | | 254 | pcb = lwp_getpcb(l); |
250 | | | 255 | |
251 | #if 1 | | 256 | #if 1 |
252 | va = (vaddr_t) info->si_addr; | | 257 | va = (vaddr_t) info->si_addr; |
253 | printf("illegal instruction trap lwp = %p pid = %d lid = %d, va = %p\n", | | 258 | printf("illegal instruction trap lwp = %p pid = %d lid = %d, va = %p\n", |
254 | curlwp, | | 259 | curlwp, |
255 | curlwp->l_proc->p_pid, | | 260 | curlwp->l_proc->p_pid, |
| @@ -277,14 +282,15 @@ illegal_instruction_handler(int sig, sig | | | @@ -277,14 +282,15 @@ illegal_instruction_handler(int sig, sig |
277 | printf("\t\tCoprocessor error"); | | 282 | printf("\t\tCoprocessor error"); |
278 | if (info->si_code == ILL_BADSTK) | | 283 | if (info->si_code == ILL_BADSTK) |
279 | printf("\t\tInternal stack error"); | | 284 | printf("\t\tInternal stack error"); |
280 | printf("\tsi_addr = %p\n", info->si_addr); | | 285 | printf("\tsi_addr = %p\n", info->si_addr); |
281 | printf("\tsi_trap = %d\n", info->si_trap); | | 286 | printf("\tsi_trap = %d\n", info->si_trap); |
282 | #endif | | 287 | #endif |
283 | | | 288 | |
284 | if (recurse > 1) | | 289 | if (recurse > 1) |
285 | printf("leaving trap recursion level %d\n", recurse); | | 290 | printf("leaving trap recursion level %d\n", recurse); |
286 | recurse--; | | 291 | recurse--; |
287 | | | 292 | |
288 | panic("illegal instruction encountered\n"); | | 293 | panic("illegal instruction encountered\n"); |
289 | } | | 294 | } |
| | | 295 | cpu_lwp_inkernel--; |
290 | } | | 296 | } |