CVS commit: [netbsd-5-0] src/sys/arch/amd64/amd64

2012-06-15 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Fri Jun 15 09:20:48 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: trap.c

Log Message:
Fix build fallout from ticket #1772 for Xen kernels


To generate a diff of this commit:
cvs rdiff -u -r1.52.6.3 -r1.52.6.4 src/sys/arch/amd64/amd64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.52.6.3 src/sys/arch/amd64/amd64/trap.c:1.52.6.4
--- src/sys/arch/amd64/amd64/trap.c:1.52.6.3	Tue Jun 12 20:43:59 2012
+++ src/sys/arch/amd64/amd64/trap.c	Fri Jun 15 09:20:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.52.6.3 2012/06/12 20:43:59 riz Exp $	*/
+/*	$NetBSD: trap.c,v 1.52.6.4 2012/06/15 09:20:48 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52.6.3 2012/06/12 20:43:59 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52.6.4 2012/06/15 09:20:48 bouyer Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -183,7 +183,9 @@ trap(struct trapframe *frame)
 #if defined(COMPAT_10) || defined(COMPAT_IBCS2)
 	extern char IDTVEC(oosyscall)[];
 #endif
+#ifndef XEN
 	struct trapframe *vframe;
+#endif
 	void *onfault;
 	int error;
 	uint64_t cr2;



CVS commit: [netbsd-5-0] src/sys/arch/amd64

2012-06-12 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Jun 12 20:43:59 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: trap.c vector.S
src/sys/arch/amd64/include [netbsd-5-0]: frameasm.h

Log Message:
Pull up following revision(s) (requested by spz in ticket #1772):
sys/arch/amd64/amd64/trap.c: revision 1.71 via patch
sys/arch/amd64/amd64/vector.S: revision 1.41 via patch
sys/arch/amd64/include/frameasm.h: patch

Treat traps in kernel mode during the 'return to user' iret sequence
as user faults.
Based heavily in the i386 code with the correct opcode bytes inserted.
iret path tested, arranging for segment register errors is harder.
User %fs and %gs (32bit apps) are loaded much earlier and any errors
will generate kernel panics - there is probably code to try to stop
the invalid values being set.
If we get a fault setting the user %gs, or on a iret that is returning
to userspace, we must do a 'swapgs' to reload the kernel %gs_base.
Also save the %ds, %es, %fs, %gs selector values in the frame so
they can be restored if we finally return to user (probably after
an application SIGSEGV handler has fixed the error).
Without this any such fault leaves the kernel running with the wrong
%gs offset and it will most likely fault again early in trap().
Repeats until the stack tramples on something important.
iret change works, invalid %gs is a little harder to arrange.


To generate a diff of this commit:
cvs rdiff -u -r1.52.6.2 -r1.52.6.3 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.28.6.1 -r1.28.6.1.2.1 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.12 -r1.12.14.1 src/sys/arch/amd64/include/frameasm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.52.6.2 src/sys/arch/amd64/amd64/trap.c:1.52.6.3
--- src/sys/arch/amd64/amd64/trap.c:1.52.6.2	Fri Aug 14 21:32:18 2009
+++ src/sys/arch/amd64/amd64/trap.c	Tue Jun 12 20:43:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.52.6.2 2009/08/14 21:32:18 snj Exp $	*/
+/*	$NetBSD: trap.c,v 1.52.6.3 2012/06/12 20:43:59 riz Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52.6.2 2009/08/14 21:32:18 snj Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52.6.3 2012/06/12 20:43:59 riz Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -124,6 +124,7 @@ __KERNEL_RCSID(0, $NetBSD: trap.c,v 1.5
 #endif
 
 void trap(struct trapframe *);
+void trap_return_fault_return(struct trapframe *) __dead;
 
 const char *trap_type[] = {
 	privileged instruction fault,		/*  0 T_PRIVINFLT */
@@ -178,16 +179,11 @@ trap(struct trapframe *frame)
 	struct proc *p;
 	int type = (int)frame-tf_trapno;
 	struct pcb *pcb;
-	extern char fusuintrfailure[], kcopy_fault[],
-		resume_iret[];
+	extern char fusuintrfailure[], kcopy_fault[];
 #if defined(COMPAT_10) || defined(COMPAT_IBCS2)
 	extern char IDTVEC(oosyscall)[];
 #endif
