| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | | | 1 | |
2 | /* $NetBSD: trap.c,v 1.294 2018/05/16 08:16:36 maxv Exp $ */ | | 2 | /* $NetBSD: trap.c,v 1.295 2018/05/16 16:33:23 maxv Exp $ */ |
3 | | | 3 | |
4 | /*- | | 4 | /*- |
5 | * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. | | 5 | * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Charles M. Hannum. | | 9 | * by Charles M. Hannum. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
| @@ -59,27 +59,27 @@ | | | @@ -59,27 +59,27 @@ |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
62 | * SUCH DAMAGE. | | 62 | * SUCH DAMAGE. |
63 | * | | 63 | * |
64 | * @(#)trap.c 7.4 (Berkeley) 5/13/91 | | 64 | * @(#)trap.c 7.4 (Berkeley) 5/13/91 |
65 | */ | | 65 | */ |
66 | | | 66 | |
67 | /* | | 67 | /* |
68 | * 386 Trap and System call handling | | 68 | * 386 Trap and System call handling |
69 | */ | | 69 | */ |
70 | | | 70 | |
71 | #include <sys/cdefs.h> | | 71 | #include <sys/cdefs.h> |
72 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.294 2018/05/16 08:16:36 maxv Exp $"); | | 72 | __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.295 2018/05/16 16:33:23 maxv Exp $"); |
73 | | | 73 | |
74 | #include "opt_ddb.h" | | 74 | #include "opt_ddb.h" |
75 | #include "opt_kgdb.h" | | 75 | #include "opt_kgdb.h" |
76 | #include "opt_lockdebug.h" | | 76 | #include "opt_lockdebug.h" |
77 | #include "opt_multiprocessor.h" | | 77 | #include "opt_multiprocessor.h" |
78 | #include "opt_xen.h" | | 78 | #include "opt_xen.h" |
79 | #include "opt_dtrace.h" | | 79 | #include "opt_dtrace.h" |
80 | #include "opt_compat_netbsd.h" | | 80 | #include "opt_compat_netbsd.h" |
81 | | | 81 | |
82 | #include <sys/param.h> | | 82 | #include <sys/param.h> |
83 | #include <sys/systm.h> | | 83 | #include <sys/systm.h> |
84 | #include <sys/proc.h> | | 84 | #include <sys/proc.h> |
85 | #include <sys/acct.h> | | 85 | #include <sys/acct.h> |
| @@ -118,27 +118,29 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2 | | | @@ -118,27 +118,29 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2 |
118 | /* | | 118 | /* |
119 | * This is a hook which is initialized by the dtrace module | | 119 | * This is a hook which is initialized by the dtrace module |
120 | * to handle traps which might occur during DTrace probe | | 120 | * to handle traps which might occur during DTrace probe |
121 | * execution. | | 121 | * execution. |
122 | */ | | 122 | */ |
123 | dtrace_trap_func_t dtrace_trap_func = NULL; | | 123 | dtrace_trap_func_t dtrace_trap_func = NULL; |
124 | | | 124 | |
125 | dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL; | | 125 | dtrace_doubletrap_func_t dtrace_doubletrap_func = NULL; |
126 | #endif | | 126 | #endif |
127 | | | 127 | |
128 | void trap(struct trapframe *); | | 128 | void trap(struct trapframe *); |
129 | void trap_tss(struct i386tss *, int, int); | | 129 | void trap_tss(struct i386tss *, int, int); |
130 | void trap_return_fault_return(struct trapframe *) __dead; | | 130 | void trap_return_fault_return(struct trapframe *) __dead; |
| | | 131 | #ifndef XEN |
131 | int ss_shadow(struct trapframe *tf); | | 132 | int ss_shadow(struct trapframe *tf); |
| | | 133 | #endif |
132 | | | 134 | |
133 | const char * const trap_type[] = { | | 135 | const char * const trap_type[] = { |
134 | "privileged instruction fault", /* 0 T_PRIVINFLT */ | | 136 | "privileged instruction fault", /* 0 T_PRIVINFLT */ |
135 | "breakpoint trap", /* 1 T_BPTFLT */ | | 137 | "breakpoint trap", /* 1 T_BPTFLT */ |
136 | "arithmetic trap", /* 2 T_ARITHTRAP */ | | 138 | "arithmetic trap", /* 2 T_ARITHTRAP */ |
137 | "asynchronous system trap", /* 3 T_ASTFLT */ | | 139 | "asynchronous system trap", /* 3 T_ASTFLT */ |
138 | "protection fault", /* 4 T_PROTFLT */ | | 140 | "protection fault", /* 4 T_PROTFLT */ |
139 | "trace trap", /* 5 T_TRCTRAP */ | | 141 | "trace trap", /* 5 T_TRCTRAP */ |
140 | "page fault", /* 6 T_PAGEFLT */ | | 142 | "page fault", /* 6 T_PAGEFLT */ |
141 | "alignment fault", /* 7 T_ALIGNFLT */ | | 143 | "alignment fault", /* 7 T_ALIGNFLT */ |
142 | "integer divide fault", /* 8 T_DIVIDE */ | | 144 | "integer divide fault", /* 8 T_DIVIDE */ |
143 | "non-maskable interrupt", /* 9 T_NMI */ | | 145 | "non-maskable interrupt", /* 9 T_NMI */ |
144 | "overflow trap", /* 10 T_OFLOW */ | | 146 | "overflow trap", /* 10 T_OFLOW */ |
| @@ -227,44 +229,46 @@ trap_print(const struct trapframe *frame | | | @@ -227,44 +229,46 @@ trap_print(const struct trapframe *frame |
227 | printf("unknown trap %d", type); | | 229 | printf("unknown trap %d", type); |
228 | } | | 230 | } |
229 | printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor"); | | 231 | printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor"); |
230 | | | 232 | |
231 | printf("trap type %d code %#x eip %#x cs %#x eflags %#x cr2 %#lx " | | 233 | printf("trap type %d code %#x eip %#x cs %#x eflags %#x cr2 %#lx " |
232 | "ilevel %#x esp %#x\n", | | 234 | "ilevel %#x esp %#x\n", |
233 | type, frame->tf_err, frame->tf_eip, frame->tf_cs, frame->tf_eflags, | | 235 | type, frame->tf_err, frame->tf_eip, frame->tf_cs, frame->tf_eflags, |
234 | (long)rcr2(), curcpu()->ci_ilevel, frame->tf_esp); | | 236 | (long)rcr2(), curcpu()->ci_ilevel, frame->tf_esp); |
235 | | | 237 | |
236 | printf("curlwp %p pid %d lid %d lowest kstack %p\n", | | 238 | printf("curlwp %p pid %d lid %d lowest kstack %p\n", |
237 | l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l)); | | 239 | l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l)); |
238 | } | | 240 | } |
239 | | | 241 | |
| | | 242 | #ifndef XEN |
240 | int | | 243 | int |
241 | ss_shadow(struct trapframe *tf) | | 244 | ss_shadow(struct trapframe *tf) |
242 | { | | 245 | { |
243 | struct gate_descriptor *gd; | | 246 | struct gate_descriptor *gd; |
244 | uintptr_t eip, func; | | 247 | uintptr_t eip, func; |
245 | size_t i; | | 248 | size_t i; |
246 | | | 249 | |
247 | eip = tf->tf_eip; | | 250 | eip = tf->tf_eip; |
248 | | | 251 | |
249 | for (i = 0; i < 256; i++) { | | 252 | for (i = 0; i < 256; i++) { |
250 | gd = &idt[i]; | | 253 | gd = &idt[i]; |
251 | func = (gd->gd_hioffset << 16) | gd->gd_looffset; | | 254 | func = (gd->gd_hioffset << 16) | gd->gd_looffset; |
252 | if (eip == func) | | 255 | if (eip == func) |
253 | return 1; | | 256 | return 1; |
254 | } | | 257 | } |
255 | | | 258 | |
256 | return 0; | | 259 | return 0; |
257 | } | | 260 | } |
| | | 261 | #endif |
258 | | | 262 | |
259 | /* | | 263 | /* |
260 | * trap(frame): exception, fault, and trap interface to BSD kernel. | | 264 | * trap(frame): exception, fault, and trap interface to BSD kernel. |
261 | * | | 265 | * |
262 | * This common code is called from assembly language IDT gate entry routines | | 266 | * This common code is called from assembly language IDT gate entry routines |
263 | * that prepare a suitable stack frame, and restore this frame after the | | 267 | * that prepare a suitable stack frame, and restore this frame after the |
264 | * exception has been processed. Note that the effect is as if the arguments | | 268 | * exception has been processed. Note that the effect is as if the arguments |
265 | * were passed call by reference. | | 269 | * were passed call by reference. |
266 | */ | | 270 | */ |
267 | void | | 271 | void |
268 | trap(struct trapframe *frame) | | 272 | trap(struct trapframe *frame) |
269 | { | | 273 | { |
270 | struct lwp *l = curlwp; | | 274 | struct lwp *l = curlwp; |