CVS commit: src/sys/arch/amd64/amd64

2015-11-28 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Nov 28 15:06:55 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
If the kernel jumps to NULL, print where it came from instead of trying
to dereference and faulting again.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/arch/amd64/amd64/trap.c:1.82
--- src/sys/arch/amd64/amd64/trap.c:1.81	Sun Nov 22 13:41:24 2015
+++ src/sys/arch/amd64/amd64/trap.c	Sat Nov 28 15:06:55 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.81 2015/11/22 13:41:24 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.82 2015/11/28 15:06:55 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.81 2015/11/22 13:41:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.82 2015/11/28 15:06:55 dholland Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -342,6 +342,16 @@ kernelfault:
 		/* Get %rsp value before fault - there may be a pad word
 		 * below the trap frame. */
 		vframe = (void *)frame->tf_rsp;
+		if (frame->tf_rip == 0) {
+			/*
+			 * Assume that if we jumped to null we
+			 * probably did it via a null function
+			 * pointer, so print the return address.
+			 */
+			printf("kernel jumped to null; return addr was %p\n",
+			   *(void **)frame->tf_rsp);
+			goto we_re_toast;
+		}
 		switch (*(uint16_t *)frame->tf_rip) {
 		case 0xcf48:	/* iretq */
 			/*



CVS commit: src/sys/arch/amd64/amd64

2015-11-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Nov 25 16:00:10 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Cosmetic changes.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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.82 src/sys/arch/amd64/amd64/locore.S:1.83
--- src/sys/arch/amd64/amd64/locore.S:1.82	Sun Nov 22 14:06:08 2015
+++ src/sys/arch/amd64/amd64/locore.S	Wed Nov 25 16:00:09 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.82 2015/11/22 14:06:08 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.83 2015/11/25 16:00:09 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -191,6 +191,43 @@
 #define	_RELOC(x)	((x) - KERNBASE)
 #define	RELOC(x)	_RELOC(_C_LABEL(x))
 
+#if L2_SLOT_KERNBASE > 0
+#define TABLE_L2_ENTRIES (2 * (NKL2_KIMG_ENTRIES + 1))
+#else
+#define TABLE_L2_ENTRIES (NKL2_KIMG_ENTRIES + 1)
+#endif
+
+#if L3_SLOT_KERNBASE > 0
+#define TABLE_L3_ENTRIES (2 * NKL3_KIMG_ENTRIES)
+#else
+#define TABLE_L3_ENTRIES NKL3_KIMG_ENTRIES
+#endif
+
+#define PROC0_PML4_OFF	0
+#define PROC0_STK_OFF	(PROC0_PML4_OFF + PAGE_SIZE)
+#define PROC0_PTP3_OFF	(PROC0_STK_OFF + UPAGES * PAGE_SIZE)
+#define PROC0_PTP2_OFF	(PROC0_PTP3_OFF + NKL4_KIMG_ENTRIES * PAGE_SIZE)
+#define PROC0_PTP1_OFF	(PROC0_PTP2_OFF + TABLE_L3_ENTRIES * PAGE_SIZE)
+#define TABLESIZE \
+  ((NKL4_KIMG_ENTRIES + TABLE_L3_ENTRIES + TABLE_L2_ENTRIES + 1 + UPAGES) \
+* PAGE_SIZE)
+
+/*
+ * fillkpt - Fill in a kernel page table
+ *	eax = pte (page frame | control | status)
+ *	ebx = page table address
+ *	ecx = number of pages to map
+ *
+ * Each entry is 8 (PDE_SIZE) bytes long: we must set the 4 upper bytes to 0.
+ */
+#define fillkpt	\
+1:	movl	%eax,(%ebx)		; 	/* store phys addr */	\
+	movl	$0,(PDE_SIZE-4)(%ebx)	; 	/* upper 32 bits 0 */	\
+	addl	$PDE_SIZE,%ebx		; 	/* next PTE/PDE */	\
+	addl	$PAGE_SIZE,%eax		; 	/* next phys page */	\
+	loop	1b			;
+
+
 #ifdef XEN
 
 /*
@@ -358,7 +395,7 @@ ENTRY(start)
 
 	/*
 	 * Load parameters from the stack (32 bits):   
-	 * boothowto, [bootdev], bootinfo, esym, basemem, extmem
+	 * boothowto, [bootdev], bootinfo, esym, biosbasemem, biosextmem
 	 * We are not interested in 'bootdev'.
 	 */
 
@@ -443,24 +480,29 @@ bootinfo_finished:
 	movl	%eax,(%ebp)
 	movl	$KERNBASE_HI,4(%ebp)
 
+	/* Load 'biosextmem' */
 	movl	$RELOC(biosextmem),%ebp
 	movl	(%ebp),%eax
-	testl	%eax,%eax
-	jnz	1f
+	testl	%eax,%eax		/* already set? */
+	jnz	biosextmem_finished
 
 	movl	20(%esp),%eax
 	movl	%eax,(%ebp)
 
-1:
+biosextmem_finished:
+	/* Load 'biosbasemem' */
 	movl	$RELOC(biosbasemem),%ebp
 	movl	(%ebp),%eax
-	testl	%eax,%eax
-	jnz	1f
+	testl	%eax,%eax		/* already set? */
+	jnz	biosbasemem_finished
+
 	movl	24(%esp),%eax
 	movl	%eax,(%ebp)
-1:
 
-	/* First, reset the PSL. */
+biosbasemem_finished:
+	/*
+	 * Done with the parameters. First, reset the PSL.
+	 */
 	pushl	$PSL_MBO
 	popfl
 
@@ -489,45 +531,9 @@ bootinfo_finished:
  *0  1   2  3
  */
 
-#if L2_SLOT_KERNBASE > 0
-#define TABLE_L2_ENTRIES (2 * (NKL2_KIMG_ENTRIES + 1))
-#else
-#define TABLE_L2_ENTRIES (NKL2_KIMG_ENTRIES + 1)
-#endif
-
-#if L3_SLOT_KERNBASE > 0
-#define TABLE_L3_ENTRIES (2 * NKL3_KIMG_ENTRIES)
-#else
-#define TABLE_L3_ENTRIES NKL3_KIMG_ENTRIES
-#endif
-
-#define PROC0_PML4_OFF	0
-#define PROC0_STK_OFF	(PROC0_PML4_OFF + PAGE_SIZE)
-#define PROC0_PTP3_OFF	(PROC0_STK_OFF + UPAGES * PAGE_SIZE)
-#define PROC0_PTP2_OFF	(PROC0_PTP3_OFF + NKL4_KIMG_ENTRIES * PAGE_SIZE)
-#define PROC0_PTP1_OFF	(PROC0_PTP2_OFF + TABLE_L3_ENTRIES * PAGE_SIZE)
-#define TABLESIZE \
-  ((NKL4_KIMG_ENTRIES + TABLE_L3_ENTRIES + TABLE_L2_ENTRIES + 1 + UPAGES) \
-* PAGE_SIZE)
-
-/*
- * fillkpt - Fill in a kernel page table
- *	eax = pte (page frame | control | status)
- *	ebx = page table address
- *	ecx = number of pages to map
- *
- * Each entry is 8 (PDE_SIZE) bytes long: we must set the 4 upper bytes to 0.
- */
-
-#define fillkpt	\
-1:	movl	%eax,(%ebx)		; 	/* store phys addr */	\
-	movl	$0,(PDE_SIZE-4)(%ebx)	; 	/* upper 32 bits 0 */	\
-	addl	$PDE_SIZE,%ebx		; 	/* next PTE/PDE */	\
-	addl	$PAGE_SIZE,%eax		; 	/* next phys page */	\
-	loop	1b			;
-
 	/* Find end of kernel image. */
 	movl	$RELOC(end),%edi
+
 #if (NKSYMS || defined(DDB) || defined(MODULAR)) && !defined(makeoptions_COPY_SYMTAB)
 	/* Save the symbols (if loaded). */
 	movl	RELOC(esym),%eax
@@ -551,17 +557,18 @@ bootinfo_finished:
 	andl	$~PGOFSET,%esi
 	movl	%esi,%edi
 
+	/* Clear the tables */
 	xorl	%eax,%eax
 	cld
 	movl	$TABLESIZE,%ecx
 	shrl	$2,%ecx
 	rep
-	stosl
+	stosl/* copy eax -> edi */
 
 /*
  * Build initial page tables.
  */
-	leal	(PROC0_PTP1_OFF)(%esi), %ebx
+	leal	(PROC0_PTP1_OFF)(%esi),%ebx
 
 	/* Skip the first MB */
 	movl	$(KERNTEXTOFF_LO - KERNBASE_LO),%eax
@@ -570,9 +577,9 @@ bootinfo_finish

CVS commit: src/sys/arch/amd64/amd64

2015-11-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Nov 22 14:06:08 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Remove cpu_vendorname (unused). It is retrieved later in identcpu.c.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/arch/amd64/amd64/locore.S:1.82
--- src/sys/arch/amd64/amd64/locore.S:1.81	Sun Nov 22 10:18:59 2015
+++ src/sys/arch/amd64/amd64/locore.S	Sun Nov 22 14:06:08 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.81 2015/11/22 10:18:59 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.82 2015/11/22 14:06:08 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -247,7 +247,6 @@ _C_LABEL(lapic_isr):
 END(lapic_isr)
 #endif
 
-	.globl	_C_LABEL(cpu_vendorname)
 	.globl	_C_LABEL(cpuid_level)
 	.globl	_C_LABEL(esym)
 	.globl	_C_LABEL(eblob)
@@ -267,10 +266,6 @@ END(cputype)
 LABEL(cpuid_level)	.long	-1	# max. level accepted by 'cpuid'
 	#   instruction
 END(cpuid_level)
-	.type	_C_LABEL(cpu_vendorname), @object
-LABEL(cpu_vendorname)	.space	16	# vendor string returned by `cpuid'
-	#   instruction
-END(cpu_vendorname)
 	.type	_C_LABEL(esym), @object
 LABEL(esym)		.quad	0	# ptr to end of syms
 END(esym)
@@ -472,11 +467,6 @@ bootinfo_finished:
 	xorl	%eax,%eax
 	cpuid
 	movl	%eax,RELOC(cpuid_level)
-	movl	$RELOC(cpu_vendorname),%ebp
-	movl	%ebx,(%ebp)
-	movl	%edx,4(%ebp)
-	movl	%ecx,8(%ebp)
-	movl	$0, 12(%ebp)
 
 	/*
 	 * Finished with old stack; load new %esp now instead of later so we



CVS commit: src/sys/arch/amd64/amd64

2015-11-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Nov 22 13:41:24 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: amd64_trap.S autoconf.c bios32.c gdt.c
kgdb_machdep.c linux32_sigcode.S machdep.c mptramp.S
netbsd32_machdep.c spl.S trap.c vector.S

Log Message:
KNF a bit, so I don't get scared each time I open a file


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/amd64/amd64/amd64_trap.S \
src/sys/arch/amd64/amd64/linux32_sigcode.S
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/amd64/autoconf.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/amd64/amd64/bios32.c
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/amd64/amd64/gdt.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/amd64/kgdb_machdep.c
cvs rdiff -u -r1.213 -r1.214 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/amd64/mptramp.S
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/amd64/amd64/spl.S
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/vector.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/amd64_trap.S
diff -u src/sys/arch/amd64/amd64/amd64_trap.S:1.2 src/sys/arch/amd64/amd64/amd64_trap.S:1.3
--- src/sys/arch/amd64/amd64/amd64_trap.S:1.2	Wed Feb 12 19:53:49 2014
+++ src/sys/arch/amd64/amd64/amd64_trap.S	Sun Nov 22 13:41:24 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64_trap.S,v 1.2 2014/02/12 19:53:49 dsl Exp $	*/
+/*	$NetBSD: amd64_trap.S,v 1.3 2015/11/22 13:41:24 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.2 2014/02/12 19:53:49 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amd64_trap.S,v 1.3 2015/11/22 13:41:24 maxv Exp $");
 #endif
 
 /*
@@ -144,7 +144,7 @@ IDTVEC(trap03)
 #else
 	ZTRAP_NJ(T_BPTFLT)
 	INTRENTRY
-  	STI(si)
+	STI(si)
 	/*
 	 * DTrace Function Boundary Trace (fbt) probes are triggered
 	 * by int3 (0xcc).
@@ -378,7 +378,7 @@ END(trap_return_fault_return)
  */
 NENTRY(alltraps)
 	INTRENTRY
-  	STI(si)
+	STI(si)
 
 calltrap:
 #ifdef DIAGNOSTIC
@@ -393,11 +393,11 @@ calltrap:
 .Lalltraps_checkast:
 	movq	CPUVAR(CURLWP),%r14
 	/* Check for ASTs on exit to user mode. */
-  	CLI(si)
+	CLI(si)
 	CHECK_ASTPENDING(%r14)
 	je	3f
 	CLEAR_ASTPENDING(%r14)
-  	STI(si)
+	STI(si)
 	movl	$T_ASTFLT,TF_TRAPNO(%rsp)
 	movq	%rsp,%rdi
 	incq	CPUVAR(NTRAP)
@@ -411,7 +411,7 @@ calltrap:
 6:	cmpl	CPUVAR(ILEVEL),%ebx
 	jne	3f
 	INTRFASTEXIT
-3:  	STI(si)
+3:	STI(si)
 	movabsq	$4f,%rdi
 	movl	CPUVAR(ILEVEL),%esi
 	movl	%ebx,%edx
Index: src/sys/arch/amd64/amd64/linux32_sigcode.S
diff -u src/sys/arch/amd64/amd64/linux32_sigcode.S:1.2 src/sys/arch/amd64/amd64/linux32_sigcode.S:1.3
--- src/sys/arch/amd64/amd64/linux32_sigcode.S:1.2	Mon Aug  1 22:21:01 2011
+++ src/sys/arch/amd64/amd64/linux32_sigcode.S	Sun Nov 22 13:41:24 2015
@@ -1,28 +1,28 @@
-/*	$NetBSD: linux32_sigcode.S,v 1.2 2011/08/01 22:21:01 joerg Exp $ */
+/*	$NetBSD: linux32_sigcode.S,v 1.3 2015/11/22 13:41:24 maxv Exp $ */
 
 #include "assym.h"
 #include 
 
 	.code32
 NENTRY(linux32_sigcode)
-	 call*LINUX32_SF_HANDLER(%esp)
-	 lealLINUX32_SF_SC(%esp),%ebx # scp
-	 pushl   %eax
-	 movl$LINUX32_SYS_sigreturn,%eax
-	 int $0x80
-	 movl$LINUX32_SYS_exit,%eax
-	 int $0x80
-  
-	.balign 16
+	call	*LINUX32_SF_HANDLER(%esp)
+	leal	LINUX32_SF_SC(%esp),%ebx	# scp
+	pushl	%eax
+	movl	$LINUX32_SYS_sigreturn,%eax
+	int	$0x80
+	movl	$LINUX32_SYS_exit,%eax
+	int	$0x80
+
+	.balign	16
 NENTRY(linux32_rt_sigcode)
-	 call*LINUX32_RT_SF_HANDLER(%esp)
-	 lealLINUX32_RT_SF_UC(%esp),%ebx # scp
-	 pushl   %eax
-	 movl$LINUX32_SYS_rt_sigreturn,%eax
-	 int $0x80
-	 movl$LINUX32_SYS_exit,%eax
-	 int $0x80
-	.balign 16
-	 .globl  _C_LABEL(linux32_esigcode)
-_C_LABEL(linux32_esigcode): 
+	call	*LINUX32_RT_SF_HANDLER(%esp)
+	leal	LINUX32_RT_SF_UC(%esp),%ebx	# scp
+	pushl	%eax
+	movl	$LINUX32_SYS_rt_sigreturn,%eax
+	int	$0x80
+	movl	$LINUX32_SYS_exit,%eax
+	int	$0x80
+	.balign	16
+	.globl	_C_LABEL(linux32_esigcode)
+_C_LABEL(linux32_esigcode):
 

Index: src/sys/arch/amd64/amd64/autoconf.c
diff -u src/sys/arch/amd64/amd64/autoconf.c:1.24 src/sys/arch/amd64/amd64/autoconf.c:1.25
--- src/sys/arch/amd64/amd64/autoconf.c:1.24	Thu Nov  8 02:00:44 2012
+++ src/sys/arch/amd64/amd64/autoconf.c	Sun Nov 22 13:41:24 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.24 2012/11/08 02:00:44 chs Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.25 2015/11/22 13:41:24 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.24 2012/11/08 02:00:44 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.25 2015/11/22 13:41:24 maxv Exp $");
 
 #include "opt_multip

CVS commit: src/sys/arch/amd64/amd64

2015-11-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Nov 22 10:19:00 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Clarify:
 - add some comments
 - rename some jumps
 - KNF
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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.80 src/sys/arch/amd64/amd64/locore.S:1.81
--- src/sys/arch/amd64/amd64/locore.S:1.80	Fri Nov 20 11:58:00 2015
+++ src/sys/arch/amd64/amd64/locore.S	Sun Nov 22 10:18:59 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.80 2015/11/20 11:58:00 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.81 2015/11/22 10:18:59 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -357,70 +357,94 @@ tmpstk:
 ENTRY(start)
 #ifndef XEN
 	.code32
-	movw	$0x1234,0x472			# warm boot
+
+	/* Warm boot */
+	movw	$0x1234,0x472
+
 	/*
-	 * Load parameters from stack
-	 * (howto, [bootdev], bootinfo, esym, basemem, extmem).
+	 * Load parameters from the stack (32 bits):   
+	 * boothowto, [bootdev], bootinfo, esym, basemem, extmem
+	 * We are not interested in 'bootdev'.
 	 */
+
+	/* Load 'boothowto' */
 	movl	4(%esp),%eax
 	movl	%eax,RELOC(boothowto)
+
+	/* Load 'bootinfo' */
 	movl	12(%esp),%eax
-	testl	%eax, %eax
-	jz	1f
-	movl	(%eax), %ebx		/* number of entries */
+	testl	%eax,%eax		/* bootinfo = NULL? */
+	jz	bootinfo_finished
+
+	movl	(%eax),%ebx		/* number of entries */
 	movl	$RELOC(bootinfo),%ebp
-	movl	%ebp, %edx
+	movl	%ebp,%edx
 	addl	$BOOTINFO_MAXSIZE,%ebp
-	movl	%ebx, (%edx)
-	addl	$4, %edx
-2:
-	testl	%ebx, %ebx
-	jz	1f
-	addl	$4, %eax
-	movl	(%eax), %ecx		/* address of entry */
+	movl	%ebx,(%edx)
+	addl	$4,%edx
+
+bootinfo_entryloop:
+	testl	%ebx,%ebx		/* no remaining entries? */
+	jz	bootinfo_finished
+
+	addl	$4,%eax
+	movl	(%eax),%ecx		/* address of entry */
 	pushl	%edi
 	pushl	%esi
 	pushl	%eax
 
-	movl	(%ecx),%eax	/* len */
+	movl	(%ecx),%eax		/* size of entry */
 	movl	%edx,%edi
-	addl	(%ecx), %edx		/* update dest pointer */
-	cmpl	%ebp, %edx
-	jg	2f
+	addl	(%ecx),%edx		/* update dest pointer */
+	cmpl	%ebp,%edx		/* beyond bootinfo+BOOTINFO_MAXSIZE? */
+	jg	bootinfo_overflow
+
 	movl	%ecx,%esi
 	movl	%eax,%ecx
+
 	/*
-	 * If any modules were loaded, record where they
-	 * end.  We'll need to skip over them.
+	 * If any modules were loaded, record where they end.  We'll need to
+	 * skip over them.
 	 */
-	cmpl	$BTINFO_MODULELIST, 4(%esi)
+	cmpl	$BTINFO_MODULELIST,4(%esi)
 	jne	0f
+
 	pushl	12(%esi)		/* endpa */
 	popl	RELOC(eblob)
-	addl	$KERNBASE_LO, RELOC(eblob)
-	adcl	$KERNBASE_HI, RELOC(eblob)+4
+	addl	$KERNBASE_LO,RELOC(eblob)
+	adcl	$KERNBASE_HI,RELOC(eblob)+4
+
 0:
 	rep
-	movsb
+	movsb/* copy esi -> edi */
 	popl	%eax
 	popl	%esi
 	popl	%edi
-	subl	$1, %ebx
-	jmp	2b
-2:	/* cleanup for overflow case */
+	subl	$1,%ebx			/* decrement the # of entries */
+	jmp	bootinfo_entryloop
+
+bootinfo_overflow:
+	/*
+	 * Cleanup for overflow case. Pop the registers, and correct the number
+	 * of entries.
+	 */
 	popl	%eax
 	popl	%esi
 	popl	%edi
 	movl	$RELOC(bootinfo),%ebp
-	movl	%ebp, %edx
-	subl	%ebx, (%edx)		/* correct number of entries */
-1:
+	movl	%ebp,%edx
+	subl	%ebx,(%edx)		/* correct the number of entries */
 
+bootinfo_finished:
+	/* Load 'esym' */
 	movl	16(%esp),%eax
-	testl	%eax,%eax
+	testl	%eax,%eax		/* esym = NULL? */
 	jz	1f
+
 	addl	$KERNBASE_LO,%eax
-1: 	movl	$RELOC(esym),%ebp
+
+1:
+	movl	$RELOC(esym),%ebp
 	movl	%eax,(%ebp)
 	movl	$KERNBASE_HI,4(%ebp)
 
@@ -428,8 +452,10 @@ ENTRY(start)
 	movl	(%ebp),%eax
 	testl	%eax,%eax
 	jnz	1f
+
 	movl	20(%esp),%eax
 	movl	%eax,(%ebp)
+
 1:
 	movl	$RELOC(biosbasemem),%ebp
 	movl	(%ebp),%eax
@@ -470,7 +496,7 @@ ENTRY(start)
  * Virtual address space of kernel:
  *
  * text | data | bss | [syms] | page dir | proc0 kstack | L1 ptp | L2 ptp | L3
- *			  0  1   2  3
+ *0  1   2  3
  */
 
 #if L2_SLOT_KERNBASE > 0
@@ -485,7 +511,6 @@ ENTRY(start)
 #define TABLE_L3_ENTRIES NKL3_KIMG_ENTRIES
 #endif
 
-
 #define PROC0_PML4_OFF	0
 #define PROC0_STK_OFF	(PROC0_PML4_OFF + PAGE_SIZE)
 #define PROC0_PTP3_OFF	(PROC0_STK_OFF + UPAGES * PAGE_SIZE)
@@ -507,7 +532,7 @@ ENTRY(start)
 #define fillkpt	\
 1:	movl	%eax,(%ebx)		; 	/* store phys addr */	\
 	movl	$0,(PDE_SIZE-4)(%ebx)	; 	/* upper 32 bits 0 */	\
-	addl	$PDE_SIZE,%ebx		; 	/* next pte/pde */	\
+	addl	$PDE_SIZE,%ebx		; 	/* next PTE/PDE */	\
 	addl	$PAGE_SIZE,%eax		; 	/* next phys page */	\
 	loop	1b			;
 
@@ -529,12 +554,13 @@ ENTRY(start)
 	subl	$KERNBASE_LO,%eax	/* XXX */
 	movl	%eax,%edi
 1:
+
 	/* Compute sizes */
 	movl	%edi,%esi
-	addl	$PGOFSET,%esi			# page align up
+	addl	$PGOFSET,%esi		/* page align up */
 	andl	$~PGOFSET,%esi
-
 	movl	%esi,%edi
+
 	xorl	%eax,%eax
 	cld
 	movl	$TABLESIZE,%ecx
@@ -542,11 +568,17 @@ ENT

CVS commit: src/sys/arch/amd64/amd64

2015-11-21 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Nov 21 12:34:48 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: copy.S

Log Message:
Remove the amd64 implementation of fuword and suword. They are not used in
the MI+amd64 code - Christos replaced them yesterday by copy*.

They are both buggy:
 - suword does not properly check the userspace limit: 64 bits are copied,
   but the max address checked is VM_MAXUSER_ADDRESS-4, which means that 4
   bytes may overflow. Reported by Ed Schouten.
 - fuword is supposed to be symmetrical with suword. But it uses 32bit
   registers, so it stores 32bit values! Spotted by Chuck (chs@).


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/amd64/copy.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/copy.S
diff -u src/sys/arch/amd64/amd64/copy.S:1.18 src/sys/arch/amd64/amd64/copy.S:1.19
--- src/sys/arch/amd64/amd64/copy.S:1.18	Wed Jul  7 01:13:29 2010
+++ src/sys/arch/amd64/amd64/copy.S	Sat Nov 21 12:34:48 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.18 2010/07/07 01:13:29 chs Exp $	*/
+/*	$NetBSD: copy.S,v 1.19 2015/11/21 12:34:48 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -359,19 +359,6 @@ ENTRY(copystr)
 
 7:	ret
 
-ENTRY(fuword)
-	DEFERRED_SWITCH_CHECK
-	movq	$VM_MAXUSER_ADDRESS-4,%r11
-	cmpq	%r11,%rdi
-	ja	_C_LABEL(fusuaddrfault)
-	GET_CURPCB(%rcx)
-	leaq	_C_LABEL(fusufailure)(%rip),%r11
-	movq	%r11,PCB_ONFAULT(%rcx)
-	movl	(%rdi),%eax
-	movq	$0,PCB_ONFAULT(%rcx)
-	ret
-	DEFERRED_SWITCH_CALL
-	
 ENTRY(fusword)
 	DEFERRED_SWITCH_CHECK
 	movq	$VM_MAXUSER_ADDRESS-2,%r11
@@ -411,22 +398,6 @@ ENTRY(fubyte)
 	ret
 	DEFERRED_SWITCH_CALL
 
-ENTRY(suword)
-	DEFERRED_SWITCH_CHECK
-	movq	$VM_MAXUSER_ADDRESS-4,%r11
-	cmpq	%r11,%rdi
-	ja	_C_LABEL(fusuaddrfault)
-
-	GET_CURPCB(%rcx)
-	leaq	_C_LABEL(fusufailure)(%rip),%r11
-	movq	%r11,PCB_ONFAULT(%rcx)
-
-	movq	%rsi,(%rdi)
-	xorq	%rax,%rax
-	movq	%rax,PCB_ONFAULT(%rcx)
-	ret
-	DEFERRED_SWITCH_CALL
-	
 ENTRY(susword)
 	DEFERRED_SWITCH_CHECK
 	movq	$VM_MAXUSER_ADDRESS-2,%r11



CVS commit: src/sys/arch/amd64/amd64

2015-11-20 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 20 11:58:00 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S

Log Message:
A few changes:
 - remove cpu_id and cpu_brand_id (unused)
 - copy a comment from i386 about fillkpt
 - define PDE_SIZE (i386)


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.79 -r1.80 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/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.59 src/sys/arch/amd64/amd64/genassym.cf:1.60
--- src/sys/arch/amd64/amd64/genassym.cf:1.59	Wed Aug 26 03:00:53 2015
+++ src/sys/arch/amd64/amd64/genassym.cf	Fri Nov 20 11:58:00 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.59 2015/08/26 03:00:53 uebayasi Exp $
+#	$NetBSD: genassym.cf,v 1.60 2015/11/20 11:58:00 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -145,6 +145,8 @@ define	L1_SLOT_KERNBASE	pl1_pi(KERNBASE)
 
 define	PDIR_SLOT_PTE		PDIR_SLOT_PTE
 
+define	PDE_SIZE		sizeof(pd_entry_t)
+
 define	VM_MAXUSER_ADDRESS	(unsigned long long)VM_MAXUSER_ADDRESS
 
 define	L_PCB			offsetof(struct lwp, l_addr)

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.79 src/sys/arch/amd64/amd64/locore.S:1.80
--- src/sys/arch/amd64/amd64/locore.S:1.79	Sat Nov 14 14:01:23 2015
+++ src/sys/arch/amd64/amd64/locore.S	Fri Nov 20 11:58:00 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.79 2015/11/14 14:01:23 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.80 2015/11/20 11:58:00 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -247,9 +247,7 @@ _C_LABEL(lapic_isr):
 END(lapic_isr)
 #endif
 
-	.globl	_C_LABEL(cpu_id)
 	.globl	_C_LABEL(cpu_vendorname)
-	.globl	_C_LABEL(cpu_brand_id)
 	.globl	_C_LABEL(cpuid_level)
 	.globl	_C_LABEL(esym)
 	.globl	_C_LABEL(eblob)
@@ -265,9 +263,6 @@ END(lapic_isr)
 	.type	_C_LABEL(cputype), @object
 LABEL(cputype)		.long	0	# are we 80486, Pentium, or..
 END(cputype)
-	.type	_C_LABEL(cpu_id), @object
-LABEL(cpu_id)		.long	0	# saved from `cpuid' instruction
-END(cpu_id)
 	.type	_C_LABEL(cpuid_level), @object
 LABEL(cpuid_level)	.long	-1	# max. level accepted by 'cpuid'
 	#   instruction
@@ -276,9 +271,6 @@ END(cpuid_level)
 LABEL(cpu_vendorname)	.space	16	# vendor string returned by `cpuid'
 	#   instruction
 END(cpu_vendorname)
-	.type	_C_LABEL(cpu_brand_id), @object
-LABEL(cpu_brand_id)	.long	0	# brand ID from 'cpuid' instruction
-END(cpu_brand_id)
 	.type	_C_LABEL(esym), @object
 LABEL(esym)		.quad	0	# ptr to end of syms
 END(esym)
@@ -460,14 +452,6 @@ ENTRY(start)
 	movl	%ecx,8(%ebp)
 	movl	$0, 12(%ebp)
 
-	movl	$1,%eax
-	cpuid
-	movl	%eax,RELOC(cpu_id)
-
-	/* Brand ID is bits 0-7 of %ebx */
-	andl	$255,%ebx
-	movl	%ebx,RELOC(cpu_brand_id)
-
 	/*
 	 * Finished with old stack; load new %esp now instead of later so we
 	 * can trace this code without having to worry about the trace trap
@@ -511,10 +495,19 @@ ENTRY(start)
   ((NKL4_KIMG_ENTRIES + TABLE_L3_ENTRIES + TABLE_L2_ENTRIES + 1 + UPAGES) \
 * PAGE_SIZE)
 
+/*
+ * fillkpt - Fill in a kernel page table
+ *	eax = pte (page frame | control | status)
+ *	ebx = page table address
+ *	ecx = number of pages to map
+ *
+ * Each entry is 8 (PDE_SIZE) bytes long: we must set the 4 upper bytes to 0.
+ */
+
 #define fillkpt	\
 1:	movl	%eax,(%ebx)		; 	/* store phys addr */	\
-	movl	$0,4(%ebx)		; 	/* upper 32 bits 0 */	\
-	addl	$8,%ebx			; 	/* next pte/pde */	\
+	movl	$0,(PDE_SIZE-4)(%ebx)	; 	/* upper 32 bits 0 */	\
+	addl	$PDE_SIZE,%ebx		; 	/* next pte/pde */	\
 	addl	$PAGE_SIZE,%eax		; 	/* next phys page */	\
 	loop	1b			;
 
@@ -567,7 +560,7 @@ ENTRY(start)
 	 */
 	movl	$(KERNTEXTOFF_LO - KERNBASE_LO),%eax
 	movl	%eax,%ecx
-	shrl	$(PGSHIFT-3),%ecx	/* ((n >> PGSHIFT) << 3) for # pdes */
+	shrl	$(PGSHIFT-3),%ecx	/* ((n >> PGSHIFT) << 3) for # PDEs */
 	addl	%ecx,%ebx
 
 	/* Map the kernel text read-only. */
@@ -580,14 +573,14 @@ ENTRY(start)
 	/* Map the data, BSS, and bootstrap tables read-write. */
 	leal	(PG_V|PG_KW)(%edx),%eax
 	movl	$TABLESIZE,%ecx
-	addl	%esi,%ecx# end of tables
-	subl	%edx,%ecx# subtract end of text
+	addl	%esi,%ecx		/* end of tables */
+	subl	%edx,%ecx		/* subtract end of text */
 	shrl	$PGSHIFT,%ecx
 	fillkpt
 
 	/* Map ISA I/O mem (later atdevbase) */
-	movl	$(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax	# having these bits set
-	movl	$(IOM_SIZE>>PGSHIFT),%ecx		# for this many pte s,
+	movl	$(IOM_BEGIN|PG_V|PG_KW/*|PG_N*/),%eax
+	movl	$(IOM_SIZE>>PGSHIFT),%ecx
 	fillkpt
 
 /*



CVS commit: src/sys/arch/amd64/amd64

2015-07-14 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 15 04:10:02 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
 Add comment (ACPI_WAKEUP_ADDR).


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/sys/arch/amd64/amd64/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.212 src/sys/arch/amd64/amd64/machdep.c:1.213
--- src/sys/arch/amd64/amd64/machdep.c:1.212	Fri Apr 24 00:04:04 2015
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Jul 15 04:10:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.212 2015/04/24 00:04:04 khorben Exp $	*/
+/*	$NetBSD: machdep.c,v 1.213 2015/07/15 04:10:02 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.212 2015/04/24 00:04:04 khorben Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.213 2015/07/15 04:10:02 msaitoh Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1581,7 +1581,7 @@ init_x86_64(paddr_t first_avail)
 	 * Page 0:	BIOS data
 	 * Page 1:	BIOS callback (not used yet, for symmetry with i386)
 	 * Page 2:	MP bootstrap
-	 * Page 3:	ACPI wakeup code
+	 * Page 3:	ACPI wakeup code (ACPI_WAKEUP_ADDR)
 	 * Page 4:	Temporary page table for 0MB-4MB
 	 * Page 5:	Temporary page directory
 	 * Page 6:	Temporary page map level 3



CVS commit: src/sys/arch/amd64/amd64

2015-06-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jun 30 21:08:24 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: cpu_in_cksum.S

Log Message:
handle PIC compilation (if we are building a PIE system; this is used by tests)


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/amd64/amd64/cpu_in_cksum.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/cpu_in_cksum.S
diff -u src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.2 src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.3
--- src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.2	Sat Jun 22 01:56:32 2013
+++ src/sys/arch/amd64/amd64/cpu_in_cksum.S	Tue Jun 30 17:08:24 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_in_cksum.S,v 1.2 2013/06/22 05:56:32 uebayasi Exp $ */
+/* $NetBSD: cpu_in_cksum.S,v 1.3 2015/06/30 21:08:24 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger .
@@ -285,9 +285,13 @@ ENTRY(cpu_in_cksum)
 	ret
 
 .Mout_of_mbufs:
+#ifdef __PIC__
+	leaq	.Mout_of_mbufs_msg(%rip), %rdi
+#else
 	movq	$.Mout_of_mbufs_msg, %rdi
+#endif
 	movl	$0, %eax
-	call	_C_LABEL(printf)
+	call	PIC_PLT(_C_LABEL(printf))
 	jmp	.Mreturn
 END(cpu_in_cksum)
 



CVS commit: src/sys/arch/amd64/amd64

2015-05-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 12 23:16:47 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: db_disasm.c

Log Message:
When in Rome... use true or false, instead of TRUE and FALSE.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/amd64/amd64/db_disasm.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/db_disasm.c
diff -u src/sys/arch/amd64/amd64/db_disasm.c:1.21 src/sys/arch/amd64/amd64/db_disasm.c:1.22
--- src/sys/arch/amd64/amd64/db_disasm.c:1.21	Tue May 12 15:24:57 2015
+++ src/sys/arch/amd64/amd64/db_disasm.c	Tue May 12 19:16:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.21 2015/05/12 19:24:57 msaitoh Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.22 2015/05/12 23:16:47 christos Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.21 2015/05/12 19:24:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.22 2015/05/12 23:16:47 christos Exp $");
 
 #ifndef _KERNEL
 #include 
@@ -213,23 +213,23 @@ const struct inst db_inst_0f0x[] = {
 };
 
 const struct inst db_inst_0f1x[] = {
-/*10*/	{ "",  FALSE, NONE,  0,	  0 },
-/*11*/	{ "",  FALSE, NONE,  0,	  0 },
-/*12*/	{ "",  FALSE, NONE,  0,	  0 },
-/*13*/	{ "",  FALSE, NONE,  0,	  0 },
-/*14*/	{ "",  FALSE, NONE,  0,	  0 },
-/*15*/	{ "",  FALSE, NONE,  0,	  0 },
-/*16*/	{ "",  FALSE, NONE,  0,	  0 },
-/*17*/	{ "",  FALSE, NONE,  0,	  0 },
-
-/*18*/	{ "",  FALSE, NONE,  0,	  0 },
-/*19*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1a*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1b*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1c*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1d*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1e*/	{ "",  FALSE, NONE,  0,	  0 },
-/*1f*/	{ "nopl",  TRUE,  SDEP,  0,	  "nopw" },
+/*10*/	{ "",  false, NONE,  0,	  0 },
+/*11*/	{ "",  false, NONE,  0,	  0 },
+/*12*/	{ "",  false, NONE,  0,	  0 },
+/*13*/	{ "",  false, NONE,  0,	  0 },
+/*14*/	{ "",  false, NONE,  0,	  0 },
+/*15*/	{ "",  false, NONE,  0,	  0 },
+/*16*/	{ "",  false, NONE,  0,	  0 },
+/*17*/	{ "",  false, NONE,  0,	  0 },
+
+/*18*/	{ "",  false, NONE,  0,	  0 },
+/*19*/	{ "",  false, NONE,  0,	  0 },
+/*1a*/	{ "",  false, NONE,  0,	  0 },
+/*1b*/	{ "",  false, NONE,  0,	  0 },
+/*1c*/	{ "",  false, NONE,  0,	  0 },
+/*1d*/	{ "",  false, NONE,  0,	  0 },
+/*1e*/	{ "",  false, NONE,  0,	  0 },
+/*1f*/	{ "nopl",  true,  SDEP,  0,	  "nopw" },
 };
 
 const struct inst db_inst_0f2x[] = {



CVS commit: src/sys/arch/amd64/amd64

2015-03-07 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar  7 18:41:40 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: linux32_syscall.c linux_syscall.c
netbsd32_syscall.c

Log Message:
add dtrace hooks


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/linux32_syscall.c \
src/sys/arch/amd64/amd64/linux_syscall.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/amd64/netbsd32_syscall.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/linux32_syscall.c
diff -u src/sys/arch/amd64/amd64/linux32_syscall.c:1.31 src/sys/arch/amd64/amd64/linux32_syscall.c:1.32
--- src/sys/arch/amd64/amd64/linux32_syscall.c:1.31	Tue Nov 25 14:54:08 2014
+++ src/sys/arch/amd64/amd64/linux32_syscall.c	Sat Mar  7 13:41:40 2015
@@ -1,7 +1,7 @@
-/*	$NetBSD: linux32_syscall.c,v 1.31 2014/11/25 19:54:08 christos Exp $ */
+/*	$NetBSD: linux32_syscall.c,v 1.32 2015/03/07 18:41:40 christos Exp $ */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux32_syscall.c,v 1.31 2014/11/25 19:54:08 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_syscall.c,v 1.32 2015/03/07 18:41:40 christos Exp $");
 
 #include 
 #include 
@@ -63,14 +63,14 @@ linux32_syscall(struct trapframe *frame)
 	args[4] = frame->tf_rdi & 0x;
 	args[5] = frame->tf_rbp & 0x;
 
-	if (__predict_false(p->p_trace_enabled)) {
+	if (__predict_false(p->p_trace_enabled || KDTRACE_ENTRY(callp->sy_return))) {
 		narg = callp->sy_narg;
 		if (__predict_false(narg > __arraycount(args)))
 			panic("impossible syscall narg, code %d, narg %zu",
 			code, narg);
 		for (i = 0; i < narg; i++)
 			args64[i] = args[i] & 0x;
-		if ((error = trace_enter(code, args64, narg)) != 0)
+		if ((error = trace_enter(code, callp, args64)) != 0)
 			goto out;
 	}
 
@@ -102,7 +102,11 @@ out:
 		break;
 	}
 
-	if (__predict_false(p->p_trace_enabled))
-		trace_exit(code, rval, error);
+	if (__predict_false(p->p_trace_enabled || KDTRACE_ENTRY(callp->sy_return))) {
+		narg = callp->sy_narg;
+		for (i = 0; i < narg; i++)
+			args64[i] = args[i] & 0x;
+		trace_exit(code, callp, args64, rval, error);
+	}
 	userret(l);
 }
Index: src/sys/arch/amd64/amd64/linux_syscall.c
diff -u src/sys/arch/amd64/amd64/linux_syscall.c:1.31 src/sys/arch/amd64/amd64/linux_syscall.c:1.32
--- src/sys/arch/amd64/amd64/linux_syscall.c:1.31	Sun Dec 19 19:25:24 2010
+++ src/sys/arch/amd64/amd64/linux_syscall.c	Sat Mar  7 13:41:40 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_syscall.c,v 1.31 2010/12/20 00:25:24 matt Exp $ */
+/*	$NetBSD: linux_syscall.c,v 1.32 2015/03/07 18:41:40 christos Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_syscall.c,v 1.31 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_syscall.c,v 1.32 2015/03/07 18:41:40 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_linux.h"
@@ -97,8 +97,8 @@ linux_syscall(struct trapframe *frame)
 	 * already adjacent in the syscall trapframe.
 	 */
 
-	if (__predict_false(p->p_trace_enabled)
-	&& (error = trace_enter(code, args, callp->sy_narg)) != 0)
+	if (__predict_false(p->p_trace_enabled || KDTRACE_ENTRY(callp->sy_entry))
+	&& (error = trace_enter(code, callp, args)) != 0)
 		goto out;
 
 	rval[0] = 0;
@@ -126,8 +126,8 @@ out:
 		break;
 	}
 