-#if 0
-	extern char resume_pop_ds[], resume_pop_es[];
-#endif
 	struct trapframe *vframe;
-	void *resume;
 	void *onfault;
 	int error;
 	uint64_t cr2;
@@ -274,50 +270,78 @@ copyfault:
 
 		/*
 		 * Check for failure during return to user mode.
+		 * This can happen loading invalid values into the segment
+		 * registers, or during the 'iret' itself.
 		 *
-		 * XXXfvdl check for rex prefix?
-		 *
-		 * We do this by looking at the instruction we faulted on.  The
-		 * specific instructions we recognize only happen when
+		 * We do this by looking at the instruction we faulted on.
+		 * The specific instructions we recognize only happen when
 		 * returning from a trap, syscall, or interrupt.
-		 *
-		 * XXX
-		 * The heuristic used here will currently fail for the case of
-		 * one of the 2 pop instructions faulting when returning from a
-		 * a fast interrupt.  This should not be possible.  It can be
-		 * fixed by rearranging the trap frame so that the stack format
-		 * at this point is the same as on exit from a `slow'
-		 * interrupt.
 		 */
-		switch (*(u_char *)frame-tf_rip) {
-		case 0xcf:	/* iret */
-			vframe = (void *)((uint64_t)frame-tf_rsp - 44);
-			resume = resume_iret;
-			break;
-/*
- * XXXfvdl these are illegal in long mode (not in compat mode, though)
- * and we do not take back the descriptors from the signal context anyway,
- * but may do so later for USER_LDT, in which case we need to intercept
- * other instructions (movl %eax, %Xs).
- */
-#if 0
-		case 0x1f:	/* popl %ds */
-			vframe = (void *)((uint64_t)frame-tf_rsp - 4);
-			resume = resume_pop_ds;
-			break;
-		case 0x07:	/* popl %es */
-			vframe = (void *)((uint64_t)frame-tf_rsp - 0);
-			resume = resume_pop_es;
+
+kernelfault:
+#ifdef XEN
+		/*
+		 * XXX: there has to be an equivalent 'problem'
+		 * but I (dsl) don't know exactly what happens!
+		 * For now panic the 

CVS commit: [netbsd-5-0] src/sys/arch/amd64/amd64

2012-06-12 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Jun 12 23:17:58 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: machdep.c netbsd32_machdep.c

Log Message:
Pull up following revision(s) (requested by spz in ticket #1773):
sys/arch/amd64/amd64/machdep.c: revision 1.184
sys/arch/amd64/amd64/netbsd32_machdep.c: revision 1.77
If the user process provided a bogus signal handler address, kill it
now instead of trying to jump to the bogus address.


To generate a diff of this commit:
cvs rdiff -u -r1.102.4.10.2.1 -r1.102.4.10.2.2 \
src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.55.6.2 -r1.55.6.3 \
src/sys/arch/amd64/amd64/netbsd32_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.102.4.10.2.1 src/sys/arch/amd64/amd64/machdep.c:1.102.4.10.2.2
--- src/sys/arch/amd64/amd64/machdep.c:1.102.4.10.2.1	Fri Apr 23 04:17:29 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Jun 12 23:17:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.102.4.10.2.1 2010/04/23 04:17:29 snj Exp $	*/
+/*	$NetBSD: machdep.c,v 1.102.4.10.2.2 2012/06/12 23:17:57 riz Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -112,7 +112,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.102.4.10.2.1 2010/04/23 04:17:29 snj Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.102.4.10.2.2 2012/06/12 23:17:57 riz Exp $);
 
 /* #define XENDEBUG_LOW  */
 
@@ -628,6 +628,16 @@ sendsig(const ksiginfo_t *ksi, const sig
 	/* Remember that we're now on the signal stack. */
 	if (onstack)
 		l-l_sigstk.ss_flags |= SS_ONSTACK;
+
+	if ((vaddr_t)catcher = VM_MAXUSER_ADDRESS) {
+		/* 
+		 * process has given an invalid address for the
+		 * handler. Stop it, but do not do it before so
+		 * we can return the right info to userland (or in core dump)
+		 */
+		sigexit(l, SIGILL);
+		/* NOTREACHED */
+	}
 }
 
 void 

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.2 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.3
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.2	Tue Sep  7 19:38:44 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue Jun 12 23:17:58 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.55.6.2 2010/09/07 19:38:44 bouyer Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.55.6.3 2012/06/12 23:17:58 riz Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: netbsd32_machdep.c,v 1.55.6.2 2010/09/07 19:38:44 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: netbsd32_machdep.c,v 1.55.6.3 2012/06/12 23:17:58 riz Exp $);
 
 #include opt_compat_netbsd.h
 #include opt_coredump.h
@@ -275,6 +275,16 @@ netbsd32_sendsig_sigcontext(const ksigin
 	/* Remember that we're now on the signal stack. */
 	if (onstack)
 		l-l_sigstk.ss_flags |= SS_ONSTACK;
+
+	if ((vaddr_t)catcher = VM_MAXUSER_ADDRESS32) {
+		/*
+		 * process has given an invalid address for the
+		 * handler. Stop it, but do not do it before so
+		 * we can return the right info to userland (or in core dump)
+		 */
+		sigexit(l, SIGILL);
+		/* NOTREACHED */
+	}
 }
 #endif
 
@@ -360,6 +370,16 @@ netbsd32_sendsig_siginfo(const ksiginfo_
 	/* Remember that we're now on the signal stack. */
 	if (onstack)
 		l-l_sigstk.ss_flags |= SS_ONSTACK;
+
+	if ((vaddr_t)catcher = VM_MAXUSER_ADDRESS32) {
+		/*
+		 * process has given an invalid address for the
+		 * handler. Stop it, but do not do it before so
+		 * we can return the right info to userland (or in core dump)
+		 */
+		sigexit(l, SIGILL);
+		/* NOTREACHED */
+	}
 }
 
 void



CVS commit: [netbsd-5-0] src/sys/arch/amd64

2010-09-07 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Sep  7 19:38:45 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: netbsd32_machdep.c
src/sys/arch/amd64/include [netbsd-5-0]: segments.h

Log Message:
Pull up following revision(s) (requested by chs in ticket #1449):
sys/arch/amd64/amd64/netbsd32_machdep.c: revisions 1.66, 1.67
sys/arch/amd64/include/segments.h: revision 1.21
in check_mcontext32(), accept the LDT selector for 32-bit user code
as well as the GDT selector.  fixes PR 43835.
accept the LDT selector in check_sigcontext32() too.


To generate a diff of this commit:
cvs rdiff -u -r1.55.6.1 -r1.55.6.2 \
src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.19 -r1.19.10.1 src/sys/arch/amd64/include/segments.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.1 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.2
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.55.6.1	Fri Jul 16 18:43:58 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue Sep  7 19:38:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.55.6.1 2010/07/16 18:43:58 riz Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.55.6.2 2010/09/07 19:38:44 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: netbsd32_machdep.c,v 1.55.6.1 2010/07/16 18:43:58 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: netbsd32_machdep.c,v 1.55.6.2 2010/09/07 19:38:44 bouyer Exp $);
 
 #include opt_compat_netbsd.h
 #include opt_coredump.h
@@ -938,7 +938,7 @@
 {
 
 	if (((scp-sc_eflags ^ tf-tf_rflags)  PSL_USERSTATIC) != 0 ||
-	scp-sc_cs != GSEL(GUCODE32_SEL, SEL_UPL))
+	!VALID_USER_CSEL32(scp-sc_cs))
 		return EINVAL;
 	if (scp-sc_fs != 0  !VALID_USER_DSEL32(scp-sc_fs))
 		return EINVAL;
@@ -961,7 +961,7 @@
 	gr = mcp-__gregs;
 
 	if (((gr[_REG32_EFL] ^ tf-tf_rflags)  PSL_USERSTATIC) != 0 ||
-	gr[_REG32_CS] != GSEL(GUCODE32_SEL, SEL_UPL))
+	!VALID_USER_CSEL32(gr[_REG32_CS]))
 		return EINVAL;
 	if (gr[_REG32_FS] != 0  !VALID_USER_DSEL32(gr[_REG32_FS]))
 		return EINVAL;