-	if (__predict_false(p->p_trace_enabled))
-		trace_exit(code, rval, error);
+	if (__predict_false(p->p_trace_enabled || KDTRACE_ENTRY(callp->sy_return)))
+		trace_exit(code, callp, args, rval, error);
 
 	userret(l);
 }

Index: src/sys/arch/amd64/amd64/netbsd32_syscall.c
diff -u src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.32 src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.33
--- src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.32	Fri May 16 08:55:43 2014
+++ src/sys/arch/amd64/amd64/netbsd32_syscall.c	Sat Mar  7 13:41:40 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_syscall.c,v 1.32 2014/05/16 12:55:43 njoly Exp $	*/
+/*	$NetBSD: netbsd32_syscall.c,v 1.33 2015/03/07 18:41:40 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -29,8 +29,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if defined(_KERNEL) && defined(_KERNEL_OPT)
+#include "opt_dtrace.h"
+#endif
+
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscall.c,v 1.32 2014/05/16 12:55:43 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscall.c,v 1.33 2015/03/07 18:41:40 christos Exp $");
 
 #include 
 #include 
@@ -88,12 +92,12 @@ netbsd32_syscall(struct trapframe *frame
 			goto bad;
 	}
 
-	if (__predict_false(p->p_trace_enabled)
+	if (__predict_false(p->p_trace_enabled || KDTRACE_ENTRY(callp->sy_entry))
 	&& !__predict_false(callp->sy_flags & SYCALL_INDIRECT)) {
 		int narg = callp->sy_argsize >> 2;
 		for (i = 0; i < narg; i++)
 			args64[i] = args[i];
-		error = trace_enter(code, args64, narg);
+	

CVS commit: src/sys/arch/amd64/amd64

2015-02-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 27 15:35:10 UTC 2015

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Tidy up error handling, and return SIGBUS for mmap past the end of file
as required by the spec.


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/arch/amd64/amd64/trap.c:1.80
--- src/sys/arch/amd64/amd64/trap.c:1.79	Sat Oct 18 04:33:24 2014
+++ src/sys/arch/amd64/amd64/trap.c	Fri Feb 27 10:35:10 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.79 2014/10/18 08:33:24 snj Exp $	*/
+/*	$NetBSD: trap.c,v 1.80 2015/02/27 15:35:10 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.79 2014/10/18 08:33:24 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.80 2015/02/27 15:35:10 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -608,15 +608,6 @@ faultcommon:
 			}
 			goto out;
 		}
-		KSI_INIT_TRAP(&ksi);
-		ksi.ksi_trap = type & ~T_USER;
-		ksi.ksi_addr = (void *)cr2;
-		if (error == EACCES) {
-			ksi.ksi_code = SEGV_ACCERR;
-			error = EFAULT;
-		} else {
-			ksi.ksi_code = SEGV_MAPERR;
-		}
 
 		if (type == T_PAGEFLT) {
 			onfault = onfault_handler(pcb, frame);
@@ -626,20 +617,38 @@ faultcommon:
 			map, va, ftype, error);
 			goto kernelfault;
 		}
-		if (error == ENOMEM) {
+
+		KSI_INIT_TRAP(&ksi);
+		ksi.ksi_trap = type & ~T_USER;
+		ksi.ksi_addr = (void *)cr2;
+		switch (error) {
+		case EINVAL:
+			ksi.ksi_signo = SIGBUS;
+			ksi.ksi_code = BUS_ADRERR;
+			break;
+		case EACCES:
+			ksi.ksi_signo = SIGSEGV;
+			ksi.ksi_code = SEGV_ACCERR;
+			error = EFAULT;
+			break;
+		case ENOMEM:
 			ksi.ksi_signo = SIGKILL;
-			printf("UVM: pid %d.%d (%s), uid %d killed: out of swap\n",
-			   p->p_pid, l->l_lid, p->p_comm,
-			   l->l_cred ?
-			   kauth_cred_geteuid(l->l_cred) : -1);
-		} else {
-#ifdef TRAP_SIGDEBUG
-			printf("pid %d.%d (%s): SEGV at rip %lx addr %lx\n",
-			p->p_pid, l->l_lid, p->p_comm, frame->tf_rip, va);
-			frame_dump(frame);
-#endif
+			printf("UVM: pid %d.%d (%s), uid %d killed: "
+			"out of swap\n", p->p_pid, l->l_lid, p->p_comm,
+			l->l_cred ?  kauth_cred_geteuid(l->l_cred) : -1);
+			break;
+		default:
 			ksi.ksi_signo = SIGSEGV;
+			ksi.ksi_code = SEGV_MAPERR;
+			break;
 		}
+
+#ifdef TRAP_SIGDEBUG
+		printf("pid %d.%d (%s): signal %d at rip %lx addr %lx "
+		"error %d\n", p->p_pid, l->l_lid, p->p_comm, ksi.ksi_signo,
+		frame->tf_rip, va, error);
+		frame_dump(frame);
+#endif
 		(*p->p_emul->e_trapsignal)(l, &ksi);
 		break;
 	}



CVS commit: src/sys/arch/amd64/amd64

2014-12-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Dec 14 21:27:49 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c
Added Files:
src/sys/arch/amd64/amd64: compat_13_machdep.c compat_16_machdep.c

Log Message:
Move the empty sigreturn functions to their own files to allow the compat
module to load by itself.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/amd64/amd64/compat_13_machdep.c
cvs rdiff -u -r0 -r1.5 src/sys/arch/amd64/amd64/compat_16_machdep.c
cvs rdiff -u -r1.92 -r1.93 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.92 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.93
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.92	Sat Feb 15 17:20:41 2014
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Sun Dec 14 16:27:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.92 2014/02/15 22:20:41 dsl Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.93 2014/12/14 21:27:49 christos Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.92 2014/02/15 22:20:41 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.93 2014/12/14 21:27:49 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -106,19 +106,6 @@ cpu_exec_aout_makecmds(struct lwp *p, st
 }
 #endif
 
-#ifdef COMPAT_16
-/*
- * There is no NetBSD-1.6 compatibility for native code.
- * COMPAT_16 is useful for i386 emulation (COMPAT_NETBSD32) only.
- */
-int
-compat_16_sys___sigreturn14(struct lwp *l, const struct compat_16_sys___sigreturn14_args *uap, register_t *retval)
-{
-
-	return ENOSYS;
-}
-#endif
-
 void
 netbsd32_setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)
 {
@@ -954,12 +941,6 @@ netbsd32_vm_default_addr(struct proc *p,
 
 #ifdef COMPAT_13
 int
-compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
-{
-	return ENOSYS;
-}
-
-int
 compat_13_netbsd32_sigreturn(struct lwp *l, const struct compat_13_netbsd32_sigreturn_args *uap, register_t *retval)
 {
 	/* {

Added files:

Index: src/sys/arch/amd64/amd64/compat_13_machdep.c
diff -u /dev/null src/sys/arch/amd64/amd64/compat_13_machdep.c:1.1
--- /dev/null	Sun Dec 14 16:27:49 2014
+++ src/sys/arch/amd64/amd64/compat_13_machdep.c	Sun Dec 14 16:27:49 2014
@@ -0,0 +1,63 @@
+/*	$NetBSD: compat_13_machdep.c,v 1.1 2014/12/14 21:27:49 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include 
+__KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.1 2014/12/14 21:27:49 christos Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_compat_netbsd.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#ifdef COMPAT_13
+
+int compat_13_sys_sigreturn(struct lwp *, const struct compat_13_sys_sigreturn_args *, register_t *);
+
+/*
+ * There is no NetBSD-1.6 compatibility for native code.
+ * COMPAT_13 is useful for i386 emulation (COMPAT_NETBSD32) only.
+ */
+int
+compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
+{
+
+	return ENOSYS;
+}
+#endif

Index: src/sys/arch/amd64/amd64/compat_16_machdep.c
diff -u /dev/null src/sys/arch/amd64/amd64/compat_16_machde

CVS commit: src/sys/arch/amd64/amd64

2014-11-26 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Thu Nov 27 04:48:39 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: spl.S

Log Message:
Comments.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/amd64/amd64/spl.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/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.28 src/sys/arch/amd64/amd64/spl.S:1.29
--- src/sys/arch/amd64/amd64/spl.S:1.28	Sun Jan 12 20:31:50 2014
+++ src/sys/arch/amd64/amd64/spl.S	Thu Nov 27 04:48:39 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.28 2014/01/12 20:31:50 joerg Exp $	*/
+/*	$NetBSD: spl.S,v 1.29 2014/11/27 04:48:39 uebayasi Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -115,7 +115,7 @@ IDTVEC(softintr)
 	xchgq	%r15,CPUVAR(CURLWP)	/* must be globally visible */
 	popq	%r15			/* unwind switchframe */
 	addq	$(5 * 8),%rsp
-	jmp	*%r13			/* back to splx/doreti */
+	jmp	*%r13			/* back to Xspllower/Xdoreti */
 END(Xsoftintr)
 
 /*
@@ -130,7 +130,7 @@ NENTRY(softintr_ret)
 	incl	CPUVAR(MTX_COUNT)	/* re-adjust after mi_switch */
 	movl	$0, L_CTXSWTCH(%rax)	/* %rax from cpu_switchto */
 	cli
-	jmp	*%r13			/* back to splx/doreti */
+	jmp	*%r13			/* back to Xspllower/Xdoreti */
 END(softintr_ret)
 
 /*
@@ -155,7 +155,7 @@ IDTVEC(preemptrecurse)
 	xorq	%rdi, %rdi
 	call	_C_LABEL(kpreempt)
 	cli
-	jmp	*%r13
+	jmp	*%r13			/* back to Xspllower */
 END(Xpreemptrecurse)
 
 /*
@@ -171,11 +171,11 @@ IDTVEC(preemptresume)
 	movq	TF_RIP(%rsp), %rdi
 	call	_C_LABEL(kpreempt)		# from kernel
 	cli
-	jmp	*%r13
+	jmp	*%r13			/* back to Xdoreti */
 1:
 	call	_C_LABEL(preempt)		# from user
 	cli
-	jmp	*%r13
+	jmp	*%r13			/* back to Xdoreti */
 END(Xpreemptresume)
 
 /*
@@ -303,6 +303,8 @@ IDTVEC(spllower)
 END(Xspllower)
 
 /*
+ * void Xdoreti(void);
+ * 
  * Handle return from interrupt after device handler finishes.
  *
  * Important registers:



CVS commit: src/sys/arch/amd64/amd64

2014-11-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Nov 25 19:54:08 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: linux32_syscall.c

Log Message:
CID 981752: printf format


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/amd64/amd64/linux32_syscall.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/linux32_syscall.c
diff -u src/sys/arch/amd64/amd64/linux32_syscall.c:1.30 src/sys/arch/amd64/amd64/linux32_syscall.c:1.31
--- src/sys/arch/amd64/amd64/linux32_syscall.c:1.30	Sun Dec 19 19:25:24 2010
+++ src/sys/arch/amd64/amd64/linux32_syscall.c	Tue Nov 25 14:54:08 2014
@@ -1,7 +1,7 @@
-/*	$NetBSD: linux32_syscall.c,v 1.30 2010/12/20 00:25:24 matt Exp $ */
+/*	$NetBSD: linux32_syscall.c,v 1.31 2014/11/25 19:54:08 christos Exp $ */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux32_syscall.c,v 1.30 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_syscall.c,v 1.31 2014/11/25 19:54:08 christos Exp $");
 
 #include 
 #include 
@@ -66,7 +66,7 @@ linux32_syscall(struct trapframe *frame)
 	if (__predict_false(p->p_trace_enabled)) {
 		narg = callp->sy_narg;
 		if (__predict_false(narg > __arraycount(args)))
-			panic("impossible syscall narg, code %d, narg %zd",
+			panic("impossible syscall narg, code %d, narg %zu",
 			code, narg);
 		for (i = 0; i < narg; i++)
 			args64[i] = args[i] & 0x;



CVS commit: src/sys/arch/amd64/amd64

2014-06-29 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sun Jun 29 23:21:28 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: rbus_machdep.c

Log Message:
drop trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/amd64/amd64/rbus_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/rbus_machdep.c
diff -u src/sys/arch/amd64/amd64/rbus_machdep.c:1.5 src/sys/arch/amd64/amd64/rbus_machdep.c:1.6
--- src/sys/arch/amd64/amd64/rbus_machdep.c:1.5	Fri Jul  1 19:24:14 2011
+++ src/sys/arch/amd64/amd64/rbus_machdep.c	Sun Jun 29 23:21:28 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rbus_machdep.c,v 1.5 2011/07/01 19:24:14 dyoung Exp $	*/
+/*	$NetBSD: rbus_machdep.c,v 1.6 2014/06/29 23:21:28 jakllsch Exp $	*/
 
 /*
  * Copyright (c) 1999
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.5 2011/07/01 19:24:14 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.6 2014/06/29 23:21:28 jakllsch Exp $");
 
 #include "opt_pcifixup.h"
 
@@ -92,11 +92,11 @@ rbus_pccbb_parent_mem(struct pci_attach_
 	 * which is not recognised by the kernel as already reserved.
 	 */
 
-	if (start < rbus_min_start) 
+	if (start < rbus_min_start)
 		start = rbus_min_start;
 
 	size = ex->ex_end - start;
-  
+
 	return rbus_new_root_share(pa->pa_memt, ex, start, size, 0);
 }
 



CVS commit: src/sys/arch/amd64/amd64

2014-05-16 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Fri May 16 12:55:43 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_syscall.c

Log Message:
Do not compute code value more than once. Remove unneeded before
trace_enter()/trace_exit() calls.

This fix some cases where tracing show unexpected SYSRET number value
because some syscalls, such as setcontext(2), modified the trapframe
register values.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/netbsd32_syscall.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/netbsd32_syscall.c
diff -u src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.31 src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.32
--- src/sys/arch/amd64/amd64/netbsd32_syscall.c:1.31	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/netbsd32_syscall.c	Fri May 16 12:55:43 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_syscall.c,v 1.31 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: netbsd32_syscall.c,v 1.32 2014/05/16 12:55:43 njoly Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscall.c,v 1.31 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscall.c,v 1.32 2014/05/16 12:55:43 njoly Exp $");
 
 #include 
 #include 
@@ -86,8 +86,6 @@ netbsd32_syscall(struct trapframe *frame
 		error = copyin(params, args, callp->sy_argsize);
 		if (__predict_false(error != 0))
 			goto bad;
-		/* Recover 'code' - not in a register */
-		code = frame->tf_rax & (SYS_NSYSENT - 1);
 	}
 
 	if (__predict_false(p->p_trace_enabled)
@@ -107,8 +105,6 @@ netbsd32_syscall(struct trapframe *frame
 out:
 	if (__predict_false(p->p_trace_enabled)
 	&& !__predict_false(callp->sy_flags & SYCALL_INDIRECT)) {
-		/* Recover 'code' - the compiler doesn't assign it a register */
-		code = frame->tf_rax & (SYS_NSYSENT - 1);
 		trace_exit(code, rval, error);
 	}
 



CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Mon May 12 17:27:23 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
revert previous; the 128 bytes is for the AMD64 redzone


To generate a diff of this commit:
cvs rdiff -u -r1.209 -r1.210 src/sys/arch/amd64/amd64/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.209 src/sys/arch/amd64/amd64/machdep.c:1.210
--- src/sys/arch/amd64/amd64/machdep.c:1.209	Mon May 12 13:49:24 2014
+++ src/sys/arch/amd64/amd64/machdep.c	Mon May 12 17:27:23 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.209 2014/05/12 13:49:24 uebayasi Exp $	*/
+/*	$NetBSD: machdep.c,v 1.210 2014/05/12 17:27:23 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.209 2014/05/12 13:49:24 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.210 2014/05/12 17:27:23 jakllsch Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -563,7 +563,7 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	if (onstack)
 		sp = ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
 	else
-		sp = (char *)tf->tf_rsp;
+		sp = (char *)tf->tf_rsp - 128;
 
 	sp -= sizeof(struct sigframe_siginfo);
 	/* Round down the stackpointer to a multiple of 16 for the ABI. */



CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Mon May 12 13:49:24 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Don't reserve space (128) on signal stack for unknown reasons; the actual
space for struct sigframe_siginfo (+ alignment) is allocated just below.

Confirmed by the following tests:

tests/lib/libc/gen/t_siginfo
tests/lib/libc/sys/t_sigtimedwait
tests/lib/libc/sys/t_sigaction
tests/lib/libc/sys/t_sigqueue


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/sys/arch/amd64/amd64/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.208 src/sys/arch/amd64/amd64/machdep.c:1.209
--- src/sys/arch/amd64/amd64/machdep.c:1.208	Mon May 12 09:01:34 2014
+++ src/sys/arch/amd64/amd64/machdep.c	Mon May 12 13:49:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.208 2014/05/12 09:01:34 uebayasi Exp $	*/
+/*	$NetBSD: machdep.c,v 1.209 2014/05/12 13:49:24 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.208 2014/05/12 09:01:34 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.209 2014/05/12 13:49:24 uebayasi Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -563,7 +563,7 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	if (onstack)
 		sp = ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
 	else
-		sp = (char *)tf->tf_rsp - 128;
+		sp = (char *)tf->tf_rsp;
 
 	sp -= sizeof(struct sigframe_siginfo);
 	/* Round down the stackpointer to a multiple of 16 for the ABI. */



CVS commit: src/sys/arch/amd64/amd64

2014-05-12 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Mon May 12 09:01:35 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
stmt;; -> stmt;


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 src/sys/arch/amd64/amd64/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.207 src/sys/arch/amd64/amd64/machdep.c:1.208
--- src/sys/arch/amd64/amd64/machdep.c:1.207	Sun Feb 23 12:56:40 2014
+++ src/sys/arch/amd64/amd64/machdep.c	Mon May 12 09:01:34 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.207 2014/02/23 12:56:40 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.208 2014/05/12 09:01:34 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.207 2014/02/23 12:56:40 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.208 2014/05/12 09:01:34 uebayasi Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1888,7 +1888,7 @@ cpu_getmcontext(struct lwp *l, mcontext_
 
 	*flags |= _UC_CPU;
 
-	mcp->_mc_tlsbase = (uintptr_t)l->l_private;;
+	mcp->_mc_tlsbase = (uintptr_t)l->l_private;
 	*flags |= _UC_TLSBASE;
 
 	process_read_fpregs_xmm(l, (struct fxsave *)&mcp->__fpregs);



CVS commit: src/sys/arch/amd64/amd64

2014-03-11 Thread Lars Heidieker
Module Name:src
Committed By:   para
Date:   Tue Mar 11 20:54:29 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
mark a diagnostic only variable


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sys/arch/amd64/amd64/trap.c:1.78
--- src/sys/arch/amd64/amd64/trap.c:1.77	Wed Feb 12 19:53:49 2014
+++ src/sys/arch/amd64/amd64/trap.c	Tue Mar 11 20:54:29 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.77 2014/02/12 19:53:49 dsl Exp $	*/
+/*	$NetBSD: trap.c,v 1.78 2014/03/11 20:54:29 para Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.77 2014/02/12 19:53:49 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.78 2014/03/11 20:54:29 para Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -705,7 +705,7 @@ startlwp(void *arg)
 {
 	ucontext_t *uc = arg;
 	lwp_t *l = curlwp;
-	int error;
+	int error __diagused;
 
 	error = cpu_setmcontext(l, &uc->uc_mcontext, uc->uc_flags);
 	KASSERT(error == 0);



CVS commit: src/sys/arch/amd64/amd64

2014-02-09 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Feb  9 23:02:25 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: fpu.c

Log Message:
Steal the table from i386/isa/npx.c than selects the highest priority
  floating point error when raising a signal.
Multiple errors bits can easily be set if different sub-fields of an
xmm simd operation generate different errors.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amd64/amd64/fpu.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/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.47 src/sys/arch/amd64/amd64/fpu.c:1.48
--- src/sys/arch/amd64/amd64/fpu.c:1.47	Sun Feb  9 22:19:02 2014
+++ src/sys/arch/amd64/amd64/fpu.c	Sun Feb  9 23:02:25 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.47 2014/02/09 22:19:02 dsl Exp $	*/
+/*	$NetBSD: fpu.c,v 1.48 2014/02/09 23:02:25 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.47 2014/02/09 22:19:02 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.48 2014/02/09 23:02:25 dsl Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -144,7 +144,83 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.47
  */
 
 void		fpudna(struct cpu_info *);
-static int	x86fpflags_to_ksiginfo(uint32_t);
+
+/* 
+ * The following table is used to ensure that the FPE_... value
+ * that is passed as a trapcode to the signal handler of the user
+ * process does not have more than one bit set.
+ * 
+ * Multiple bits may be set if SSE simd instructions generate errors
+ * on more than one value or if the user process modifies the control
+ * word while a status word bit is already set (which this is a sign
+ * of bad coding).
+ * We have no choise than to narrow them down to one bit, since we must
+ * not send a trapcode that is not exactly one of the FPE_ macros.
+ *
+ * The mechanism has a static table with 127 entries.  Each combination
+ * of the 7 FPU status word exception bits directly translates to a
+ * position in this table, where a single FPE_... value is stored.
+ * This FPE_... value stored there is considered the "most important"
+ * of the exception bits and will be sent as the signal code.  The
+ * precedence of the bits is based upon Intel Document "Numerical
+ * Applications", Chapter "Special Computational Situations".
+ *
+ * The code to choose one of these values does these steps:
+ * 1) Throw away status word bits that cannot be masked.
+ * 2) Throw away the bits currently masked in the control word,
+ *assuming the user isn't interested in them anymore.
+ * 3) Reinsert status word bit 7 (stack fault) if it is set, which
+ *cannot be masked but must be presered.
+ *'Stack fault' is a sub-class of 'invalid operation'.
+ * 4) Use the remaining bits to point into the trapcode table.
+ *
+ * The 6 maskable bits in order of their preference, as stated in the
+ * above referenced Intel manual:
+ * 1  Invalid operation (FP_X_INV)
+ * 1a   Stack underflow
+ * 1b   Stack overflow
+ * 1c   Operand of unsupported format
+ * 1d   SNaN operand.
+ * 2  QNaN operand (not an exception, irrelavant here)
+ * 3  Any other invalid-operation not mentioned above or zero divide
+ *  (FP_X_INV, FP_X_DZ)
+ * 4  Denormal operand (FP_X_DNML)
+ * 5  Numeric over/underflow (FP_X_OFL, FP_X_UFL)
+ * 6  Inexact result (FP_X_IMP) 
+ *
+ * NB: the above seems to mix up the mxscr error bits and the x87 ones.
+ * They are in the same order, but there is no EN_SW_STACK_FAULT in the mmx
+ * status.
+ *
+ * The table is nearly, but not quite, in bit order (ZERODIV and DENORM
+ * are swapped).
+ *
+ * This table assumes that any stack fault is cleared - so that an INVOP
+ * fault will only be reported as FLTSUB once.
+ * This might not happen if the mask is being changed.
+ */
+#define FPE_xxx1(f) (f & EN_SW_INVOP \
+		? (f & EN_SW_STACK_FAULT ? FPE_FLTSUB : FPE_FLTINV) \
+	: f & EN_SW_ZERODIV ? FPE_FLTDIV \
+	: f & EN_SW_DENORM ? FPE_FLTUND \
+	: f & EN_SW_OVERFLOW ? FPE_FLTOVF \
+	: f & EN_SW_UNDERFLOW ? FPE_FLTUND \
+	: f & EN_SW_PRECLOSS ? FPE_FLTRES \
+	: f & EN_SW_STACK_FAULT ? FPE_FLTSUB : 0)
+#define	FPE_xxx2(f)	FPE_xxx1(f),	FPE_xxx1((f + 1))
+#define	FPE_xxx4(f)	FPE_xxx2(f),	FPE_xxx2((f + 2))
+#define	FPE_xxx8(f)	FPE_xxx4(f),	FPE_xxx4((f + 4))
+#define	FPE_xxx16(f)	FPE_xxx8(f),	FPE_xxx8((f + 8))
+#define	FPE_xxx32(f)	FPE_xxx16(f),	FPE_xxx16((f + 16))
+static const uint8_t fpetable[128] = {
+	FPE_xxx32(0), FPE_xxx32(32), FPE_xxx32(64), FPE_xxx32(96)
+};
+#undef FPE_xxx1
+#undef FPE_xxx2
+#undef FPE_xxx4
+#undef FPE_xxx8
+#undef FPE_xxx16
+#undef FPE_xxx32
 
 /*
  * Init the FPU.
@@ -225,33 +301,11 @@ fputrap(struct trapframe *frame)
 	KSI_INIT_TRAP(&ksi);
 	ksi.ksi_signo = SIGFPE;
 	ksi.ksi_addr = (void *)frame->tf_rip;
-	ksi.ksi_code = x86fpflags_to_ksiginfo(statbits);
+	ksi.ksi_code = fpetable[statbits & 0

CVS commit: src/sys/arch/amd64/amd64

2014-02-09 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Feb  9 22:19:02 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: fpu.c

Log Message:
Simplify fputrap() considerably.
There is no need to save the fpu state here, and definitely no need
  to initialise the fpu.
The code is running with interrupts disabled having trapped on either
  an x87 instruction (the one after the one that generated the error)
  or on an SSE (etc) instruction that caused the error.
So all it needs to do it obtain the 'error' bits from the relevant
  status register, clear the bits, and then raise any signal.
The signal code will save the fp state if the signal itself isn't masked.
It also passes the FP state to the signal handler - which can modify it.
(I suspect that wasn't thecase when this code was written.)
Seems to work for both 64bit and 32bit 'divide by zero' errors.
For the xmm trap, the xmm registers are updated for the result of the
  instruction, but the trap returns to re-execute the instruction!
This makes it difficult for the signal handler to do anything sensible.

I've also changed the code to only use unmasked error bits when deciding
the signal code.


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/amd64/amd64/fpu.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/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.46 src/sys/arch/amd64/amd64/fpu.c:1.47
--- src/sys/arch/amd64/amd64/fpu.c:1.46	Fri Feb  7 22:40:22 2014
+++ src/sys/arch/amd64/amd64/fpu.c	Sun Feb  9 22:19:02 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.46 2014/02/07 22:40:22 dsl Exp $	*/
+/*	$NetBSD: fpu.c,v 1.47 2014/02/09 22:19:02 dsl Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46 2014/02/07 22:40:22 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.47 2014/02/09 22:19:02 dsl Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -110,12 +110,8 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
 #include 
 
-#include 
 #include 
 #include 
 #include 
@@ -124,11 +120,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.46
 #include 
 #include 
 
-#ifndef XEN
-#include 
-#include 
-#endif
-
 #ifdef XEN
 #define clts() HYPERVISOR_fpu_taskswitch(0)
 #define stts() HYPERVISOR_fpu_taskswitch(1)
@@ -167,55 +158,76 @@ fpuinit(struct cpu_info *ci)
 }
 
 /*
- * Record the FPU state and reinitialize it all except for the control word.
- * Then generate a SIGFPE.
+ * This is a synchronous trap on either an x87 instruction (due to an
+ * unmasked error on the previous x87 instruction) or on an SSE/SSE2 etc
+ * instruction due to an error on the instruction itself.
+ *
+ * If trap actually generates a signal, then the fpu state is saved
+ * and then copied onto the process's user-stack, and then recovered
+ * from there when the signal returns (or from the jmp_buf if the
+ * signal handler exits with a longjmp()).
+ *
+ * All this code need to do is save the reason for the trap.
+ * For x87 interrupts the status word bits need clearing to stop the
+ * trap re-occurring.
+ *
+ * The mxcsr bits are 'sticky' and need clearing to not confuse a later trap.
+ *
+ * Since this is a synchronous trap, the fpu registers must still belong
+ * to the correct process (we trap through an interrupt gate so that
+ * interrupts are disabled on entry).
+ * Interrupts (these better include IPIs) are left disabled until we've
+ * finished looking at fpu registers.
  *
- * Reinitializing the state allows naive SIGFPE handlers to longjmp without
- * doing any fixups.
+ * For amd64 the calling code (in amd64_trap.S) has already checked
+ * that we trapped from usermode.
  */
 
 void
 fputrap(struct trapframe *frame)
 {
-	struct lwp *l = curlwp;
-	struct pcb *pcb = lwp_getpcb(l);
-	union savefpu *sfp = &pcb->pcb_savefpu;
-	uint32_t mxcsr, statbits;
+	uint32_t statbits;
 	ksiginfo_t ksi;
 
-	KPREEMPT_DISABLE(l);
-	x86_enable_intr();
-
 	/*
 	 * At this point, fpcurlwp should be curlwp.  If it wasn't, the TS bit
 	 * should be set, and we should have gotten a DNA exception.
 	 */
-	KASSERT(l == curlwp);
-	fxsave(sfp);
+	KASSERT(curcpu()->ci_fpcurlwp == curlwp);
 
 	if (frame->tf_trapno == T_XMM) {
-		mxcsr = sfp->sv_xmm.fx_mxcsr;
+		uint32_t mxcsr;
+		x86_stmxcsr(&mxcsr);
 		statbits = mxcsr;
+		/* Clear the sticky status bits */
 		mxcsr &= ~0x3f;
 		x86_ldmxcsr(&mxcsr);
+
+		/* Remove masked interrupts and non-status bits */
+		statbits &= ~(statbits >> 7) & 0x3f;
+		/* Mark this is an XMM status */
+		statbits |= 0x1;
 	} else {
-		uint16_t cw;
+		uint16_t cw, sw;
+		/* Get current control and status words */
+		fnstcw(&cw);
+		fnstsw(&sw);
+		/* Clear any pending exceptions from status word */
+		fnclex();
 
-		fninit();
-		fwait();
-		cw = sfp->sv_xmm.fx_cw;
-		fldcw(&cw);
-		fwait()

CVS commit: src/sys/arch/amd64/amd64

2014-02-09 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Feb  9 19:42:04 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S

Log Message:
Best if x86_stmxcsr executes stmxcsr.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/amd64/cpufunc.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/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.23 src/sys/arch/amd64/amd64/cpufunc.S:1.24
--- src/sys/arch/amd64/amd64/cpufunc.S:1.23	Sun Feb  9 17:07:41 2014
+++ src/sys/arch/amd64/amd64/cpufunc.S	Sun Feb  9 19:42:04 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.23 2014/02/09 17:07:41 dsl Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.24 2014/02/09 19:42:04 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -505,7 +505,7 @@ ENTRY(xrstor)
 	ret
 
 ENTRY(x86_stmxcsr)
-	ldmxcsr	(%rdi)
+	stmxcsr	(%rdi)
 	ret
 
 ENTRY(x86_ldmxcsr)



CVS commit: src/sys/arch/amd64/amd64

2014-01-11 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Jan 11 19:31:47 UTC 2014

Modified Files:
src/sys/arch/amd64/amd64: mptramp.S

Log Message:
remove unused and undefined .globl


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/amd64/amd64/mptramp.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/mptramp.S
diff -u src/sys/arch/amd64/amd64/mptramp.S:1.15 src/sys/arch/amd64/amd64/mptramp.S:1.16
--- src/sys/arch/amd64/amd64/mptramp.S:1.15	Sat Jun 22 13:09:07 2013
+++ src/sys/arch/amd64/amd64/mptramp.S	Sat Jan 11 19:31:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mptramp.S,v 1.15 2013/06/22 13:09:07 uebayasi Exp $	*/
+/*	$NetBSD: mptramp.S,v 1.16 2014/01/11 19:31:47 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -114,8 +114,6 @@
 	.global _C_LABEL(mp_pdirpa)
 	.global _C_LABEL(local_apic)
 
-	.globl	gdt64
-
 	.text
 	.align 4,0x0
 	.code16



CVS commit: src/sys/arch/amd64/amd64

2013-12-12 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Dec 12 22:41:03 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Since regs->fxstate is actually of type 'struct fxsave64' use a structure
  copy instead of a 'not obviously incorrect' memcpy().


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/amd64/process_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/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.23 src/sys/arch/amd64/amd64/process_machdep.c:1.24
--- src/sys/arch/amd64/amd64/process_machdep.c:1.23	Sun Dec  1 01:05:16 2013
+++ src/sys/arch/amd64/amd64/process_machdep.c	Thu Dec 12 22:41:03 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.23 2013/12/01 01:05:16 christos Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.24 2013/12/12 22:41:03 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.23 2013/12/01 01:05:16 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.24 2013/12/12 22:41:03 dsl Exp $");
 
 #include 
 #include 
@@ -130,7 +130,7 @@ process_read_fpregs(struct lwp *l, struc
 		l->l_md.md_flags |= MDL_USEDFPU;
 	}
 
-	memcpy(®s->fxstate, frame, sizeof(*regs));
+	regs->fxstate = *frame;
 	return (0);
 }
 



CVS commit: src/sys/arch/amd64/amd64

2013-11-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Nov  2 00:41:58 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
sprinkle __diagused


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.82 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.83
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.82	Wed Oct 23 16:18:50 2013
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Fri Nov  1 20:41:58 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.82 2013/10/23 20:18:50 drochner Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.83 2013/11/02 00:41:58 christos Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.82 2013/10/23 20:18:50 drochner Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.83 2013/11/02 00:41:58 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -956,7 +956,7 @@ startlwp32(void *arg)
 {
 	ucontext32_t *uc = arg;
 	lwp_t *l = curlwp;
-	int error;
+	int error __diagused;
 
 	error = cpu_setmcontext32(l, &uc->uc_mcontext, uc->uc_flags);
 	KASSERT(error == 0);



CVS commit: src/sys/arch/amd64/amd64

2013-10-27 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun Oct 27 16:25:01 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: fpu.c

Log Message:
- fpu_state_save() on amd64: ci->ci_fpsaving is no longer used, simplify.
- Remove some unnecessary header inclusions.  Misc clean up while here.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/fpu.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/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.41 src/sys/arch/amd64/amd64/fpu.c:1.42
--- src/sys/arch/amd64/amd64/fpu.c:1.41	Wed Oct 23 20:18:50 2013
+++ src/sys/arch/amd64/amd64/fpu.c	Sun Oct 27 16:25:01 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.41 2013/10/23 20:18:50 drochner Exp $	*/
+/*	$NetBSD: fpu.c,v 1.42 2013/10/27 16:25:01 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -95,24 +95,13 @@
  *	@(#)npx.c	7.2 (Berkeley) 5/12/91
  */
 
-/*
- * XXXfvdl update copyright notice. this started out as a stripped isa/npx.c
- */
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.41 2013/10/23 20:18:50 drochner Exp $");
-
-#include "opt_multiprocessor.h"
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.42 2013/10/27 16:25:01 rmind Exp $");
 
 #include 
 #include 
-#include 
 #include 
-#include 
 #include 
-#include 
-#include 
-#include 
 #include 
 
 #include 
@@ -134,7 +123,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.41
 #define stts() HYPERVISOR_fpu_taskswitch(1)
 #endif
 
-
 /*
  * We do lazy initialization and switching using the TS bit in cr0 and the
  * MDL_USEDFPU bit in mdlwp.
@@ -153,8 +141,8 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.41
  * state is saved.
  */
 
-void fpudna(struct cpu_info *);
-static int x86fpflags_to_ksiginfo(uint32_t);
+void		fpudna(struct cpu_info *);
+static int	x86fpflags_to_ksiginfo(uint32_t);
 
 /*
  * Init the FPU.
@@ -178,11 +166,10 @@ fpuinit(struct cpu_info *ci)
 void
 fputrap(struct trapframe *frame)
 {
-	register struct lwp *l = curlwp;
+	struct lwp *l = curlwp;
 	struct pcb *pcb = lwp_getpcb(l);
 	struct savefpu *sfp = &pcb->pcb_savefpu;
 	uint32_t mxcsr, statbits;
-	uint16_t cw;
 	ksiginfo_t ksi;
 
 	KPREEMPT_DISABLE(l);
@@ -198,6 +185,8 @@ fputrap(struct trapframe *frame)
 		mxcsr &= ~0x3f;
 		x86_ldmxcsr(&mxcsr);
 	} else {
+		uint16_t cw;
+
 		fninit();
 		fwait();
 		cw = sfp->fp_fxsave.fx_fcw;
@@ -218,7 +207,6 @@ fputrap(struct trapframe *frame)
 static int
 x86fpflags_to_ksiginfo(uint32_t flags)
 {
-	int i;
 	static int x86fp_ksiginfo_table[] = {
 		FPE_FLTINV, /* bit 0 - invalid operation */
 		FPE_FLTRES, /* bit 1 - denormal operand */
@@ -229,12 +217,13 @@ x86fpflags_to_ksiginfo(uint32_t flags)
 		FPE_FLTINV, /* bit 6 - stack fault	*/
 	};
 
-	for (i=0;i < sizeof(x86fp_ksiginfo_table)/sizeof(int); i++) {
-		if (flags & (1 << i))
-			return (x86fp_ksiginfo_table[i]);
+	for (u_int i = 0; i < __arraycount(x86fp_ksiginfo_table); i++) {
+		if (flags & (1U << i))
+			return x86fp_ksiginfo_table[i];
 	}
-	/* punt if flags not set */
-	return (FPE_FLTINV);
+
+	/* Punt if flags not set. */
+	return FPE_FLTINV;
 }
 
 /*
@@ -250,24 +239,23 @@ extern const pcu_ops_t fpu_ops;
 void
 fpudna(struct cpu_info *ci)
 {
-
 	pcu_load(&fpu_ops);
 }
 
-
 static void
 fpu_state_load(struct lwp *l, u_int flags)
 {
-	uint16_t cw;
-	uint32_t mxcsr;
-	struct pcb * const pcb = lwp_getpcb(l);
+	struct pcb *pcb = lwp_getpcb(l);
 
 	clts();
 	pcb->pcb_cr0 &= ~CR0_TS;
-	if (!(flags & PCU_RELOAD))
+	if ((flags & PCU_RELOAD) == 0)
 		return;
 
-	if (!(flags & PCU_LOADED)) {
+	if ((flags & PCU_LOADED) == 0) {
+		uint32_t mxcsr;
+		uint16_t cw;
+
 		fninit();
 		cw = pcb->pcb_savefpu.fp_fxsave.fx_fcw;
 		fldcw(&cw);
@@ -281,6 +269,7 @@ fpu_state_load(struct lwp *l, u_int flag
 		 */
 		static const double zero = 0.0;
 		int status;
+
 		/*
 		 * Clear the ES bit in the x87 status word if it is currently
 		 * set, in order to avoid causing a fault in the upcoming load.
@@ -288,6 +277,7 @@ fpu_state_load(struct lwp *l, u_int flag
 		fnstsw(&status);
 		if (status & 0x80)
 			fnclex();
+
 		/*
 		 * Load the dummy variable into the x87 stack.  This mangles
 		 * the x87 stack, but we don't care since we're about to call
@@ -301,26 +291,16 @@ fpu_state_load(struct lwp *l, u_int flag
 static void
 fpu_state_save(struct lwp *l, u_int flags)
 {
-	struct cpu_info *ci;
-	struct pcb * const pcb = lwp_getpcb(l);
+	struct pcb *pcb = lwp_getpcb(l);
 
-	ci = curcpu();
-	/*
-	 * Set ci->ci_fpsaving, so that any pending exception will
-	 * be thrown away.  It will be caught again if/when the
-	 * FPU state is restored.
-	 */
-	KASSERT(ci->ci_fpsaving == 0);
 	clts();
-	ci->ci_fpsaving = 1;
 	fxsave(&pcb->pcb_savefpu);
-	ci->ci_fpsaving = 0;
 }
 
 static void
 fpu_state_release(struct lwp *l, u_int flags)
 {
-	struct pcb * const pcb = lwp_getpcb(l);
+	struct pcb *pcb = lwp_getpcb(l);
 
 	stts();
 	pcb->pcb_cr0 |= CR0_TS;



CVS commit: src/sys/arch/amd64/amd64

2013-10-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Oct 17 20:57:58 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
remove unused variable, and move variable used only by XEN in the XEN ifdef.


To generate a diff of this commit:
cvs rdiff -u -r1.195 -r1.196 src/sys/arch/amd64/amd64/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.195 src/sys/arch/amd64/amd64/machdep.c:1.196
--- src/sys/arch/amd64/amd64/machdep.c:1.195	Wed Jun  5 10:37:04 2013
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Oct 17 16:57:58 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.195 2013/06/05 14:37:04 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.196 2013/10/17 20:57:58 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.195 2013/06/05 14:37:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.196 2013/10/17 20:57:58 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1051,7 +1051,6 @@ cpu_dump_mempagecnt(void)
 int
 cpu_dump(void)
 {
-	int (*dump)(dev_t, daddr_t, void *, size_t);
 	kcore_seg_t seg;
 	cpu_kcore_hdr_t cpuhdr;
 	const struct bdevsw *bdev;
@@ -1060,8 +1059,6 @@ cpu_dump(void)
 	if (bdev == NULL)
 		return (ENXIO);
 
-	dump = bdev->d_dump;
-
 	/*
 	 * Generate a segment header.
 	 */
@@ -1567,7 +1564,6 @@ init_x86_64(paddr_t first_avail)
 	extern void consinit(void);
 	struct region_descriptor region;
 	struct mem_segment_descriptor *ldt_segp;
-	struct pcb *pcb;
 	int x;
 #ifndef XEN
 	int ist;
@@ -1588,11 +1584,11 @@ init_x86_64(paddr_t first_avail)
 
 	cpu_init_msrs(&cpu_info_primary, true);
 
-	pcb = lwp_getpcb(&lwp0);
 
 	use_pae = 1; /* PAE always enabled in long mode */
 
 #ifdef XEN
+	struct pcb *pcb = lwp_getpcb(&lwp0);
 	mutex_init(&pte_lock, MUTEX_DEFAULT, IPL_VM);
 	pcb->pcb_cr3 = xen_start_info.pt_base - KERNBASE;
 	__PRINTK(("pcb_cr3 0x%lx\n", xen_start_info.pt_base - KERNBASE));



CVS commit: src/sys/arch/amd64/amd64

2013-10-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 16 18:07:56 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: gdt.c

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/amd64/gdt.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/gdt.c
diff -u src/sys/arch/amd64/amd64/gdt.c:1.24 src/sys/arch/amd64/amd64/gdt.c:1.25
--- src/sys/arch/amd64/amd64/gdt.c:1.24	Tue Jul  6 21:14:52 2010
+++ src/sys/arch/amd64/amd64/gdt.c	Wed Oct 16 14:07:56 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.24 2010/07/07 01:14:52 chs Exp $	*/
+/*	$NetBSD: gdt.c,v 1.25 2013/10/16 18:07:56 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.24 2010/07/07 01:14:52 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.25 2013/10/16 18:07:56 christos Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -300,9 +300,6 @@ tss_alloc(struct x86_64_tss *tss)
 {
 #ifndef XEN
 	int slot;
-	struct sys_segment_descriptor *gdt;
-
-	gdt = (struct sys_segment_descriptor *)&gdtstore[DYNSEL_START];
 
 	mutex_enter(&cpu_lock);
 	slot = gdt_get_slot();



CVS commit: src/sys/arch/amd64/amd64

2013-06-25 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue Jun 25 21:08:07 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Improve the dodgy code that writes the FP regs into core dumps of 32bit apps.
(I'm not pretending it is correct yet!)
The 'struct fpreg32' (written to coredumps) is shorter than 'struct save87'
so netbsd32_process_read_fpregs() hadn't better write to the extra items.
Doing so overwrites stack in coredump_note() in core_elf32.c - I'm amazed
it doesn't cause a panic!
Also correct (I think) the code and data addresses associated with the FP
unit.
This probably wants pulling up.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.80 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.81
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.80	Mon Dec 31 16:20:17 2012
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue Jun 25 21:08:07 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.80 2012/12/31 16:20:17 dsl Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.81 2013/06/25 21:08:07 dsl Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.80 2012/12/31 16:20:17 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.81 2013/06/25 21:08:07 dsl Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -567,11 +567,27 @@ xmm_to_s87_tag(const uint8_t *fpac, int 
 int
 netbsd32_process_read_fpregs(struct lwp *l, struct fpreg32 *regs)
 {
-	struct pcb *pcb = lwp_getpcb(l);
 	struct fpreg regs64;
 	struct save87 *s87 = (struct save87 *)regs;
 	int error, i;
 
+	union fp_addr {
+	uint64_t fa_64; /* Linear address for 64bit systems */
+	struct {
+	uint32_t fa_off;/* Linear address for 32 bit */
+	uint16_t fa_seg;/* Code/data (etc) segment */
+	uint16_t fa_pad;
+	} fa_32; 
+	} fa;
+
+	/* 
+	 * NOTE: This 'struct fpreg32' is just char[108] and is shorter
+	 * than 'struct save87'.
+	 * If we write to the extra fields we trash the stack when writing
+	 * process coredumps (see coredump_note() in core_elf32.c).
+	 * This code must not set sv_env.en_tw or s87->sv_ex_sw.
+	 */
+
 	/*
 	 * All that stuff makes no sense in i386 code :(
 	 */
@@ -582,29 +598,24 @@ netbsd32_process_read_fpregs(struct lwp 
 
 	s87->sv_env.en_cw = regs64.fxstate.fx_fcw;
 	s87->sv_env.en_sw = regs64.fxstate.fx_fsw;
-	s87->sv_env.en_fip = regs64.fxstate.fx_rip >> 16; /* XXX Order? */
-	s87->sv_env.en_fcs = regs64.fxstate.fx_rip & 0x;
+	fa.fa_64 = regs64.fxstate.fx_rip;
+	s87->sv_env.en_fip = fa.fa_32.fa_off;
+	s87->sv_env.en_fcs = fa.fa_32.fa_seg;
 	s87->sv_env.en_opcode = regs64.fxstate.fx_fop;
-	s87->sv_env.en_foo = regs64.fxstate.fx_rdp >> 16; /* XXX See above */
-	s87->sv_env.en_fos = regs64.fxstate.fx_rdp & 0x;
+	fa.fa_64 = regs64.fxstate.fx_rdp;
+	s87->sv_env.en_foo = fa.fa_32.fa_off;
+	s87->sv_env.en_fos = fa.fa_32.fa_seg;
 
 	s87->sv_env.en_tw = 0;
-	s87->sv_ex_tw = 0;
 	for (i = 0; i < 8; i++) {
 		s87->sv_env.en_tw |=
 		(xmm_to_s87_tag((uint8_t *)®s64.fxstate.fx_st[i][0], i,
 		 regs64.fxstate.fx_ftw) << (i * 2));
 
-		s87->sv_ex_tw |=
-		(xmm_to_s87_tag((uint8_t *)®s64.fxstate.fx_st[i][0], i,
-		 pcb->pcb_savefpu_i387.fp_ex_tw) << (i * 2));
-
 		memcpy(&s87->sv_ac[i].fp_bytes, ®s64.fxstate.fx_st[i][0],
 		sizeof(s87->sv_ac[i].fp_bytes));
 	}
 
-	s87->sv_ex_sw = pcb->pcb_savefpu_i387.fp_ex_sw;
-
 	return (0);
 }
 



CVS commit: src/sys/arch/amd64/amd64

2013-06-21 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Sat Jun 22 06:23:28 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: lock_stubs.S

Log Message:
Use END() to set ELF symbol size.  Set local data type/size too.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/amd64/lock_stubs.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/lock_stubs.S
diff -u src/sys/arch/amd64/amd64/lock_stubs.S:1.24 src/sys/arch/amd64/amd64/lock_stubs.S:1.25
--- src/sys/arch/amd64/amd64/lock_stubs.S:1.24	Wed Jan 12 23:12:11 2011
+++ src/sys/arch/amd64/amd64/lock_stubs.S	Sat Jun 22 06:23:28 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: lock_stubs.S,v 1.24 2011/01/12 23:12:11 joerg Exp $	*/
+/*	$NetBSD: lock_stubs.S,v 1.25 2013/06/22 06:23:28 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,6 +68,7 @@ ENTRY(mutex_enter)
 	RET(1)
 1:
 	jmp	_C_LABEL(mutex_vector_enter)
+END(mutex_enter)
 
 /*
  * void mutex_exit(kmutex_t *mtx);
@@ -86,6 +87,7 @@ ENTRY(mutex_exit)
 	ret
 1:
 	jmp	_C_LABEL(mutex_vector_exit)
+END(mutex_exit)
 
 /*
  * void mutex_spin_enter(kmutex_t *mtx);
@@ -110,6 +112,7 @@ ENTRY(mutex_spin_enter)
 	RET(2)
 1:
 	jmp	_C_LABEL(mutex_spin_retry)	/* failed; hard case */
+END(mutex_spin_enter)
 
 /*
  * void mutex_spin_exit(kmutex_t *mtx);
@@ -167,6 +170,8 @@ ENTRY(mutex_spin_exit)
 
 #endif	/* DIAGNOSTIC */
 
+END(mutex_spin_exit)
+
 /*
  * void	rw_enter(krwlock_t *rwl, krw_t op);
  *
@@ -203,6 +208,7 @@ ENTRY(rw_enter)
 	RET(4)
 3:
 	jmp	_C_LABEL(rw_vector_enter)
+END(rw_enter)
 
 /*
  * void	rw_exit(krwlock_t *rwl);
@@ -241,6 +247,7 @@ ENTRY(rw_exit)
 	ret
 
 3:	jmp	_C_LABEL(rw_vector_exit)
+END(rw_exit)
 
 /*
  * int	rw_tryenter(krwlock_t *rwl, krw_t op);
@@ -283,6 +290,7 @@ ENTRY(rw_tryenter)
 4:
 	xorl	%eax, %eax
 	jmp	3b
+END(rw_tryenter)
 
 #endif	/* LOCKDEBUG */
 
@@ -292,6 +300,7 @@ ENTRY(rw_tryenter)
 ENTRY(__cpu_simple_lock_init)
 	movb	$0, (%rdi)
 	ret
+END(__cpu_simple_lock_init)
 
 NENTRY(__cpu_simple_lock)
 	movl	$0x0100, %eax
@@ -308,10 +317,12 @@ NENTRY(__cpu_simple_lock)
 	cmpb	$0, (%rdi)
 	je	1b
 	jmp	2b
+END(__cpu_simple_lock)
 
 ENTRY(__cpu_simple_unlock)
 	movb	$0, (%rdi)
 	ret
+END(__cpu_simple_unlock)
 
 ENTRY(__cpu_simple_lock_try)
 	movl	$0x0100, %eax
@@ -320,21 +331,26 @@ ENTRY(__cpu_simple_lock_try)
 	movl	$0, %eax
 	setz	%al
 	RET(8)
+END(__cpu_simple_lock_try)
 
 /*
  * Patchpoints to replace with NOP when ncpu == 1.
  */
 #ifndef LOCKDEBUG
+	.type	_C_LABEL(x86_lockpatch), @object
 LABEL(x86_lockpatch)
 	.quad	.Lpatch1, .Lpatch2, .Lpatch3, .Lpatch4
 	.quad	.Lpatch5, .Lpatch6, .Lpatch7, .Lpatch8
 	.quad	.Lpatch9
 	.quad	0
+END(x86_lockpatch)
 #endif
 
+	.type	_C_LABEL(x86_retpatch), @object
 LABEL(x86_retpatch)
 #ifndef LOCKDEBUG
 	.quad	.Lret1, .Lret2, .Lret3, .Lret4, .Lret5, .Lret6
 #endif
 	.quad	.Lret7, .Lret8
 	.quad	0
+END(x86_retpatch)



CVS commit: src/sys/arch/amd64/amd64

2013-06-21 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Sat Jun 22 05:56:32 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: cpu_in_cksum.S

Log Message:
Use END() to set ELF symbol size.  Set local string type/size too.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amd64/amd64/cpu_in_cksum.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/cpu_in_cksum.S
diff -u src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.1 src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.2
--- src/sys/arch/amd64/amd64/cpu_in_cksum.S:1.1	Fri Jan 25 21:12:10 2008
+++ src/sys/arch/amd64/amd64/cpu_in_cksum.S	Sat Jun 22 05:56:32 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_in_cksum.S,v 1.1 2008/01/25 21:12:10 joerg Exp $ */
+/* $NetBSD: cpu_in_cksum.S,v 1.2 2013/06/22 05:56:32 uebayasi Exp $ */
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger .
@@ -289,7 +289,10 @@ ENTRY(cpu_in_cksum)
 	movl	$0, %eax
 	call	_C_LABEL(printf)
 	jmp	.Mreturn
+END(cpu_in_cksum)
 
 	.section	.rodata
+	.type		.Mout_of_mbufs_msg, @object
 .Mout_of_mbufs_msg:
 	.string		"in_cksum: out of data\n"
+END(.Mout_of_mbufs_msg)



CVS commit: src/sys/arch/amd64/amd64

2013-06-21 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Sat Jun 22 02:33:44 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: amd64func.S

Log Message:
Use END() to set ELF symbol size.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/amd64/amd64func.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/amd64func.S
diff -u src/sys/arch/amd64/amd64/amd64func.S:1.6 src/sys/arch/amd64/amd64/amd64func.S:1.7
--- src/sys/arch/amd64/amd64/amd64func.S:1.6	Sat May 10 16:12:32 2008
+++ src/sys/arch/amd64/amd64/amd64func.S	Sat Jun 22 02:33:44 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: amd64func.S,v 1.6 2008/05/10 16:12:32 ad Exp $	*/
+/*	$NetBSD: amd64func.S,v 1.7 2013/06/22 02:33:44 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -47,3 +47,4 @@ ENTRY(tsc_get_timecount)
 	ret
 2:
 	jmp	1b
+END(tsc_get_timecount)



CVS commit: src/sys/arch/amd64/amd64

2013-06-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun  5 14:37:04 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
declaring mtrr_funcs once should be enough.


To generate a diff of this commit:
cvs rdiff -u -r1.194 -r1.195 src/sys/arch/amd64/amd64/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.194 src/sys/arch/amd64/amd64/machdep.c:1.195
--- src/sys/arch/amd64/amd64/machdep.c:1.194	Fri Apr 12 12:59:40 2013
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Jun  5 10:37:04 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.194 2013/04/12 16:59:40 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.195 2013/06/05 14:37:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.194 2013/04/12 16:59:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.195 2013/06/05 14:37:04 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -291,10 +291,6 @@ void (*initclock_func)(void) = xen_initc
 #endif
 
 
-#ifdef MTRR
-struct mtrr_funcs *mtrr_funcs;
-#endif
-
 /*
  * Size of memory segments, before any memory is stolen.
  */



CVS commit: src/sys/arch/amd64/amd64

2013-04-02 Thread Takahiro Kambe
Module Name:src
Committed By:   taca
Date:   Tue Apr  2 13:28:42 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Use printf_nolog() as i386 when print remaing bytes at crash dump to
prevent message buffer with cound down.


To generate a diff of this commit:
cvs rdiff -u -r1.192 -r1.193 src/sys/arch/amd64/amd64/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.192 src/sys/arch/amd64/amd64/machdep.c:1.193
--- src/sys/arch/amd64/amd64/machdep.c:1.192	Sat Jan 12 16:56:11 2013
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Apr  2 13:28:41 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.192 2013/01/12 16:56:11 chs Exp $	*/
+/*	$NetBSD: machdep.c,v 1.193 2013/04/02 13:28:41 taca Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.192 2013/01/12 16:56:11 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.193 2013/04/02 13:28:41 taca Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1197,7 +1197,7 @@ dumpsys_seg(paddr_t maddr, paddr_t bytes
 	for (i = 0; i < bytes; i += n, dump_totalbytesleft -= n) {
 		/* Print out how many MBs we have left to go. */
 		if ((dump_totalbytesleft % (1024*1024)) == 0)
-			printf("%lu ", (unsigned long)
+			printf_nolog("%lu ", (unsigned long)
 			(dump_totalbytesleft / (1024 * 1024)));
 
 		/* Limit size for next transfer. */



CVS commit: src/sys/arch/amd64/amd64

2013-01-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jan 14 00:06:12 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
print the lid too.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 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.74 src/sys/arch/amd64/amd64/trap.c:1.75
--- src/sys/arch/amd64/amd64/trap.c:1.74	Tue Aug 28 11:54:40 2012
+++ src/sys/arch/amd64/amd64/trap.c	Sun Jan 13 19:06:11 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.74 2012/08/28 15:54:40 christos Exp $	*/
+/*	$NetBSD: trap.c,v 1.75 2013/01/14 00:06:11 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.74 2012/08/28 15:54:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.75 2013/01/14 00:06:11 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -199,7 +199,7 @@ trap_print(const struct trapframe *frame
 	type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs,
 	frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, frame->tf_rsp);
 
-	printf("curlwp %p pid %d lid %d lowest kstack %p\n",
+	printf("curlwp %p pid %d.%d lowest kstack %p\n",
 	l, l->l_proc->p_pid, l->l_lid, KSTACK_LOWEST_ADDR(l));
 }
 
@@ -390,8 +390,8 @@ kernelfault:
 	case T_STKFLT|T_USER:
 	case T_ALIGNFLT|T_USER:
 #ifdef TRAP_SIGDEBUG
-		printf("pid %d (%s): BUS/SEGV (%x) at rip %lx addr %lx\n",
-		p->p_pid, p->p_comm, type, frame->tf_rip, rcr2());
+		printf("pid %d.%d (%s): BUS/SEGV (%x) at rip %lx addr %lx\n",
+		p->p_pid, l->l_lid, p->p_comm, type, frame->tf_rip, rcr2());
 		frame_dump(frame);
 #endif
 		KSI_INIT_TRAP(&ksi);
@@ -424,8 +424,8 @@ kernelfault:
 	case T_PRIVINFLT|T_USER:	/* privileged instruction fault */
 	case T_FPOPFLT|T_USER:		/* coprocessor operand fault */
 #ifdef TRAP_SIGDEBUG
-		printf("pid %d (%s): ILL at rip %lx addr %lx\n",
-		p->p_pid, p->p_comm, frame->tf_rip, rcr2());
+		printf("pid %d.%d (%s): ILL at rip %lx addr %lx\n",
+		p->p_pid, l->l_lid, p->p_comm, frame->tf_rip, rcr2());
 		frame_dump(frame);
 #endif
 		KSI_INIT_TRAP(&ksi);
@@ -463,8 +463,8 @@ kernelfault:
 
 #if 0 /* handled by fpudna() */
 	case T_DNA|T_USER: {
-		printf("pid %d killed due to lack of floating point\n",
-		p->p_pid);
+		printf("pid %d.%d killed due to lack of floating point\n",
+		p->p_pid, l->l_lid);
 		KSI_INIT_TRAP(&ksi);
 		ksi.ksi_signo = SIGKILL;
 		ksi.ksi_trap = type & ~T_USER;
@@ -639,14 +639,14 @@ faultcommon:
 		}
 		if (error == ENOMEM) {
 			ksi.ksi_signo = SIGKILL;
-			printf("UVM: pid %d (%s), uid %d killed: out of swap\n",
-			   p->p_pid, p->p_comm,
+			printf("UVM: pid %d.%d (%s), uid %d killed: out of swap\n",
+			   p->p_pid, l->l_lid, p->p_comm,
 			   l->l_cred ?
 			   kauth_cred_geteuid(l->l_cred) : -1);
 		} else {
 #ifdef TRAP_SIGDEBUG
-			printf("pid %d (%s): SEGV at rip %lx addr %lx\n",
-			p->p_pid, p->p_comm, frame->tf_rip, va);
+			printf("pid %d.%d (%s): SEGV at rip %lx addr %lx\n",
+			p->p_pid, l->l_lid, p->p_comm, frame->tf_rip, va);
 			frame_dump(frame);
 #endif
 			ksi.ksi_signo = SIGSEGV;



CVS commit: src/sys/arch/amd64/amd64

2013-01-12 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sat Jan 12 16:56:11 UTC 2013

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
enable sparse dumps by default.


To generate a diff of this commit:
cvs rdiff -u -r1.191 -r1.192 src/sys/arch/amd64/amd64/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.191 src/sys/arch/amd64/amd64/machdep.c:1.192
--- src/sys/arch/amd64/amd64/machdep.c:1.191	Tue Nov 13 14:09:36 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Jan 12 16:56:11 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.191 2012/11/13 14:09:36 chs Exp $	*/
+/*	$NetBSD: machdep.c,v 1.192 2013/01/12 16:56:11 chs Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.191 2012/11/13 14:09:36 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.192 2013/01/12 16:56:11 chs Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -238,7 +238,7 @@ int	cpu_class;
 int	use_pae;
 
 #ifndef NO_SPARSE_DUMP
-int sparse_dump = 0;
+int sparse_dump = 1;
 
 paddr_t max_paddr = 0;
 unsigned char *sparse_dump_physmap;



CVS commit: src/sys/arch/amd64/amd64

2012-11-13 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Tue Nov 13 14:09:36 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
fix sparse crash dumps to contain enough data to be useful,
in particular the top-level page table pages.
use pmap_kremove_local() while writing crash dumps
to avoid spurious warning messages.


To generate a diff of this commit:
cvs rdiff -u -r1.190 -r1.191 src/sys/arch/amd64/amd64/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.190 src/sys/arch/amd64/amd64/machdep.c:1.191
--- src/sys/arch/amd64/amd64/machdep.c:1.190	Mon Sep  3 05:01:44 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Nov 13 14:09:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.191 2012/11/13 14:09:36 chs Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.191 2012/11/13 14:09:36 chs Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -317,7 +317,7 @@ int dump_seg_iter(int (*)(paddr_t, paddr
 
 #ifndef NO_SPARSE_DUMP
 void sparse_dump_reset(void);
-void sparse_dump_mark(vaddr_t, vaddr_t, int);
+void sparse_dump_mark(void);
 void cpu_dump_prep_sparse(void);
 #endif
 
@@ -821,7 +821,7 @@ haltsys:
  * XXXfvdl share dumpcode.
  */
 
- /*
+/*
  * Perform assorted dump-related initialization tasks.  Assumes that
  * the maximum physical memory address will not increase afterwards.
  */
@@ -873,34 +873,39 @@ sparse_dump_reset(void)
 }
 
 /*
- * Include or exclude pages in a sparse dump, by half-open virtual
- * address interval (which may wrap around the end of the space).
+ * Include or exclude pages in a sparse dump.
  */
 void
-sparse_dump_mark(vaddr_t vbegin, vaddr_t vend, int includep)
+sparse_dump_mark(void)
 {
-	pmap_t pmap;
-	paddr_t p;
-	vaddr_t v;
+	paddr_t p, pstart, pend;
+	struct vm_page *pg;
+	int i;
 
 	/*
-	 * If a partial page is called for, the whole page must be included.
+	 * Mark all memory pages, then unmark pages that are uninteresting.
+	 * Dereferenceing pg->uobject might crash again if another CPU
+	 * frees the object out from under us, but we can't lock anything
+	 * so it's a risk we have to take.
 	 */
-	if (includep) {
-		vbegin = rounddown(vbegin, PAGE_SIZE);
-		vend = roundup(vend, PAGE_SIZE);
-	} else {
-		vbegin = roundup(vbegin, PAGE_SIZE);
-		vend = rounddown(vend, PAGE_SIZE);
+
+	for (i = 0; i < mem_cluster_cnt; ++i) {
+		pstart = mem_clusters[i].start / PAGE_SIZE;
+		pend = pstart + mem_clusters[i].size / PAGE_SIZE;
+
+		for (p = pstart; p < pend; p++) {
+			setbit(sparse_dump_physmap, p);
+		}
 	}
+	for (i = 0; i < vm_nphysseg; i++) {
+		struct vm_physseg *seg = VM_PHYSMEM_PTR(i);
 
-	pmap = pmap_kernel();
-	for (v = vbegin; v != vend; v += PAGE_SIZE) {
-		if (pmap_extract(pmap, v, &p)) {
-			if (includep)
-setbit(sparse_dump_physmap, p/PAGE_SIZE);
-			else
-clrbit(sparse_dump_physmap, p/PAGE_SIZE);
+		for (pg = seg->pgs; pg < seg->lastpg; pg++) {
+			if (pg->uanon || (pg->pqflags & PQ_FREE) ||
+			(pg->uobject && pg->uobject->pgops)) {
+p = VM_PAGE_TO_PHYS(pg) / PAGE_SIZE;
+clrbit(sparse_dump_physmap, p);
+			}
 		}
 	}
 }
@@ -914,7 +919,7 @@ cpu_dump_prep_sparse(void)
 {
 	sparse_dump_reset();
 	/* XXX could the alternate recursive page table be skipped? */
-	sparse_dump_mark((vaddr_t)PTE_BASE, (vaddr_t)KERN_BASE, 1);
+	sparse_dump_mark();
 	/* Memory for I/O buffers could be unmarked here, for example. */
 	/* The kernel text could also be unmarked, but gdb would be upset. */
 }
@@ -1206,6 +1211,7 @@ dumpsys_seg(paddr_t maddr, paddr_t bytes
 		pmap_update(pmap_kernel());
 
 		error = (*dump)(dumpdev, blkno, (void *)dumpspace, n);
+		pmap_kremove_local(dumpspace, n);
 		if (error)
 			return error;
 		maddr += n;



CVS commit: src/sys/arch/amd64/amd64

2012-11-07 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Thu Nov  8 02:00:44 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: autoconf.c

Log Message:
add include of opt_intrdebug.h.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/amd64/amd64/autoconf.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/autoconf.c
diff -u src/sys/arch/amd64/amd64/autoconf.c:1.23 src/sys/arch/amd64/amd64/autoconf.c:1.24
--- src/sys/arch/amd64/amd64/autoconf.c:1.23	Tue Feb 22 06:37:24 2011
+++ src/sys/arch/amd64/amd64/autoconf.c	Thu Nov  8 02:00:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.23 2011/02/22 06:37:24 dholland Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.24 2012/11/08 02:00:44 chs Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -46,9 +46,10 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.23 2011/02/22 06:37:24 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.24 2012/11/08 02:00:44 chs Exp $");
 
 #include "opt_multiprocessor.h"
+#include "opt_intrdebug.h"
 
 #include 
 #include 



CVS commit: src/sys/arch/amd64/amd64

2012-11-02 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Fri Nov  2 08:33:16 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
comment


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/amd64/amd64/vector.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/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.41 src/sys/arch/amd64/amd64/vector.S:1.42
--- src/sys/arch/amd64/amd64/vector.S:1.41	Tue May 22 21:10:26 2012
+++ src/sys/arch/amd64/amd64/vector.S	Fri Nov  2 08:33:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.41 2012/05/22 21:10:26 dsl Exp $	*/
+/*	$NetBSD: vector.S,v 1.42 2012/11/02 08:33:16 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -573,7 +573,7 @@ IDTVEC(intr_ ## name ## num)		;\
 	incq	CPUVAR(NINTR)		/* statistical info */		;\
 	incq	IS_EVCNT(%r14)		;\
 1:	\
-	pushq	%r13			;\
+	pushq	%r13			/* save for Xdoreti */		;\
 	movl	%ebx,CPUVAR(ILEVEL)	;\
 	sti;\
 	incl	CPUVAR(IDEPTH)		;\



CVS commit: src/sys/arch/amd64/amd64

2012-11-02 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Fri Nov  2 08:31:29 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: spl.S

Log Message:
fix a comment


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/amd64/spl.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/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.24 src/sys/arch/amd64/amd64/spl.S:1.25
--- src/sys/arch/amd64/amd64/spl.S:1.24	Fri Mar 18 15:18:16 2011
+++ src/sys/arch/amd64/amd64/spl.S	Fri Nov  2 08:31:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.24 2011/03/18 15:18:16 joerg Exp $	*/
+/*	$NetBSD: spl.S,v 1.25 2012/11/02 08:31:28 yamt Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -186,7 +186,7 @@ ENTRY(splraise)
 /*
  * void spllower(int s);
  *
- * Must be the same size as i686_spllower().  This must use
+ * Must be the same size as cx8_spllower().  This must use
  * pushf/cli/popf as it is used early in boot where interrupts
  * are disabled via eflags/IE.
  */



CVS commit: src/sys/arch/amd64/amd64

2012-10-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Oct  3 17:43:22 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
Use db_read_value to read the trapframe fields in db_nextframe.

Fixes SIGSEGV on bt in crash(8) when the stack trace ends in syscall,
and probably other problems as well.

ok christos


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/amd64/amd64/db_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/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.3 src/sys/arch/amd64/amd64/db_machdep.c:1.4
--- src/sys/arch/amd64/amd64/db_machdep.c:1.3	Thu Jul 12 17:14:39 2012
+++ src/sys/arch/amd64/amd64/db_machdep.c	Wed Oct  3 17:43:22 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.3 2012/07/12 17:14:39 dsl Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $	*/
 
 /* 
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.3 2012/07/12 17:14:39 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $");
 
 #include 
 #include 
@@ -134,17 +134,20 @@ db_nextframe(long **nextframe, long **re
 		tf = (struct trapframe *)argp;
 		switch (is_trap) {
 		case TRAP:
-			(*pr)("--- trap (number %d) ---\n", tf->tf_trapno);
+			(*pr)("--- trap (number %"DDB_EXPR_FMT"u) ---\n",
+db_get_value((long)&tf->tf_trapno, 8, false));
 			break;
 		case SYSCALL:
-			(*pr)("--- syscall (number %ld) ---\n", tf->tf_rax);
+			(*pr)("--- syscall (number %"DDB_EXPR_FMT"u) ---\n",
+db_get_value((long)&tf->tf_rax, 8, false));
 			break;
 		case INTERRUPT:
 			(*pr)("--- interrupt ---\n");
 			break;
 		}
-		*ip = (db_addr_t)tf->tf_rip;
-		fp = (struct x86_64_frame *)tf->tf_rbp;
+		*ip = (db_addr_t)db_get_value((long)&tf->tf_rip, 8, false);
+		fp = (struct x86_64_frame *)
+			db_get_value((long)&tf->tf_rbp, 8, false);
 		if (fp == NULL)
 			return 0;
 		*nextframe = (long *)&fp->f_frame;



CVS commit: src/sys/arch/amd64/amd64

2012-09-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Sep  3 05:01:45 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Revert to unmanaged x86 memory mapped isa and pci space.
This is a revert of commit r1.169:
http://mail-index.netbsd.org/source-changes/2011/11/06/msg028702.html

This should allow X to run on NetBSD/xen amd64 dom0, and fixes PR #46634


To generate a diff of this commit:
cvs rdiff -u -r1.189 -r1.190 src/sys/arch/amd64/amd64/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.189 src/sys/arch/amd64/amd64/machdep.c:1.190
--- src/sys/arch/amd64/amd64/machdep.c:1.189	Sun Jul 15 15:17:56 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Mon Sep  3 05:01:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.189 2012/07/15 15:17:56 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.189 2012/07/15 15:17:56 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.190 2012/09/03 05:01:44 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1723,8 +1723,8 @@ init_x86_64(paddr_t first_avail)
 	/* Determine physical address space */
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages);
-	pmap_pa_start = 0;
-	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
+	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
+	pmap_pa_end = avail_end;
 	__PRINTK(("pmap_pa_start 0x%lx avail_start 0x%lx avail_end 0x%lx\n",
 	pmap_pa_start, avail_start, avail_end));
 #endif	/* !XEN */



CVS commit: src/sys/arch/amd64/amd64

2012-08-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Aug 28 15:54:41 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
don't undef TRAP_SIGDEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 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.73 src/sys/arch/amd64/amd64/trap.c:1.74
--- src/sys/arch/amd64/amd64/trap.c:1.73	Sun Jul 15 11:17:56 2012
+++ src/sys/arch/amd64/amd64/trap.c	Tue Aug 28 11:54:40 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.73 2012/07/15 15:17:56 dsl Exp $	*/
+/*	$NetBSD: trap.c,v 1.74 2012/08/28 15:54:40 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.73 2012/07/15 15:17:56 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.74 2012/08/28 15:54:40 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -153,8 +153,6 @@ int	trapdebug = 0;
 
 #define	IDTVEC(name)	__CONCAT(X, name)
 
-#undef TRAP_SIGDEBUG
-
 #ifdef TRAP_SIGDEBUG
 static void frame_dump(struct trapframe *);
 #endif



CVS commit: src/sys/arch/amd64/amd64

2012-06-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Jun 16 16:42:27 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Annotate tautological if, so that clang doesn't warn about the dt usage
later on.


To generate a diff of this commit:
cvs rdiff -u -r1.184 -r1.185 src/sys/arch/amd64/amd64/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.184 src/sys/arch/amd64/amd64/machdep.c:1.185
--- src/sys/arch/amd64/amd64/machdep.c:1.184	Tue Jun 12 22:16:05 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Jun 16 16:42:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.184 2012/06/12 22:16:05 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.185 2012/06/16 16:42:26 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.184 2012/06/12 22:16:05 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.185 2012/06/16 16:42:26 joerg Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -2206,6 +2206,7 @@ memseg_baseaddr(struct lwp *l, uint64_t 
 	} else {
 		if (seg != GUDATA_SEL || seg != GUDATA32_SEL)
 			return EINVAL;
+		__builtin_unreachable();
 	}
 
 	sdp = (struct mem_segment_descriptor *)(dt + off);



CVS commit: src/sys/arch/amd64/amd64

2012-06-12 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Tue Jun 12 22:16:05 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c netbsd32_machdep.c

Log Message:
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.183 -r1.184 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.76 -r1.77 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.183 src/sys/arch/amd64/amd64/machdep.c:1.184
--- src/sys/arch/amd64/amd64/machdep.c:1.183	Mon May 21 14:15:17 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Tue Jun 12 22:16:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.183 2012/05/21 14:15:17 martin Exp $	*/
+/*	$NetBSD: machdep.c,v 1.184 2012/06/12 22:16:05 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.183 2012/05/21 14:15:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.184 2012/06/12 22:16:05 bouyer Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -711,6 +711,16 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	/* 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 */
+	}
 }
 
 struct pcb dumppcb;

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.76 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.77
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.76	Mon May 21 14:15:17 2012
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue Jun 12 22:16:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.76 2012/05/21 14:15:17 martin Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.77 2012/06/12 22:16:05 bouyer Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.76 2012/05/21 14:15:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.77 2012/06/12 22:16:05 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -278,6 +278,15 @@ 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
 
@@ -366,6 +375,15 @@ 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: src/sys/arch/amd64/amd64

2012-05-22 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue May 22 21:14:37 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 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.70 src/sys/arch/amd64/amd64/trap.c:1.71
--- src/sys/arch/amd64/amd64/trap.c:1.70	Sun Feb 19 21:06:02 2012
+++ src/sys/arch/amd64/amd64/trap.c	Tue May 22 21:14:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.70 2012/02/19 21:06:02 rmind Exp $	*/
+/*	$NetBSD: trap.c,v 1.71 2012/05/22 21:14:37 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.70 2012/02/19 21:06:02 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.71 2012/05/22 21:14:37 dsl Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -120,6 +120,7 @@ dtrace_doubletrap_func_t	dtrace_doubletr
 #endif
 
 void trap(struct trapframe *);
+void trap_return_fault_return(struct trapframe *) __dead;
 
 const char * const trap_type[] = {
 	"privileged instruction fault",		/*  0 T_PRIVINFLT */
@@ -198,17 +199,14 @@ trap(struct trapframe *frame)
 	struct lwp *l = curlwp;
 	struct proc *p;
 	struct pcb *pcb;
-	extern char fusuintrfailure[], kcopy_fault[],
-		resume_iret[];
+	extern char fusuintrfailure[], kcopy_fault[];
 	extern char IDTVEC(oosyscall)[];
 	extern char IDTVEC(osyscall)[];
 	extern char IDTVEC(syscall32)[];
-#if 0
-	extern char resume_pop_ds[], resume_pop_es[];
-#endif
+#ifndef XEN
 	struct trapframe *vframe;
+#endif
 	ksiginfo_t ksi;
-	void *resume;
 	void *onfault;
 	int type, error;
 	uint64_t cr2;
@@ -310,50 +308,76 @@ 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 kernel.
+		 */
+		goto we_re_toast;
+#else
+		KSI_INIT_TRAP(&ksi);
+		ksi.ksi_signo = SIGSEGV;
+		ksi.ksi_code = SEGV_ACCERR;
+		ksi.ksi_trap = type;
+
+		/* Get %rsp value before fault - there may be a pad word
+		 * below the trap frame. */
+		vframe = (void *)frame->tf_rsp;
+		switch (*(uint16_t *)frame->tf_rip) {
+		case 0xcf48:	/* iretq */
+			/*
+			 * The 'iretq' instruction faulted, wo we have the
+			 * 'user' registers saved after the kernel
+			 * %rip:%cs:%fl:%rsp:%ss of the iret, and below that
+			 * the user %rip:%cs:%fl:%rsp:%ss the 'iret' was
+			 * processing.
+			 * We must copy the user register back over the
+			 * kernel fault frame to generate a normal stack
+			 * frame (eg for sending a SIGSEGV).
+			 */
+			vframe = (void *)((char *)vframe
+			- offsetof(struct trapframe, tf_rip));
+			memmove(vframe, frame,
+			offsetof(struct trapframe, tf_rip));
+			/* Set the faulting address to the user %eip */
+			ksi.ksi_addr = (void *)vframe->tf_rip;
+			break;
+		case 0x8

CVS commit: src/sys/arch/amd64/amd64

2012-05-22 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue May 22 21:10:26 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
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.40 -r1.41 src/sys/arch/amd64/amd64/vector.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/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.40 src/sys/arch/amd64/amd64/vector.S:1.41
--- src/sys/arch/amd64/amd64/vector.S:1.40	Mon May  7 21:09:29 2012
+++ src/sys/arch/amd64/amd64/vector.S	Tue May 22 21:10:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.40 2012/05/07 21:09:29 dsl Exp $	*/
+/*	$NetBSD: vector.S,v 1.41 2012/05/22 21:10:26 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -224,14 +224,53 @@ IDTVEC(trap09)
 IDTVEC(trap0a)
 	TRAP(T_TSSFLT)
 
-IDTVEC(trap0b)
-	TRAP(T_SEGNPFLT)
-
-IDTVEC(trap0c)
-	TRAP(T_STKFLT)
+#ifdef XEN
+/*
+ * I don't believe XEN generates in-kernel traps for the
+ * equivalent of iret, if it does this code would be needed
+ * in order to copy the user segment registers into the fault frame.
+ */
+#define check_swapgs alltraps
+#endif
 
-IDTVEC(trap0d)
-	TRAP(T_PROTFLT)
+IDTVEC(trap0b)		/* #NP() Segment not present */
+	TRAP_NJ(T_SEGNPFLT)
+	jmp	check_swapgs
+
+IDTVEC(trap0c)		/* #SS() Stack exception */
+	TRAP_NJ(T_STKFLT)
+	jmp	check_swapgs
+
+IDTVEC(trap0d)		/* #GP() General protection */
+	TRAP_NJ(T_PROTFLT)
+#ifdef check_swapgs
+	jmp	check_swapgs
+#else
+/* We need to worry about traps while the kernel %gs_base isn't loaded.
+ * These are either loads to %gs (only 32bit) or faults on iret during
+ * return to user. */
+check_swapgs:
+	INTRENTRY_L(3f,1:)
+2:	sti
+	jmp	calltrap
+3:
+	/* Trap in kernel mode. */
+	/* If faulting instruction is 'iret' we may need to do a 'swapgs'. */
+	movq	TF_RIP(%rsp),%rax
+	cmpw	$0xcf48,(%rax)		/* Faulting instruction is iretq ? */
+	jne	5f			/* Jump if not */
+	movq	TF_RSP(%rsp),%rax	/* Must read %rsp, may be a pad word */
+	testb	$SEL_UPL,8(%rax)	/* Check %cs of outer iret frame */
+	je	2b			/* jump if iret was to kernel  */
+	jmp	1b			/* to user - must restore %gs */
+5:
+	/* Not 'iret', all moves to %gs also need a swapgs */
+	movw	(%rax),%ax
+	andb	$070,%ah		/* mask mod/rm from mod/reg/rm */
+	cmpw	$0x8e+050*256,%ax	/* Any move to %gs (reg 5) */
+	jne	2b			/* No - normal kernel fault */
+	jmp	1b			/* Yes - restore %gs */
+#endif
 
 IDTVEC(trap0e)
 	TRAP(T_PAGEFLT)
@@ -305,25 +344,20 @@ IDTVEC(exceptions)
 	.quad	_C_LABEL(Xtrap1e), _C_LABEL(Xtrap1f)
 
 /*
- * If an error is detected during trap, syscall, or interrupt exit, trap() will
- * change %eip to point to one of these labels.  We clean up the stack, if
- * necessary, and resume as if we were handling a general protection fault.
- * This will cause the process to get a SIGBUS.
- *
- * XXXfvdl currently unused, as pop %ds and pop %es are illegal in long
- * mode. However, if the x86-64 port is going to support USER_LDT, we
- * may need something like this after all.
+ * trap() calls here when it detects a fault in INTRFASTEXIT (loading the
+ * segment registers or during the iret itself).
+ * The address of the (possibly reconstructed) user trap frame is
+ * passed as an argument.
+ * Typically the code will have raised a SIGSEGV which will be actioned
+ * by the code below.
  */
-NENTRY(resume_iret)
-	ZTRAP(T_PROTFLT)
-#if 0
-NENTRY(resume_pop_ds)
-	movl	$GSEL(GDATA_SEL, SEL_KPL),%eax
-	movl	%eax,%es
-NENTRY(resume_pop_es)
-	movl	$T_PROTFLT,TF_TRAPNO(%rsp)
-	jmp	calltrap
-#endif
+_C_LABEL(trap_return_fault_return):	.globl	trap_return_fault_return
+	mov	%rdi,%rsp		/* frame for user return */
+#ifdef DIAGNOSTIC
+	/* We can't recover the saved %rbx, so suppress warning */
+	movl	CPUVAR(ILEVEL),%ebx
+#endif /* DIAGNOSTIC */
+	jmp	.Lalltraps_checkusr
 
 /*
  * All traps go through here. Call the generic trap handler, and



CVS commit: src/sys/arch/amd64/amd64

2012-05-07 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Mon May  7 21:09:29 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Rejig the way TRAP() and ZTRAP() are defined and add Z/TRAP_NJ() that
  excludes the 'jmp alltraps'.
Use the _NJ versions for trap entries with non-standard code.
Move all the KDTRACE_HOOKS code into a single block inside the
  IDTVEC(trap03) code. This removes a mis-predicted from every
  trap when KDTRACE_HOOKS are enabled.
Add a few blank lines, need some comments as well :-)
No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/amd64/amd64/vector.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/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.39 src/sys/arch/amd64/amd64/vector.S:1.40
--- src/sys/arch/amd64/amd64/vector.S:1.39	Sat Apr 21 18:52:36 2012
+++ src/sys/arch/amd64/amd64/vector.S	Mon May  7 21:09:29 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.39 2012/04/21 18:52:36 christos Exp $	*/
+/*	$NetBSD: vector.S,v 1.40 2012/05/07 21:09:29 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -100,40 +100,25 @@
 
 /*/
 
-#ifndef	XEN
-#define PRE_TRAP
-#define	TRAP(a)		pushq $(a) ; jmp _C_LABEL(alltraps)
-#define	ZTRAP(a)	pushq $0 ; TRAP(a)
-#else
+#ifdef	XEN
 #define	PRE_TRAP	movq (%rsp),%rcx ; movq 8(%rsp),%r11 ; addq $0x10,%rsp 
-#define	POST_TRAP(a)	pushq $(a) ; jmp _C_LABEL(alltraps)
-#define	TRAP(a)		PRE_TRAP ; POST_TRAP(a)
-#define ZTRAP(a)	PRE_TRAP ; pushq $0 ; POST_TRAP(a)
+#else
+#define	PRE_TRAP
 #endif
 
-#define	BPTTRAP(a)	ZTRAP(a)
+#define	TRAP_NJ(a)	PRE_TRAP ; pushq $(a)
+#define	ZTRAP_NJ(a)	PRE_TRAP ; pushq $0 ; pushq $(a)
+#define	TRAP(a)		TRAP_NJ(a) ; jmp _C_LABEL(alltraps)
+#define	ZTRAP(a)	ZTRAP_NJ(a) ; jmp _C_LABEL(alltraps)
 
-#ifdef KDTRACE_HOOKS
-	.bss
-	.globl	dtrace_invop_jump_addr
-	.align	8
-	.type	dtrace_invop_jump_addr, @object
-	.size	dtrace_invop_jump_addr, 8
-dtrace_invop_jump_addr:
-	.zero	8
-	.globl	dtrace_invop_calltrap_addr
-	.align	8
-	.type	dtrace_invop_calltrap_addr, @object
-	.size	dtrace_invop_calltrap_addr, 8
-dtrace_invop_calltrap_addr:
-	.zero	8
-#endif
 	.text
 
 IDTVEC(trap00)
 	ZTRAP(T_DIVIDE)
+
 IDTVEC(trap01)
-	BPTTRAP(T_TRCTRAP)
+	ZTRAP(T_TRCTRAP)
+
 IDTVEC(trap02)
 #if defined(XEN)
 	ZTRAP(T_NMI)
@@ -167,18 +152,61 @@ IDTVEC(trap02)
 	addq	$TF_REGSIZE+16,%rsp
 	iretq
 #endif /* defined(XEN) */
+
 IDTVEC(trap03)
-	BPTTRAP(T_BPTFLT)
+#ifndef KDTRACE_HOOKS
+	ZTRAP(T_BPTFLT)
+#else
+	ZTRAP_NJ(T_BPTFLT)
+	INTRENTRY
+  	STI(si)
+	/*
+	 * DTrace Function Boundary Trace (fbt) probes are triggered
+	 * by int3 (0xcc).
+	 */
+	/* Check if there is no DTrace hook registered. */
+	cmpq	$0,dtrace_invop_jump_addr
+	je	calltrap
+
+	/*
+	 * Set our jump address for the jump back in the event that
+	 * the exception wasn't caused by DTrace at all.
+	 */
+	/* XXX: This doesn't look right for SMP - unless it is a
+	 * constant - so why set it everytime. (dsl) */
+	movq	$calltrap, dtrace_invop_calltrap_addr(%rip)
+
+	/* Jump to the code hooked in by DTrace. */
+	movq	dtrace_invop_jump_addr, %rax
+	jmpq	*dtrace_invop_jump_addr
+
+	.bss
+	.globl	dtrace_invop_jump_addr
+	.align	8
+	.type	dtrace_invop_jump_addr, @object
+	.size	dtrace_invop_jump_addr, 8
+dtrace_invop_jump_addr:
+	.zero	8
+	.globl	dtrace_invop_calltrap_addr
+	.align	8
+	.type	dtrace_invop_calltrap_addr, @object
+	.size	dtrace_invop_calltrap_addr, 8
+dtrace_invop_calltrap_addr:
+	.zero	8
+	.text
+#endif
+
 IDTVEC(trap04)
 	ZTRAP(T_OFLOW)
+
 IDTVEC(trap05)
 	ZTRAP(T_BOUND)
+
 IDTVEC(trap06)
 	ZTRAP(T_PRIVINFLT)
+
 IDTVEC(trap07)
-	PRE_TRAP;
-	pushq	$0			# dummy error code
-	pushq	$T_ASTFLT
+	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
 	movl	CPUVAR(ILEVEL),%ebx
@@ -186,34 +214,39 @@ IDTVEC(trap07)
 	movq	CPUVAR(SELF),%rdi
 	call	_C_LABEL(fpudna)
 	jmp	.Lalltraps_checkusr
+
 IDTVEC(trap08)
 	TRAP(T_DOUBLEFLT)
+
 IDTVEC(trap09)
 	ZTRAP(T_FPOPFLT)
+
 IDTVEC(trap0a)
 	TRAP(T_TSSFLT)
+
 IDTVEC(trap0b)
 	TRAP(T_SEGNPFLT)
+
 IDTVEC(trap0c)
 	TRAP(T_STKFLT)
+
 IDTVEC(trap0d)
 	TRAP(T_PROTFLT)
+
 IDTVEC(trap0e)
 	TRAP(T_PAGEFLT)
+
 IDTVEC(intrspurious)
 IDTVEC(trap0f)
-	PRE_TRAP;
-	pushq	$0			# dummy error code
-	pushq	$T_ASTFLT
+	ZTRAP_NJ(T_ASTFLT)
 	INTRENTRY
 #ifdef DIAGNOSTIC
 	movl	CPUVAR(ILEVEL),%ebx
 #endif /* DIAGNOSTIC */
 	jmp	.Lalltraps_checkusr
+
 IDTVEC(trap10)
-	PRE_TRAP;
-	pushq	$0			# dummy error code
-	pushq	$T_ARITHTRAP
+	ZTRAP_NJ(T_ARITHTRAP)
 .Ldo_fputrap:
 	INTRENTRY
 #ifdef DIAGNOSTIC
@@ -227,15 +260,17 @@ IDTVEC(trap10)
 1:
   	STI(si)
 	jmp	calltrap
+
 IDTVEC(trap11)
 	TRAP(T_ALIGNFLT)
+
 IDTVEC(trap12)
 	ZTRAP(T_MCA)
+
 IDTVEC(trap13)
-	PRE_TRAP;
-	pushq	$0			# dummy error code
-	pushq	$T_XMM
+	ZTRAP_NJ(T_XMM)
 	jmp	.Ldo_fputrap
+
 IDTVEC(trap14)
 IDTVEC(t

CVS commit: src/sys/arch/amd64/amd64

2012-05-07 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Mon May  7 12:20:27 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: db_memrw.c

Log Message:
invlpg on a non canonical address is a noop, so no chance to invalidate
the TLB and the CPU will not notice the access right change.

This results in write protection faults in supervisor mode when patching
kernel code through ddb(4) (originally mapped as read only).

Bug reported by David Laight on port-amd64@ (thanks!), patch and test by
me.

i386 is unaffected as PG_LGFRAME does not mask the sign bits. For the
sake of correctness, use VA_SIGN_NEG(...) anyway.

XXX this is the patch that will be pulled-up to -5 and -6.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/amd64/amd64/db_memrw.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/db_memrw.c
diff -u src/sys/arch/amd64/amd64/db_memrw.c:1.10 src/sys/arch/amd64/amd64/db_memrw.c:1.11
--- src/sys/arch/amd64/amd64/db_memrw.c:1.10	Mon May  7 12:12:04 2012
+++ src/sys/arch/amd64/amd64/db_memrw.c	Mon May  7 12:20:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.10 2012/05/07 12:12:04 jym Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.11 2012/05/07 12:20:27 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.10 2012/05/07 12:12:04 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.11 2012/05/07 12:20:27 jym Exp $");
 
 #include 
 #include 
@@ -123,7 +123,7 @@ db_write_text(vaddr_t addr, size_t size,
 		 * Get the VA for the page.
 		 */
 		if (pte & PG_PS)
-			pgva = (vaddr_t)dst & PG_LGFRAME;
+			pgva = VA_SIGN_NEG((vaddr_t)dst & PG_LGFRAME);
 		else
 			pgva = x86_trunc_page(dst);
 



CVS commit: src/sys/arch/amd64/amd64

2012-04-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 29 21:54:51 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
tidy up...


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 src/sys/arch/amd64/amd64/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.181 src/sys/arch/amd64/amd64/machdep.c:1.182
--- src/sys/arch/amd64/amd64/machdep.c:1.181	Sat Apr 14 20:34:09 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Apr 29 17:54:51 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.181 2012/04/15 00:34:09 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.182 2012/04/29 21:54:51 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.181 2012/04/15 00:34:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.182 2012/04/29 21:54:51 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1229,17 +1229,18 @@ dodumpsys(void)
 	 */
 	if (dumpsize == 0)
 		cpu_dumpconf();
-	if (dumplo <= 0 || dumpsize == 0) {
-		printf("\ndump to dev %u,%u not possible\n", major(dumpdev),
-		minor(dumpdev));
+
+	printf("\ndumping to dev %llu,%llu (offset=%ld, size=%d):",
+	(unsigned long long)major(dumpdev),
+	(unsigned long long)minor(dumpdev), dumplo, dumpsize);
+
+	if (dumplo <= 0 || dumpsize <= 0) {
+		printf(" not possible\n");
 		return;
 	}
-	printf("\ndumping to dev %llu,%llu offset %ld\n",
-	(unsigned long long)major(dumpdev),
-	(unsigned long long)minor(dumpdev), dumplo);
 
 	psize = bdev_size(dumpdev);
-	printf("dump ");
+	printf("\ndump ");
 	if (psize == -1) {
 		printf("area unavailable\n");
 		return;
@@ -1346,7 +1347,11 @@ cpu_dumpconf(void)
 	dumpblks = cpu_dumpsize();
 	if (dumpblks < 0)
 		goto bad;
-	dumpblks += ctod(cpu_dump_mempagecnt());
+
+	/* dumpsize is in page units, and doesn't include headers. */
+	dumpsize = cpu_dump_mempagecnt();
+
+	dumpblks += ctod(dumpsize);
 
 	/* If dump won't fit (incl. room for possible label), punt. */
 	if (dumpblks > (nblks - ctod(1))) {
@@ -1362,8 +1367,6 @@ cpu_dumpconf(void)
 		dumplo = nblks - dumpblks;
 	}
 
-	/* dumpsize is in page units, and doesn't include headers. */
-	dumpsize = cpu_dump_mempagecnt();
 
 	/* Now that we've decided this will work, init ancillary stuff. */
 	dump_misc_init();



CVS commit: src/sys/arch/amd64/amd64

2012-04-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 21 18:52:37 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: vector.S

Log Message:
Alignment fault traps push the error code automatically, so don't use ZTRAP!


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/amd64/amd64/vector.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/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.38 src/sys/arch/amd64/amd64/vector.S:1.39
--- src/sys/arch/amd64/amd64/vector.S:1.38	Sat Jun 11 23:35:38 2011
+++ src/sys/arch/amd64/amd64/vector.S	Sat Apr 21 14:52:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.38 2011/06/12 03:35:38 rmind Exp $	*/
+/*	$NetBSD: vector.S,v 1.39 2012/04/21 18:52:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -228,7 +228,7 @@ IDTVEC(trap10)
   	STI(si)
 	jmp	calltrap
 IDTVEC(trap11)
-	ZTRAP(T_ALIGNFLT)
+	TRAP(T_ALIGNFLT)
 IDTVEC(trap12)
 	ZTRAP(T_MCA)
 IDTVEC(trap13)



CVS commit: src/sys/arch/amd64/amd64

2012-04-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 15 00:34:09 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Fix check_mcontext for PK_32 binaries. Makes gdb work for i386 binaries on
amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.180 -r1.181 src/sys/arch/amd64/amd64/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.180 src/sys/arch/amd64/amd64/machdep.c:1.181
--- src/sys/arch/amd64/amd64/machdep.c:1.180	Sat Mar  3 18:43:17 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Apr 14 20:34:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.180 2012/03/03 23:43:17 mrg Exp $	*/
+/*	$NetBSD: machdep.c,v 1.181 2012/04/15 00:34:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.180 2012/03/03 23:43:17 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.181 2012/04/15 00:34:09 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -2071,6 +2071,7 @@ check_mcontext(struct lwp *l, const mcon
 	uint16_t sel;
 	int error;
 	struct pmap *pmap = l->l_proc->p_vmspace->vm_map.pmap;
+	struct proc *p = l->l_proc;
 
 	gr = mcp->__gregs;
 
@@ -2104,33 +2105,42 @@ check_mcontext(struct lwp *l, const mcon
 			return error;
 #endif
 	} else {
+#define VUD(sel) \
+((p->p_flag & PK_32) ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel))
 		sel = gr[_REG_ES] & 0x;
-		if (sel != 0 && !VALID_USER_DSEL(sel))
+		if (sel != 0 && !VUD(sel))
 			return EINVAL;
 
+/* XXX: Shouldn't this be FSEL32? */
+#define VUF(sel) \
+((p->p_flag & PK_32) ? VALID_USER_DSEL32(sel) : VALID_USER_DSEL(sel))
 		sel = gr[_REG_FS] & 0x;
-		if (sel != 0 && !VALID_USER_DSEL(sel))
+		if (sel != 0 && !VUF(sel))
 			return EINVAL;
 
+#define VUG(sel) \
+((p->p_flag & PK_32) ? VALID_USER_GSEL32(sel) : VALID_USER_DSEL(sel))
 		sel = gr[_REG_GS] & 0x;
-		if (sel != 0 && !VALID_USER_DSEL(sel))
+		if (sel != 0 && !VUG(sel))
 			return EINVAL;
 
 		sel = gr[_REG_DS] & 0x;
-		if (!VALID_USER_DSEL(sel))
+		if (!VUD(sel))
 			return EINVAL;
 
 #ifndef XEN
 		sel = gr[_REG_SS] & 0x;
-		if (!VALID_USER_DSEL(sel)) 
+		if (!VUD(sel))
 			return EINVAL;
 #endif
 
 	}
 
 #ifndef XEN
+#define VUC(sel) \
+((p->p_flag & PK_32) ? VALID_USER_CSEL32(sel) : VALID_USER_CSEL(sel))
 	sel = gr[_REG_CS] & 0x;
-	if (!VALID_USER_CSEL(sel))
+	if (!VUC(sel))
 		return EINVAL;
 #endif
 



CVS commit: src/sys/arch/amd64/amd64

2012-02-24 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Feb 25 00:13:28 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: bios32.c

Log Message:
Avoid empty loop bodies.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/amd64/amd64/bios32.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/bios32.c
diff -u src/sys/arch/amd64/amd64/bios32.c:1.19 src/sys/arch/amd64/amd64/bios32.c:1.20
--- src/sys/arch/amd64/amd64/bios32.c:1.19	Sat Nov  7 07:27:40 2009
+++ src/sys/arch/amd64/amd64/bios32.c	Sat Feb 25 00:13:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bios32.c,v 1.19 2009/11/07 07:27:40 cegger Exp $	*/
+/*	$NetBSD: bios32.c,v 1.20 2012/02/25 00:13:28 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.19 2009/11/07 07:27:40 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.20 2012/02/25 00:13:28 joerg Exp $");
 
 #include 
 #include 
@@ -145,16 +145,16 @@ bios32_init(void)
 		if (sh->sig != BIOS32_MAKESIG('_', 'S', 'M', '_'))
 			continue;
 		i = sh->len;
-		for (chksum = 0; i--; chksum += p[i])
-			;
+		for (chksum = 0; i--; )
+			chksum += p[i];
 		if (chksum != 0)
 			continue;
 		p += 0x10;
 		if (p[0] != '_' && p[1] != 'D' && p[2] != 'M' &&
 		p[3] != 'I' && p[4] != '_')
 			continue;
-		for (chksum = 0, i = 0xf; i--; chksum += p[i]);
-			;
+		for (chksum = 0, i = 0xf; i--; )
+			chksum += p[i];
 		if (chksum != 0)
 			continue;
 



CVS commit: src/sys/arch/amd64/amd64

2012-02-22 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Feb 22 14:12:04 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: db_machdep.c

Log Message:
fix stack backtraces through traps.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amd64/amd64/db_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/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.1 src/sys/arch/amd64/amd64/db_machdep.c:1.2
--- src/sys/arch/amd64/amd64/db_machdep.c:1.1	Sun Apr 10 20:36:49 2011
+++ src/sys/arch/amd64/amd64/db_machdep.c	Wed Feb 22 14:12:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.1 2011/04/10 20:36:49 christos Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.2 2012/02/22 14:12:04 chs Exp $	*/
 
 /* 
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.1 2011/04/10 20:36:49 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.2 2012/02/22 14:12:04 chs Exp $");
 
 #include 
 #include 
@@ -131,7 +131,7 @@ db_nextframe(long **nextframe, long **re
 	default:
 
 		/* The only argument to trap() or syscall() is the trapframe. */
-		tf = *(struct trapframe **)argp;
+		tf = (struct trapframe *)argp;
 		switch (is_trap) {
 		case TRAP:
 			(*pr)("--- trap (number %d) ---\n", tf->tf_trapno);
@@ -141,7 +141,6 @@ db_nextframe(long **nextframe, long **re
 			break;
 		case INTERRUPT:
 			(*pr)("--- interrupt ---\n");
-			tf = (struct trapframe *)argp;
 			break;
 		}
 		*ip = (db_addr_t)tf->tf_rip;



CVS commit: src/sys/arch/amd64/amd64

2012-02-19 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sun Feb 19 23:15:24 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Remove extern variables defined in headers.


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 src/sys/arch/amd64/amd64/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.176 src/sys/arch/amd64/amd64/machdep.c:1.177
--- src/sys/arch/amd64/amd64/machdep.c:1.176	Sun Feb 19 21:06:00 2012
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Feb 19 23:15:24 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.176 2012/02/19 21:06:00 rmind Exp $	*/
+/*	$NetBSD: machdep.c,v 1.177 2012/02/19 23:15:24 matt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.176 2012/02/19 21:06:00 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.177 2012/02/19 23:15:24 matt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -217,10 +217,6 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 char machine[] = "amd64";		/* CPU "architecture" */
 char machine_arch[] = "x86_64";		/* machine == machine_arch */
 
-/* Our exported CPU info; we have only one right now. */  
-struct cpu_info cpu_info_primary;
-struct cpu_info *cpu_info_list;
-
 extern struct bi_devmatch *x86_alldisks;
 extern int x86_ndisks;
 
@@ -236,7 +232,6 @@ int	cpu_class = CPUCLASS_686;
 struct mtrr_funcs *mtrr_funcs;
 #endif
 
-int	physmem;
 uint64_t	dumpmem_low;
 uint64_t	dumpmem_high;
 int	cpu_class;



CVS commit: src/sys/arch/amd64/amd64

2012-02-04 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Sat Feb  4 22:45:42 UTC 2012

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Fix address of SIGILL instruction on amd64 as previously fixed on i386. It
used to return the effective address of the faulted memory access but on
SIGILL its obviously wrong since there is no MMU fault.

Instead return the instruction counter register.
OK by releng


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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.68 src/sys/arch/amd64/amd64/trap.c:1.69
--- src/sys/arch/amd64/amd64/trap.c:1.68	Sun Nov  6 15:53:04 2011
+++ src/sys/arch/amd64/amd64/trap.c	Sat Feb  4 22:45:40 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $	*/
+/*	$NetBSD: trap.c,v 1.69 2012/02/04 22:45:40 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69 2012/02/04 22:45:40 reinoud Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -404,7 +404,7 @@ copyfault:
 		KSI_INIT_TRAP(&ksi);
 		ksi.ksi_signo = SIGILL;
 		ksi.ksi_trap = type & ~T_USER;
-		ksi.ksi_addr = (void *)rcr2();
+		ksi.ksi_addr = (void *) frame->tf_rip;
 		switch (type) {
 		case T_PRIVINFLT|T_USER:
 			ksi.ksi_code = ILL_PRVOPC;



CVS commit: src/sys/arch/amd64/amd64

2011-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Dec 20 13:17:05 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
from 
http://www.freshbsd.org/commit/openbsd/ae7f934ae5bdf57dcf3431ba55fd1da93b8f1963

Initialize abridged tag word properly. x87 spec says FNINIT says tag word
contains h (all stack locations empty) which would make abridged tag
word 00h. From the Intel 64 and IA-32 Architectures Software Developer's
Manual:

"The FXSAVE instruction saves an abridged version of the x87 FPU tag word
in the FTW field (unlike the FSAVE instruction, which saves the complete
tag word). The tag information is saved in physical register order (R0
through R7), rather than in top-of- stack (TOS) order. With the FXSAVE
instruction, however, only a single bit (1 for valid or 0 for empty) is
saved for each tag."

ok rmind@


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/amd64/process_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/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.18 src/sys/arch/amd64/amd64/process_machdep.c:1.19
--- src/sys/arch/amd64/amd64/process_machdep.c:1.18	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/process_machdep.c	Tue Dec 20 13:17:05 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.18 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.19 2011/12/20 13:17:05 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.18 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.19 2011/12/20 13:17:05 jmcneill Exp $");
 
 #include 
 #include 
@@ -124,7 +124,7 @@ process_read_fpregs(struct lwp *l, struc
 		memset(frame, 0, sizeof(*regs));
 		frame->fx_fcw = cw;
 		frame->fx_fsw = 0x;
-		frame->fx_ftw = 0xff;
+		frame->fx_ftw = 0x00;	/* abridged tag; all empty */
 		frame->fx_mxcsr = mxcsr;
 		frame->fx_mxcsr_mask = mxcsr_mask;
 		l->l_md.md_flags |= MDP_USEDFPU;



CVS commit: src/sys/arch/amd64/amd64

2011-11-22 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Wed Nov 23 01:15:02 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: db_memrw.c

Log Message:
Kill dependency to xpmap_update(), and use setbits/clearbits to update
kernel PTE rights.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/amd64/db_memrw.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/db_memrw.c
diff -u src/sys/arch/amd64/amd64/db_memrw.c:1.8 src/sys/arch/amd64/amd64/db_memrw.c:1.9
--- src/sys/arch/amd64/amd64/db_memrw.c:1.8	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/db_memrw.c	Wed Nov 23 01:15:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.8 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.9 2011/11/23 01:15:02 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -51,9 +51,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.8 2010/12/20 00:25:24 matt Exp $");
-
-#include "opt_xen.h"
+__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.9 2011/11/23 01:15:02 jym Exp $");
 
 #include 
 #include 
@@ -99,7 +97,7 @@ db_read_bytes(vaddr_t addr, size_t size,
 static void
 db_write_text(vaddr_t addr, size_t size, const char *data)
 {
-	pt_entry_t *pte, oldpte, tmppte;
+	pt_entry_t *ppte, pte;
 	vaddr_t pgva;
 	size_t limit;
 	char *dst;
@@ -113,10 +111,10 @@ db_write_text(vaddr_t addr, size_t size,
 		/*
 		 * Get the PTE for the page.
 		 */
-		pte = kvtopte(addr);
-		oldpte = *pte;
+		ppte = kvtopte(addr);
+		pte = *ppte;
 
-		if ((oldpte & PG_V) == 0) {
+		if ((pte & PG_V) == 0) {
 			printf(" address %p not a valid page\n", dst);
 			return;
 		}
@@ -124,7 +122,7 @@ db_write_text(vaddr_t addr, size_t size,
 		/*
 		 * Get the VA for the page.
 		 */
-		if (oldpte & PG_PS)
+		if (pte & PG_PS)
 			pgva = (vaddr_t)dst & PG_LGFRAME;
 		else
 			pgva = x86_trunc_page(dst);
@@ -134,7 +132,7 @@ db_write_text(vaddr_t addr, size_t size,
 		 * with this mapping and subtract it from the
 		 * total size.
 		 */
-		if (oldpte & PG_PS)
+		if (pte & PG_PS)
 			limit = NBPD_L2 - ((vaddr_t)dst & (NBPD_L2 - 1));
 		else
 			limit = PAGE_SIZE - ((vaddr_t)dst & PGOFSET);
@@ -142,12 +140,11 @@ db_write_text(vaddr_t addr, size_t size,
 			limit = size;
 		size -= limit;
 
-		tmppte = (oldpte & ~PG_KR) | PG_KW;
-#ifdef XEN
-		xpmap_update(pte, tmppte);
-#else
-		*pte = tmppte;
-#endif
+		/*
+		 * Make the kernel text page writable.
+		 */
+		pmap_pte_clearbits(ppte, PG_KR);
+		pmap_pte_setbits(ppte, PG_KW);
 		pmap_update_pg(pgva);
 
 		/*
@@ -158,14 +155,10 @@ db_write_text(vaddr_t addr, size_t size,
 			*dst++ = *data++;
 
 		/*
-		 * Restore the old PTE.
+		 * Turn the page back to read-only.
 		 */
-#ifdef XEN
-		xpmap_update(pte, oldpte);
-#else
-		*pte = oldpte;
-#endif
-
+		pmap_pte_clearbits(ppte, PG_KW);
+		pmap_pte_setbits(ppte, PG_KR);
 		pmap_update_pg(pgva);
 		
 	} while (size != 0);



CVS commit: src/sys/arch/amd64/amd64

2011-11-20 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Sun Nov 20 18:42:56 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
revert machdep.c rev. 1.168 because it's likely to have the same problem
as i386's one.
http://mail-index.NetBSD.org/source-changes-d/2011/11/19/msg004283.html


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/arch/amd64/amd64/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.170 src/sys/arch/amd64/amd64/machdep.c:1.171
--- src/sys/arch/amd64/amd64/machdep.c:1.170	Thu Nov 10 00:12:04 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Nov 20 18:42:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.170 2011/11/10 00:12:04 jym Exp $	*/
+/*	$NetBSD: machdep.c,v 1.171 2011/11/20 18:42:56 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.170 2011/11/10 00:12:04 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.171 2011/11/20 18:42:56 yamt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1182,7 +1182,6 @@ dumpsys_seg(paddr_t maddr, paddr_t bytes
 		pmap_update(pmap_kernel());
 
 		error = (*dump)(dumpdev, blkno, (void *)dumpspace, n);
-		pmap_kremove(dumpspace, n * PAGE_SIZE);
 		if (error)
 			return error;
 		maddr += n;



CVS commit: src/sys/arch/amd64/amd64

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:53:04 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Use the right format strings with printf


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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.67 src/sys/arch/amd64/amd64/trap.c:1.68
--- src/sys/arch/amd64/amd64/trap.c:1.67	Wed Oct  5 20:39:24 2011
+++ src/sys/arch/amd64/amd64/trap.c	Sun Nov  6 15:53:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $	*/
+/*	$NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.68 2011/11/06 15:53:04 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -275,7 +275,7 @@ trap(struct trapframe *frame)
 		else
 			printf("unknown trap %ld", (u_long)frame->tf_trapno);
 		printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor");
-		printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2"
+		printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2 "
 		   " %lx cpl %x rsp %lx\n",
 		type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs,
 		frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, frame->tf_rsp);
@@ -733,7 +733,7 @@ frame_dump(struct trapframe *tf)
 	(void *)tf->tf_r13, (void *)tf->tf_r14, (void *)tf->tf_r15);
 	printf("rbp %p  rbx %p  rax %p\n",
 	(void *)tf->tf_rbp, (void *)tf->tf_rbx, (void *)tf->tf_rax);
-	printf("cs %p  ds %p  es %p  fs %p  gs %p  ss %p\n",
+	printf("cs %lx  ds %lx  es %lx  fs %lx  gs %lx  ss %lx\n",
 		tf->tf_cs & 0x, tf->tf_ds & 0x, tf->tf_es & 0x,
 		tf->tf_fs & 0x, tf->tf_gs & 0x, tf->tf_ss & 0x);
 	



CVS commit: src/sys/arch/amd64/amd64

2011-11-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Nov  6 15:51:09 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
DTRT with macros and use xen's info page when initialising pmap_pa_start and 
pmap_pa_end.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/arch/amd64/amd64/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.168 src/sys/arch/amd64/amd64/machdep.c:1.169
--- src/sys/arch/amd64/amd64/machdep.c:1.168	Mon Oct 31 12:42:36 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Nov  6 15:51:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.169 2011/11/06 15:51:09 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.169 2011/11/06 15:51:09 cherry Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1684,8 +1684,8 @@ init_x86_64(paddr_t first_avail)
 	/* Determine physical address space */
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages);
-	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
-	pmap_pa_end = avail_end;
+	pmap_pa_start = XPMAP_OFFSET;
+	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
 	__PRINTK(("pmap_pa_start 0x%lx avail_start 0x%lx avail_end 0x%lx\n",
 	pmap_pa_start, avail_start, avail_end));
 #endif	/* !XEN */



CVS commit: src/sys/arch/amd64/amd64

2011-10-31 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Mon Oct 31 12:42:36 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
dumpsys_seg: don't overwrite the previous mapping


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/arch/amd64/amd64/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.167 src/sys/arch/amd64/amd64/machdep.c:1.168
--- src/sys/arch/amd64/amd64/machdep.c:1.167	Wed Aug 31 18:52:37 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Mon Oct 31 12:42:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.167 2011/08/31 18:52:37 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.167 2011/08/31 18:52:37 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.168 2011/10/31 12:42:36 yamt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1182,6 +1182,7 @@ dumpsys_seg(paddr_t maddr, paddr_t bytes
 		pmap_update(pmap_kernel());
 
 		error = (*dump)(dumpdev, blkno, (void *)dumpspace, n);
+		pmap_kremove(dumpspace, n * PAGE_SIZE);
 		if (error)
 			return error;
 		maddr += n;



CVS commit: src/sys/arch/amd64/amd64

2011-10-05 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Wed Oct  5 20:39:24 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
Remove extra space.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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.66 src/sys/arch/amd64/amd64/trap.c:1.67
--- src/sys/arch/amd64/amd64/trap.c:1.66	Sun Apr  3 22:29:25 2011
+++ src/sys/arch/amd64/amd64/trap.c	Wed Oct  5 20:39:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.66 2011/04/03 22:29:25 dyoung Exp $	*/
+/*	$NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.66 2011/04/03 22:29:25 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.67 2011/10/05 20:39:24 njoly Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -275,7 +275,7 @@ trap(struct trapframe *frame)
 		else
 			printf("unknown trap %ld", (u_long)frame->tf_trapno);
 		printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor");
-		printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2 "
+		printf("trap type %d code %lx rip %lx cs %lx rflags %lx cr2"
 		   " %lx cpl %x rsp %lx\n",
 		type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs,
 		frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, frame->tf_rsp);



CVS commit: src/sys/arch/amd64/amd64

2011-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 31 18:52:38 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
fix reversed test.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/arch/amd64/amd64/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.166 src/sys/arch/amd64/amd64/machdep.c:1.167
--- src/sys/arch/amd64/amd64/machdep.c:1.166	Wed Aug 31 13:03:17 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Aug 31 14:52:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.166 2011/08/31 17:03:17 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.167 2011/08/31 18:52:37 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.166 2011/08/31 17:03:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.167 2011/08/31 18:52:37 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -821,7 +821,7 @@
 	printf("dump_misc_init: max_paddr = 0x%lx\n",
 	(unsigned long)max_paddr);
 #endif
-	if (max_paddr != 0) {
+	if (max_paddr == 0) {
 		printf("Your machine does not initialize mem_clusters; "
 		"sparse_dumps disabled\n");
 		sparse_dump = 0;



CVS commit: src/sys/arch/amd64/amd64

2011-08-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Aug 31 17:03:17 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
on xen we don't initialize memory segment maps, so no sparse dumps for now.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/arch/amd64/amd64/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.165 src/sys/arch/amd64/amd64/machdep.c:1.166
--- src/sys/arch/amd64/amd64/machdep.c:1.165	Sat Aug 27 12:23:44 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Aug 31 13:03:17 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.165 2011/08/27 16:23:44 christos Exp $	*/
+/*	$NetBSD: machdep.c,v 1.166 2011/08/31 17:03:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.165 2011/08/27 16:23:44 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.166 2011/08/31 17:03:17 christos Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -821,12 +821,17 @@
 	printf("dump_misc_init: max_paddr = 0x%lx\n",
 	(unsigned long)max_paddr);
 #endif
-
-	sparse_dump_physmap = (void*)uvm_km_alloc(kernel_map,
-	roundup(max_paddr / (PAGE_SIZE * NBBY), PAGE_SIZE),
-	PAGE_SIZE, UVM_KMF_WIRED|UVM_KMF_ZERO);
+	if (max_paddr != 0) {
+		printf("Your machine does not initialize mem_clusters; "
+		"sparse_dumps disabled\n");
+		sparse_dump = 0;
+	} else {
+		sparse_dump_physmap = (void *)uvm_km_alloc(kernel_map,
+		roundup(max_paddr / (PAGE_SIZE * NBBY), PAGE_SIZE),
+		PAGE_SIZE, UVM_KMF_WIRED|UVM_KMF_ZERO);
+	}
 #endif
-	dump_headerbuf = (void*)uvm_km_alloc(kernel_map,
+	dump_headerbuf = (void *)uvm_km_alloc(kernel_map,
 	dump_headerbuf_size,
 	PAGE_SIZE, UVM_KMF_WIRED|UVM_KMF_ZERO);
 	/* XXXjld should check for failure here, disable dumps if so. */
@@ -920,7 +925,7 @@
 		 * them could also break the assumption that a sparse
 		 * dump will always be smaller than a full one.
 		 */
-		if (sparse_dump) {
+		if (sparse_dump && sparse_dump_physmap) {
 			paddr_t p, start, end;
 			int lastset;
 
@@ -956,7 +961,7 @@
 dump_seg_prep(void)
 {
 #ifndef NO_SPARSE_DUMP
-	if (sparse_dump)
+	if (sparse_dump && sparse_dump_physmap)
 		cpu_dump_prep_sparse();
 #endif
 



CVS commit: src/sys/arch/amd64/amd64

2011-08-01 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Aug  1 22:21:01 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: linux32_sigcode.S

Log Message:
Remove redundant , after .balign.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amd64/amd64/linux32_sigcode.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/linux32_sigcode.S
diff -u src/sys/arch/amd64/amd64/linux32_sigcode.S:1.1 src/sys/arch/amd64/amd64/linux32_sigcode.S:1.2
--- src/sys/arch/amd64/amd64/linux32_sigcode.S:1.1	Thu Feb  9 19:18:56 2006
+++ src/sys/arch/amd64/amd64/linux32_sigcode.S	Mon Aug  1 22:21:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_sigcode.S,v 1.1 2006/02/09 19:18:56 manu Exp $ */
+/*	$NetBSD: linux32_sigcode.S,v 1.2 2011/08/01 22:21:01 joerg Exp $ */
 
 #include "assym.h"
 #include 
@@ -13,7 +13,7 @@
 	 movl$LINUX32_SYS_exit,%eax
 	 int $0x80
   
-	.balign 16,,
+	.balign 16
 NENTRY(linux32_rt_sigcode)
 	 call*LINUX32_RT_SF_HANDLER(%esp)
 	 lealLINUX32_RT_SF_UC(%esp),%ebx # scp
@@ -22,7 +22,7 @@
 	 int $0x80
 	 movl$LINUX32_SYS_exit,%eax
 	 int $0x80
-	.balign 16,,
+	.balign 16
 	 .globl  _C_LABEL(linux32_esigcode)
 _C_LABEL(linux32_esigcode): 
 



CVS commit: src/sys/arch/amd64/amd64

2011-07-17 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Jul 17 15:16:59 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
CR4_PAE is always set to 1 under amd64, so indicate that PAE mode is
enabled. Can be useful for 32-bits test runs on amd64 hosts.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/amd64/amd64/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.161 src/sys/arch/amd64/amd64/machdep.c:1.162
--- src/sys/arch/amd64/amd64/machdep.c:1.161	Sun Jun 12 03:35:37 2011
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Jul 17 15:16:58 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.161 2011/06/12 03:35:37 rmind Exp $	*/
+/*	$NetBSD: machdep.c,v 1.162 2011/07/17 15:16:58 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.161 2011/06/12 03:35:37 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.162 2011/07/17 15:16:58 jym Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -524,6 +524,12 @@
 		   CTLTYPE_QUAD, "tsc_freq", NULL,
 		   NULL, 0, &tsc_freq, 0,
 		   CTL_MACHDEP, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
+		   CTLTYPE_INT, "pae",
+		   SYSCTL_DESCR("Whether the kernel uses PAE"),
+		   NULL, 1, NULL, 0,
+		   CTL_MACHDEP, CTL_CREATE, CTL_EOL);
 }
 
 void



CVS commit: src/sys/arch/amd64/amd64

2011-07-01 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Fri Jul  1 19:24:14 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: fpu.c genassym.cf rbus_machdep.c

Log Message:
#include  instead of .


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/amd64/amd64/fpu.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/amd64/rbus_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/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.34 src/sys/arch/amd64/amd64/fpu.c:1.35
--- src/sys/arch/amd64/amd64/fpu.c:1.34	Mon Mar  7 02:24:57 2011
+++ src/sys/arch/amd64/amd64/fpu.c	Fri Jul  1 19:24:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $	*/
+/*	$NetBSD: fpu.c,v 1.35 2011/07/01 19:24:14 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.35 2011/07/01 19:24:14 dyoung Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -114,7 +114,7 @@
 #include 
 #include 
 
-#include 
+#include 
 #include 
 #include 
 #include 

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.47 src/sys/arch/amd64/amd64/genassym.cf:1.48
--- src/sys/arch/amd64/amd64/genassym.cf:1.47	Sun Jun 12 03:35:37 2011
+++ src/sys/arch/amd64/amd64/genassym.cf	Fri Jul  1 19:24:14 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.47 2011/06/12 03:35:37 rmind Exp $
+#	$NetBSD: genassym.cf,v 1.48 2011/07/01 19:24:14 dyoung Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -122,7 +122,7 @@
 include 
 endif  
 
-include 
+include 
 
 define	LSRUN			LSRUN
 define	LSONPROC		LSONPROC

Index: src/sys/arch/amd64/amd64/rbus_machdep.c
diff -u src/sys/arch/amd64/amd64/rbus_machdep.c:1.4 src/sys/arch/amd64/amd64/rbus_machdep.c:1.5
--- src/sys/arch/amd64/amd64/rbus_machdep.c:1.4	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/rbus_machdep.c	Fri Jul  1 19:24:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rbus_machdep.c,v 1.4 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: rbus_machdep.c,v 1.5 2011/07/01 19:24:14 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1999
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.4 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rbus_machdep.c,v 1.5 2011/07/01 19:24:14 dyoung Exp $");
 
 #include "opt_pcifixup.h"
 
@@ -36,7 +36,7 @@
 
 #include 
 
-#include 
+#include 
 #include 
 
 #include 



CVS commit: src/sys/arch/amd64/amd64

2011-05-20 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 20 13:33:11 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: busfunc.S

Log Message:
The %dx argument of in/out is not a memory reference, so don't use it as
such.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/amd64/amd64/busfunc.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/busfunc.S
diff -u src/sys/arch/amd64/amd64/busfunc.S:1.9 src/sys/arch/amd64/amd64/busfunc.S:1.10
--- src/sys/arch/amd64/amd64/busfunc.S:1.9	Wed May  5 16:53:57 2010
+++ src/sys/arch/amd64/amd64/busfunc.S	Fri May 20 13:33:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: busfunc.S,v 1.9 2010/05/05 16:53:57 dyoung Exp $	*/
+/*	$NetBSD: busfunc.S,v 1.10 2011/05/20 13:33:11 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -170,7 +170,7 @@
 	movq	%rcx, %rdi
 	movq	%r8, %rcx
 	rep
-	insb	(%dx), %es:(%rdi)
+	insb	%dx, %es:(%rdi)
 	ret
 	.align	16
 1:
@@ -192,7 +192,7 @@
 	movq	%rcx, %rdi
 	movq	%r8, %rcx
 	rep
-	insw	(%dx), %es:(%rdi)
+	insw	%dx, %es:(%rdi)
 	ret
 	.align	16
 1:
@@ -214,7 +214,7 @@
 	movq	%rcx, %rdi
 	movq	%r8, %rcx
 	rep
-	insl	(%dx), %es:(%rdi)
+	insl	%dx, %es:(%rdi)
 	ret
 	.align	16
 1:
@@ -258,7 +258,7 @@
 	movq	%rcx, %rsi
 	movq	%r8, %rcx
 	rep
-	outsb	%ds:(%rsi), (%dx)
+	outsb	%ds:(%rsi), %dx
 	ret
 	.align	16
 1:
@@ -280,7 +280,7 @@
 	movq	%rcx, %rsi
 	movq	%r8, %rcx
 	rep
-	outsw	%ds:(%rsi), (%dx)
+	outsw	%ds:(%rsi), %dx
 	ret
 	.align	16
 1:
@@ -302,7 +302,7 @@
 	movq	%rcx, %rsi
 	movq	%r8, %rcx
 	rep
-	outsl	%ds:(%rsi), (%dx)
+	outsl	%ds:(%rsi), %dx
 	ret
 	.align	16
 1:



CVS commit: src/sys/arch/amd64/amd64

2011-05-20 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 20 13:32:35 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Be more explicit that the "w" part of %r11 is meant.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 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.64 src/sys/arch/amd64/amd64/locore.S:1.65
--- src/sys/arch/amd64/amd64/locore.S:1.64	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/locore.S	Fri May 20 13:32:35 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.64 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: locore.S,v 1.65 2011/05/20 13:32:35 joerg Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1132,8 +1132,8 @@
 	swapgs
 #endif
 	INTR_RESTORE_GPRS
-	movw	$(LSEL(LUDATA_SEL, SEL_UPL)),%r11
-	movw	%r11,%ds
+	movw	$(LSEL(LUDATA_SEL, SEL_UPL)), %r11w
+	movw	%r11w,%ds
 	addq	$TF_REGSIZE+16,%rsp	/* + T_xxx and error code */
 #ifndef XEN
 	popq	%rcx	/* return rip */



CVS commit: src/sys/arch/amd64/amd64

2011-03-06 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Mar  7 02:24:57 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: fpu.c

Log Message:
Use macros clts/stts instead of directly manipulating CR0 flags.
Expose fpuinit to XEN build. (remove #ifdef XEN)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/amd64/amd64/fpu.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/fpu.c
diff -u src/sys/arch/amd64/amd64/fpu.c:1.33 src/sys/arch/amd64/amd64/fpu.c:1.34
--- src/sys/arch/amd64/amd64/fpu.c:1.33	Mon Dec 20 00:25:24 2010
+++ src/sys/arch/amd64/amd64/fpu.c	Mon Mar  7 02:24:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.33 2010/12/20 00:25:24 matt Exp $	*/
+/*	$NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.  All
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.33 2010/12/20 00:25:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.34 2011/03/07 02:24:57 cherry Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -155,18 +155,16 @@
 void fpudna(struct cpu_info *);
 static int x86fpflags_to_ksiginfo(uint32_t);
 
-#ifndef XEN
 /*
  * Init the FPU.
  */
 void
 fpuinit(struct cpu_info *ci)
 {
-	lcr0(rcr0() & ~(CR0_EM|CR0_TS));
+	clts();
 	fninit();
-	lcr0(rcr0() | (CR0_TS));
+	stts();
 }
-#endif
 
 /*
  * Record the FPU state and reinitialize it all except for the control word.



CVS commit: src/sys/arch/amd64/amd64

2011-02-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Feb 23 03:31:49 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
C&P error


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.71 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.72
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.71	Wed Feb 23 02:58:38 2011
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Feb 23 03:31:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.71 2011/02/23 02:58:38 joerg Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.72 2011/02/23 03:31:49 joerg Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.71 2011/02/23 02:58:38 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.72 2011/02/23 03:31:49 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -870,7 +870,7 @@
 			fpusave_lwp(l, false);
 		}
 		memcpy(&pcb->pcb_savefpu.fp_fxsave, &mcp->__fpregs,
-+		sizeof (pcb->pcb_savefpu.fp_fxsave));
+		sizeof (pcb->pcb_savefpu.fp_fxsave));
 		/* If not set already. */
 		l->l_md.md_flags |= MDP_USEDFPU;
 	}



CVS commit: src/sys/arch/amd64/amd64

2011-02-21 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Tue Feb 22 07:12:29 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: mainbus.c

Log Message:
Fix build in admittedly quixotic case with IPMI but no PCI or ACPI.
(ACPI currently doesn't work without PCI, fwiw.)


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/amd64/amd64/mainbus.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/mainbus.c
diff -u src/sys/arch/amd64/amd64/mainbus.c:1.31 src/sys/arch/amd64/amd64/mainbus.c:1.32
--- src/sys/arch/amd64/amd64/mainbus.c:1.31	Wed Apr 28 19:17:03 2010
+++ src/sys/arch/amd64/amd64/mainbus.c	Tue Feb 22 07:12:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.31 2010/04/28 19:17:03 dyoung Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.32 2011/02/22 07:12:29 dholland Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.31 2010/04/28 19:17:03 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.32 2011/02/22 07:12:29 dholland Exp $");
 
 #include 
 #include 
@@ -149,9 +149,11 @@
 void
 mainbus_attach(device_t parent, device_t self, void *aux)
 {
+#if NPCI > 0 || NACPICA > 0 || NIPMI > 0
+	union mainbus_attach_args mba;
+#endif
 #if NPCI > 0
 	int mode;
-	union mainbus_attach_args mba;
 #endif
 #if NACPICA > 0
 	int acpi_present = 0;



CVS commit: src/sys/arch/amd64/amd64

2011-02-21 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Feb 22 05:07:36 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: cpufunc.S

Log Message:
Be explicit about the member of the fld family wanted here.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/amd64/cpufunc.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/cpufunc.S
diff -u src/sys/arch/amd64/amd64/cpufunc.S:1.17 src/sys/arch/amd64/amd64/cpufunc.S:1.18
--- src/sys/arch/amd64/amd64/cpufunc.S:1.17	Wed Jul  7 01:14:52 2010
+++ src/sys/arch/amd64/amd64/cpufunc.S	Tue Feb 22 05:07:36 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.17 2010/07/07 01:14:52 chs Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.18 2011/02/22 05:07:36 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -427,7 +427,7 @@
 
 ENTRY(fldummy)
 	ffree	%st(7)
-	fld	(%rdi)
+	flds	(%rdi)
 	ret
 
 ENTRY(x86_ldmxcsr)



CVS commit: src/sys/arch/amd64/amd64

2011-02-18 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Fri Feb 18 18:00:52 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: db_disasm.c

Log Message:
fix misinterpretation of REX prefixes where use of the accumulator
as operand is hardwired into the instruction code,
mostly from Wolfgang Stukenbrock per PR port-amd64/44405


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/amd64/amd64/db_disasm.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/db_disasm.c
diff -u src/sys/arch/amd64/amd64/db_disasm.c:1.13 src/sys/arch/amd64/amd64/db_disasm.c:1.14
--- src/sys/arch/amd64/amd64/db_disasm.c:1.13	Sat Mar 14 21:04:03 2009
+++ src/sys/arch/amd64/amd64/db_disasm.c	Fri Feb 18 18:00:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.13 2009/03/14 21:04:03 dsl Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.14 2011/02/18 18:00:52 drochner Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.13 2009/03/14 21:04:03 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.14 2011/02/18 18:00:52 drochner Exp $");
 
 #ifndef _KERNEL
 #include "stubs.h"
@@ -1393,11 +1393,9 @@
 		case Si:
 			db_printf("%s", db_seg_reg[f_reg(inst)]);
 			break;
-		case A: {
-			int ext = ((rex & REX_w) != 0);
-			db_printf("%s", db_reg[ext][size][0]);	/* acc */
+		case A:
+			db_printf("%s", db_reg[0][size][0]);	/* acc */
 			break;
-		}
 		case BX:
 			if (seg)
 db_printf("%s:", seg);



CVS commit: src/sys/arch/amd64/amd64

2011-01-26 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Wed Jan 26 21:44:32 UTC 2011

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Do mask the upper 16 bits, when sanity checking fs/gs register values.
Fix my own PR/43842.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.68 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.69
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.68	Wed Nov 17 18:22:17 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Jan 26 21:44:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.69 2011/01/26 21:44:31 njoly Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.69 2011/01/26 21:44:31 njoly Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -952,6 +952,12 @@
  * and rely on catching invalid user contexts on exit from the kernel.
  * These functions perform the needed checks.
  */
+
+#define	VALID_FS32(s) \
+(((s) & 0x) == GSEL(GUFS_SEL, SEL_UPL))
+#define	VALID_GS32(s) \
+(((s) & 0x) == GSEL(GUGS_SEL, SEL_UPL))
+
 static int
 check_sigcontext32(struct lwp *l, const struct netbsd32_sigcontext *scp)
 {
@@ -965,10 +971,10 @@
 	!VALID_USER_CSEL32(scp->sc_cs))
 		return EINVAL;
 	if (scp->sc_fs != 0 && !VALID_USER_DSEL32(scp->sc_fs) &&
-	!(scp->sc_fs == GSEL(GUFS_SEL, SEL_UPL) && pcb->pcb_fs != 0))
+	!(VALID_FS32(scp->sc_fs) && pcb->pcb_fs != 0))
 		return EINVAL;
 	if (scp->sc_gs != 0 && !VALID_USER_DSEL32(scp->sc_gs) &&
-	!(scp->sc_gs == GSEL(GUGS_SEL, SEL_UPL) && pcb->pcb_gs != 0))
+	!(VALID_GS32(scp->sc_gs) && pcb->pcb_gs != 0))
 		return EINVAL;
 	if (scp->sc_es != 0 && !VALID_USER_DSEL32(scp->sc_es))
 		return EINVAL;
@@ -994,10 +1000,10 @@
 	!VALID_USER_CSEL32(gr[_REG32_CS]))
 		return EINVAL;
 	if (gr[_REG32_FS] != 0 && !VALID_USER_DSEL32(gr[_REG32_FS]) &&
-	!(gr[_REG32_FS] == GSEL(GUFS_SEL, SEL_UPL) && pcb->pcb_fs != 0))
+	!(VALID_FS32(gr[_REG32_FS]) && pcb->pcb_fs != 0))
 		return EINVAL;
 	if (gr[_REG32_GS] != 0 && !VALID_USER_DSEL32(gr[_REG32_GS]) &&
-	!(gr[_REG32_GS] == GSEL(GUGS_SEL, SEL_UPL) && pcb->pcb_gs != 0))
+	!(VALID_GS32(gr[_REG32_GS]) && pcb->pcb_gs != 0))
 		return EINVAL;
 	if (gr[_REG32_ES] != 0 && !VALID_USER_DSEL32(gr[_REG32_ES]))
 		return EINVAL;



CVS commit: src/sys/arch/amd64/amd64

2010-12-18 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sat Dec 18 13:53:34 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Free tables are already zeroed in xen_pmap_bootstrap. No need to
do it a second time in assembly code.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/amd64/amd64/locore.S:1.63
--- src/sys/arch/amd64/amd64/locore.S:1.62	Thu Oct 21 11:43:22 2010
+++ src/sys/arch/amd64/amd64/locore.S	Sat Dec 18 13:53:34 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.62 2010/10/21 11:43:22 yamt Exp $	*/
+/*	$NetBSD: locore.S,v 1.63 2010/12/18 13:53:34 jym Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -786,12 +786,6 @@
 	movq	%rax, %rsi
 	movq	%rsi,(_C_LABEL(lwp0)+L_PCB)	/* XXX L_PCB != uarea */
 	
-	xorq	%rax,%rax
-	movq	%rsi,%rdi
-	movq	$USPACE,%rcx
-	rep
-	stosb
-
 	/*
 	 * Set new stack and clear segments
 	 */
@@ -799,6 +793,7 @@
 	leaq	(USPACE-FRAMESIZE)(%rsi),%rsp
 	xorq	%rbp,%rbp
 
+	xorw	%ax,%ax
 	movw	%ax,%gs
 	movw	%ax,%fs
 	



CVS commit: src/sys/arch/amd64/amd64

2010-11-17 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Wed Nov 17 18:22:17 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Fix build with COMPAT_13.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.67 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.68
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.67	Sun Sep  5 20:52:38 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Nov 17 18:22:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.67 2010/09/05 20:52:38 chs Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.67 2010/09/05 20:52:38 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.68 2010/11/17 18:22:17 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1085,7 +1085,7 @@
 	/*
 	 * Check for security violations.
 	 */
-	error = check_sigcontext32((const struct netbsd32_sigcontext *)&context, tf);
+	error = check_sigcontext32(l, (const struct netbsd32_sigcontext *)&context);
 	if (error != 0)
 		return error;
 



CVS commit: src/sys/arch/amd64/amd64

2010-11-14 Thread Masao Uebayashi
Module Name:src
Committed By:   uebayasi
Date:   Mon Nov 15 06:12:28 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
struct lwp * and struct proc * derefs.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/amd64/amd64/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.156 src/sys/arch/amd64/amd64/machdep.c:1.157
--- src/sys/arch/amd64/amd64/machdep.c:1.156	Fri Nov 12 13:18:56 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Mon Nov 15 06:12:28 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.156 2010/11/12 13:18:56 uebayasi Exp $	*/
+/*	$NetBSD: machdep.c,v 1.157 2010/11/15 06:12:28 uebayasi Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.156 2010/11/12 13:18:56 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.157 2010/11/15 06:12:28 uebayasi Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -148,6 +148,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #ifdef KGDB
 #include 



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:43:23 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Xosyscall: sync with Xsyscall.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 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.61 src/sys/arch/amd64/amd64/locore.S:1.62
--- src/sys/arch/amd64/amd64/locore.S:1.61	Thu Oct 21 11:42:26 2010
+++ src/sys/arch/amd64/amd64/locore.S	Thu Oct 21 11:43:22 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.61 2010/10/21 11:42:26 yamt Exp $	*/
+/*	$NetBSD: locore.S,v 1.62 2010/10/21 11:43:22 yamt Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1258,37 +1258,41 @@
 .Losyscall_checkast:
 	/* Check for ASTs on exit to user mode. */
 	CLI(si)
-	CHECK_ASTPENDING(%r14)
-	je	1f
-	/* Always returning to user mode here. */
-	CLEAR_ASTPENDING(%r14)
-	STI(si)
-	/* Pushed T_ASTFLT into tf_trapno on entry. */
-	movq	%rsp,%rdi
-	call	_C_LABEL(trap)
-	jmp	.Losyscall_checkast
-1:	CHECK_DEFERRED_SWITCH
+	movl	L_MD_ASTPENDING(%r14), %eax
+	orl	CPUVAR(WANT_PMAPLOAD), %eax
 	jnz	9f
 iret_return:
-#ifndef DIAGNOSTIC
-	INTRFASTEXIT
-#else /* DIAGNOSTIC */
+#ifdef DIAGNOSTIC
 	cmpl	$IPL_NONE,CPUVAR(ILEVEL)
 	jne	3f
+#endif
 	INTRFASTEXIT
-3:
-	STI(si)
-	movabsq	$4f, %rdi
+#ifdef DIAGNOSTIC
+3:	movabsq	$4f, %rdi
+	movl	TF_RAX(%rsp),%esi
+	movl	TF_RDI(%rsp),%edx
+	movl	%ebx,%ecx
+	movl	CPUVAR(ILEVEL),%r8d
 	xorq	%rax,%rax
 	call	_C_LABEL(printf)
 	movl	$IPL_NONE,%edi
 	call	_C_LABEL(spllower)
 	jmp	.Losyscall_checkast
-4:	.asciz	"WARNING: SPL NOT LOWERED ON SYSCALL EXIT\n"
-#endif /* DIAGNOSTIC */
-9:	STI(si)
+4:	.asciz	"WARNING: SPL NOT LOWERED ON SYSCALL %d %d EXIT %x %x\n"
+#endif
+9:
+	cmpl	$0, CPUVAR(WANT_PMAPLOAD)
+	jz	10f
+	STI(si)
 	call	_C_LABEL(do_pmap_load)
 	jmp	.Losyscall_checkast	/* re-check ASTs */
+10:
+	CLEAR_ASTPENDING(%r14)
+	STI(si)
+	/* Pushed T_ASTFLT into tf_trapno on entry. */
+	movq	%rsp,%rdi
+	call	_C_LABEL(trap)
+	jmp	.Losyscall_checkast	/* re-check ASTs */
 
 /*
  * void sse2_idlezero_page(void *pg)



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:42:27 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Xsyscall: remove a stale comment.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 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.60 src/sys/arch/amd64/amd64/locore.S:1.61
--- src/sys/arch/amd64/amd64/locore.S:1.60	Thu Oct 21 11:41:31 2010
+++ src/sys/arch/amd64/amd64/locore.S	Thu Oct 21 11:42:26 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.60 2010/10/21 11:41:31 yamt Exp $	*/
+/*	$NetBSD: locore.S,v 1.61 2010/10/21 11:42:26 yamt Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1171,7 +1171,6 @@
 	call	_C_LABEL(do_pmap_load)
 	jmp	.Lsyscall_checkast	/* re-check ASTs */
 10:
-	/* Always returning to user mode here. */
 	CLEAR_ASTPENDING(%r14)
 	STI(si)
 	/* Pushed T_ASTFLT into tf_trapno on entry. */



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:41:31 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Xsyscall: remove an unused label.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/sys/arch/amd64/amd64/locore.S:1.60
--- src/sys/arch/amd64/amd64/locore.S:1.59	Thu Oct 21 11:39:45 2010
+++ src/sys/arch/amd64/amd64/locore.S	Thu Oct 21 11:41:31 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.59 2010/10/21 11:39:45 yamt Exp $	*/
+/*	$NetBSD: locore.S,v 1.60 2010/10/21 11:41:31 yamt Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1128,7 +1128,6 @@
 	jnz	9f
 	testl	$MDP_IRET, L_MD_FLAGS(%r14)
 	jne	iret_return;
-syscall_return:
 #ifdef DIAGNOSTIC
 	cmpl	$IPL_NONE,CPUVAR(ILEVEL)
 	jne	3f



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:39:45 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
Xsyscall: save %es before enabling interrupts.  otherwise it can be
clobbered by preemption.  PR/43903.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/sys/arch/amd64/amd64/locore.S:1.59
--- src/sys/arch/amd64/amd64/locore.S:1.58	Wed Jul  7 01:14:52 2010
+++ src/sys/arch/amd64/amd64/locore.S	Thu Oct 21 11:39:45 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.58 2010/07/07 01:14:52 chs Exp $	*/
+/*	$NetBSD: locore.S,v 1.59 2010/10/21 11:39:45 yamt Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1085,12 +1085,12 @@
 	pushq	$(LSEL(LUDATA_SEL, SEL_UPL))	/* Known to be user ss */
 	pushq	%r15/* User space rsp */
 	movq	CPUVAR(SCRATCH),%r15
-	sti
 	subq	$TF_REGSIZE+(TF_RSP-TF_TRAPNO),%rsp
+	movw	%es,TF_ES(%rsp)
+	sti
 	INTR_SAVE_GPRS
 	movw	%fs,TF_FS(%rsp)
 	movw	%gs,TF_GS(%rsp)
-	movw	%es,TF_ES(%rsp)
 	movw	$(LSEL(LUDATA_SEL, SEL_UPL)),TF_DS(%rsp)
 	movq	%r11, TF_RFLAGS(%rsp)	/* old rflags from syscall insn */
 	movq	$(LSEL(LUCODE_SEL, SEL_UPL)), TF_CS(%rsp)



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:28:34 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
cpu_setmcontext: add a comment


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 src/sys/arch/amd64/amd64/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.152 src/sys/arch/amd64/amd64/machdep.c:1.153
--- src/sys/arch/amd64/amd64/machdep.c:1.152	Thu Oct 21 11:27:46 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Oct 21 11:28:34 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.152 2010/10/21 11:27:46 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.153 2010/10/21 11:28:34 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.152 2010/10/21 11:27:46 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.153 2010/10/21 11:28:34 yamt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1632,6 +1632,9 @@
 		if (error != 0)
 			return error;
 		/*
+		 * save and restore some values we don't want to change.
+		 * _FRAME_GREG(copy_to_tf) below overwrites them.
+		 *
 		 * XXX maybe inline this.
 		 */
 		rflags = tf->tf_rflags;



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:27:46 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
cpu_fsgs_zero: clear %fs and %gs even in the case of !PK_32.


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 src/sys/arch/amd64/amd64/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.151 src/sys/arch/amd64/amd64/machdep.c:1.152
--- src/sys/arch/amd64/amd64/machdep.c:1.151	Thu Oct 21 11:22:55 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Oct 21 11:27:46 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.151 2010/10/21 11:22:55 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.152 2010/10/21 11:27:46 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.151 2010/10/21 11:22:55 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.152 2010/10/21 11:27:46 yamt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1831,24 +1831,22 @@
 void
 cpu_fsgs_zero(struct lwp *l)
 {
-	struct trapframe *tf;
+	struct trapframe * const tf = l->l_md.md_regs;
 	struct pcb *pcb;
 	uint64_t zero = 0;
 
 	pcb = lwp_getpcb(l);
 	if (l == curlwp) {
-		tf = l->l_md.md_regs;
 		kpreempt_disable();
 		tf->tf_fs = 0;
 		tf->tf_gs = 0;
-		if (l->l_proc->p_flag & PK_32) {
-			setfs(0);
+		setfs(0);
 #ifndef XEN
-			setusergs(0);
+		setusergs(0);
 #else
-			HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, 0);
+		HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, 0);
 #endif
-		} else {
+		if ((l->l_proc->p_flag & PK_32) == 0) {
 #ifndef XEN
 			wrmsr(MSR_FSBASE, 0);
 			wrmsr(MSR_KERNELGSBASE, 0);



CVS commit: src/sys/arch/amd64/amd64

2010-10-21 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Thu Oct 21 11:22:55 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
cpu_fsgs_zero: always clear tf_fs and tf_gs.


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/arch/amd64/amd64/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.150 src/sys/arch/amd64/amd64/machdep.c:1.151
--- src/sys/arch/amd64/amd64/machdep.c:1.150	Thu Oct 21 11:17:55 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Oct 21 11:22:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.150 2010/10/21 11:17:55 yamt Exp $	*/
+/*	$NetBSD: machdep.c,v 1.151 2010/10/21 11:22:55 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.150 2010/10/21 11:17:55 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.151 2010/10/21 11:22:55 yamt Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1863,6 +1863,8 @@
 		update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &zero);
 		kpreempt_enable();
 	} else {
+		tf->tf_fs = 0;
+		tf->tf_gs = 0;
 		pcb->pcb_fs = 0;
 		pcb->pcb_gs = 0;
 	}



CVS commit: src/sys/arch/amd64/amd64

2010-09-22 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Wed Sep 22 16:16:52 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Avoid fault if acpi_softc is NULL at attempted power-off.
XXX at least some of this should be factored off into arch/x86.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/amd64/amd64/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.148 src/sys/arch/amd64/amd64/machdep.c:1.149
--- src/sys/arch/amd64/amd64/machdep.c:1.148	Sat Aug  7 20:07:25 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Wed Sep 22 16:16:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.148 2010/08/07 20:07:25 jruoho Exp $	*/
+/*	$NetBSD: machdep.c,v 1.149 2010/09/22 16:16:51 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.148 2010/08/07 20:07:25 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.149 2010/09/22 16:16:51 jakllsch Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -697,8 +697,10 @@
 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
 #ifndef XEN
 #if NACPICA > 0
-		acpi_enter_sleep_state(acpi_softc, ACPI_STATE_S5);
-		printf("WARNING: powerdown failed!\n");
+		if (acpi_softc != NULL) {
+			acpi_enter_sleep_state(acpi_softc, ACPI_STATE_S5);
+			printf("WARNING: ACPI powerdown failed!\n");
+		}
 #endif
 #else /* XEN */
 		HYPERVISOR_shutdown();



CVS commit: src/sys/arch/amd64/amd64

2010-09-05 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Sep  5 20:52:38 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
accept the LDT selector in check_sigcontext32() too.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.66 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.67
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.66	Sun Sep  5 20:14:39 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Sun Sep  5 20:52:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.66 2010/09/05 20:14:39 chs Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.67 2010/09/05 20:52:38 chs Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.66 2010/09/05 20:14:39 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.67 2010/09/05 20:52:38 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -962,7 +962,7 @@
 	pcb = lwp_getpcb(curlwp);
 
 	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) &&
 	!(scp->sc_fs == GSEL(GUFS_SEL, SEL_UPL) && pcb->pcb_fs != 0))



CVS commit: src/sys/arch/amd64/amd64

2010-07-31 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Jul 31 18:38:33 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: machdep.c

Log Message:
Add machdep.fpu_present, machdep.sse and machdep.sse2 sysctls for
compatibility with i386 and compat32.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/sys/arch/amd64/amd64/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.146 src/sys/arch/amd64/amd64/machdep.c:1.147
--- src/sys/arch/amd64/amd64/machdep.c:1.146	Wed Jul  7 01:14:52 2010
+++ src/sys/arch/amd64/amd64/machdep.c	Sat Jul 31 18:38:32 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.146 2010/07/07 01:14:52 chs Exp $	*/
+/*	$NetBSD: machdep.c,v 1.147 2010/07/31 18:38:32 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.146 2010/07/07 01:14:52 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.147 2010/07/31 18:38:32 joerg Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -500,6 +500,21 @@
 		   sysctl_machdep_diskinfo, 0, NULL, 0,
 		   CTL_MACHDEP, CPU_DISKINFO, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
+		   CTLTYPE_INT, "fpu_present", NULL,
+		   NULL, 1, NULL, 0,
+		   CTL_MACHDEP, CPU_FPU_PRESENT, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
+		   CTLTYPE_INT, "sse", NULL,
+		   NULL, 1, NULL, 0,
+		   CTL_MACHDEP, CPU_SSE, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT | CTLFLAG_IMMEDIATE,
+		   CTLTYPE_INT, "sse2", NULL,
+		   NULL, 1, NULL, 0,
+		   CTL_MACHDEP, CPU_SSE2, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT,
 		   CTLTYPE_QUAD, "tsc_freq", NULL,
 		   NULL, 0, &tsc_freq, 0,



CVS commit: src/sys/arch/amd64/amd64

2010-07-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Jul 26 12:39:04 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
follow suit with the i386, and correct the siginfo codes for integer overflow
and zerodivide.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 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.63 src/sys/arch/amd64/amd64/trap.c:1.64
--- src/sys/arch/amd64/amd64/trap.c:1.63	Tue Jul  6 21:15:34 2010
+++ src/sys/arch/amd64/amd64/trap.c	Mon Jul 26 08:39:04 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.63 2010/07/07 01:15:34 chs Exp $	*/
+/*	$NetBSD: trap.c,v 1.64 2010/07/26 12:39:04 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.63 2010/07/07 01:15:34 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.64 2010/07/26 12:39:04 christos Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -464,13 +464,15 @@
 		ksi.ksi_signo = SIGFPE;
 		ksi.ksi_trap = type & ~T_USER;
 		ksi.ksi_addr = (void *)frame->tf_rip;
-		switch (type ) {
+		switch (type) {
 		case T_BOUND|T_USER:
+			ksi.ksi_code = FPE_FLTSUB;
+			break;
 		case T_OFLOW|T_USER:
-			ksi.ksi_code = FPE_FLTOVF;
+			ksi.ksi_code = FPE_INTOVF;
 			break;
 		case T_DIVIDE|T_USER:
-			ksi.ksi_code = FPE_FLTDIV;
+			ksi.ksi_code = FPE_INTDIV;
 			break;
 		default:
 #ifdef DIAGNOSTIC



CVS commit: src/sys/arch/amd64/amd64

2010-07-06 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Jul  7 01:15:35 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: trap.c

Log Message:
clean up the check for tracing into a syscall handler.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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.62 src/sys/arch/amd64/amd64/trap.c:1.63
--- src/sys/arch/amd64/amd64/trap.c:1.62	Fri Apr 23 19:18:09 2010
+++ src/sys/arch/amd64/amd64/trap.c	Wed Jul  7 01:15:34 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.62 2010/04/23 19:18:09 rmind Exp $	*/
+/*	$NetBSD: trap.c,v 1.63 2010/07/07 01:15:34 chs Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.62 2010/04/23 19:18:09 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.63 2010/07/07 01:15:34 chs Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -197,6 +197,7 @@
  * exception has been processed. Note that the effect is as if the arguments
  * were passed call by reference.
  */
+
 void
 trap(struct trapframe *frame)
 {
@@ -206,6 +207,8 @@
 	extern char fusuintrfailure[], kcopy_fault[],
 		resume_iret[];
 	extern char IDTVEC(oosyscall)[];
+	extern char IDTVEC(osyscall)[];
+	extern char IDTVEC(syscall32)[];
 #if 0
 	extern char resume_pop_ds[], resume_pop_es[];
 #endif
@@ -642,9 +645,9 @@
 
 	case T_TRCTRAP:
 		/* Check whether they single-stepped into a lcall. */
-		if (frame->tf_rip == (int)IDTVEC(oosyscall))
-			return;
-		if (frame->tf_rip == (int)IDTVEC(oosyscall) + 1) {
+		if (frame->tf_rip == (uint64_t)IDTVEC(oosyscall) ||
+		frame->tf_rip == (uint64_t)IDTVEC(osyscall) ||
+		frame->tf_rip == (uint64_t)IDTVEC(syscall32)) {
 			frame->tf_rflags &= ~PSL_T;
 			return;
 		}
@@ -655,6 +658,7 @@
 		/*
 		 * Don't go single-stepping into a RAS.
 		 */
+
 		if (p->p_raslist == NULL ||
 		(ras_lookup(p, (void *)frame->tf_rip) == (void *)-1)) {
 			KSI_INIT_TRAP(&ksi);



CVS commit: src/sys/arch/amd64/amd64

2010-07-06 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Jul  7 01:13:29 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: copy.S

Log Message:
fix more bugs in ucas_*():
move the "old" value to %*ax so that cmpxchg* can work.
remove the PCB_ONFAULT stuff, onfault_handler() handles this already.
return the error from fault handler in ucas_fault rather than forcing EFAULT.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/amd64/copy.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/copy.S
diff -u src/sys/arch/amd64/amd64/copy.S:1.17 src/sys/arch/amd64/amd64/copy.S:1.18
--- src/sys/arch/amd64/amd64/copy.S:1.17	Tue Jun 22 18:26:05 2010
+++ src/sys/arch/amd64/amd64/copy.S	Wed Jul  7 01:13:29 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.17 2010/06/22 18:26:05 rmind Exp $	*/
+/*	$NetBSD: copy.S,v 1.18 2010/07/07 01:13:29 chs Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -502,13 +502,11 @@
 	movq	$VM_MAXUSER_ADDRESS-8, %r8
 	cmpq	%r8, %rdi
 	ja	_C_LABEL(ucas_fault)
-	/* Label for fault handler */
+	movq	%rsi, %rax
 .Lucas64_start:
 	/* Perform the CAS */
 	lock
 	cmpxchgq %rdx, (%rdi)
-	/* Clear the fault handler */
-	movq	%rax, PCB_ONFAULT(%r8)
 .Lucas64_end:
 	/*
 	 * Note: %rax is "old" value.
@@ -516,8 +514,6 @@
 	 */
 	movq	%rax, (%rcx)
 	xorq	%rax, %rax
-	/* Clear the fault handler */
-	movq	%rax, PCB_ONFAULT(%r8)
 	ret
 	DEFERRED_SWITCH_CALL
 
@@ -530,7 +526,7 @@
 	movq	$VM_MAXUSER_ADDRESS-4, %r8
 	cmpq	%r8, %rdi
 	ja	_C_LABEL(ucas_fault)
-	/* Label for fault handler */
+	movl	%esi, %eax
 .Lucas32_start:
 	/* Perform the CAS */
 	lock
@@ -546,15 +542,15 @@
 	DEFERRED_SWITCH_CALL
 
 /*
- * Fault handler for ucas_32() and ucas_64().
- * Unset the handler and return the failure.
+ * Fault handler for ucas_*().
+ * Just return the error set by trap().
  */
 NENTRY(ucas_fault)
-	movq	$EFAULT, %rax
 	ret
 
 /*
- * int	ucas_ptr(volatile void *uptr, void *old, void *new, void *ret);
+ * int	ucas_ptr(volatile void **uptr, void *old, void *new, void **ret);
+ * int	ucas_int(volatile int *uptr, int old, intnew, int *ret);
  */
 STRONG_ALIAS(ucas_ptr, ucas_64)
 STRONG_ALIAS(ucas_int, ucas_32)



CVS commit: src/sys/arch/amd64/amd64

2010-06-22 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Tue Jun 22 18:26:05 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: copy.S

Log Message:
Fix ucas_32/ucas_64 on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/amd64/amd64/copy.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/copy.S
diff -u src/sys/arch/amd64/amd64/copy.S:1.16 src/sys/arch/amd64/amd64/copy.S:1.17
--- src/sys/arch/amd64/amd64/copy.S:1.16	Fri Nov 27 03:23:04 2009
+++ src/sys/arch/amd64/amd64/copy.S	Tue Jun 22 18:26:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.16 2009/11/27 03:23:04 rmind Exp $	*/
+/*	$NetBSD: copy.S,v 1.17 2010/06/22 18:26:05 rmind Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -501,7 +501,7 @@
 	/* Fail if kernel-space */
 	movq	$VM_MAXUSER_ADDRESS-8, %r8
 	cmpq	%r8, %rdi
-	ja	1f
+	ja	_C_LABEL(ucas_fault)
 	/* Label for fault handler */
 .Lucas64_start:
 	/* Perform the CAS */
@@ -518,9 +518,6 @@
 	xorq	%rax, %rax
 	/* Clear the fault handler */
 	movq	%rax, PCB_ONFAULT(%r8)
-1:
-	/* Failure case */
-	movq	$EFAULT, %rax
 	ret
 	DEFERRED_SWITCH_CALL
 
@@ -532,7 +529,7 @@
 	/* Fail if kernel-space */
 	movq	$VM_MAXUSER_ADDRESS-4, %r8
 	cmpq	%r8, %rdi
-	ja	1f
+	ja	_C_LABEL(ucas_fault)
 	/* Label for fault handler */
 .Lucas32_start:
 	/* Perform the CAS */
@@ -545,9 +542,6 @@
 	 */
 	movl	%eax, (%rcx)
 	xorq	%rax, %rax
-1:
-	/* Failure case */
-	movq	$EFAULT, %rax
 	ret
 	DEFERRED_SWITCH_CALL
 



CVS commit: src/sys/arch/amd64/amd64

2010-05-10 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue May 11 02:34:40 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Fix indentation


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.62 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.63
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.62	Fri Apr 23 19:18:09 2010
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Tue May 11 02:34:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.62 2010/04/23 19:18:09 rmind Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.63 2010/05/11 02:34:39 joerg Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.62 2010/04/23 19:18:09 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.63 2010/05/11 02:34:39 joerg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -612,21 +612,21 @@
 	int error;
 
 	switch (SCARG(uap, op)) {
-		case X86_IOPL:
-			error = x86_iopl(l,
-			NETBSD32PTR64(SCARG(uap, parms)), retval);
-			break;
-		case X86_GET_MTRR:
-			error = x86_64_get_mtrr32(l,
-			NETBSD32PTR64(SCARG(uap, parms)), retval);
-			break;
-		case X86_SET_MTRR:
-			error = x86_64_set_mtrr32(l,
-			NETBSD32PTR64(SCARG(uap, parms)), retval);
-			break;
-		default:
-			error = EINVAL;
-			break;
+	case X86_IOPL:
+		error = x86_iopl(l,
+		NETBSD32PTR64(SCARG(uap, parms)), retval);
+		break;
+	case X86_GET_MTRR:
+		error = x86_64_get_mtrr32(l,
+		NETBSD32PTR64(SCARG(uap, parms)), retval);
+		break;
+	case X86_SET_MTRR:
+		error = x86_64_set_mtrr32(l,
+		NETBSD32PTR64(SCARG(uap, parms)), retval);
+		break;
+	default:
+		error = EINVAL;
+		break;
 	}
 	return error;
 }



CVS commit: src/sys/arch/amd64/amd64

2010-05-05 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Wed May  5 16:53:58 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: busfunc.S

Log Message:
As Andrew Doran points out, _ALIGN_TEXT is unused, and to test that
X86_BUS_SPACE_IO equals 0 is no longer necessary.  Get rid of the
_ALIGN_TEXT definition, and do not "assert" that X86_BUS_SPACE_IO == 0.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/amd64/busfunc.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/busfunc.S
diff -u src/sys/arch/amd64/amd64/busfunc.S:1.8 src/sys/arch/amd64/amd64/busfunc.S:1.9
--- src/sys/arch/amd64/amd64/busfunc.S:1.8	Wed Apr 28 19:17:03 2010
+++ src/sys/arch/amd64/amd64/busfunc.S	Wed May  5 16:53:57 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: busfunc.S,v 1.8 2010/04/28 19:17:03 dyoung Exp $	*/
+/*	$NetBSD: busfunc.S,v 1.9 2010/05/05 16:53:57 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -33,14 +33,6 @@
 
 #include "assym.h"
 
-/* XXX */
-#undef	_ALIGN_TEXT
-#define	_ALIGN_TEXT	.align 16
-
-#if X86_BUS_SPACE_IO != 0
-#error depends on X86_BUS_SPACE_IO == 0
-#endif
-
 .Ldopanic:
 	movq	$.Lpstr, %rdi
 	call	_C_LABEL(panic)



CVS commit: src/sys/arch/amd64/amd64

2010-04-20 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Tue Apr 20 15:42:21 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: mptramp.S

Log Message:
Enable the NX bit feature early in the MP trampoline code (do not rely on
cpu_init_msrs() to do it). Having NX bit set on a page will raise a #GP
on fetch if NXE is not enabled, which can happen early when structures
(like idlelwp) are allocated with just rw- rights.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/amd64/amd64/mptramp.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/mptramp.S
diff -u src/sys/arch/amd64/amd64/mptramp.S:1.11 src/sys/arch/amd64/amd64/mptramp.S:1.12
--- src/sys/arch/amd64/amd64/mptramp.S:1.11	Sun Apr 18 23:47:50 2010
+++ src/sys/arch/amd64/amd64/mptramp.S	Tue Apr 20 15:42:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mptramp.S,v 1.11 2010/04/18 23:47:50 jym Exp $	*/
+/*	$NetBSD: mptramp.S,v 1.12 2010/04/20 15:42:21 jym Exp $	*/
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -216,6 +216,18 @@
 
 	
 _C_LABEL(cpu_spinup_trampoline_end):	#end of code copied to MP_TRAMPOLINE
+	/*
+	 * If EFER_NXE is not enabled, fetching a page with a NX bit set
+	 * will raise a #GP. Avoid that by setting the NXE feature now.
+	 */
+	movl	_C_LABEL(cpu_feature)+2*4,%eax	/* cpu_feature[2] */
+	andl	$CPUID_NOX,%eax
+	jz	1f
+	movl	$MSR_EFER,%ecx
+	rdmsr
+	orl	$EFER_NXE,%eax	/* enable No-Execute feature */
+	wrmsr
+
 1:
 	/* Don't touch lapic until BP has done init sequence. */
 	movq	_C_LABEL(cpu_starting),%rdi
@@ -223,7 +235,6 @@
 	testq	%rdi, %rdi
 	jz	1b
 
-1:
 	movq	CPU_INFO_IDLELWP(%rdi),%rsi
 	movq	L_PCB(%rsi),%rsi
 	



CVS commit: src/sys/arch/amd64/amd64

2010-04-18 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Sun Apr 18 15:24:54 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: locore.S

Log Message:
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.55 -r1.56 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.55 src/sys/arch/amd64/amd64/locore.S:1.56
--- src/sys/arch/amd64/amd64/locore.S:1.55	Fri Nov 27 03:23:04 2009
+++ src/sys/arch/amd64/amd64/locore.S	Sun Apr 18 15:24:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.55 2009/11/27 03:23:04 rmind Exp $	*/
+/*	$NetBSD: locore.S,v 1.56 2010/04/18 15:24:54 jym Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -269,13 +269,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 */
@@ -638,7 +650,7 @@
 	 * in it to do that.
 	 */
 
-	movl	$RELOC(gdt64),%eax
+	movl	$RELOC(gdt64_lo),%eax
 	lgdt	(%eax)
 	movl	$RELOC(farjmp64),%eax
 	ljmp	*(%eax)
@@ -654,9 +666,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: src/sys/arch/amd64/amd64

2010-02-22 Thread Christoph Egger
Module Name:src
Committed By:   cegger
Date:   Tue Feb 23 06:27:40 UTC 2010

Modified Files:
src/sys/arch/amd64/amd64: trap.c vector.S

Log Message:
dtrace kernel hooks

ok darran@


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/amd64/amd64/trap.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/amd64/amd64/vector.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/trap.c
diff -u src/sys/arch/amd64/amd64/trap.c:1.60 src/sys/arch/amd64/amd64/trap.c:1.61
--- src/sys/arch/amd64/amd64/trap.c:1.60	Sat Nov 21 03:11:01 2009
+++ src/sys/arch/amd64/amd64/trap.c	Tue Feb 23 06:27:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.60 2009/11/21 03:11:01 rmind Exp $	*/
+/*	$NetBSD: trap.c,v 1.61 2010/02/23 06:27:40 cegger Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,11 +68,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.60 2009/11/21 03:11:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.61 2010/02/23 06:27:40 cegger Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 #include "opt_xen.h"
+#include "opt_dtrace.h"
 
 #include 
 #include 
@@ -111,6 +112,19 @@
 #include 
 #endif
 
+#ifdef KDTRACE_HOOKS
+#include 
+
+/*
+ * This is a hook which is initialized by the dtrace module
+ * to handle traps which might occur during DTrace probe
+ * execution.
+ */
+dtrace_trap_func_t	dtrace_trap_func = NULL;
+
+dtrace_doubletrap_func_t	dtrace_doubletrap_func = NULL;
+#endif
+
 void trap(struct trapframe *);
 
 const char * const trap_type[] = {
@@ -232,6 +246,27 @@
 		LWP_CACHE_CREDS(l, p);
 	}
 
+#ifdef KDTRACE_HOOKS
+	/*
+	 * A trap can occur while DTrace executes a probe. Before
+	 * executing the probe, DTrace blocks re-scheduling and sets
+	 * a flag in it's per-cpu flags to indicate that it doesn't
+	 * want to fault. On returning from the the probe, the no-fault
+	 * flag is cleared and finally re-scheduling is enabled.
+	 *
+	 * If the DTrace kernel module has registered a trap handler,
+	 * call it and if it returns non-zero, assume that it has
+	 * handled the trap and modified the trap frame so that this
+	 * function can return normally.
+	 */
+	if ((type == T_PROTFLT || type == T_PAGEFLT) &&
+	dtrace_trap_func != NULL) {
+		if ((*dtrace_trap_func)(frame, type)) {
+			return;
+		}
+	}
+#endif
+
 	switch (type) {
 
 	default:

Index: src/sys/arch/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.32 src/sys/arch/amd64/amd64/vector.S:1.33
--- src/sys/arch/amd64/amd64/vector.S:1.32	Tue Feb 23 00:23:36 2010
+++ src/sys/arch/amd64/amd64/vector.S	Tue Feb 23 06:27:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.32 2010/02/23 00:23:36 cegger Exp $	*/
+/*	$NetBSD: vector.S,v 1.33 2010/02/23 06:27:40 cegger Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,6 +69,7 @@
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
+#include "opt_dtrace.h"
 
 #define ALIGN_TEXT	.align 16,0x90
 
@@ -112,6 +113,21 @@
 
 #define	BPTTRAP(a)	ZTRAP(a)
 
+#ifdef KDTRACE_HOOKS
+	.bss
+	.globl	dtrace_invop_jump_addr
+	.align	8
+	.type	dtrace_invop_jump_addr, @object
+	.size	dtrace_invop_jump_addr, 8
+dtrace_invop_jump_addr:
+	.zero	8
+	.globl	dtrace_invop_calltrap_addr
+	.align	8
+	.type	dtrace_invop_calltrap_addr, @object
+	.size	dtrace_invop_calltrap_addr, 8
+dtrace_invop_calltrap_addr:
+	.zero	8
+#endif
 	.text
 
 IDTVEC(trap00)
@@ -283,6 +299,30 @@
 NENTRY(alltraps)
 	INTRENTRY
   	STI(si)
+#ifdef KDTRACE_HOOKS
+	/*
+	 * DTrace Function Boundary Trace (fbt) probes are triggered
+	 * by int3 (0xcc) which causes the #BP (T_BPTFLT) breakpoint
+	 * interrupt. For all other trap types, just handle them in
+	 * the usual way.
+	 */
+	cmpl$T_BPTFLT,TF_TRAPNO(%rsp)
+	jne calltrap
+
+	/* Check if there is no DTrace hook registered. */
+	cmpq	$0,dtrace_invop_jump_addr
+	je	calltrap
+
+	/*
+	 * Set our jump address for the jump back in the event that
+	 * the exception wasn't caused by DTrace at all.
+	 */
+	movq	$calltrap, dtrace_invop_calltrap_addr(%rip)
+
+	/* Jump to the code hooked in by DTrace. */
+	movq	dtrace_invop_jump_addr, %rax
+	jmpq	*dtrace_invop_jump_addr
+#endif
 calltrap:
 #ifdef DIAGNOSTIC
 	movl	CPUVAR(ILEVEL),%ebx



<    1   2   3   4   >