Index: src/sys/arch/amd64/include/segments.h
diff -u src/sys/arch/amd64/include/segments.h:1.19 src/sys/arch/amd64/include/segments.h:1.19.10.1
--- src/sys/arch/amd64/include/segments.h:1.19	Sun Oct 26 00:08:15 2008
+++ src/sys/arch/amd64/include/segments.h	Tue Sep  7 19:38:45 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: segments.h,v 1.19 2008/10/26 00:08:15 mrg Exp $	*/
+/*	$NetBSD: segments.h,v 1.19.10.1 2010/09/07 19:38:45 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -382,10 +382,8 @@
 #define VALID_USER_DSEL32(s) \
 (((s)  0x) == GSEL(GUDATA32_SEL, SEL_UPL) || \
  ((s)  0x) == LSEL(LUDATA32_SEL, SEL_UPL))
-#if 0 /* not used */
 #define VALID_USER_CSEL32(s) \
 ((s) == GSEL(GUCODE32_SEL, SEL_UPL) || (s) == LSEL(LUCODE32_SEL, SEL_UPL))
-#endif
 
 #define VALID_USER_CSEL(s) \
 ((s) == GSEL(GUCODE_SEL, SEL_UPL) || (s) == LSEL(LUCODE_SEL, SEL_UPL))



CVS commit: [netbsd-5-0] src/sys/arch/amd64/amd64

2010-04-22 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Apr 22 19:39:45 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: locore.S

Log Message:
Pull up following revision(s) (requested by jym in ticket #1376):
sys/arch/amd64/amd64/locore.S: revision 1.56
When kernel remaps to high memory in amd64 locore, the GDT used before
becomes invalid. As such, split it in two parts, one for use when system
boots in low memory, and one for use when it jumps to high memory.


To generate a diff of this commit:
cvs rdiff -u -r1.47.8.2 -r1.47.8.2.2.1 src/sys/arch/amd64/amd64/locore.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.47.8.2 src/sys/arch/amd64/amd64/locore.S:1.47.8.2.2.1
--- src/sys/arch/amd64/amd64/locore.S:1.47.8.2	Mon Feb  2 03:24:05 2009
+++ src/sys/arch/amd64/amd64/locore.S	Thu Apr 22 19:39:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.47.8.2 2009/02/02 03:24:05 snj Exp $	*/
+/*	$NetBSD: locore.S,v 1.47.8.2.2.1 2010/04/22 19:39:44 snj Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -274,13 +274,25 @@
 #define	RELOC(x)	_RELOC(_C_LABEL(x))
 
 #ifndef XEN
-	.globl	gdt64
+	.globl	gdt64_lo
+	.globl	gdt64_hi
 
-gdt64:
-	.word	gdt64_end-gdt64_start
+#define GDT64_LIMIT gdt64_end-gdt64_start-1
+
+/* Temporary gdt64, with base address in low memory */
+gdt64_lo:
+	.word	GDT64_LIMIT
 	.quad	_RELOC(gdt64_start)
 .align 64
 
+/* Temporary gdt64, with base address in high memory */
+gdt64_hi:
+	.word	GDT64_LIMIT
+	.quad	gdt64_start
+.align 64
+
+#undef GDT64_LIMIT
+
 gdt64_start:
 	.quad 0x	/* always empty */
 	.quad 0x00af9a00	/* kernel CS */
@@ -643,7 +655,7 @@
 	 * in it to do that.
 	 */
 
-	movl	$RELOC(gdt64),%eax
+	movl	$RELOC(gdt64_lo),%eax
 	lgdt	(%eax)
 	movl	$RELOC(farjmp64),%eax
 	ljmp	*(%eax)
@@ -659,9 +671,17 @@
 	 */
 	movabsq	$longmode_hi,%rax
 	jmp	*%rax
+
 longmode_hi:
+
+	/*
+	 * We left the identity mapped area. Base address of
+	 * the temporary gdt64 should now be in high memory.
+	 */
+	movq	$RELOC(gdt64_hi),%rax
+	lgdt	(%rax)
+
 	/*
-	 * We have arrived.
 	 * There's no need anymore for the identity mapping in low
 	 * memory, remove it.
 	 */



CVS commit: [netbsd-5-0] src/sys/arch/amd64/include

2009-11-13 Thread Stephen Borrill
Module Name:src
Committed By:   sborrill
Date:   Fri Nov 13 20:42:49 UTC 2009

Added Files:
src/sys/arch/amd64/include [netbsd-5-0]: Makefile.inc

Log Message:
Pull up the following revisions(s) (requested by cube in ticket #1140):
sys/arch/amd64/include/Makefile.inc:revision 1.1

Build kernel modules with -mno-red-zone like kernel is build. This fixes
frequent panics in amd64 zfs module, plus other reported problems.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1.4.2 src/sys/arch/amd64/include/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/arch/amd64/include/Makefile.inc
diff -u /dev/null src/sys/arch/amd64/include/Makefile.inc:1.1.4.2
--- /dev/null	Fri Nov 13 20:42:49 2009
+++ src/sys/arch/amd64/include/Makefile.inc	Fri Nov 13 20:42:49 2009
@@ -0,0 +1,3 @@
+# $NetBSD: Makefile.inc,v 1.1.4.2 2009/11/13 20:42:49 sborrill Exp $
+
+CFLAGS+=-mno-red-zone



CVS commit: [netbsd-5-0] src/sys/arch/amd64/amd64

2009-07-20 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Jul 21 00:37:30 UTC 2009

Modified Files:
src/sys/arch/amd64/amd64 [netbsd-5-0]: trap.c

Log Message:
Pull up following revision(s) (requested by rmind in ticket #865):
sys/arch/amd64/amd64/trap.c: revisions 1.56, 1.57
handle protection fault properly.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.52.6.1 src/sys/arch/amd64/amd64/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.52 src/sys/arch/amd64/amd64/trap.c:1.52.6.1
--- src/sys/arch/amd64/amd64/trap.c:1.52	Wed Oct 15 06:51:17 2008
+++ src/sys/arch/amd64/amd64/trap.c	Tue Jul 21 00:37:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.52 2008/10/15 06:51:17 wrstuden Exp $	*/
+/*	$NetBSD: trap.c,v 1.52.6.1 2009/07/21 00:37:29 snj Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52 2008/10/15 06:51:17 wrstuden Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.52.6.1 2009/07/21 00:37:29 snj Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -325,26 +325,35 @@
 	case T_STKFLT|T_USER:
 	case T_ALIGNFLT|T_USER:
 #ifdef TRAP_SIGDEBUG
-		printf(pid %d (%s): BUS (%x) at rip %lx addr %lx\n,
+		printf(pid %d (%s): BUS/SEGV (%x) at rip %lx addr %lx\n,
 		p-p_pid, p-p_comm, type, frame-tf_rip, rcr2());
 		frame_dump(frame);
 #endif
 		KSI_INIT_TRAP(ksi);
-		ksi.ksi_signo = SIGBUS;
 		ksi.ksi_trap = type  ~T_USER;
 		ksi.ksi_addr = (void *)rcr2();
 		switch (type) {
 		case T_SEGNPFLT|T_USER:
 		case T_STKFLT|T_USER:
+			ksi.ksi_signo = SIGBUS;
 			ksi.ksi_code = BUS_ADRERR;
 			break;
 		case T_TSSFLT|T_USER:
+			ksi.ksi_signo = SIGBUS;
 			ksi.ksi_code = BUS_OBJERR;
 			break;
 		case T_ALIGNFLT|T_USER:
+			ksi.ksi_signo = SIGBUS;
 			ksi.ksi_code = BUS_ADRALN;
 			break;
+		case T_PROTFLT|T_USER:
+			ksi.ksi_signo = SIGSEGV;
+			ksi.ksi_code = SEGV_ACCERR;
+			break;
 		default:
+#ifdef DIAGNOSTIC
+			panic(unhandled type %x\n, type);
+#endif
 			break;
 		}
 		goto trapsignal;
@@ -368,6 +377,9 @@
 			ksi.ksi_code = ILL_COPROC;
 			break;
 		default:
+#ifdef DIAGNOSTIC
+			panic(unhandled type %x\n, type);
+#endif
 			break;
 		}
 		goto trapsignal;
@@ -414,6 +426,9 @@
 			ksi.ksi_code = FPE_FLTDIV;
 			break;
 		default:
+#ifdef DIAGNOSTIC
+			panic(unhandled type %x\n, type);
+#endif
 			break;
 		}
 		goto trapsignal;