CVS commit: src/sys/arch/i386/i386

2017-10-02 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Oct  2 17:48:01 UTC 2017

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

Log Message:
Fix (once again) Xen boot


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.153 src/sys/arch/i386/i386/locore.S:1.154
--- src/sys/arch/i386/i386/locore.S:1.153	Sat Sep 30 11:43:57 2017
+++ src/sys/arch/i386/i386/locore.S	Mon Oct  2 17:48:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.153 2017/09/30 11:43:57 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.154 2017/10/02 17:48:01 bouyer Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.153 2017/09/30 11:43:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.154 2017/10/02 17:48:01 bouyer Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -910,6 +910,7 @@ begin:
 	pushl	$0	/* init386() expects a 64 bits paddr_t with PAE */
 #endif
 	pushl	%esi
+	call	_C_LABEL(init_bootspace)
 	call	_C_LABEL(init386)
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	call 	_C_LABEL(main)



CVS commit: src/sys/arch/i386/i386

2017-09-12 Thread Andreas Gustafsson
Module Name:src
Committed By:   gson
Date:   Tue Sep 12 14:10:49 UTC 2017

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

Log Message:
Don't use a const variable as an array size, because it is not a
constant expression and will cause the array to needlessly become a
variable-size one.  Fixes "error: stack protector not protecting local
variables: variable length buffer [-Werror=stack-protector]" when
building i386 with MKDEBUG=YES -V COPTS="-g".


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.289 src/sys/arch/i386/i386/trap.c:1.290
--- src/sys/arch/i386/i386/trap.c:1.289	Sat Aug 12 07:07:53 2017
+++ src/sys/arch/i386/i386/trap.c	Tue Sep 12 14:10:49 2017
@@ -1,5 +1,5 @@
 
-/*	$NetBSD: trap.c,v 1.289 2017/08/12 07:07:53 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.290 2017/09/12 14:10:49 gson Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.289 2017/08/12 07:07:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.290 2017/09/12 14:10:49 gson Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -421,7 +421,7 @@ kernelfault:
 	{
 		static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 };
 		const size_t sz = sizeof(lcall);
-		char tmp[sz];
+		char tmp[sizeof(lcall)];
 
 		/* Check for the osyscall lcall instruction. */
 		if (frame->tf_eip < VM_MAXUSER_ADDRESS - sz &&



CVS commit: src/sys/arch/i386/i386

2017-08-30 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Aug 30 15:34:57 UTC 2017

Modified Files:
src/sys/arch/i386/i386: i386_trap.S

Log Message:
Pfff, use %ss and not %ds. The latter is controlled by userland, the former
contains the kernel value (flat); FreeBSD fixed this too a few weeks ago.

As I said earlier, this dtrace code is complete bullshit.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/i386/i386/i386_trap.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/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.11 src/sys/arch/i386/i386/i386_trap.S:1.12
--- src/sys/arch/i386/i386/i386_trap.S:1.11	Fri Aug 18 14:52:19 2017
+++ src/sys/arch/i386/i386/i386_trap.S	Wed Aug 30 15:34:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.11 2017/08/18 14:52:19 maxv Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.12 2017/08/30 15:34:57 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.11 2017/08/18 14:52:19 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.12 2017/08/30 15:34:57 maxv Exp $");
 #endif
 
 /*
@@ -139,7 +139,7 @@ IDTVEC_END(trap05)
 	SUPERALIGN_TEXT
 IDTVEC(trap06)
 	/* Check if there is no DTrace hook registered. */
-	cmpl	$0,dtrace_invop_jump_addr
+	cmpl	$0,%ss:dtrace_invop_jump_addr
 	je	norm_ill
 
 	/* Check if this is a user fault. */



CVS commit: src/sys/arch/i386/i386

2017-08-15 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Tue Aug 15 06:39:37 UTC 2017

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

Log Message:
Remove __ELF__ vestige.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/i386/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/i386/i386/db_machdep.c
diff -u src/sys/arch/i386/i386/db_machdep.c:1.5 src/sys/arch/i386/i386/db_machdep.c:1.6
--- src/sys/arch/i386/i386/db_machdep.c:1.5	Sat Jan 11 17:11:50 2014
+++ src/sys/arch/i386/i386/db_machdep.c	Tue Aug 15 06:39:37 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.5 2014/01/11 17:11:50 christos Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.6 2017/08/15 06:39:37 maxv Exp $	*/
 
 /* 
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.5 2014/01/11 17:11:50 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.6 2017/08/15 06:39:37 maxv Exp $");
 
 #include 
 #include 
@@ -131,7 +131,6 @@ db_frame_info(long *frame, db_addr_t cal
 		 * locations rather than on trap, since some traps
 		 * (e.g., npxdna) don't go through trap()
 		 */
-#ifdef __ELF__
 		if (!strcmp(name, "trap_tss")) {
 			*is_trap = TRAP_TSS;
 			narg = 0;
@@ -158,34 +157,6 @@ db_frame_info(long *frame, db_addr_t cal
 narg = 0;
 			}
 		}
-#else
-		if (!strcmp(name, "_trap_tss")) {
-			*is_trap = TRAP_TSS;
-			narg = 0;
-		} else if (!strcmp(name, "_trap")) {
-			*is_trap = TRAP;
-			narg = 0;
-		} else if (!strcmp(name, "_syscall")) {
-			*is_trap = SYSCALL;
-			narg = 0;
-		} else if (name[0] == '_' && name[1] == 'X') {
-			if (!strncmp(name, "_Xintr", 6) ||
-			!strncmp(name, "_Xresume", 8) ||
-			!strncmp(name, "_Xstray", 7) ||
-			!strncmp(name, "_Xhold", 6) ||
-			!strncmp(name, "_Xrecurse", 9) ||
-			!strcmp(name, "_Xdoreti")) {
-*is_trap = INTERRUPT;
-narg = 0;
-			} else if (!strcmp(name, "_Xsoftintr")) {
-*is_trap = SOFTINTR;
-narg = 0;
-			} else if (!strncmp(name, "_Xtss_", 6)) {
-*is_trap = INTERRUPT_TSS;
-narg = 0;
-			}
-		}
-#endif /* __ELF__ */
 	}
 
 	if (offp != NULL)



CVS commit: src/sys/arch/i386/i386

2017-08-12 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Aug 12 19:06:23 UTC 2017

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

Log Message:
Remove what is now an unused variable.   One less build issue...


To generate a diff of this commit:
cvs rdiff -u -r1.790 -r1.791 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.790 src/sys/arch/i386/i386/machdep.c:1.791
--- src/sys/arch/i386/i386/machdep.c:1.790	Sat Aug 12 13:16:14 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Aug 12 19:06:23 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.790 2017/08/12 13:16:14 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.791 2017/08/12 19:06:23 kre Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.790 2017/08/12 13:16:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.791 2017/08/12 19:06:23 kre Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -629,7 +629,6 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	int sig = ksi->ksi_signo;
 	struct sigframe_siginfo *fp = getframe(l, sig, ), frame;
 	sig_t catcher = SIGACTION(p, sig).sa_handler;
-	struct trapframe *tf = l->l_md.md_regs;
 
 	KASSERT(mutex_owned(p->p_lock));
 



CVS commit: src/sys/arch/i386/i386

2017-08-12 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Aug 12 13:16:14 UTC 2017

Modified Files:
src/sys/arch/i386/i386: genassym.cf machdep.c

Log Message:
Remove references to PSL_VM (implicitly vm86).


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.789 -r1.790 src/sys/arch/i386/i386/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/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.102 src/sys/arch/i386/i386/genassym.cf:1.103
--- src/sys/arch/i386/i386/genassym.cf:1.102	Tue Aug  8 08:04:05 2017
+++ src/sys/arch/i386/i386/genassym.cf	Sat Aug 12 13:16:14 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.102 2017/08/08 08:04:05 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.103 2017/08/12 13:16:14 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -355,7 +355,6 @@ define	IREENT_MAGIC		IREENT_MAGIC
 define	PSL_AC			PSL_AC
 define	PSL_MBO			PSL_MBO
 define	PSL_ID			PSL_ID
-define	PSL_VM			PSL_VM
 define	PSL_I			PSL_I
 
 define	MTX_IPL			offsetof(struct kmutex, u.s.mtxs_ipl)

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.789 src/sys/arch/i386/i386/machdep.c:1.790
--- src/sys/arch/i386/i386/machdep.c:1.789	Sat Aug 12 07:07:53 2017
+++ src/sys/arch/i386/i386/machdep.c	Sat Aug 12 13:16:14 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.789 2017/08/12 07:07:53 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.790 2017/08/12 13:16:14 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.789 2017/08/12 07:07:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.790 2017/08/12 13:16:14 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -647,8 +647,6 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	? _UC_SETSTACK : _UC_CLRSTACK;
 	memset(_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
 
-	if (tf->tf_eflags & PSL_VM)
-		(*p->p_emul->e_syscall_intern)(p);
 	sendsig_reset(l, sig);
 
 	mutex_exit(p->p_lock);



CVS commit: src/sys/arch/i386/i386

2017-08-10 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Aug 10 14:13:45 UTC 2017

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

Log Message:
Switch to the temporary stack right away when booted via multiboot. GRUB
happens to give a correct stack, but it is not guaranteed by the spec. This
temporary stack will be reset later, which is fine.

Fixes PR/50245.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.149 src/sys/arch/i386/i386/locore.S:1.150
--- src/sys/arch/i386/i386/locore.S:1.149	Sat Jul 29 12:34:34 2017
+++ src/sys/arch/i386/i386/locore.S	Thu Aug 10 14:13:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.149 2017/07/29 12:34:34 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.150 2017/08/10 14:13:45 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.149 2017/07/29 12:34:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.150 2017/08/10 14:13:45 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -342,11 +342,13 @@ _C_LABEL(Multiboot_Header):
 	jne	1f
 
 	/*
-	 * Indeed, a multiboot-compliant boot loader executed us.  We copy
-	 * the received Multiboot information structure into kernel's data
-	 * space to process it later -- after we are relocated.  It will
-	 * be safer to run complex C code than doing it at this point.
+	 * Indeed, a multiboot-compliant boot loader executed us. We switch
+	 * to the temporary stack, and copy the received Multiboot information
+	 * structure into kernel's data space to process it later -- after we
+	 * are relocated. It will be safer to run complex C code than doing it
+	 * at this point.
 	 */
+	movl	$_RELOC(tmpstk),%esp
 	pushl	%ebx		/* Address of Multiboot information */
 	call	_C_LABEL(multiboot_pre_reloc)
 	addl	$4,%esp



CVS commit: src/sys/arch/i386/i386

2017-07-29 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jul 29 12:34:34 UTC 2017

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

Log Message:
Remove undocumented hack.


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.148 src/sys/arch/i386/i386/locore.S:1.149
--- src/sys/arch/i386/i386/locore.S:1.148	Sat Jul 29 11:54:14 2017
+++ src/sys/arch/i386/i386/locore.S	Sat Jul 29 12:34:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.148 2017/07/29 11:54:14 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.149 2017/07/29 12:34:34 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.148 2017/07/29 11:54:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.149 2017/07/29 12:34:34 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -841,24 +841,6 @@ begin:
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	addl	$NGDT*8,%esp		/* pop temporary gdt */
 
-#ifdef SAFARI_FIFO_HACK
-	movb	$5,%al
-	movw	$0x37b,%dx
-	outb	%al,%dx
-	movw	$0x37f,%dx
-	inb	%dx,%al
-	movb	%al,%cl
-
-	orb	$1,%cl
-
-	movb	$5,%al
-	movw	$0x37b,%dx
-	outb	%al,%dx
-	movw	$0x37f,%dx
-	movb	%cl,%al
-	outb	%al,%dx
-#endif /* SAFARI_FIFO_HACK */
-
 	call 	_C_LABEL(main)
 #else /* XEN */
 	/* First, reset the PSL. */



CVS commit: src/sys/arch/i386/i386

2017-07-06 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Thu Jul  6 20:23:57 UTC 2017

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

Log Message:
gdt_size is now in bytes, but the HYPERVISOR_set_gdt() expects a number
of entries and has not been converted.
Xen/i386 now boots again.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.64 src/sys/arch/i386/i386/gdt.c:1.65
--- src/sys/arch/i386/i386/gdt.c:1.64	Sun Jul  2 11:21:13 2017
+++ src/sys/arch/i386/i386/gdt.c	Thu Jul  6 20:23:57 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.64 2017/07/02 11:21:13 maxv Exp $	*/
+/*	$NetBSD: gdt.c,v 1.65 2017/07/06 20:23:57 bouyer Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.64 2017/07/02 11:21:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.65 2017/07/06 20:23:57 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -202,13 +202,14 @@ gdt_init_cpu(struct cpu_info *ci)
 	setregion(, ci->ci_gdt, max_len - 1);
 	lgdt();
 #else
-	size_t len = gdt_size;
+	size_t len = roundup(gdt_size, PAGE_SIZE);
 	unsigned long frames[len >> PAGE_SHIFT];
 	vaddr_t va;
 	pt_entry_t *ptp;
 	size_t f;
 
-	for (va = (vaddr_t)ci->ci_gdt, f = 0; va < (vaddr_t)ci->ci_gdt + len;
+	for (va = (vaddr_t)ci->ci_gdt, f = 0;
+	va < (vaddr_t)ci->ci_gdt + gdt_size;
 	va += PAGE_SIZE, f++) {
 		KASSERT(va >= VM_MIN_KERNEL_ADDRESS);
 		ptp = kvtopte(va);
@@ -226,7 +227,7 @@ gdt_init_cpu(struct cpu_info *ci)
 		}
 	}
 
-	if (HYPERVISOR_set_gdt(frames, gdt_size))
+	if (HYPERVISOR_set_gdt(frames, gdt_size / sizeof(gdtstore[0])))
 		panic("HYPERVISOR_set_gdt failed!\n");
 	lgdt_finish();
 #endif



CVS commit: src/sys/arch/i386/i386

2017-06-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun 17 09:32:53 UTC 2017

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

Log Message:
Remove dead and broken code. It is not a bad idea to implement USER_LDT on
Xen, but it certainly shouldn't be done this way.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.60 src/sys/arch/i386/i386/gdt.c:1.61
--- src/sys/arch/i386/i386/gdt.c:1.60	Wed Feb  8 18:53:01 2017
+++ src/sys/arch/i386/i386/gdt.c	Sat Jun 17 09:32:53 2017
@@ -1,6 +1,6 @@
-/*	$NetBSD: gdt.c,v 1.60 2017/02/08 18:53:01 kre Exp $	*/
+/*	$NetBSD: gdt.c,v 1.61 2017/06/17 09:32:53 maxv Exp $	*/
 
-/*-
+/*
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.60 2017/02/08 18:53:01 kre Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.61 2017/06/17 09:32:53 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -45,28 +45,20 @@ __KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.60
 
 #include 
 
-#ifndef XEN
-int gdt_size[1];	/* total number of GDT entries */
-int gdt_count[1];	/* number of GDT entries in use */
-int gdt_next[1];	/* next available slot for sweeping */
-int gdt_free[1];	/* next free slot; terminated with GNULL_SEL */
-#else
-int gdt_size[2];	/* total number of GDT entries */
-int gdt_count[2];	/* number of GDT entries in use */
-int gdt_next[2];	/* next available slot for sweeping */
-int gdt_free[2];	/* next free slot; terminated with GNULL_SEL */
-#endif
+int gdt_size;	/* total number of GDT entries */
+int gdt_count;	/* number of GDT entries in use */
+int gdt_next;	/* next available slot for sweeping */
+int gdt_free;	/* next free slot; terminated with GNULL_SEL */
 
+#ifndef XEN
 static int ldt_count;	/* number of LDTs */
 static int ldt_max = 1000;/* max number of LDTs */
-
-#ifndef XEN
 static void setgdt(int, const void *, size_t, int, int, int, int);
+static int gdt_get_slot(void);
+static void gdt_put_slot(int);
+static void gdt_grow(void);
 #endif
 void gdt_init(void);
-static void gdt_grow(int);
-static int gdt_get_slot1(int);
-static void gdt_put_slot1(int, int);
 
 void
 update_descriptor(union descriptor *table, union descriptor *entry)
@@ -96,12 +88,6 @@ setgdt(int sel, const void *base, size_t
 	CPU_INFO_ITERATOR cii;
 	struct cpu_info *ci;
 
-#ifdef XEN
-	if (type == SDT_SYS386TSS) {
-		/* printk("XXX TSS descriptor not supported in GDT\n"); */
-		return;
-	}
-#endif
 	setsegment(sd, base, limit, type, dpl, def32, gran);
 	for (CPU_INFO_FOREACH(cii, ci)) {
 		if (ci->ci_gdt != NULL)
@@ -127,17 +113,10 @@ gdt_init(void)
 	max_len = MAXGDTSIZ * sizeof(gdtstore[0]);
 	min_len = MINGDTSIZ * sizeof(gdtstore[0]);
 
-	gdt_size[0] = MINGDTSIZ;
-	gdt_count[0] = NGDT;
-	gdt_next[0] = NGDT;
-	gdt_free[0] = GNULL_SEL;
-#ifdef XEN
-	max_len = max_len * 2;
-	gdt_size[1] = 0;
-	gdt_count[1] = MAXGDTSIZ;
-	gdt_next[1] = MAXGDTSIZ;
-	gdt_free[1] = GNULL_SEL;
-#endif
+	gdt_size = MINGDTSIZ;
+	gdt_count = NGDT;
+	gdt_next = NGDT;
+	gdt_free = GNULL_SEL;
 
 	old_gdt = gdtstore;
 	gdtstore = (union descriptor *)uvm_km_alloc(kernel_map, max_len,
@@ -185,7 +164,7 @@ gdt_alloc_cpu(struct cpu_info *ci)
 	}
 	pmap_update(pmap_kernel());
 	memset(ci->ci_gdt, 0, min_len);
-	memcpy(ci->ci_gdt, gdtstore, gdt_count[0] * sizeof(gdtstore[0]));
+	memcpy(ci->ci_gdt, gdtstore, gdt_count * sizeof(gdtstore[0]));
 	setsegment(>ci_gdt[GCPU_SEL].sd, ci,
 	sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0);
 }
@@ -205,7 +184,7 @@ gdt_init_cpu(struct cpu_info *ci)
 	setregion(, ci->ci_gdt, max_len - 1);
 	lgdt();
 #else
-	size_t len = gdt_size[0] * sizeof(gdtstore[0]);
+	size_t len = gdt_size * sizeof(gdtstore[0]);
 	unsigned long frames[len >> PAGE_SHIFT];
 	vaddr_t va;
 	pt_entry_t *ptp;
@@ -229,19 +208,20 @@ gdt_init_cpu(struct cpu_info *ci)
 		}
 	}
 
-	if (HYPERVISOR_set_gdt(frames, gdt_size[0]))
+	if (HYPERVISOR_set_gdt(frames, gdt_size))
 		panic("HYPERVISOR_set_gdt failed!\n");
 	lgdt_finish();
 #endif
 }
 
+#ifndef XEN
 /*
  * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all
  * of them. We already have the virtual memory, we only need to grow the
  * physical memory.
  */
 void
-gdt_grow(int which)
+gdt_grow(void)
 {
 	size_t old_len, new_len;
 	CPU_INFO_ITERATOR cii;
@@ -249,33 +229,10 @@ gdt_grow(int which)
 	struct vm_page *pg;
 	vaddr_t va;
 
-	old_len = gdt_size[which] * sizeof(gdtstore[0]);
-	gdt_size[which] <<= 1;
+	old_len = gdt_size * sizeof(gdtstore[0]);
+	gdt_size <<= 1;
 	new_len = old_len << 1;
 
-#ifdef XEN
-	if (which != 0) {
-		size_t max_len = MAXGDTSIZ * sizeof(gdtstore[0]);
-		if (old_len == 0) {
-			gdt_size[which] = MINGDTSIZ;
-			new_len = gdt_size[which] * 

CVS commit: src/sys/arch/i386/i386

2017-06-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jun 14 17:21:04 UTC 2017

Modified Files:
src/sys/arch/i386/i386: i386_trap.S

Log Message:
Disable interrupts for T_NMI (inline calltrap). Note that there's still a
way to evade the NMI mode here, if a segment register faults in
INTRFASTEXIT; but we don't care. I didn't test this change, but it seems
fine enough.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/i386/i386/i386_trap.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/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.7 src/sys/arch/i386/i386/i386_trap.S:1.8
--- src/sys/arch/i386/i386/i386_trap.S:1.7	Wed Jun 14 17:02:16 2017
+++ src/sys/arch/i386/i386/i386_trap.S	Wed Jun 14 17:21:04 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.7 2017/06/14 17:02:16 maxv Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.8 2017/06/14 17:21:04 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.7 2017/06/14 17:02:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.8 2017/06/14 17:21:04 maxv Exp $");
 #endif
 
 /*
@@ -98,11 +98,26 @@ IDTVEC(trap01)
 	BPTTRAP(T_TRCTRAP)
 IDTVEC_END(trap01)
 
+/*
+ * Non Maskable Interrupts are a special case: they can be triggered even
+ * with interrupts disabled, and once triggered they block further NMIs
+ * until an 'iret' instruction is executed.
+ *
+ * Therefore we don't enable interrupts, because the CPU could switch to
+ * another LWP, call 'iret' and unintentionally leave the NMI mode.
+ */
 IDTVEC(trap02)
 	pushl	$0
 	pushl	$(T_NMI)
 	INTRENTRY
-	jmp	_C_LABEL(calltrap)
+
+	addl	$1,CPUVAR(NTRAP)	/* statistical info */
+	adcl	$0,CPUVAR(NTRAP)+4
+	pushl	%esp
+	call	_C_LABEL(trap)
+	addl	$4,%esp
+
+	INTRFASTEXIT
 IDTVEC_END(trap02)
 
 IDTVEC(trap03)



CVS commit: src/sys/arch/i386/i386

2017-06-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed Jun 14 17:02:16 UTC 2017

Modified Files:
src/sys/arch/i386/i386: i386_trap.S

Log Message:
style


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/i386/i386/i386_trap.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/i386/i386/i386_trap.S
diff -u src/sys/arch/i386/i386/i386_trap.S:1.6 src/sys/arch/i386/i386/i386_trap.S:1.7
--- src/sys/arch/i386/i386/i386_trap.S:1.6	Mon Feb 27 06:46:59 2017
+++ src/sys/arch/i386/i386/i386_trap.S	Wed Jun 14 17:02:16 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap.S,v 1.6 2017/02/27 06:46:59 chs Exp $	*/
+/*	$NetBSD: i386_trap.S,v 1.7 2017/06/14 17:02:16 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -35,7 +35,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*-
+/*
  * Copyright (c) 1998, 2007, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -66,7 +66,7 @@
 
 #if 0
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.6 2017/02/27 06:46:59 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i386_trap.S,v 1.7 2017/06/14 17:02:16 maxv Exp $");
 #endif
 
 /*
@@ -78,10 +78,10 @@ __KERNEL_RCSID(0, "$NetBSD: i386_trap.S,
  * (possibly the next clock tick).  Thus, we disable interrupt before checking,
  * and only enable them again on the final `iret' or before calling the AST
  * handler.
- */ 
+ */
 
-#define TRAP(a)			pushl $(a) ; jmp _C_LABEL(alltraps)
-#define ZTRAP(a)		pushl $0 ; TRAP(a)
+#define TRAP(a)		pushl $(a) ; jmp _C_LABEL(alltraps)
+#define ZTRAP(a)	pushl $0 ; TRAP(a)
 
 #ifdef IPKDB
 #define BPTTRAP(a)	pushl $0; pushl $(a); jmp _C_LABEL(bpttraps)
@@ -89,29 +89,34 @@ __KERNEL_RCSID(0, "$NetBSD: i386_trap.S,
 #define BPTTRAP(a)	ZTRAP(a)
 #endif
 
-
 	.text
 IDTVEC(trap00)
 	ZTRAP(T_DIVIDE)
 IDTVEC_END(trap00)
+
 IDTVEC(trap01)
 	BPTTRAP(T_TRCTRAP)
 IDTVEC_END(trap01)
+
 IDTVEC(trap02)
-	pushl $0
-	pushl $(T_NMI)
+	pushl	$0
+	pushl	$(T_NMI)
 	INTRENTRY
-	jmp _C_LABEL(calltrap)
+	jmp	_C_LABEL(calltrap)
 IDTVEC_END(trap02)
+
 IDTVEC(trap03)
 	BPTTRAP(T_BPTFLT)
 IDTVEC_END(trap03)
+
 IDTVEC(trap04)
 	ZTRAP(T_OFLOW)
 IDTVEC_END(trap04)
+
 IDTVEC(trap05)
 	ZTRAP(T_BOUND)
 IDTVEC_END(trap05)
+
 /*
  * Privileged instruction fault.
  */
@@ -124,21 +129,21 @@ IDTVEC(trap06)
 
 	/* Check if this is a user fault. */
 	/* XXX this was 0x0020 in FreeBSD */
-	cmpl	$GSEL(GCODE_SEL, SEL_KPL), 4(%esp)   /* Check code segment. */
+	cmpl	$GSEL(GCODE_SEL, SEL_KPL),4(%esp) /* Check code segment. */
 
 	/* If so, just handle it as a normal trap. */
 	jne	norm_ill
-  
+
 	/*
 	 * This is a kernel instruction fault that might have been caused
 	 * by a DTrace provider.
 	 */
-	
+
 	/*
 	 * Set our jump address for the jump back in the event that
 	 * the exception wasn't caused by DTrace at all.
 	 */
-	movl	$norm_ill, dtrace_invop_calltrap_addr
+	movl	$norm_ill,dtrace_invop_calltrap_addr
 
 	/* Jump to the code hooked in by DTrace. */
 	jmpl	*dtrace_invop_jump_addr
@@ -154,8 +159,9 @@ IDTVEC(trap06)
 	ZTRAP(T_PRIVINFLT)
 IDTVEC_END(trap06)
 #endif
+
 IDTVEC(trap07)
-	pushl	$0			# dummy error code
+	pushl	$0			/* dummy error code */
 	pushl	$T_DNA
 	INTRENTRY
 #ifdef DIAGNOSTIC
@@ -166,24 +172,31 @@ IDTVEC(trap07)
 	addl	$4,%esp
 	jmp	_C_LABEL(trapreturn)
 IDTVEC_END(trap07)
+
 IDTVEC(trap08)
 	TRAP(T_DOUBLEFLT)
 IDTVEC_END(trap08)
+
 IDTVEC(trap09)
 	ZTRAP(T_FPOPFLT)
 IDTVEC_END(trap09)
+
 IDTVEC(trap0a)
 	TRAP(T_TSSFLT)
 IDTVEC_END(trap0a)
+
 IDTVEC(trap0b)
 	TRAP(T_SEGNPFLT)
 IDTVEC_END(trap0b)
+
 IDTVEC(trap0c)
 	TRAP(T_STKFLT)
 IDTVEC_END(trap0c)
+
 IDTVEC(trap0d)
 	TRAP(T_PROTFLT)
 IDTVEC_END(trap0d)
+
 IDTVEC(trap0e)
 #ifndef XEN
 	pushl	$T_PAGEFLT
@@ -197,9 +210,9 @@ IDTVEC(trap0e)
 	jne	calltrap
 	movb	$T_PRIVINFLT,TF_TRAPNO(%esp)
 	jmp	calltrap
-#else /* !XEN */
+#else
 	TRAP(T_PAGEFLT)
-#endif /* !XEN */
+#endif
 IDTVEC_END(trap0e)
 
 IDTVEC(intrspurious)
@@ -208,11 +221,11 @@ IDTVEC(trap0f)
 	 * The Pentium Pro local APIC may erroneously call this vector for a
 	 * default IR7.  Just ignore it.
 	 *
-	 * (The local APIC does this when CPL is raised while it's on the 
-	 * way to delivering an interrupt.. presumably enough has been set 
+	 * (The local APIC does this when CPL is raised while it's on the
+	 * way to delivering an interrupt.. presumably enough has been set
 	 * up that it's inconvenient to abort delivery completely..)
 	 */
-	pushl	$0			# dummy error code
+	pushl	$0			/* dummy error code */
 	pushl	$T_ASTFLT
 	INTRENTRY
 	STI(%eax)
@@ -229,18 +242,19 @@ IDTVEC(trap10)
 	 * error.  It would be better to handle npx interrupts as traps but
 	 * this is difficult for nested interrupts.
 	 */
-	pushl	$0			# dummy error code
+	pushl	$0			/* dummy error code */
 	pushl	$T_ARITHTRAP
 .Ldo_fputrap:
 	INTRENTRY
 	movl	CPUVAR(ILEVEL),%ebx
 	pushl	%esp
-	addl	$1,CPUVAR(NTRAP)	# statistical info
+	addl	$1,CPUVAR(NTRAP)	/* statistical info */
 	adcl	

CVS commit: src/sys/arch/i386/i386

2017-03-14 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Mar 14 07:02:53 UTC 2017

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

Log Message:
Use frame_dump if TRAP_SIGDEBUG is enabled

This unbreaks the build of i386 ALL kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.285 -r1.286 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.285 src/sys/arch/i386/i386/trap.c:1.286
--- src/sys/arch/i386/i386/trap.c:1.285	Thu Mar  9 00:16:51 2017
+++ src/sys/arch/i386/i386/trap.c	Tue Mar 14 07:02:53 2017
@@ -1,5 +1,5 @@
 
-/*	$NetBSD: trap.c,v 1.285 2017/03/09 00:16:51 chs Exp $	*/
+/*	$NetBSD: trap.c,v 1.286 2017/03/14 07:02:53 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.285 2017/03/09 00:16:51 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.286 2017/03/14 07:02:53 ozaki-r Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -421,6 +421,11 @@ kernelfault:
 	case T_SEGNPFLT|T_USER:
 	case T_STKFLT|T_USER:
 	case T_ALIGNFLT|T_USER:
+#ifdef TRAP_SIGDEBUG
+		printf("pid %d.%d (%s): BUS/SEGV (%#x) at eip %#x addr %#lx\n",
+		p->p_pid, l->l_lid, p->p_comm, type, frame->tf_eip, rcr2());
+		frame_dump(frame, pcb);
+#endif
 		KSI_INIT_TRAP();
 
 		ksi.ksi_addr = (void *)rcr2();
@@ -463,6 +468,11 @@ kernelfault:
 
 	case T_PRIVINFLT|T_USER:	/* privileged instruction fault */
 	case T_FPOPFLT|T_USER:		/* coprocessor operand fault */
+#ifdef TRAP_SIGDEBUG
+		printf("pid %d.%d (%s): ILL at eip %#x addr %#lx\n",
+		p->p_pid, l->l_lid, p->p_comm, frame->tf_eip, rcr2());
+		frame_dump(frame, pcb);
+#endif
 		KSI_INIT_TRAP();
 		ksi.ksi_signo = SIGILL;
 		ksi.ksi_addr = (void *) frame->tf_eip;
@@ -679,6 +689,7 @@ faultcommon:
 		printf("pid %d.%d (%s): signal %d at eip %#x addr %#lx "
 		"error %d\n", p->p_pid, l->l_lid, p->p_comm, ksi.ksi_signo,
 		frame->tf_eip, va, error);
+		frame_dump(frame, pcb);
 #endif
 		(*p->p_emul->e_trapsignal)(l, );
 		break;



CVS commit: src/sys/arch/i386/i386

2017-03-11 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Sat Mar 11 23:39:49 UTC 2017

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

Log Message:
fix build failure.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/i386/i386/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/i386/i386/bios32.c
diff -u src/sys/arch/i386/i386/bios32.c:1.30 src/sys/arch/i386/i386/bios32.c:1.31
--- src/sys/arch/i386/i386/bios32.c:1.30	Sat Mar 11 07:21:10 2017
+++ src/sys/arch/i386/i386/bios32.c	Sat Mar 11 23:39:49 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: bios32.c,v 1.30 2017/03/11 07:21:10 nonaka Exp $	*/
+/*	$NetBSD: bios32.c,v 1.31 2017/03/11 23:39:49 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.30 2017/03/11 07:21:10 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bios32.c,v 1.31 2017/03/11 23:39:49 nonaka Exp $");
 
 #include 
 #include 
@@ -188,9 +188,7 @@ bios32_init(void)
 			goto out;
 		}
 	}
-#ifndef XEN
 out:
-#endif
 	pmap_update(pmap_kernel());
 }
 



CVS commit: src/sys/arch/i386/i386

2017-03-08 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Thu Mar  9 00:16:51 UTC 2017

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

Log Message:
improve readability of TRAP_SIGDEBUG info.
also print the trapframe info like amd64 does.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.284 src/sys/arch/i386/i386/trap.c:1.285
--- src/sys/arch/i386/i386/trap.c:1.284	Thu Feb 23 03:34:22 2017
+++ src/sys/arch/i386/i386/trap.c	Thu Mar  9 00:16:51 2017
@@ -1,5 +1,5 @@
 
-/*	$NetBSD: trap.c,v 1.284 2017/02/23 03:34:22 kamil Exp $	*/
+/*	$NetBSD: trap.c,v 1.285 2017/03/09 00:16:51 chs Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.284 2017/02/23 03:34:22 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.285 2017/03/09 00:16:51 chs Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -125,7 +125,6 @@ dtrace_trap_func_t	dtrace_trap_func = NU
 dtrace_doubletrap_func_t	dtrace_doubletrap_func = NULL;
 #endif
 
-
 void trap(struct trapframe *);
 void trap_tss(struct i386tss *, int, int);
 void trap_return_fault_return(struct trapframe *) __dead;
@@ -161,6 +160,10 @@ int	trapdebug = 0;
 
 #define	IDTVEC(name)	__CONCAT(X, name)
 
+#ifdef TRAP_SIGDEBUG
+static void frame_dump(struct trapframe *, struct pcb *);
+#endif
+
 void
 trap_tss(struct i386tss *tss, int trapno, int code)
 {
@@ -224,8 +227,8 @@ trap_print(const struct trapframe *frame
 	}
 	printf(" in %s mode\n", (type & T_USER) ? "user" : "supervisor");
 
-	printf("trap type %d code %x eip %x cs %x eflags %x cr2 %lx "
-	"ilevel %x esp %x\n",
+	printf("trap type %d code %#x eip %#x cs %#x eflags %#x cr2 %#lx "
+	"ilevel %#x esp %#x\n",
 	type, frame->tf_err, frame->tf_eip, frame->tf_cs, frame->tf_eflags,
 	(long)rcr2(), curcpu()->ci_ilevel, frame->tf_esp);
 
@@ -673,7 +676,7 @@ faultcommon:
 		}
 
 #ifdef TRAP_SIGDEBUG
-		printf("pid %d.%d (%s): signal %d at eip %x addr %lx "
+		printf("pid %d.%d (%s): signal %d at eip %#x addr %#lx "
 		"error %d\n", p->p_pid, l->l_lid, p->p_comm, ksi.ksi_signo,
 		frame->tf_eip, va, error);
 #endif
@@ -768,3 +771,37 @@ startlwp(void *arg)
 	kmem_free(uc, sizeof(ucontext_t));
 	userret(l);
 }
+
+#ifdef TRAP_SIGDEBUG
+void
+frame_dump(struct trapframe *tf, struct pcb *pcb)
+{
+	int i;
+	unsigned long *p;
+	uint64_t fsd, gsd;
+
+	printf("trapframe %p\n", tf);
+	printf("eip 0x%08x  esp 0x%08x  efl 0x%08x\n",
+	tf->tf_eip, tf->tf_esp, tf->tf_eflags);
+	printf("edi 0x%08x  esi 0x%08x  edx 0x%08x\n",
+	tf->tf_edi, tf->tf_esi, tf->tf_edx);
+	printf("ecx 0x%08x\n",
+	tf->tf_ecx);
+	printf("ebp 0x%08x  ebx 0x%08x  eax 0x%08x\n",
+	tf->tf_ebp, tf->tf_ebx, tf->tf_eax);
+	printf("cs 0x%04x  ds 0x%04x  es 0x%04x  "
+	   "fs 0x%04x  gs 0x%04x  ss 0x%04x\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);
+	memcpy(, >pcb_fsd, sizeof(fsd));
+	memcpy(, >pcb_gsd, sizeof(gsd));
+	printf("fsbase 0x%016llx gsbase 0x%016llx\n", fsd, gsd);
+	printf("\n");
+	printf("Stack dump:\n");
+	for (i = 0, p = (unsigned long *) tf; i < 20; i ++, p += 8)
+		printf(" 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx"
+		   " 0x%.8lx 0x%.8lx 0x%.8lx 0x%.8lx\n",
+		   p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
+	printf("\n");
+}
+#endif



CVS commit: src/sys/arch/i386/i386

2017-02-18 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Feb 18 15:56:03 UTC 2017

Modified Files:
src/sys/arch/i386/i386: pmc.c

Log Message:
Fix a bug I introduced yesterday. The arguments are 8-bit ints, so the unit
gets truncated. By luck, the counters I was testing could accept a null
unit.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/i386/pmc.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/i386/i386/pmc.c
diff -u src/sys/arch/i386/i386/pmc.c:1.22 src/sys/arch/i386/i386/pmc.c:1.23
--- src/sys/arch/i386/i386/pmc.c:1.22	Fri Feb 17 12:10:40 2017
+++ src/sys/arch/i386/i386/pmc.c	Sat Feb 18 15:56:03 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmc.c,v 1.22 2017/02/17 12:10:40 maxv Exp $	*/
+/*	$NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $	*/
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.22 2017/02/17 12:10:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmc.c,v 1.23 2017/02/18 15:56:03 maxv Exp $");
 
 #include 
 #include 
@@ -156,6 +156,8 @@ pmc_apply(pmc_state_t *pmc)
 static void
 pmc_start(pmc_state_t *pmc, struct x86_pmc_startstop_args *args)
 {
+	uint64_t event, unit;
+
 	pmc->running = true;
 
 	/*
@@ -185,10 +187,10 @@ pmc_start(pmc_state_t *pmc, struct x86_p
 		break;
 
 	case PMC_TYPE_K7:
-		args->event &= K7_EVTSEL_EVENT;
-		args->unit = (args->unit << K7_EVTSEL_UNIT_SHIFT) &
+		event = (args->event & K7_EVTSEL_EVENT);
+		unit = (args->unit << K7_EVTSEL_UNIT_SHIFT) &
 		K7_EVTSEL_UNIT;
-		pmc->evtval = args->event | args->unit | K7_EVTSEL_EN |
+		pmc->evtval = event | unit | K7_EVTSEL_EN |
 		((args->flags & PMC_SETUP_KERNEL) ? K7_EVTSEL_OS : 0) |
 		((args->flags & PMC_SETUP_USER) ? K7_EVTSEL_USR : 0) |
 		((args->flags & PMC_SETUP_EDGE) ? K7_EVTSEL_E : 0) |



CVS commit: src/sys/arch/i386/i386

2017-02-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed Feb  8 18:53:01 UTC 2017

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

Log Message:
Analagous fix to that just committed to the equiv amd64 sources.
Note: this one has yet to be compile tested, so anything is possible...


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.59 src/sys/arch/i386/i386/gdt.c:1.60
--- src/sys/arch/i386/i386/gdt.c:1.59	Wed Feb  8 10:08:26 2017
+++ src/sys/arch/i386/i386/gdt.c	Wed Feb  8 18:53:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.59 2017/02/08 10:08:26 maxv Exp $	*/
+/*	$NetBSD: gdt.c,v 1.60 2017/02/08 18:53:01 kre Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.59 2017/02/08 10:08:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.60 2017/02/08 18:53:01 kre Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -60,7 +60,9 @@ int gdt_free[2];	/* next free slot; term
 static int ldt_count;	/* number of LDTs */
 static int ldt_max = 1000;/* max number of LDTs */
 
+#ifndef XEN
 static void setgdt(int, const void *, size_t, int, int, int, int);
+#endif
 void gdt_init(void);
 static void gdt_grow(int);
 static int gdt_get_slot1(int);
@@ -82,6 +84,7 @@ update_descriptor(union descriptor *tabl
 #endif
 }
 
+#ifndef XEN
 /*
  * Called on a newly-allocated GDT slot, so no race between CPUs.
  */
@@ -106,6 +109,7 @@ setgdt(int sel, const void *base, size_t
 			(union descriptor *)sd);
 	}
 }
+#endif
 
 /*
  * Initialize the GDT. We already have a gdtstore, which was temporarily used



CVS commit: src/sys/arch/i386/i386

2017-01-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Jan 22 20:17:10 UTC 2017

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

Log Message:
Use xpmap_pg_nx. Not tested (due to some unrelated panic I'm getting), but
obvious enough.


To generate a diff of this commit:
cvs rdiff -u -r1.776 -r1.777 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.776 src/sys/arch/i386/i386/machdep.c:1.777
--- src/sys/arch/i386/i386/machdep.c:1.776	Mon Dec 26 17:54:06 2016
+++ src/sys/arch/i386/i386/machdep.c	Sun Jan 22 20:17:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.777 2017/01/22 20:17:10 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.777 2017/01/22 20:17:10 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1006,11 +1006,11 @@ initgdt(union descriptor *tgdt)
 		 * which are in the callpath of pmap_kenter_pa().
 		 * So we mash up our own - this is MD code anyway.
 		 */
+		extern pt_entry_t xpmap_pg_nx;
 		pt_entry_t pte;
-		pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0);
 
 		pte = pmap_pa2pte((vaddr_t)gdt - KERNBASE);
-		pte |= PG_k | PG_RO | pg_nx | PG_V;
+		pte |= PG_k | PG_RO | xpmap_pg_nx | PG_V;
 
 		if (HYPERVISOR_update_va_mapping((vaddr_t)gdt, pte, UVMF_INVLPG) < 0) {
 			panic("gdt page RO update failed.\n");
@@ -1208,11 +1208,11 @@ init386(paddr_t first_avail)
 
 	/* Reclaim the boot gdt page - see locore.s */
 	{
+		extern pt_entry_t xpmap_pg_nx;
 		pt_entry_t pte;
-		pt_entry_t pg_nx = (cpu_feature[2] & CPUID_NOX ? PG_NX : 0);
 
 		pte = pmap_pa2pte((vaddr_t)tmpgdt - KERNBASE);
-		pte |= PG_k | PG_RW | pg_nx | PG_V;
+		pte |= PG_k | PG_RW | xpmap_pg_nx | PG_V;
 
 		if (HYPERVISOR_update_va_mapping((vaddr_t)tmpgdt, pte, UVMF_INVLPG) < 0) {
 			panic("tmpgdt page relaim RW update failed.\n");



CVS commit: src/sys/arch/i386/i386

2017-01-06 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Jan  6 08:36:56 UTC 2017

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

Log Message:
Explain the computation


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.143 src/sys/arch/i386/i386/locore.S:1.144
--- src/sys/arch/i386/i386/locore.S:1.143	Fri Dec 16 19:52:22 2016
+++ src/sys/arch/i386/i386/locore.S	Fri Jan  6 08:36:56 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.143 2016/12/16 19:52:22 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.144 2017/01/06 08:36:56 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.143 2016/12/16 19:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.144 2017/01/06 08:36:56 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -633,7 +633,7 @@ no_NOX:
 	incl	%eax		/* one more PTP for VAs stolen by bootstrap */
 1:	movl	%eax,RELOC(nkptp)+1*4
 
-	/* tablesize = (PDP_SIZE + UPAGES + nkptp) << PGSHIFT; */
+	/* tablesize = (PDP_SIZE + UPAGES + nkptp[1]) << PGSHIFT; */
 	addl	$(PDP_SIZE+UPAGES),%eax
 #ifdef PAE
 	incl	%eax 		/* one more page for L3 */
@@ -643,7 +643,8 @@ no_NOX:
 #endif
 	movl	%eax,RELOC(tablesize)
 
-	/* Ensure that nkptp covers BOOTSTRAP TABLES. */
+	/* Ensure that nkptp[1] covers BOOTSTRAP TABLES, ie:
+	 * (esi + tablesize) >> L2_SHIFT + 1 < nkptp[1] */
 	addl	%esi,%eax
 	addl	$~L2_FRAME,%eax
 	shrl	$L2_SHIFT,%eax



CVS commit: src/sys/arch/i386/i386

2016-12-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec 26 15:47:48 UTC 2016

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

Log Message:
Make the msgbuf initialisation track closer to the original
pre-uvm_physseg.h one.

To see the exact changes with the original, line for line, do:

cvs rdiff -u -r1.772 -r1.775 src/sys/arch/i386/i386/machdep.c


To generate a diff of this commit:
cvs rdiff -u -r1.774 -r1.775 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.774 src/sys/arch/i386/i386/machdep.c:1.775
--- src/sys/arch/i386/i386/machdep.c:1.774	Fri Dec 23 09:24:57 2016
+++ src/sys/arch/i386/i386/machdep.c	Mon Dec 26 15:47:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $	*/
+/*	$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1037,30 +1037,46 @@ initgdt(union descriptor *tgdt)
 static void
 init386_msgbuf(void)
 {
-/* Message buffer is located at end of core. */
-	psize_t reqsz = round_page(MSGBUFSIZE);
-	psize_t sz = 0;
+	/* Message buffer is located at end of core. */
+	psize_t sz = round_page(MSGBUFSIZE);
+	psize_t reqsz = sz;
+	uvm_physseg_t x;
+		
+search_again:
+for (x = uvm_physseg_get_first();
+	 uvm_physseg_valid_p(x);
+	 x = uvm_physseg_get_next(x)) {
+		if (ctob(uvm_physseg_get_avail_end(x)) == avail_end) {
+			break;
+		}
+	}
+	if (uvm_physseg_valid_p(x) == false)
+		panic("init386: can't find end of memory");
 
-	for (sz = 0; sz < reqsz; sz += PAGE_SIZE) {
-		paddr_t stolenpa;
+	/* Shrink so it'll fit in the last segment. */
+	if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
+		sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
 
-		if (!uvm_page_physget())
-			break;
+	uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
+	msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
+msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
 
-		if (stolenpa == (msgbuf_p_seg[msgbuf_p_cnt].paddr
-			+ PAGE_SIZE)) {
-			/* contiguous: append it to current buf alloc */
-			msgbuf_p_seg[msgbuf_p_cnt].sz += PAGE_SIZE;
-		} else  {
-			/* non-contiguous: start a new msgbuf seg */
-			msgbuf_p_seg[msgbuf_p_cnt].sz = PAGE_SIZE;
-			msgbuf_p_seg[msgbuf_p_cnt++].paddr = stolenpa;
-		}
+	/* Now find where the new avail_end is. */
+	avail_end = ctob(uvm_physseg_get_avail_end(x));
+
+	if (sz == reqsz)
+		return;
+
+	reqsz -= sz;
+	if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
+		/* No more segments available, bail out. */
+		printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
+		(size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
+		return;
 	}
 
-	if (sz != reqsz)
-		printf("%s: could only allocate %"PRIxPSIZE" bytes of requested"
-		" %"PRIxPSIZE" bytes\n", __func__, sz, reqsz);
+	sz = reqsz;
+	goto search_again;
 }
 
 #ifndef XEN



CVS commit: src/sys/arch/i386/i386

2016-12-23 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri Dec 23 09:24:57 UTC 2016

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

Log Message:
Use PRIxPSIZE when printing psize_t.

Fixes i386 kernels build.


To generate a diff of this commit:
cvs rdiff -u -r1.773 -r1.774 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.773 src/sys/arch/i386/i386/machdep.c:1.774
--- src/sys/arch/i386/i386/machdep.c:1.773	Fri Dec 23 07:15:27 2016
+++ src/sys/arch/i386/i386/machdep.c	Fri Dec 23 09:24:57 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.773 2016/12/23 07:15:27 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.773 2016/12/23 07:15:27 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1059,8 +1059,8 @@ init386_msgbuf(void)
 	}
 
 	if (sz != reqsz)
-		printf("%s: could only allocate %ld bytes of requested %ld bytes\n",
-		__func__, sz, reqsz);
+		printf("%s: could only allocate %"PRIxPSIZE" bytes of requested"
+		" %"PRIxPSIZE" bytes\n", __func__, sz, reqsz);
 }
 
 #ifndef XEN



CVS commit: src/sys/arch/i386/i386

2016-12-17 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Dec 17 14:27:53 UTC 2016

Modified Files:
src/sys/arch/i386/i386: gdt.c machdep.c

Log Message:
Put a limit in the percpu segment, so we can detect overflows on %fs.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/i386/i386/gdt.c
cvs rdiff -u -r1.768 -r1.769 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.55 src/sys/arch/i386/i386/gdt.c:1.56
--- src/sys/arch/i386/i386/gdt.c:1.55	Sat Aug 20 19:46:54 2016
+++ src/sys/arch/i386/i386/gdt.c	Sat Dec 17 14:27:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.55 2016/08/20 19:46:54 christos Exp $	*/
+/*	$NetBSD: gdt.c,v 1.56 2016/12/17 14:27:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.55 2016/08/20 19:46:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.56 2016/12/17 14:27:53 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -144,8 +144,8 @@ gdt_init(void)
 	pmap_update(pmap_kernel());
 	memcpy(gdt, old_gdt, NGDT * sizeof(gdt[0]));
 	ci->ci_gdt = gdt;
-	setsegment(>ci_gdt[GCPU_SEL].sd, ci, 0xf,
-	SDT_MEMRWA, SEL_KPL, 1, 1);
+	setsegment(>ci_gdt[GCPU_SEL].sd, ci,
+	sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0);
 
 	gdt_init_cpu(ci);
 }
@@ -175,8 +175,8 @@ gdt_alloc_cpu(struct cpu_info *ci)
 	pmap_update(pmap_kernel());
 	memset(ci->ci_gdt, 0, min_len);
 	memcpy(ci->ci_gdt, gdt, gdt_count[0] * sizeof(gdt[0]));
-	setsegment(>ci_gdt[GCPU_SEL].sd, ci, 0xf,
-	SDT_MEMRWA, SEL_KPL, 1, 1);
+	setsegment(>ci_gdt[GCPU_SEL].sd, ci,
+	sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0);
 }
 
 

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.768 src/sys/arch/i386/i386/machdep.c:1.769
--- src/sys/arch/i386/i386/machdep.c:1.768	Fri Dec 16 19:52:22 2016
+++ src/sys/arch/i386/i386/machdep.c	Sat Dec 17 14:27:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.768 2016/12/16 19:52:22 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.769 2016/12/17 14:27:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.768 2016/12/16 19:52:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.769 2016/12/17 14:27:53 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -988,8 +988,8 @@ initgdt(union descriptor *tgdt)
 	setsegment([GBIOSDATA_SEL].sd, 0, 0xf, SDT_MEMRWA, SEL_KPL, 0,
 	0);
 #endif
-	setsegment([GCPU_SEL].sd, _info_primary, 0xf,
-	SDT_MEMRWA, SEL_KPL, 1, 1);
+	setsegment([GCPU_SEL].sd, _info_primary,
+	sizeof(struct cpu_info) - 1, SDT_MEMRWA, SEL_KPL, 1, 0);
 
 #ifndef XEN
 	setregion(, gdt, NGDT * sizeof(gdt[0]) - 1);



CVS commit: src/sys/arch/i386/i386

2016-12-11 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Dec 11 22:38:50 UTC 2016

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

Log Message:
Make kernels w/o ACPICA compile.


To generate a diff of this commit:
cvs rdiff -u -r1.765 -r1.766 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.765 src/sys/arch/i386/i386/machdep.c:1.766
--- src/sys/arch/i386/i386/machdep.c:1.765	Sun Dec 11 08:31:53 2016
+++ src/sys/arch/i386/i386/machdep.c	Sun Dec 11 22:38:50 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.765 2016/12/11 08:31:53 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.766 2016/12/11 22:38:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.765 2016/12/11 08:31:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.766 2016/12/11 22:38:50 martin Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -188,6 +188,8 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include 
 #define ACPI_MACHDEP_PRIVATE
 #include 
+#else
+#include 
 #endif
 
 #include "isa.h"



CVS commit: src/sys/arch/i386/i386

2016-11-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Nov 13 12:38:14 UTC 2016

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

Log Message:
The reason we are not using INTRENTRY here is because this interrupt goes
through a task gate that points to a TSS entry in the GDT, and therefore
the GPRs are saved in the TSS by the hardware itself. Explain it, otherwise
it easily looks buggy.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/arch/i386/i386/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/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.66 src/sys/arch/i386/i386/vector.S:1.67
--- src/sys/arch/i386/i386/vector.S:1.66	Sun Oct 16 10:38:49 2016
+++ src/sys/arch/i386/i386/vector.S	Sun Nov 13 12:38:14 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.66 2016/10/16 10:38:49 maxv Exp $	*/
+/*	$NetBSD: vector.S,v 1.67 2016/11/13 12:38:14 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.66 2016/10/16 10:38:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.67 2016/11/13 12:38:14 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -194,6 +194,10 @@ IDTVEC(intr_lapic_tlb)
 IDTVEC_END(intr_lapic_tlb)
 
 #if defined(DDB)
+/*
+ * No need to use INTRENTRY, since we were brought here through a task-gate
+ * which triggered a hardware context switch and saved the GPRs in the TSS.
+ */
 IDTVEC(intrddbipi)
 1:
 	str	%ax



CVS commit: src/sys/arch/i386/i386

2016-11-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Nov 11 11:00:38 UTC 2016

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

Log Message:
KNF and simplify Xen, and reduce the diff with amd64 a little


To generate a diff of this commit:
cvs rdiff -u -r1.138 -r1.139 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.138 src/sys/arch/i386/i386/locore.S:1.139
--- src/sys/arch/i386/i386/locore.S:1.138	Sun Oct 16 10:51:31 2016
+++ src/sys/arch/i386/i386/locore.S	Fri Nov 11 11:00:38 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.138 2016/10/16 10:51:31 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.139 2016/11/11 11:00:38 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.138 2016/10/16 10:51:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.139 2016/11/11 11:00:38 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -847,7 +847,7 @@ begin:
 	pushl	$0	/* init386() expects a 64 bits paddr_t with PAE */
 #endif
 	pushl	%eax
-	call	_C_LABEL(init386)	/* wire 386 chip for unix operation */
+	call	_C_LABEL(init386)
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	addl	$NGDT*8,%esp		/* pop temporary gdt */
 
@@ -876,38 +876,43 @@ begin:
 	popfl
 
 	cld
-	movl	%esp, %ebx		/* save start of available space */
-	movl	$_RELOC(tmpstk),%esp	/* bootstrap stack end location */
+
+	/*
+	 * Xen info:
+	 * - %esp -> stack, *theoretically* the last used page by Xen bootstrap
+	 */
+	movl	%esp,%ebx
+	movl	$_RELOC(tmpstk),%esp
 
 	/* Clear BSS. */
 	xorl	%eax,%eax
 	movl	$RELOC(__bss_start),%edi
 	movl	$RELOC(_end),%ecx
 	subl	%edi,%ecx
-	rep stosb
+	rep
+	stosb
 
 	/* Copy the necessary stuff from start_info structure. */
 	/* We need to copy shared_info early, so that sti/cli work */
 	movl	$RELOC(start_info_union),%edi
 	movl	$128,%ecx
-	rep movsl
+	rep
+	movsl
 
-	/* Clear segment registers; always null in proc0. */
+	/* Clear segment registers. */
 	xorl	%eax,%eax
 	movw	%ax,%fs
 	movw	%ax,%gs
-	decl	%eax
-	movl	%eax,RELOC(cpuid_level)
 
 	xorl	%eax,%eax
 	cpuid
 	movl	%eax,RELOC(cpuid_level)
 
 	/*
-	 * Use a temp page. We'll re- add it to uvm(9) once we're
-	 * done using it.
+	 * Use a temporary GDT page. We'll re-add it to uvm(9) once we're done
+	 * using it.
 	 */
-	movl	$RELOC(tmpgdt), %eax
+	movl	$RELOC(tmpgdt),%eax
 	pushl	%eax		/* start of temporary gdt */
 	call	_C_LABEL(initgdt)
 	addl	$4,%esp
@@ -915,23 +920,23 @@ begin:
 	call	xen_pmap_bootstrap
 
 	/*
-	 * First avail returned by xen_pmap_bootstrap in %eax
+	 * The first VA available is returned by xen_pmap_bootstrap in %eax. We
+	 * use it as the UAREA, and set up the stack here.
 	 */
-	movl	%eax, %esi;
-	movl	%esi, _C_LABEL(lwp0uarea)
-
-	/* Set up bootstrap stack. */
+	movl	%eax,%esi
+	movl	%esi,_C_LABEL(lwp0uarea)
 	leal	(USPACE-FRAMESIZE)(%eax),%esp
 	xorl	%ebp,%ebp		/* mark end of frames */
 
-	addl	$USPACE, %esi
-	subl	$KERNBASE, %esi		/* init386 wants a physical address */
+	/* Set first_avail after the UAREA. */
+	addl	$USPACE,%esi
+	subl	$KERNBASE,%esi		/* init386 wants a physical address */
 
 #ifdef PAE
 	pushl	$0	/* init386() expects a 64 bits paddr_t with PAE */
 #endif
 	pushl	%esi
-	call	_C_LABEL(init386)	/* wire 386 chip for unix operation */
+	call	_C_LABEL(init386)
 	addl	$PDE_SIZE,%esp		/* pop paddr_t */
 	call 	_C_LABEL(main)
 #endif /* XEN */



CVS commit: src/sys/arch/i386/i386

2016-10-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Oct 16 10:38:49 UTC 2016

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

Log Message:
Use offsets to access the TPR, and not lapic_tpr.

For the record: I'm not sure exactly why it was originally done this way,
and the cvs logs are not quite enlightening. It might have been a way to
speed up the asm access, but it would sound a little bizarre since there
are many more legitimate reasons to do it on the EOI register instead.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/arch/i386/i386/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/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.65 src/sys/arch/i386/i386/vector.S:1.66
--- src/sys/arch/i386/i386/vector.S:1.65	Sun Aug  7 10:17:32 2016
+++ src/sys/arch/i386/i386/vector.S	Sun Oct 16 10:38:49 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.65 2016/08/07 10:17:32 maxv Exp $	*/
+/*	$NetBSD: vector.S,v 1.66 2016/10/16 10:38:49 maxv Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.65 2016/08/07 10:17:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.66 2016/10/16 10:38:49 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -201,12 +201,12 @@ IDTVEC(intrddbipi)
 	movzwl	(%eax),%eax
 	GET_TSS
 	pushl	%eax
-	movl	$0xff,_C_LABEL(lapic_tpr)
+	movl	$0xff,_C_LABEL(local_apic)+LAPIC_TPRI
 	movl	$0,_C_LABEL(local_apic)+LAPIC_EOI
 	sti
 	call	_C_LABEL(ddb_ipi_tss)
 	addl	$4,%esp
-	movl	$0,_C_LABEL(lapic_tpr)
+	movl	$0,_C_LABEL(local_apic)+LAPIC_TPRI
 	iret
 	jmp	1b
 IDTVEC_END(intrddbipi)



CVS commit: src/sys/arch/i386/i386

2016-09-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sun Sep 25 12:59:19 UTC 2016

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

Log Message:
Fix outdated comment, and #ifdef.


To generate a diff of this commit:
cvs rdiff -u -r1.761 -r1.762 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.761 src/sys/arch/i386/i386/machdep.c:1.762
--- src/sys/arch/i386/i386/machdep.c:1.761	Sat Aug 27 16:07:26 2016
+++ src/sys/arch/i386/i386/machdep.c	Sun Sep 25 12:59:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.761 2016/08/27 16:07:26 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.762 2016/09/25 12:59:19 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.761 2016/08/27 16:07:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.762 2016/09/25 12:59:19 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1280,19 +1280,15 @@ init386(paddr_t first_avail)
 
 	init386_msgbuf();
 
-#ifndef XEN
+#if !defined(XEN) && NBIOSCALL > 0
 	/*
 	 * XXX Remove this
 	 *
 	 * Setup a temporary Page Table Entry to allow identity mappings of
-	 * the real mode address. This is required by:
-	 * - bioscall
-	 * - MP bootstrap
-	 * - ACPI wakecode
+	 * the real mode address. This is required by bioscall.
 	 */
 	init386_pte0();
 
-#if NBIOSCALL > 0
 	KASSERT(biostramp_image_size <= PAGE_SIZE);
 	pmap_kenter_pa((vaddr_t)BIOSTRAMP_BASE, (paddr_t)BIOSTRAMP_BASE,
 	VM_PROT_ALL, 0);
@@ -1302,7 +1298,6 @@ init386(paddr_t first_avail)
 	/* Needed early, for bioscall() */
 	cpu_info_primary.ci_pmap = pmap_kernel();
 #endif
-#endif /* !XEN */
 
 	pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	pmap_kenter_pa(gdt_vaddr, gdt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);



CVS commit: src/sys/arch/i386/i386

2016-09-16 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri Sep 16 12:28:41 UTC 2016

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

Log Message:
x86_copyargs takes as third argument a size, but still copies two chunks of
16 and 24 bytes, without checking the userland<->kernel limit accordingly.
Fix it by just checking the maximum size direcly.

It means that even if 16 bytes are copied, the kernel now makes sure 40
bytes are in userland. We could make it more fine-grained, but it would
probably unoptimize the function, and we don't care enough.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/i386/i386/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/i386/i386/copy.S
diff -u src/sys/arch/i386/i386/copy.S:1.24 src/sys/arch/i386/i386/copy.S:1.25
--- src/sys/arch/i386/i386/copy.S:1.24	Fri May 13 13:24:01 2016
+++ src/sys/arch/i386/i386/copy.S	Fri Sep 16 12:28:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $	*/
+/*	$NetBSD: copy.S,v 1.25 2016/09/16 12:28:41 maxv Exp $	*/
 /*	NetBSD: locore.S,v 1.34 2005/04/01 11:59:31 yamt Exp $	*/
 
 /*-
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.25 2016/09/16 12:28:41 maxv Exp $");
 
 #include "assym.h"
 
@@ -687,13 +687,16 @@ ENTRY(x86_copyargs)
 	movl	16(%esp),%ecx
 
 	/*
-	 * We check that the end of the destination buffer is not past the end
-	 * of the user's address space.  If it's not, then we only need to
-	 * check that each page is readable, and the CPU will do that for us.
+	 * In this function, we may copy more than the size given in the third
+	 * argument. In order to make sure the real end of the destination
+	 * buffer is not past the end of the user's address space, we don't
+	 * check the third argument but rather the largest possible size, which
+	 * is:
+	 * 	(2 + SYS_MAXSYSARGS) * 4 = 10 * 4
 	 */
 .Lx86_copyargs_start:
 	movl	%esi,%eax
-	addl	%ecx,%eax
+	addl	$(10 * 4),%eax
 	jc	_C_LABEL(x86_copyargs_efault)
 	cmpl	$VM_MAXUSER_ADDRESS,%eax
 	ja	_C_LABEL(x86_copyargs_efault)



CVS commit: src/sys/arch/i386/i386

2016-08-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 20 19:46:55 UTC 2016

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

Log Message:
fix the build


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.54 src/sys/arch/i386/i386/gdt.c:1.55
--- src/sys/arch/i386/i386/gdt.c:1.54	Sat Aug 20 12:05:48 2016
+++ src/sys/arch/i386/i386/gdt.c	Sat Aug 20 15:46:54 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.54 2016/08/20 16:05:48 maxv Exp $	*/
+/*	$NetBSD: gdt.c,v 1.55 2016/08/20 19:46:54 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.54 2016/08/20 16:05:48 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.55 2016/08/20 19:46:54 christos Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -304,6 +304,7 @@ gdt_grow(int which)
  *the new slots.
  */
 
+#ifndef XEN
 static int
 gdt_get_slot(void)
 {
@@ -312,6 +313,7 @@ gdt_get_slot(void)
 
 	return gdt_get_slot1(0);
 }
+#endif
 
 static int
 gdt_get_slot1(int which)
@@ -343,6 +345,7 @@ gdt_get_slot1(int which)
 /*
  * Deallocate a GDT slot, putting it on the free list.
  */
+#ifndef XEN
 static void
 gdt_put_slot(int slot)
 {
@@ -351,6 +354,7 @@ gdt_put_slot(int slot)
 
 	gdt_put_slot1(slot, 0);
 }
+#endif
 
 static void
 gdt_put_slot1(int slot, int which)



CVS commit: src/sys/arch/i386/i386

2016-08-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Aug 11 15:03:23 UTC 2016

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

Log Message:
This should be VM_MIN_KERNEL_ADDRESS, not KERNBASE.


To generate a diff of this commit:
cvs rdiff -u -r1.277 -r1.278 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.277 src/sys/arch/i386/i386/trap.c:1.278
--- src/sys/arch/i386/i386/trap.c:1.277	Thu Aug 11 14:58:29 2016
+++ src/sys/arch/i386/i386/trap.c	Thu Aug 11 15:03:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $	*/
+/*	$NetBSD: trap.c,v 1.278 2016/08/11 15:03:23 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.277 2016/08/11 14:58:29 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.278 2016/08/11 15:03:23 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -582,7 +582,7 @@ faultcommon:
 		 * The last can occur during an exec() copyin where the
 		 * argument space is lazy-allocated.
 		 */
-		if (type == T_PAGEFLT && va >= KERNBASE)
+		if (type == T_PAGEFLT && va >= VM_MIN_KERNEL_ADDRESS)
 			map = kernel_map;
 		else
 			map = >vm_map;



CVS commit: src/sys/arch/i386/i386

2016-07-25 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Jul 25 15:18:41 UTC 2016

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

Log Message:
This needs to be page-aligned anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.135 src/sys/arch/i386/i386/locore.S:1.136
--- src/sys/arch/i386/i386/locore.S:1.135	Sat Jul  9 06:58:06 2016
+++ src/sys/arch/i386/i386/locore.S	Mon Jul 25 15:18:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.135 2016/07/09 06:58:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.136 2016/07/25 15:18:41 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -273,11 +273,7 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 	.globl	_C_LABEL(lapic_tpr)
 
 #if NLAPIC > 0
-#ifdef __ELF__
 	.align	PAGE_SIZE
-#else
-	.align	12
-#endif
 	.globl	_C_LABEL(local_apic)
 	.globl	_C_LABEL(lapic_id)
 



CVS commit: src/sys/arch/i386/i386

2016-06-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jun 14 03:05:25 UTC 2016

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

Log Message:
fix PIC code.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/i386/i386/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/i386/i386/cpu_in_cksum.S
diff -u src/sys/arch/i386/i386/cpu_in_cksum.S:1.5 src/sys/arch/i386/i386/cpu_in_cksum.S:1.6
--- src/sys/arch/i386/i386/cpu_in_cksum.S:1.5	Mon May 30 18:58:52 2016
+++ src/sys/arch/i386/i386/cpu_in_cksum.S	Mon Jun 13 23:05:24 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_in_cksum.S,v 1.5 2016/05/30 22:58:52 christos Exp $	*/
+/*	$NetBSD: cpu_in_cksum.S,v 1.6 2016/06/14 03:05:24 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.S,v 1.5 2016/05/30 22:58:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.S,v 1.6 2016/06/14 03:05:24 christos Exp $");
 
 #include "assym.h"
 
@@ -329,9 +329,21 @@ ENTRY(cpu_in_cksum)
 	ret
 
 .Lout_of_mbufs:
-	pushl	$1f
+#ifdef __PIC__
+	PIC_PROLOGUE
+	leal	PIC_GOTOFF(.Mout_of_mbufs_msg), %eax
+	pushl	%eax
 	call	PIC_PLT(_C_LABEL(printf))
 	leal	4(%esp), %esp
+	PIC_EPILOGUE
+#else
+	pushl	.Mout_of_mbufs_msg
+	call	_C_LABEL(printf)
+	leal	4(%esp), %esp
+#endif
 	jmp	.Lreturn
-1:
+
+	.section.rodata
+	.type   .Mout_of_mbufs_msg, @object
+.Mout_of_mbufs_msg:
 	.asciz	"cksum: out of data\n"



CVS commit: src/sys/arch/i386/i386

2016-06-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  4 10:02:12 UTC 2016

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

Log Message:
Define and use fillkpt_blank on i386, like amd64. The PAE case is
included in fillkpt_blank, since PDE_SIZE is either 4 or 8 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.128 src/sys/arch/i386/i386/locore.S:1.129
--- src/sys/arch/i386/i386/locore.S:1.128	Sat Jun  4 09:52:41 2016
+++ src/sys/arch/i386/i386/locore.S	Sat Jun  4 10:02:12 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.128 2016/06/04 09:52:41 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.129 2016/06/04 10:02:12 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.128 2016/06/04 09:52:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.129 2016/06/04 10:02:12 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -219,6 +219,20 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 2:	;
 
 /*
+ * fillkpt_blank - Fill in a kernel page table with blank entries
+ *	ebx = page table address
+ *	ecx = number of pages to map
+ */
+#define fillkpt_blank	\
+	cmpl	$0,%ecx			;	/* zero-sized? */	\
+	je 	2f			; \
+1:	movl	$0,(PDE_SIZE-4)(%ebx)	;	/* upper 32 bits: 0 */	\
+	movl	$0,(%ebx)		;	/* lower 32 bits: 0 */	\
+	addl	$PDE_SIZE,%ebx		;	/* next PTE/PDE */	\
+	loop	1b			; \
+2:	;
+
+/*
  * killkpt - Destroy a kernel page table
  *	ebx = page table address
  *	ecx = number of pages to destroy
@@ -696,15 +710,12 @@ no_NOX:
 	leal	(PROC0_PTP1_OFF)(%esi),%ebx
 
 	/* Skip the first MB. */
-	movl	$(KERNTEXTOFF - KERNBASE),%eax
-	movl	%eax,%ecx
-	shrl	$(PGSHIFT-2),%ecx	/* ((n >> PGSHIFT) << 2) for # PDEs */
-#ifdef PAE
-	shll	$1,%ecx			/* PDEs are twice larger with PAE */
-#endif
-	addl	%ecx,%ebx
+	movl	$(KERNTEXTOFF - KERNBASE),%ecx
+	shrl	$PGSHIFT,%ecx
+	fillkpt_blank
 
 	/* Map the kernel text RX. */
+	movl	$(KERNTEXTOFF - KERNBASE),%eax	/* start of TEXT */
 	movl	$RELOC(__rodata_start),%ecx
 	subl	%eax,%ecx
 	shrl	$PGSHIFT,%ecx



CVS commit: src/sys/arch/i386/i386

2016-06-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat Jun  4 09:52:41 UTC 2016

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

Log Message:
Initialize cpuid_level at compile-time, not run-time. Same as amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.127 src/sys/arch/i386/i386/locore.S:1.128
--- src/sys/arch/i386/i386/locore.S:1.127	Sat Jun  4 09:45:57 2016
+++ src/sys/arch/i386/i386/locore.S	Sat Jun  4 09:52:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.127 2016/06/04 09:45:57 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.128 2016/06/04 09:52:41 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.127 2016/06/04 09:45:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.128 2016/06/04 09:52:41 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -317,7 +317,7 @@ END(nox_flag)
 LABEL(cputype)		.long	0	/* are we 80486, Pentium, or.. */
 END(cputype)
 	.type	_C_LABEL(cpuid_level), @object
-LABEL(cpuid_level)	.long	0	/* max. level accepted by cpuid instr */
+LABEL(cpuid_level)	.long	-1	/* max. level accepted by cpuid instr */
 END(cpuid_level)
 	.type	_C_LABEL(atdevbase), @object
 LABEL(atdevbase)	.long	0	/* location of start of iomem in virt */
@@ -402,8 +402,6 @@ _C_LABEL(Multiboot_Header):
 	xorl	%eax,%eax
 	movw	%ax,%fs
 	movw	%ax,%gs
-	decl	%eax
-	movl	%eax,RELOC(cpuid_level)
 
 	/* Find out our CPU type. */
 



CVS commit: src/sys/arch/i386/i386

2016-05-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon May 30 22:58:52 UTC 2016

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

Log Message:
Handle PIC linking for tests


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/i386/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/i386/i386/cpu_in_cksum.S
diff -u src/sys/arch/i386/i386/cpu_in_cksum.S:1.4 src/sys/arch/i386/i386/cpu_in_cksum.S:1.5
--- src/sys/arch/i386/i386/cpu_in_cksum.S:1.4	Mon Apr 28 16:23:24 2008
+++ src/sys/arch/i386/i386/cpu_in_cksum.S	Mon May 30 18:58:52 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_in_cksum.S,v 1.4 2008/04/28 20:23:24 martin Exp $	*/
+/*	$NetBSD: cpu_in_cksum.S,v 1.5 2016/05/30 22:58:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.S,v 1.4 2008/04/28 20:23:24 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_in_cksum.S,v 1.5 2016/05/30 22:58:52 christos Exp $");
 
 #include "assym.h"
 
@@ -330,7 +330,7 @@ ENTRY(cpu_in_cksum)
 
 .Lout_of_mbufs:
 	pushl	$1f
-	call	_C_LABEL(printf)
+	call	PIC_PLT(_C_LABEL(printf))
 	leal	4(%esp), %esp
 	jmp	.Lreturn
 1:



CVS commit: src/sys/arch/i386/i386

2016-05-30 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Mon May 30 17:45:26 UTC 2016

Modified Files:
src/sys/arch/i386/i386: multiboot.c

Log Message:
PR 51187 David Binderman: simplify redundant conditional


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/i386/multiboot.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/i386/i386/multiboot.c
diff -u src/sys/arch/i386/i386/multiboot.c:1.22 src/sys/arch/i386/i386/multiboot.c:1.23
--- src/sys/arch/i386/i386/multiboot.c:1.22	Fri Dec  7 04:49:08 2012
+++ src/sys/arch/i386/i386/multiboot.c	Mon May 30 17:45:26 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: multiboot.c,v 1.22 2012/12/07 04:49:08 msaitoh Exp $	*/
+/*	$NetBSD: multiboot.c,v 1.23 2016/05/30 17:45:26 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: multiboot.c,v 1.22 2012/12/07 04:49:08 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: multiboot.c,v 1.23 2016/05/30 17:45:26 dholland Exp $");
 
 #include "opt_multiboot.h"
 
@@ -593,7 +593,7 @@ setup_howto(struct multiboot_info *mi)
 	/* Skip kernel file name. */
 	while (*cl != '\0' && *cl != ' ')
 		cl++;
-	while (*cl != '\0' && *cl == ' ')
+	while (*cl == ' ')
 		cl++;
 
 	/* Check if there are flags and set 'howto' accordingly. */



CVS commit: src/sys/arch/i386/i386

2016-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 14 09:51:56 UTC 2016

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

Log Message:
Actually, put the NOX identification above. Old CPUs do not support the
cpuid instruction.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.121 src/sys/arch/i386/i386/locore.S:1.122
--- src/sys/arch/i386/i386/locore.S:1.121	Sat May 14 08:49:16 2016
+++ src/sys/arch/i386/i386/locore.S	Sat May 14 09:51:56 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.121 2016/05/14 08:49:16 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.122 2016/05/14 09:51:56 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.121 2016/05/14 08:49:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.122 2016/05/14 09:51:56 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -555,6 +555,16 @@ try586:	/* Use the `cpuid' instruction. 
 	cpuid
 	movl	%eax,RELOC(cpuid_level)
 
+	/*
+	 * Retrieve the NX/XD flag. We use the 32bit version of PG_NX.
+	 */
+	movl	$0x8001,%eax
+	cpuid
+	andl	$CPUID_NOX,%edx
+	jz	no_NOX
+	movl	$PG_NX32,RELOC(nox_flag)
+no_NOX:
+
 2:
 	/*
 	 * Finished with old stack; load new %esp now instead of later so we
@@ -571,16 +581,6 @@ try586:	/* Use the `cpuid' instruction. 
 	 */
 	movl	$_RELOC(tmpstk),%esp
 
-	/*
-	 * Retrieve the NX/XD flag. We use the 32bit version of PG_NX.
-	 */
-	movl	$0x8001,%eax
-	cpuid
-	andl	$CPUID_NOX,%edx
-	jz	no_NOX
-	movl	$PG_NX32,RELOC(nox_flag)
-no_NOX:
-
 /*
  * There are two different layouts possible, depending on whether PAE is
  * enabled or not.



CVS commit: src/sys/arch/i386/i386

2016-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 14 08:49:16 UTC 2016

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

Log Message:
Map rodata and data+bss independently, and give them R and RW with
fillkpt_nox. The code is exactly the same as amd64's.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.120 src/sys/arch/i386/i386/locore.S:1.121
--- src/sys/arch/i386/i386/locore.S:1.120	Sat May 14 08:39:41 2016
+++ src/sys/arch/i386/i386/locore.S	Sat May 14 08:49:16 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.120 2016/05/14 08:39:41 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.121 2016/05/14 08:49:16 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.120 2016/05/14 08:39:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.121 2016/05/14 08:49:16 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -684,10 +684,6 @@ no_NOX:
 	 */
 	leal	(PROC0_PTP1_OFF)(%esi),%ebx
 
-	/* Compute &__rodata_start - KERNBASE. */
-	movl	$RELOC(__rodata_start),%edx
-	andl	$~PGOFSET,%edx
-
 	/* Skip the first MB. */
 	movl	$(KERNTEXTOFF - KERNBASE),%eax
 	movl	%eax,%ecx
@@ -697,19 +693,43 @@ no_NOX:
 #endif
 	addl	%ecx,%ebx
 
-	/* Map the kernel text read-only. */
-	movl	%edx,%ecx
+	/* Map the kernel text RX. */
+	movl	$RELOC(__rodata_start),%ecx
 	subl	%eax,%ecx
 	shrl	$PGSHIFT,%ecx
 	orl	$(PG_V|PG_KR),%eax
 	fillkpt
 
-	/* Map the data, BSS, and bootstrap tables read-write. */
-	leal	(PG_V|PG_KW)(%edx),%eax
-	movl	RELOC(tablesize),%ecx
-	addl	%esi,%ecx			/* end of tables */
-	subl	%edx,%ecx			/* subtract end of text */
+	/* Map the kernel rodata R. */
+	movl	$RELOC(__rodata_start),%eax
+	movl	$RELOC(__data_start),%ecx
+	subl	%eax,%ecx
+	shrl	$PGSHIFT,%ecx
+	orl	$(PG_V|PG_KR),%eax
+	fillkpt_nox
+
+	/* Map the kernel data+bss RW. */
+	movl	$RELOC(__data_start),%eax
+	movl	$RELOC(__kernel_end),%ecx
+	subl	%eax,%ecx
+	shrl	$PGSHIFT,%ecx
+	orl	$(PG_V|PG_KW),%eax
+	fillkpt_nox
+
+	/*
+	 * We actually have to be careful here. The memory layout is as
+	 * follows:
+	 *+--+-+--+
+	 *| DATA+BSS < [PRELOADED MODULES] | BOOTSTRAP TABLES >
+	 *+--+-+--+
+	 * We just map everything from < to > with RWX rights.
+	 */
+	movl	$RELOC(__kernel_end),%eax
+	movl	%esi,%ecx		/* start of BOOTSTRAP TABLES */
+	addl	RELOC(tablesize),%ecx	/* end of BOOTSTRAP TABLES */
+	subl	%eax,%ecx		/* subtract end of kernel image */
 	shrl	$PGSHIFT,%ecx
+	orl	$(PG_V|PG_KW),%eax
 	fillkpt
 
 	/* Map ISA I/O mem (later atdevbase) */



CVS commit: src/sys/arch/i386/i386

2016-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 14 08:39:42 UTC 2016

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

Log Message:
Define fillkpt_nox on i386, same as amd64.

But there is a difference in the way it is done here. If PAE is not enabled,
PDE_SIZE = 4, so there is no NOX bit set. If PAE is enabled, PDE_SIZE = 8,
so the NOX bit is set.

This works exactly as intended, since NOX does not exist in the non-PAE
case.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.119 src/sys/arch/i386/i386/locore.S:1.120
--- src/sys/arch/i386/i386/locore.S:1.119	Sat May 14 08:34:00 2016
+++ src/sys/arch/i386/i386/locore.S	Sat May 14 08:39:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.120 2016/05/14 08:39:41 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.120 2016/05/14 08:39:41 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -200,6 +200,19 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 	loop	1b			;
 
 /*
+ * fillkpt_nox - Same as fillkpt, but sets the NX/XD bit.
+ */
+#define fillkpt_nox \
+	pushl	%ebp			; \
+	movl	RELOC(nox_flag),%ebp	; \
+1:	movl	%ebp,(PDE_SIZE-4)(%ebx)	;	/* upper 32 bits: NX */ \
+	movl	%eax,(%ebx)		;	/* store phys addr */	\
+	addl	$PDE_SIZE,%ebx		;	/* next PTE/PDE */	\
+	addl	$PAGE_SIZE,%eax		;	/* next phys page */	\
+	loop	1b			; \
+	popl	%ebp			;
+
+/*
  * killkpt - Destroy a kernel page table
  *	ebx = page table address
  *	ecx = number of pages to destroy



CVS commit: src/sys/arch/i386/i386

2016-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 14 08:34:01 UTC 2016

Modified Files:
src/sys/arch/i386/i386: locore.S mptramp.S

Log Message:
Fix the secondary CPUs bug in i386. Same as amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.118 src/sys/arch/i386/i386/locore.S:1.119
--- src/sys/arch/i386/i386/locore.S:1.118	Sat May 14 06:49:34 2016
+++ src/sys/arch/i386/i386/locore.S	Sat May 14 08:34:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.119 2016/05/14 08:34:00 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -168,6 +168,9 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 #endif /* XEN */
 #define	RELOC(x)	_RELOC(_C_LABEL(x))
 
+/* 32bit version of PG_NX */
+#define PG_NX32	0x8000
+
 #ifndef PAE
 #define	PROC0_PDIR_OFF	0
 #else
@@ -234,6 +237,7 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
  */
 	.data
 
+	.globl	_C_LABEL(nox_flag)
 	.globl	_C_LABEL(cputype)
 	.globl	_C_LABEL(cpuid_level)
 	.globl	_C_LABEL(esym)
@@ -279,6 +283,10 @@ LABEL(lapic_tpr)
 	.long 0
 END(lapic_tpr)
 #endif
+
+	.type	_C_LABEL(nox_flag), @object
+LABEL(nox_flag)		.long	0	/* 32bit NOX flag, set if supported */
+END(nox_flag)
 	.type	_C_LABEL(cputype), @object
 LABEL(cputype)		.long	0	/* are we 80486, Pentium, or.. */
 END(cputype)
@@ -550,6 +558,16 @@ try586:	/* Use the `cpuid' instruction. 
 	 */
 	movl	$_RELOC(tmpstk),%esp
 
+	/*
+	 * Retrieve the NX/XD flag. We use the 32bit version of PG_NX.
+	 */
+	movl	$0x8001,%eax
+	cpuid
+	andl	$CPUID_NOX,%edx
+	jz	no_NOX
+	movl	$PG_NX32,RELOC(nox_flag)
+no_NOX:
+
 /*
  * There are two different layouts possible, depending on whether PAE is
  * enabled or not.
@@ -737,7 +755,20 @@ try586:	/* Use the `cpuid' instruction. 
 	movl	%eax,%cr3
 
 	/*
-	 * 2. Enable paging and the rest of it.
+	 * 2. Set NOX in EFER, if available.
+	 */
+	movl	RELOC(nox_flag),%ebx
+	cmpl	$0,%ebx
+	je 	skip_NOX
+	movl	$MSR_EFER,%ecx
+	rdmsr
+	xorl	%eax,%eax
+	orl	$(EFER_NXE),%eax
+	wrmsr
+skip_NOX:
+
+	/*
+	 * 3. Enable paging and the rest of it.
 	 */
 	movl	%cr0,%eax
 	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax

Index: src/sys/arch/i386/i386/mptramp.S
diff -u src/sys/arch/i386/i386/mptramp.S:1.28 src/sys/arch/i386/i386/mptramp.S:1.29
--- src/sys/arch/i386/i386/mptramp.S:1.28	Thu May 12 09:40:23 2016
+++ src/sys/arch/i386/i386/mptramp.S	Sat May 14 08:34:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $	*/
+/*	$NetBSD: mptramp.S,v 1.29 2016/05/14 08:34:00 maxv Exp $	*/
 
 /*
  * Copyright (c) 2000, 2016 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.28 2016/05/12 09:40:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mptramp.S,v 1.29 2016/05/14 08:34:00 maxv Exp $");
 
 #include "opt_mpbios.h"		/* for MPDEBUG */
 
@@ -177,11 +177,25 @@ no_PSE:
 	movl	%eax,%cr4
 #endif
 
+	/*
+	 * Set NOX in EFER, if available.
+	 */
+	movl	RELOC(nox_flag),%ebx
+	cmpl	$0,%ebx
+	je 	no_NOX
+	movl	$MSR_EFER,%ecx
+	rdmsr
+	xorl	%eax,%eax
+	orl	$(EFER_NXE),%eax
+	wrmsr
+no_NOX:
+
+	/* Load %cr3. */
 	movl	RELOC(mp_pdirpa),%ecx
 	HALTT(0x5,%ecx)
-
-	/* Load base of page directory and enable mapping. */
 	movl	%ecx,%cr3		/* load PTD addr into MMU */
+
+	/* Enable paging and the rest of it. */
 	movl	%cr0,%eax
 	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP|CR0_AM),%eax
 	movl	%eax,%cr0
@@ -191,17 +205,6 @@ no_PSE:
 #endif
 	HALT(0x6)
 
-	/*
-	 * 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
 
 /*
  * ok, we are now running with paging enabled and sharing page tables



CVS commit: src/sys/arch/i386/i386

2016-05-14 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Sat May 14 06:49:34 UTC 2016

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

Log Message:
Define killkpt, and don't use _RELOC. Same as amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.117 src/sys/arch/i386/i386/locore.S:1.118
--- src/sys/arch/i386/i386/locore.S:1.117	Fri May 13 14:03:00 2016
+++ src/sys/arch/i386/i386/locore.S	Sat May 14 06:49:34 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.118 2016/05/14 06:49:34 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -196,6 +196,17 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 	addl	$PAGE_SIZE,%eax		;	/* next phys page */	\
 	loop	1b			;
 
+/*
+ * killkpt - Destroy a kernel page table
+ *	ebx = page table address
+ *	ecx = number of pages to destroy
+ */
+#define killkpt \
+1:	movl	$0,(PDE_SIZE-4)(%ebx)	;	/* upper bits (for PAE) */ \
+	movl	$0,(%ebx)		; \
+	addl	$PDE_SIZE,%ebx		; \
+	loop	1b			;
+
 
 #ifdef XEN
 /*
@@ -647,7 +658,7 @@ try586:	/* Use the `cpuid' instruction. 
 	andl	$~PGOFSET,%edx
 
 	/* Skip the first MB. */
-	movl	$_RELOC(KERNTEXTOFF),%eax
+	movl	$(KERNTEXTOFF - KERNBASE),%eax
 	movl	%eax,%ecx
 	shrl	$(PGSHIFT-2),%ecx	/* ((n >> PGSHIFT) << 2) for # PDEs */
 #ifdef PAE
@@ -743,10 +754,7 @@ begin:
 	movl	_C_LABEL(nkptp)+1*4,%ecx
 	leal	(PROC0_PDIR_OFF)(%esi),%ebx	/* old, phys address of PDIR */
 	addl	$(KERNBASE), %ebx		/* new, virt address of PDIR */
-1:	movl	$0,(PDE_SIZE-4)(%ebx)		/* upper bits (for PAE) */
-	movl	$0,(%ebx)
-	addl	$PDE_SIZE,%ebx
-	loop	1b
+	killkpt
 
 	/* Relocate atdevbase. */
 	movl	$KERNBASE,%edx



CVS commit: src/sys/arch/i386/i386

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 14:03:00 UTC 2016

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

Log Message:
Bring some amd64 swag. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.116 src/sys/arch/i386/i386/locore.S:1.117
--- src/sys/arch/i386/i386/locore.S:1.116	Thu May 12 06:45:16 2016
+++ src/sys/arch/i386/i386/locore.S	Fri May 13 14:03:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.116 2016/05/12 06:45:16 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.116 2016/05/12 06:45:16 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.117 2016/05/13 14:03:00 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -340,10 +340,13 @@ _C_LABEL(Multiboot_Header):
 1:
 	/*
 	 * At this point, we know that a NetBSD-specific boot loader
-	 * booted this kernel.  The stack carries the following parameters:
-	 * (boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem),
-	 * 4 bytes each.
+	 * booted this kernel.
+	 *
+	 * Load parameters from the stack (32 bits):
+	 * boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem
+	 * We are not interested in 'bootdev'.
 	 */
+
 	addl	$4,%esp		/* Discard return address to boot loader */
 	call	_C_LABEL(native_loader)
 	addl	$24,%esp
@@ -537,22 +540,43 @@ try586:	/* Use the `cpuid' instruction. 
 	movl	$_RELOC(tmpstk),%esp
 
 /*
- * Virtual address space of kernel, without PAE. The page dir is 1 page long.
+ * There are two different layouts possible, depending on whether PAE is
+ * enabled or not.
  *
- * text | data | bss | [syms] | [blobs] | page dir | proc0 kstack | L1 ptp
- *			0  1   2  3
+ * If PAE is not enabled, there are two levels of pages: PD -> PT. They will
+ * be referred to as: L2 -> L1. L2 is 1 page long. The BOOTSTRAP TABLES have
+ * the following layout:
+ * 	+-+++
+ * 	| L2 -> PROC0 STK -> L1 |
+ * 	+-+++
+ *
+ * If PAE is enabled, there are three levels of pages: PDP -> PD -> PT. They
+ * will be referred to as: L3 -> L2 -> L1. L3 is 1 page long, L2 is 4 page
+ * long. The BOOTSTRAP TABLES have the following layout:
+ * 	+-+-+++
+ * 	| L3 -> L2 -> PROC0 STK -> L1 |
+ * 	+-+-+++
+ *
+ * Virtual address space of the kernel in both cases:
+ * +--++--+-++-+---
+ * | TEXT | RODATA | DATA | BSS | [SYMS] | [PRELOADED MODULES] | BOOTSTRAP
+ * +--++--+-++-+---
+ * (1)  (2)   (3)
+ *
+ * ---++
+ * TABLES | ISA IO MEM |
+ * ---++
+ *   (4)
  *
- * Virtual address space of kernel, with PAE. We need 4 pages for the page dir
- * and 1 page for the L3.
- * text | data | bss | [syms] | [blobs] | L3 | page dir | proc0 kstack | L1 ptp
- * 	01  5   6  7
+ * PROC0 STK is obviously not linked as a page level. It just happens to be
+ * caught between L2 and L1.
  */
 
-	/* Find end of kernel image. */
+	/* Find end of kernel image; brings us on (1). */
 	movl	$RELOC(end),%edi
 
 #if (NKSYMS || defined(DDB) || defined(MODULAR)) && !defined(makeoptions_COPY_SYMTAB)
-	/* Save the symbols (if loaded). */
+	/* Save the symbols (if loaded); brinds us on (2). */
 	movl	RELOC(esym),%eax
 	testl	%eax,%eax
 	jz	1f
@@ -561,14 +585,15 @@ try586:	/* Use the `cpuid' instruction. 
 1:
 #endif
 
-	/* Skip over any modules/blobs. */
+	/* Skip over any modules/blobs; brings us on (3). */
 	movl	RELOC(eblob),%eax
 	testl	%eax,%eax
 	jz	1f
 	subl	$KERNBASE,%eax
 	movl	%eax,%edi
 1:
-	/* Compute sizes */
+
+	/* We are on (3). Align up for BOOTSTRAP TABLES. */
 	movl	%edi,%esi
 	addl	$PGOFSET,%esi
 	andl	$~PGOFSET,%esi
@@ -577,20 +602,20 @@ try586:	/* Use the `cpuid' instruction. 
 	movl	%esi,%eax
 	addl	$~L2_FRAME,%eax
 	shrl	$L2_SHIFT,%eax
-	incl	%eax		/* one more ptp for VAs stolen by bootstrap */
+	incl	%eax		/* one more PTP for VAs stolen by bootstrap */
 1:	movl	%eax,RELOC(nkptp)+1*4
 
 	/* tablesize = (PDP_SIZE + UPAGES + nkptp) << PGSHIFT; */
 	addl	$(PDP_SIZE+UPAGES),%eax
 #ifdef PAE
-	incl	%eax 		/* one more page for the L3 PD */
+	incl	%eax 		/* one more page for L3 */
 	shll	$PGSHIFT+1,%eax	/* PTP tables are twice larger with PAE */
 #else
 	shll	$PGSHIFT,%eax
 #endif
 	movl	%eax,RELOC(tablesize)
 
-	/* ensure that nkptp covers bootstrap tables */
+	/* Ensure that nkptp covers BOOTSTRAP TABLES. */
 	addl	%esi,%eax
 	addl	$~L2_FRAME,%eax
 	

CVS commit: src/sys/arch/i386/i386

2016-05-13 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Fri May 13 13:24:01 UTC 2016

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

Log Message:
KNF a little, use C-style comments, and remove susword/fusword. No
functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/i386/i386/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/i386/i386/copy.S
diff -u src/sys/arch/i386/i386/copy.S:1.23 src/sys/arch/i386/i386/copy.S:1.24
--- src/sys/arch/i386/i386/copy.S:1.23	Fri Jan 10 16:47:07 2014
+++ src/sys/arch/i386/i386/copy.S	Fri May 13 13:24:01 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $	*/
+/*	$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $	*/
 /*	NetBSD: locore.S,v 1.34 2005/04/01 11:59:31 yamt Exp $	*/
 
 /*-
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.24 2016/05/13 13:24:01 maxv Exp $");
 
 #include "assym.h"
 
@@ -86,10 +86,10 @@ __KERNEL_RCSID(0, "$NetBSD: copy.S,v 1.2
 #define DEFERRED_SWITCH_CHECK \
 	CHECK_DEFERRED_SWITCH			; \
 	jnz	99f; \
-98:
+	98:
 
 #define DEFERRED_SWITCH_CALL \
-99:		; \
+	99:		; \
 	call	_C_LABEL(do_pmap_load)		; \
 	jmp	98b
 
@@ -136,7 +136,7 @@ NENTRY(do_pmap_load)
  * `level' levels down the stack if level > 0.
  */
 ENTRY(return_address)
-	movl	%ebp,%eax	/* frame pointer -> %eax */ 
+	movl	%ebp,%eax	/* frame pointer -> %eax */
 	movl	4(%esp),%ecx	/* level -> %ecx */
 	movl	CPUVAR(CURLWP),%edx
 	movl	L_PCB(%edx),%edx
@@ -166,15 +166,15 @@ ENTRY(kcopy)
 .Lkcopy_start:
 	movl	%edi,%eax
 	subl	%esi,%eax
-	cmpl	%ecx,%eax		# overlapping?
+	cmpl	%ecx,%eax		/* overlapping? */
 	movl	%ecx,%edx
 	jb	1f
-	# nope, copy forward
-	shrl	$2,%ecx			# copy by 32-bit words
+	/* nope, copy forward */
+	shrl	$2,%ecx			/* copy by 32-bit words */
 	rep
 	movsl
 	movl	%edx,%ecx
-	andl	$3,%ecx			# any bytes left?
+	andl	$3,%ecx			/* any bytes left? */
 	jz	0f
 	rep
 	movsb
@@ -185,15 +185,15 @@ ENTRY(kcopy)
 	ret
 
 	ALIGN_TEXT
-1:	addl	%ecx,%edi		# copy backward
+1:	addl	%ecx,%edi		/* copy backward */
 	addl	%ecx,%esi
 	std
-	andl	$3,%ecx			# any fractional bytes?
+	andl	$3,%ecx			/* any fractional bytes? */
 	decl	%edi
 	decl	%esi
 	rep
 	movsb
-	movl	%edx,%ecx		# copy remainder by 32-bit words
+	movl	%edx,%ecx		/* copy remainder by 32-bit words */
 	shrl	$2,%ecx
 	subl	$3,%esi
 	subl	$3,%edi
@@ -337,11 +337,11 @@ ENTRY(copyoutstr)
 	DEFERRED_SWITCH_CHECK
 	pushl	%esi
 	pushl	%edi
-	movl	12(%esp),%esi		# esi = from
-	movl	16(%esp),%edi		# edi = to
-	movl	20(%esp),%edx		# edx = maxlen
+	movl	12(%esp),%esi		/* esi = from */
+	movl	16(%esp),%edi		/* edi = to */
+	movl	20(%esp),%edx		/* edx = maxlen */
 .Lcopyoutstr_start:
-5:	
+5:
 	/*
 	 * Get min(%edx, VM_MAXUSER_ADDRESS-%edi).
 	 */
@@ -388,9 +388,9 @@ ENTRY(copyinstr)
 	DEFERRED_SWITCH_CHECK
 	pushl	%esi
 	pushl	%edi
-	movl	12(%esp),%esi		# %esi = from
-	movl	16(%esp),%edi		# %edi = to
-	movl	20(%esp),%edx		# %edx = maxlen
+	movl	12(%esp),%esi		/* %esi = from */
+	movl	16(%esp),%edi		/* %edi = to */
+	movl	20(%esp),%edx		/* %edx = maxlen */
 
 	/*
 	 * Get min(%edx, VM_MAXUSER_ADDRESS-%esi).
@@ -457,9 +457,9 @@ ENTRY(copystr)
 	pushl	%esi
 	pushl	%edi
 
-	movl	12(%esp),%esi		# esi = from
-	movl	16(%esp),%edi		# edi = to
-	movl	20(%esp),%edx		# edx = maxlen
+	movl	12(%esp),%esi		/* esi = from */
+	movl	16(%esp),%edi		/* edi = to */
+	movl	20(%esp),%edx		/* edx = maxlen */
 	incl	%edx
 
 1:	decl	%edx
@@ -508,24 +508,6 @@ ENTRY(fuword)
 	DEFERRED_SWITCH_CALL
 
 /*
- * int fusword(const void *uaddr);
- * Fetch a short from the user's address space.
- * see fusword(9)
- */
-/* LINTSTUB: Func: int fusword(const void *base) */
-ENTRY(fusword)
-	DEFERRED_SWITCH_CHECK
-	movl	4(%esp),%edx
-	cmpl	$VM_MAXUSER_ADDRESS-2,%edx
-	ja	_C_LABEL(fusuaddrfault)
-	GET_CURPCB(%ecx)
-	movl	$_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
-	movzwl	(%edx),%eax
-	movl	$0,PCB_ONFAULT(%ecx)
-	ret
-	DEFERRED_SWITCH_CALL
-
-/*
  * int fuswintr(const void *uaddr);
  * Fetch a short from the user's address space.  Can be called during an
  * interrupt.
@@ -612,26 +594,6 @@ ENTRY(suword)
 	DEFERRED_SWITCH_CALL
 
 /*
- * int susword(void *uaddr, short x);
- * Store a short in the user's address space.
- * see susword(9)
- */
-/* LINTSTUB: Func: int susword(void *base, short c) */
-ENTRY(susword)
-	DEFERRED_SWITCH_CHECK
-	movl	4(%esp),%edx
-	cmpl	$VM_MAXUSER_ADDRESS-2,%edx
-	ja	_C_LABEL(fusuaddrfault)
-	GET_CURPCB(%ecx)
-	movl	$_C_LABEL(fusufault),PCB_ONFAULT(%ecx)
-	movl	8(%esp),%eax
-	movw	%ax,(%edx)
-	xorl	%eax,%eax
-	movl	%eax,PCB_ONFAULT(%ecx)
-	ret
-	DEFERRED_SWITCH_CALL
-
-/*
  * int suswintr(void *uaddr, short x);
  * Store a short in the user's address space.  Can be called during an
  * interrupt.
@@ -736,7 +698,7 @@ ENTRY(x86_copyargs)
 	cmpl	

CVS commit: src/sys/arch/i386/i386

2016-05-11 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Wed May 11 17:48:05 UTC 2016

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

Log Message:
Switch to C-style comments, and reduce a little the diff between i386 and
amd64. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.114 src/sys/arch/i386/i386/locore.S:1.115
--- src/sys/arch/i386/i386/locore.S:1.114	Sun Aug 30 01:46:03 2015
+++ src/sys/arch/i386/i386/locore.S	Wed May 11 17:48:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.114 2015/08/30 01:46:03 uebayasi Exp $	*/
+/*	$NetBSD: locore.S,v 1.115 2016/05/11 17:48:05 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -64,7 +64,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 /*-
  * Copyright (c) 1998, 2000, 2004, 2006, 2007, 2009 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -129,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.114 2015/08/30 01:46:03 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.115 2016/05/11 17:48:05 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -159,7 +158,6 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 #include 
 #endif
 
-/* XXX temporary kluge; these should not be here */
 /* Get definitions for IOM_BEGIN, IOM_END, and IOM_SIZE */
 #include 
 
@@ -170,6 +168,35 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
 #endif /* XEN */
 #define	RELOC(x)	_RELOC(_C_LABEL(x))
 
+#ifndef PAE
+#define	PROC0_PDIR_OFF	0
+#else
+#define PROC0_L3_OFF	0
+#define PROC0_PDIR_OFF	1 * PAGE_SIZE
+#endif
+
+#define	PROC0_STK_OFF	(PROC0_PDIR_OFF + PDP_SIZE * PAGE_SIZE)
+#define	PROC0_PTP1_OFF	(PROC0_STK_OFF + 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
+ *
+ * For PAE, each entry is 8 bytes long: we must set the 4 upper bytes to 0.
+ * This is done by the first instruction of fillkpt. In the non-PAE case, this
+ * instruction just clears the page table entry.
+ */
+
+#define fillkpt	\
+1:	movl	$0,(PDE_SIZE-4)(%ebx)	;	/* upper 32 bits: 0 */	\
+	movl	%eax,(%ebx)		;	/* store phys addr */	\
+	addl	$PDE_SIZE,%ebx		;	/* next PTE/PDE */	\
+	addl	$PAGE_SIZE,%eax		;	/* next phys page */	\
+	loop	1b			;
+
+
 #ifdef XEN
 /*
  * Xen guest identifier and loader selection
@@ -242,30 +269,32 @@ LABEL(lapic_tpr)
 END(lapic_tpr)
 #endif
 	.type	_C_LABEL(cputype), @object
-LABEL(cputype)		.long	0	# are we 80486, Pentium, or..
+LABEL(cputype)		.long	0	/* are we 80486, Pentium, or.. */
 END(cputype)
 	.type	_C_LABEL(cpuid_level), @object
 LABEL(cpuid_level)	.long	0
 END(cpuid_level)
 	.type	_C_LABEL(atdevbase), @object
-LABEL(atdevbase)	.long	0	# location of start of iomem in virtual
+LABEL(atdevbase)	.long	0	/* location of start of iomem in virt */
 END(atdevbase)
 	.type	_C_LABEL(lwp0uarea), @object
 LABEL(lwp0uarea)	.long	0
 END(lwp0uarea)
 	.type	_C_LABEL(PDPpaddr), @object
-LABEL(PDPpaddr)		.long	0	# paddr of PDP, for libkvm
+LABEL(PDPpaddr)		.long	0	/* paddr of PDP, for libkvm */
 END(PDPpaddr)
 	.type	_C_LABEL(tablesize), @object
 _C_LABEL(tablesize):	.long	0
 END(tablesize)
+
+	/* Space for the temporary stack */
 	.size	tmpstk, tmpstk - .
-	.space 512
+	.space	512
 tmpstk:
 #ifdef XEN
-	.align 		PAGE_SIZE, 0x0	# Align on page boundary
+	.align 		PAGE_SIZE, 0x0	/* Align on page boundary */
 LABEL(tmpgdt)
-	.space 		PAGE_SIZE	# Xen expects a page
+	.space 		PAGE_SIZE	/* Xen expects a page */
 END(tmpgdt)
 #endif /* XEN */
 
@@ -275,7 +304,10 @@ END(tmpgdt)
 
 ENTRY(start)
 #ifndef XEN
-	movw	$0x1234,0x472			# warm boot
+
+	/* Warm boot */
+	movw	$0x1234,0x472
+
 #if defined(MULTIBOOT)
 	jmp	1f
 
@@ -299,7 +331,7 @@ _C_LABEL(Multiboot_Header):
 	 * space to process it later -- after we are relocated.  It will
 	 * be safer to run complex C code than doing it at this point.
 	 */
-	pushl	%ebx		# Address of Multiboot information
+	pushl	%ebx		/* Address of Multiboot information */
 	call	_C_LABEL(multiboot_pre_reloc)
 	addl	$4,%esp
 	jmp	2f
@@ -312,7 +344,7 @@ _C_LABEL(Multiboot_Header):
 	 * (boothowto, [bootdev], bootinfo, esym, biosextmem, biosbasemem),
 	 * 4 bytes each.
 	 */
-	addl	$4,%esp		# Discard return address to boot loader
+	addl	$4,%esp		/* Discard return address to boot loader */
 	call	_C_LABEL(native_loader)
 	addl	$24,%esp
 
@@ -404,30 +436,30 @@ is486:	movl	$CPU_486,RELOC(cputype)
 	popfl
 	jmp 2f
 trycyrix486:
-	movl	$CPU_6x86,RELOC(cputype)	# set CPU type
+	movl	$CPU_6x86,RELOC(cputype)	/* set CPU type */
 	/*
 	 * Check for Cyrix 486 CPU by seeing if the flags change during a
 	 * divide. This is documented in the Cx486SLC/e SMM Programmer's
 	 * Guide.
 	 */
 	xorl	%edx,%edx
-	cmpl	%edx,%edx		# set flags to 

CVS commit: src/sys/arch/i386/i386

2015-05-11 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue May 12 05:18:50 UTC 2015

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

Log Message:
 Add missing check for db_Grp9. This change fixes a bug that cmpxchg8b can't
be disassembled.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/i386/i386/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/i386/i386/db_disasm.c
diff -u src/sys/arch/i386/i386/db_disasm.c:1.44 src/sys/arch/i386/i386/db_disasm.c:1.45
--- src/sys/arch/i386/i386/db_disasm.c:1.44	Thu Oct 23 10:01:53 2014
+++ src/sys/arch/i386/i386/db_disasm.c	Tue May 12 05:18:50 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_disasm.c,v 1.44 2014/10/23 10:01:53 msaitoh Exp $	*/
+/*	$NetBSD: db_disasm.c,v 1.45 2015/05/12 05:18:50 msaitoh Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_disasm.c,v 1.44 2014/10/23 10:01:53 msaitoh Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_disasm.c,v 1.45 2015/05/12 05:18:50 msaitoh Exp $);
 
 #include sys/param.h
 #include sys/proc.h
@@ -1212,7 +1212,8 @@ db_disasm(
 	ip-i_extra == (const char *)db_Grp2 ||
 	ip-i_extra == (const char *)db_Grp6 ||
 	ip-i_extra == (const char *)db_Grp7 ||
-	ip-i_extra == (const char *)db_Grp8) {
+	ip-i_extra == (const char *)db_Grp8 ||
+	ip-i_extra == (const char *)db_Grp9) {
 		i_name = ((const char *const*)ip-i_extra)[f_reg(regmodrm)];
 	} else if (ip-i_extra == (const char *)db_Grp3) {
 		ip = (const struct inst *)ip-i_extra;



CVS commit: src/sys/arch/i386/i386

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

Modified Files:
src/sys/arch/i386/i386: freebsd_syscall.c ibcs2_syscall.c
linux_syscall.c svr4_syscall.c

Log Message:
adjust to new trace_{enter,exit} and dtrace


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/i386/i386/freebsd_syscall.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/i386/i386/ibcs2_syscall.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/i386/i386/linux_syscall.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/i386/i386/svr4_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/i386/i386/freebsd_syscall.c
diff -u src/sys/arch/i386/i386/freebsd_syscall.c:1.39 src/sys/arch/i386/i386/freebsd_syscall.c:1.40
--- src/sys/arch/i386/i386/freebsd_syscall.c:1.39	Thu Jul 12 14:13:08 2012
+++ src/sys/arch/i386/i386/freebsd_syscall.c	Sat Mar  7 13:50:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_syscall.c,v 1.39 2012/07/12 18:13:08 dsl Exp $	*/
+/*	$NetBSD: freebsd_syscall.c,v 1.40 2015/03/07 18:50:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.39 2012/07/12 18:13:08 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.40 2015/03/07 18:50:01 christos Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -112,8 +112,8 @@ freebsd_syscall(struct trapframe *frame)
 			goto bad;
 	}
 
-	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) {
 		rval[0] = 0;
 		rval[1] = frame-tf_edx; /* need to keep edx for shared FreeBSD bins */
 		error = sy_call(callp, l, args, rval);
@@ -143,8 +143,8 @@ freebsd_syscall(struct trapframe *frame)
 		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/i386/i386/ibcs2_syscall.c
diff -u src/sys/arch/i386/i386/ibcs2_syscall.c:1.48 src/sys/arch/i386/i386/ibcs2_syscall.c:1.49
--- src/sys/arch/i386/i386/ibcs2_syscall.c:1.48	Thu Jul 12 14:13:08 2012
+++ src/sys/arch/i386/i386/ibcs2_syscall.c	Sat Mar  7 13:50:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_syscall.c,v 1.48 2012/07/12 18:13:08 dsl Exp $	*/
+/*	$NetBSD: ibcs2_syscall.c,v 1.49 2015/03/07 18:50:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.48 2012/07/12 18:13:08 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.49 2015/03/07 18:50:01 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -111,8 +111,8 @@ ibcs2_syscall(struct trapframe *frame)
 			goto bad;
 	}
 
-	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) {
 		rval[0] = 0;
 		rval[1] = 0;
 		error = sy_call(callp, l, args, rval);
@@ -143,8 +143,8 @@ ibcs2_syscall(struct trapframe *frame)
 		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/i386/i386/linux_syscall.c
diff -u src/sys/arch/i386/i386/linux_syscall.c:1.51 src/sys/arch/i386/i386/linux_syscall.c:1.52
--- src/sys/arch/i386/i386/linux_syscall.c:1.51	Wed Sep 28 13:27:21 2011
+++ src/sys/arch/i386/i386/linux_syscall.c	Sat Mar  7 13:50:01 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_syscall.c,v 1.51 2011/09/28 17:27:21 christos Exp $	*/
+/*	$NetBSD: linux_syscall.c,v 1.52 2015/03/07 18:50:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: linux_syscall.c,v 1.51 2011/09/28 17:27:21 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: linux_syscall.c,v 1.52 2015/03/07 18:50:01 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -99,12 +99,10 @@ linux_syscall(struct trapframe *frame)
 	rval[0] = 0;
 	rval[1] = 0;
 
-	if (__predict_false(l-l_proc-p_trace_enabled)) {
-		error = trace_enter(code, args, callp-sy_narg);
-		if (__predict_true(error == 0)) {
+	if (__predict_false(l-l_proc-p_trace_enabled || KDTRACE_ENTRY(callp-sy_entry))) {
+		error = trace_enter(code, callp, args);
+		if (__predict_true(error == 0))
 			error = sy_call(callp, l, args, rval);
-			trace_exit(code, rval, error);
-		}
 	} else
 		error = sy_call(callp, 

CVS commit: src/sys/arch/i386/i386

2015-02-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 27 16:41:12 UTC 2015

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

Log Message:
sync with amd64: SIGBUS for mmap out of range.


To generate a diff of this commit:
cvs rdiff -u -r1.273 -r1.274 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.273 src/sys/arch/i386/i386/trap.c:1.274
--- src/sys/arch/i386/i386/trap.c:1.273	Sat Oct 18 04:33:25 2014
+++ src/sys/arch/i386/i386/trap.c	Fri Feb 27 11:41:12 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.273 2014/10/18 08:33:25 snj Exp $	*/
+/*	$NetBSD: trap.c,v 1.274 2015/02/27 16:41:12 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.273 2014/10/18 08:33:25 snj Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.274 2015/02/27 16:41:12 christos Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -653,15 +653,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);
@@ -671,15 +662,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 (%s), uid %d killed: out of swap\n,
-			   p-p_pid, p-p_comm,
-			   l-l_cred ?
-			   kauth_cred_geteuid(l-l_cred) : -1);
-		} else {
+			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/i386/i386

2015-02-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Feb 27 17:45:52 UTC 2015

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

Log Message:
fix TRAP_SIGDEBUG compilation


To generate a diff of this commit:
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.274 src/sys/arch/i386/i386/trap.c:1.275
--- src/sys/arch/i386/i386/trap.c:1.274	Fri Feb 27 11:41:12 2015
+++ src/sys/arch/i386/i386/trap.c	Fri Feb 27 12:45:52 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.274 2015/02/27 16:41:12 christos Exp $	*/
+/*	$NetBSD: trap.c,v 1.275 2015/02/27 17:45:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.274 2015/02/27 16:41:12 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.275 2015/02/27 17:45:52 christos Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -689,10 +689,9 @@ faultcommon:
 		}
 
 #ifdef TRAP_SIGDEBUG
-		printf(pid %d.%d (%s): signal %d at rip %lx addr %lx 
+		printf(pid %d.%d (%s): signal %d at eip %x 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);
+		frame-tf_eip, va, error);
 #endif
 		(*p-p_emul-e_trapsignal)(l, ksi);
 		break;



CVS commit: src/sys/arch/i386/i386

2015-01-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 23 02:52:14 UTC 2015

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

Log Message:
whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.752 -r1.753 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.752 src/sys/arch/i386/i386/machdep.c:1.753
--- src/sys/arch/i386/i386/machdep.c:1.752	Sun Feb 23 17:36:43 2014
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan 22 21:52:14 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.753 2015/01/23 02:52:14 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.753 2015/01/23 02:52:14 christos Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -936,7 +936,8 @@ int xen_idt_idx;
 extern union descriptor tmpgdt[];
 #endif
 
-void cpu_init_idt(void)
+void 
+cpu_init_idt(void)
 {
 #ifndef XEN
 	struct region_descriptor region;



CVS commit: src/sys/arch/i386/i386

2014-09-16 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Sep 16 09:42:47 UTC 2014

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

Log Message:
fix an END() marker to match the function.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/i386/i386/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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.20 src/sys/arch/i386/i386/cpufunc.S:1.21
--- src/sys/arch/i386/i386/cpufunc.S:1.20	Thu Mar  6 12:30:24 2014
+++ src/sys/arch/i386/i386/cpufunc.S	Tue Sep 16 09:42:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.20 2014/03/06 12:30:24 nonaka Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.21 2014/09/16 09:42:47 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include sys/errno.h
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: cpufunc.S,v 1.20 2014/03/06 12:30:24 nonaka Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpufunc.S,v 1.21 2014/09/16 09:42:47 mrg Exp $);
 
 #include opt_xen.h
 
@@ -188,8 +188,7 @@ NENTRY(msr_onfault)
 	movl	$0, PCB_ONFAULT(%ecx)
 	movl	$EFAULT, %eax
 	ret
-
-END(rdmsr_safe)
+END(msr_onfault)
 
 ENTRY(cpu_counter)
 	rdtsc



CVS commit: src/sys/arch/i386/i386

2014-03-12 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Mar 12 18:59:07 UTC 2014

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

Log Message:
Mark a variable diagnostic-only, from John D. Baker.


To generate a diff of this commit:
cvs rdiff -u -r1.271 -r1.272 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.271 src/sys/arch/i386/i386/trap.c:1.272
--- src/sys/arch/i386/i386/trap.c:1.271	Wed Feb 12 23:24:09 2014
+++ src/sys/arch/i386/i386/trap.c	Wed Mar 12 18:59:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.271 2014/02/12 23:24:09 dsl Exp $	*/
+/*	$NetBSD: trap.c,v 1.272 2014/03/12 18:59:07 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.271 2014/02/12 23:24:09 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.272 2014/03/12 18:59:07 martin Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -747,7 +747,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/i386/i386

2014-03-06 Thread NONAKA Kimihiro
Module Name:src
Committed By:   nonaka
Date:   Thu Mar  6 12:30:25 UTC 2014

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

Log Message:
fix to pass collect memory address to xrstor.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/i386/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/i386/i386/cpufunc.S
diff -u src/sys/arch/i386/i386/cpufunc.S:1.19 src/sys/arch/i386/i386/cpufunc.S:1.20
--- src/sys/arch/i386/i386/cpufunc.S:1.19	Tue Feb 25 22:16:52 2014
+++ src/sys/arch/i386/i386/cpufunc.S	Thu Mar  6 12:30:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc.S,v 1.19 2014/02/25 22:16:52 dsl Exp $	*/
+/*	$NetBSD: cpufunc.S,v 1.20 2014/03/06 12:30:24 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 #include sys/errno.h
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: cpufunc.S,v 1.19 2014/02/25 22:16:52 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpufunc.S,v 1.20 2014/03/06 12:30:24 nonaka Exp $);
 
 #include opt_xen.h
 
@@ -427,7 +427,7 @@ ENTRY(xrstor)
 	movl	4(%esp), %ecx
 	movl	8(%esp), %eax	/* feature mask bits */
 	movl	12(%esp), %edx
-	xrstor	(%eax)
+	xrstor	(%ecx)
 	ret
 END(xrstor)
 



CVS commit: src/sys/arch/i386/i386

2014-02-23 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Feb 23 22:36:43 UTC 2014

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

Log Message:
Avoid unnecessary (and pointless) references to pcb-pcb_savefpu.
They were all in asserts.


To generate a diff of this commit:
cvs rdiff -u -r1.751 -r1.752 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.751 src/sys/arch/i386/i386/machdep.c:1.752
--- src/sys/arch/i386/i386/machdep.c:1.751	Sun Feb 23 12:56:40 2014
+++ src/sys/arch/i386/i386/machdep.c	Sun Feb 23 22:36:43 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.751 2014/02/23 12:56:40 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.751 2014/02/23 12:56:40 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.752 2014/02/23 22:36:43 dsl Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1185,12 +1185,6 @@ init386(paddr_t first_avail)
 	uvm_setpagesize();
 
 	/*
-	 * Saving SSE registers won't work if the save area isn't
-	 * 16-byte aligned.
-	 */
-	KASSERT((offsetof(struct pcb, pcb_savefpu)  0xf) == 0);
-
-	/*
 	 * Start with 2 color bins -- this is just a guess to get us
 	 * started.  We'll recolor when we determine the largest cache
 	 * sizes on the system.
@@ -1540,7 +1534,6 @@ cpu_getmcontext(struct lwp *l, mcontext_
 {
 	const struct trapframe *tf = l-l_md.md_regs;
 	__greg_t *gr = mcp-__gregs;
-	struct pcb *pcb;
 	__greg_t ras_eip;
 
 	/* Save register context. */
@@ -1593,7 +1586,7 @@ cpu_getmcontext(struct lwp *l, mcontext_
 	 * It wouldn't matter if we were doing the copyout here.
 	 * So we might as well convert to fxsave format.
 	 */
-	__CTASSERT(sizeof pcb-pcb_savefpu.sv_xmm ==
+	__CTASSERT(sizeof (struct fxsave) ==
 	sizeof mcp-__fpregs.__fp_reg_set.__fp_xmm_state);
 	process_read_fpregs_xmm(l, (struct fxsave *)
 	mcp-__fpregs.__fp_reg_set.__fp_xmm_state);
@@ -1626,7 +1619,6 @@ cpu_setmcontext(struct lwp *l, const mco
 {
 	struct trapframe *tf = l-l_md.md_regs;
 	const __greg_t *gr = mcp-__gregs;
-	struct pcb *pcb = lwp_getpcb(l);
 	struct proc *p = l-l_proc;
 	int error;
 
@@ -1676,9 +1668,9 @@ cpu_setmcontext(struct lwp *l, const mco
 
 	/* Restore floating point register context, if given. */
 	if ((flags  _UC_FPU) != 0) {
-		__CTASSERT(sizeof pcb-pcb_savefpu.sv_xmm ==
+		__CTASSERT(sizeof (struct fxsave) ==
 		sizeof mcp-__fpregs.__fp_reg_set.__fp_xmm_state);
-		__CTASSERT(sizeof pcb-pcb_savefpu.sv_87 ==
+		__CTASSERT(sizeof (struct save87) ==
 		sizeof mcp-__fpregs.__fp_reg_set.__fpchip_state);
 
 		if (flags  _UC_FXSAVE) {



CVS commit: src/sys/arch/i386/i386

2014-02-17 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Feb 18 01:00:57 UTC 2014

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

Log Message:
CID 1175795:  Unused pointer value


To generate a diff of this commit:
cvs rdiff -u -r1.748 -r1.749 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.748 src/sys/arch/i386/i386/machdep.c:1.749
--- src/sys/arch/i386/i386/machdep.c:1.748	Sat Feb 15 17:20:41 2014
+++ src/sys/arch/i386/i386/machdep.c	Mon Feb 17 20:00:57 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.748 2014/02/15 22:20:41 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.749 2014/02/18 01:00:57 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.748 2014/02/15 22:20:41 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.749 2014/02/18 01:00:57 christos Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -492,8 +492,11 @@ cpu_startup(void)
 void
 i386_proc0_tss_ldt_init(void)
 {
-	struct lwp *l = lwp0;
-	struct pcb *pcb = lwp_getpcb(l);
+	struct lwp *l;
+	struct pcb *pcb __diagused;
+
+	l = lwp0;
+	pcb = lwp_getpcb(l);
 
 	pmap_kernel()-pm_ldt_sel = GSEL(GLDT_SEL, SEL_KPL);
 	pcb-pcb_cr0 = rcr0()  ~CR0_TS;



CVS commit: src/sys/arch/i386/i386

2014-02-07 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Fri Feb  7 19:32:50 UTC 2014

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

Log Message:
Remove the splurious check for EN_SW_DATACHAIN when looking at mxcsr traps.
The relevant bit is always masked out higher up.
The only place I can find a reference to a 'datachain' error is for the
  weitek 1167 fpu. Even the 8087 has the corresponding bit of the x87
  status reserved.
Quite why it has appeared here is anybodies guess.


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.269 src/sys/arch/i386/i386/trap.c:1.270
--- src/sys/arch/i386/i386/trap.c:1.269	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/i386/trap.c	Fri Feb  7 19:32:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.269 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: trap.c,v 1.270 2014/02/07 19:32:50 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.269 2014/01/26 19:16:17 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.270 2014/02/07 19:32:50 dsl Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -220,8 +220,6 @@ xmm_si_code(struct lwp *l)
 		return FPE_FLTOVF;
 	case EN_SW_UNDERFLOW:
 		return FPE_FLTUND;
-	case EN_SW_DATACHAIN:
-		return FPE_FLTSUB;
 	case 0:
 	default:
 		return 0;



CVS commit: src/sys/arch/i386/i386

2014-02-04 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Tue Feb  4 22:48:26 UTC 2014

Modified Files:
src/sys/arch/i386/i386: machdep.c process_machdep.c

Log Message:
Now that the sv_xmm and sv_87 fields in the pcb are the same size as the
  hardware ones, and those in the mcontext, ptrace and core files we
  can really safely cast and copy between the types.
Remove a couple of temporary buffers and add CTASSERT()s that the sizes
  do actually match.


To generate a diff of this commit:
cvs rdiff -u -r1.745 -r1.746 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.745 src/sys/arch/i386/i386/machdep.c:1.746
--- src/sys/arch/i386/i386/machdep.c:1.745	Sun Feb  2 22:41:20 2014
+++ src/sys/arch/i386/i386/machdep.c	Tue Feb  4 22:48:26 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.746 2014/02/04 22:48:26 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.746 2014/02/04 22:48:26 dsl Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1644,14 +1644,18 @@ cpu_getmcontext(struct lwp *l, mcontext_
 		if (pcb-pcb_fpcpu)
 			fpusave_lwp(l, true);
 		if (i386_use_fxsave) {
-			memcpy(mcp-__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
+			__CTASSERT(sizeof pcb-pcb_savefpu.sv_xmm ==
+			sizeof mcp-__fpregs.__fp_reg_set.__fp_xmm_state);
+			memcpy(mcp-__fpregs.__fp_reg_set.__fp_xmm_state,
 			pcb-pcb_savefpu.sv_xmm,
-			sizeof (mcp-__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm));
+			sizeof (mcp-__fpregs.__fp_reg_set.__fp_xmm_state));
 			*flags |= _UC_FXSAVE;
 		} else {
-			memcpy(mcp-__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
+			__CTASSERT(sizeof pcb-pcb_savefpu.sv_87 ==
+			sizeof mcp-__fpregs.__fp_reg_set.__fpchip_state);
+			memcpy(mcp-__fpregs.__fp_reg_set.__fpchip_state,
 			pcb-pcb_savefpu.sv_87,
-			sizeof (mcp-__fpregs.__fp_reg_set.__fpchip_state.__fp_state));
+			sizeof (mcp-__fpregs.__fp_reg_set.__fpchip_state));
 		}
 #if 0
 		/* Apparently nothing ever touches this. */
@@ -1742,26 +1746,30 @@ cpu_setmcontext(struct lwp *l, const mco
 
 	/* Restore floating point register context, if any. */
 	if ((flags  _UC_FPU) != 0) {
+		__CTASSERT(sizeof pcb-pcb_savefpu.sv_xmm ==
+		sizeof mcp-__fpregs.__fp_reg_set.__fp_xmm_state);
+		__CTASSERT(sizeof pcb-pcb_savefpu.sv_87 ==
+		sizeof mcp-__fpregs.__fp_reg_set.__fpchip_state);
+
 		if (flags  _UC_FXSAVE) {
 			if (i386_use_fxsave) {
-memcpy(
-	pcb-pcb_savefpu.sv_xmm,
-	mcp-__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
-	sizeof (pcb-pcb_savefpu.sv_xmm));
+memcpy(pcb-pcb_savefpu.sv_xmm,
+mcp-__fpregs.__fp_reg_set.__fp_xmm_state,
+sizeof (pcb-pcb_savefpu.sv_xmm));
 			} else {
 /* This is a weird corner case */
-process_xmm_to_s87((struct fxsave *)
-mcp-__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
+process_xmm_to_s87((const struct fxsave *)
+mcp-__fpregs.__fp_reg_set.__fp_xmm_state,
 pcb-pcb_savefpu.sv_87);
 			}
 		} else {
 			if (i386_use_fxsave) {
-process_s87_to_xmm((struct save87 *)
-mcp-__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
+process_s87_to_xmm((const struct save87 *)
+mcp-__fpregs.__fp_reg_set.__fpchip_state,
 pcb-pcb_savefpu.sv_xmm);
 			} else {
 memcpy(pcb-pcb_savefpu.sv_87,
-mcp-__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
+mcp-__fpregs.__fp_reg_set.__fpchip_state,
 sizeof (pcb-pcb_savefpu.sv_87));
 			}
 		}

Index: src/sys/arch/i386/i386/process_machdep.c
diff -u src/sys/arch/i386/i386/process_machdep.c:1.80 src/sys/arch/i386/i386/process_machdep.c:1.81
--- src/sys/arch/i386/i386/process_machdep.c:1.80	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/i386/process_machdep.c	Tue Feb  4 22:48:26 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.80 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.81 2014/02/04 22:48:26 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: process_machdep.c,v 1.80 2014/01/26 19:16:17 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: process_machdep.c,v 1.81 2014/02/04 22:48:26 dsl Exp $);
 
 #include opt_vm86.h
 #include opt_ptrace.h
@@ -277,12 +277,9 @@ process_read_fpregs(struct lwp *l, struc
 		l-l_md.md_flags |= MDL_USEDFPU;
 	}
 
+	__CTASSERT(sizeof *regs == sizeof (struct save87));
 	if (i386_use_fxsave) {
-		struct save87 s87;
-
-		/* XXX Yuck */
-		

CVS commit: src/sys/arch/i386/i386

2014-02-01 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Feb  1 18:57:38 UTC 2014

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

Log Message:
Stopgap measure: set i386_fpu_present to 1 for XEN.
Stop a stream of
npxintr: came from nowherenpxintr: l = 0xc17ba560, curproc = 0xc177d880, 
fpu_present = 0
when running some ATF tests:
http://www-soc.lip6.fr/~bouyer/NetBSD-tests/xen/HEAD/i386/201401300920Z_anita.txt

XXX this is probably still broken for native i386, at last for older CPUs.
It looks like on newer CPUs (such as the one emulated by qemu) this code path
is not used.


To generate a diff of this commit:
cvs rdiff -u -r1.743 -r1.744 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.743 src/sys/arch/i386/i386/machdep.c:1.744
--- src/sys/arch/i386/i386/machdep.c:1.743	Sun Jan 26 19:16:17 2014
+++ src/sys/arch/i386/i386/machdep.c	Sat Feb  1 18:57:38 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.743 2014/01/26 19:16:17 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.744 2014/02/01 18:57:38 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.743 2014/01/26 19:16:17 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.744 2014/02/01 18:57:38 bouyer Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -229,7 +229,11 @@ struct mtrr_funcs *mtrr_funcs;
 
 int	cpu_class;
 int	use_pae;
+#ifdef XEN
+int	i386_fpu_present = 1;
+#else
 int	i386_fpu_present;
+#endif
 int	i386_fpu_exception;
 int	i386_fpu_fdivbug;
 



CVS commit: src/sys/arch/i386/i386

2014-01-25 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sat Jan 25 19:51:32 UTC 2014

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

Log Message:
Rewrite the code that converts the x87 tag word between its full and
  abridged versions.
The code in xmm_to_s87_tag() looked at the wrong register when trying
  to generate 0b01 (zero) and 0b10 (NaN etc) because the registers are
  relative to the stack top, but the tag words are absolute.
Since even a real 387 generates the correct tag values when the tag word
  (or register value) is loaded there is no point generating other than
  0b00 (used) and 0b11 (unused).
The compiler also made a pig's breakfast of the register copy loop.
When convering from fsave to (the larger) fxsave format don't bother
  copying the fp register values if none are in use.
Converting the other way we do copy them all because the target buffer
  is often written to userspace (and has no padding).
i386 core dumps still seem ok - and do use this code.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/arch/i386/i386/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/i386/i386/process_machdep.c
diff -u src/sys/arch/i386/i386/process_machdep.c:1.77 src/sys/arch/i386/i386/process_machdep.c:1.78
--- src/sys/arch/i386/i386/process_machdep.c:1.77	Sun Jan 19 14:30:37 2014
+++ src/sys/arch/i386/i386/process_machdep.c	Sat Jan 25 19:51:31 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.77 2014/01/19 14:30:37 dsl Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.78 2014/01/25 19:51:31 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: process_machdep.c,v 1.77 2014/01/19 14:30:37 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: process_machdep.c,v 1.78 2014/01/25 19:51:31 dsl Exp $);
 
 #include opt_vm86.h
 #include opt_ptrace.h
@@ -91,47 +91,41 @@ process_fpframe(struct lwp *l)
 	return pcb-pcb_savefpu;
 }
 
-static int
-xmm_to_s87_tag(const uint8_t *fpac, int regno, uint8_t tw)
-{
-	static const uint8_t empty_significand[8] = { 0 };
-	int tag;
-	uint16_t exponent;
-
-	if (tw  (1U  regno)) {
-		exponent = fpac[8] | (fpac[9]  8);
-		switch (exponent) {
-		case 0x7fff:
-			tag = 2;
-			break;
-
-		case 0x:
-			if (memcmp(empty_significand, fpac,
-   sizeof(empty_significand)) == 0)
-tag = 1;
-			else
-tag = 2;
-			break;
-
-		default:
-			if ((fpac[7]  0x80) == 0)
-tag = 2;
-			else
-tag = 0;
-			break;
-		}
-	} else
-		tag = 3;
-
-	return (tag);
-}
-
 void
 process_xmm_to_s87(const struct fxsave *sxmm, struct save87 *s87)
 {
+	unsigned int tag, ab_tag;
+	const struct fpaccxmm *fx_reg;
+	struct fpacc87 *s87_reg;
 	int i;
 
-	/* Convert context sent by userspace */
+	/*
+	 * For historic reasons core dumps and ptrace all use the old save87
+	 * layout.  Convert the important parts.
+	 * getucontext gets what we give it.
+	 * setucontext should return something given by getucontext, but
+	 * we are (at the moment) willing to change it.
+	 *
+	 * It really isn't worth setting the 'tag' bits to 01 (zero) or
+	 * 10 (NaN etc) since the processor will set any internal bits
+	 * correctly when the value is loaded (the 287 believed them).
+	 *
+	 * Additionally the s87_tw and s87_tw are 'indexed' by the actual
+	 * register numbers, whereas the registers themselves have ST(0)
+	 * first. Pairing the values and tags can only be done with
+	 * reference to the 'top of stack'.
+	 *
+	 * If any x87 registers are used, they will typically be from
+	 * r7 downwards - so the high bits of the tag register indicate
+	 * used registers. The conversions are not optimised for this.
+	 *
+	 * The ABI we use requires the FP stack to be empty on every
+	 * function call. I think this means that the stack isn't expected
+	 * to overflow - overflow doesn't drop a core in my testing.
+	 *
+	 * Note that this code writes to all of the 's87' structure that
+	 * actually gets written to userspace.
+	 */
 
 	/* FPU control/status */
 	s87-s87_cw = sxmm-fx_cw;
@@ -141,31 +135,47 @@ process_xmm_to_s87(const struct fxsave *
 	s87-s87_opcode = sxmm-fx_opcode;
 	s87-s87_dp = sxmm-fx_dp;
 
-	/* Tag word and registers. */
-	s87-s87_tw = 0;
-	s87-s87_ex_tw = 0;
-	for (i = 0; i  8; i++) {
-		s87-s87_tw |=
-		(xmm_to_s87_tag(sxmm-sv_ac[i].fp_bytes, i,
-		 sxmm-fx_tw)  (i * 2));
-
-		s87-s87_ex_tw |=
-		(xmm_to_s87_tag(sxmm-sv_ac[i].fp_bytes, i,
-		 sxmm-sv_ex_tw)  (i * 2));
+	/* FP registers (in stack order) */
+	fx_reg = sxmm-sv_ac;
+	s87_reg = s87-s87_ac;
+	for (i = 0; i  8; fx_reg++, s87_reg++, i++)
+		memcpy(s87_reg-fp_bytes, fx_reg-fp_bytes,
+		sizeof(s87_reg-fp_bytes));
 
-		memcpy(s87-s87_ac[i].fp_bytes, sxmm-sv_ac[i].fp_bytes,
-		sizeof(s87-s87_ac[i].fp_bytes));
+	/* Tag word and registers. */
+	ab_tag = sxmm-fx_tw  0xff;	/* 

CVS commit: src/sys/arch/i386/i386

2014-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 11 17:05:17 UTC 2014

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

Log Message:
fix a comment (cpu_switch() - cpu_switchto()) (Richard Hansen)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.108 src/sys/arch/i386/i386/locore.S:1.109
--- src/sys/arch/i386/i386/locore.S:1.108	Sat Nov 30 20:05:16 2013
+++ src/sys/arch/i386/i386/locore.S	Sat Jan 11 12:05:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.108 2013/12/01 01:05:16 christos Exp $	*/
+/*	$NetBSD: locore.S,v 1.109 2014/01/11 17:05:17 christos Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.108 2013/12/01 01:05:16 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.109 2014/01/11 17:05:17 christos Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -881,8 +881,9 @@ END(lgdt_finish)
  *
  * This is a trampoline function pushed onto the stack of a newly created
  * process in order to do some additional setup.  The trampoline is entered by
- * cpu_switch()ing to the process, so we abuse the callee-saved registers used
- * by cpu_switch() to store the information about the stub to call.
+ * cpu_switchto()ing to the process, so we abuse the callee-saved
+ * registers used by cpu_switchto() to store the information about the
+ * stub to call.
  * NOTE: This function does not have a normal calling sequence!
  */
 NENTRY(lwp_trampoline)



CVS commit: src/sys/arch/i386/i386

2014-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 11 17:06:15 UTC 2014

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

Log Message:
remove vestige from old call to printk()

This line was introduced with a call to printk() in CVS revision
1.22.4.3 and should have been removed when the call to printk() was
removed in CVS revision 1.22.4.6.  (Richard Hansen)


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/i386/i386/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/i386/i386/spl.S
diff -u src/sys/arch/i386/i386/spl.S:1.39 src/sys/arch/i386/i386/spl.S:1.40
--- src/sys/arch/i386/i386/spl.S:1.39	Sat Jun 22 02:57:30 2013
+++ src/sys/arch/i386/i386/spl.S	Sat Jan 11 12:06:15 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.39 2013/06/22 06:57:30 uebayasi Exp $	*/
+/*	$NetBSD: spl.S,v 1.40 2014/01/11 17:06:15 christos Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: spl.S,v 1.39 2013/06/22 06:57:30 uebayasi Exp $);
+__KERNEL_RCSID(0, $NetBSD: spl.S,v 1.40 2014/01/11 17:06:15 christos Exp $);
 
 #include opt_vm86.h
 #include opt_ddb.h
@@ -226,7 +226,6 @@ IDTVEC(spllower)
 	ret
 #if defined(DEBUG)
 .Lspllower_panic:
-	addl $8, %esp
 	pushl	$1f
 	call	_C_LABEL(panic)
 1:	.asciz	SPLLOWER: INTERRUPT ENABLED



CVS commit: src/sys/arch/i386/i386

2014-01-11 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 11 17:11:50 UTC 2014

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

Log Message:
stop ddb backtrace at Xsoftintr() (Richard Hansen)

Stop unwinding frames when db_stack_trace_print() encouters
Xsoftintr().  This avoids a recursive panic() due to an invalid
pointer dereference when a software interrupt panic()s.

Here's what happens without this change:

When db_stack_trace_print() runs during a panic() and db_nextframe()
encounters the Xsoftintr() frame, db_nextframe() does the following at
db_machdep.c:292:

  1. checks to see if there's a Xsoftintr() symbol (there is)
  2. checks to see if the frame corresponds to an interrupt (the
 symbol name begins with Xsoft so it does)

If both of the above are true (they are), db_nextframe() at
db_machdep.c:303 tries to get a pointer to a struct intrframe.
According to the comment at line 300, the second argument passed to
Xsoftintr() is a pointer to a struct intrframe.  However, the comment
and the corresponding code are not correct -- Xsoftintr() doesn't take
any arguments[1].  Attempting to fetch the second argument only yields
stack garbage, not a struct intrframe.  This causes db_machdep.c:307
to dereference a bad pointer, triggering the recursive panic().

[1] Xsoftintr() is called by Xspllower() which is called by splx()
a.k.a. spllower().  Neither Xspllower() nor Xsoftintr() set up a
standard frame when called (they don't do 'pushl %ebp; movl %esp,
%ebp'), so Xsoftintr()'s %ebp is the same as splx()'s %ebp.  This
makes splx()'s arguments look like Xsoftintr()'s arguments, and
splx() does not take any arguments.

You can reproduce the recursive panic by reverting this change and
adding a call to panic() inside ipintr().  The backtrace will look
like the following (the line numbers you see might differ from these
line numbers -- this backtrace was generated from a slightly modified
version of the NetBSD 6.1 kernel):

#0  vpanic (fmt=0xc0ba995b trap, ap=0xdaa51730) at 
/usr/src/sys/kern/subr_prf.c:211
#1  0xc0790529 in panic (fmt=0xc0ba995b trap) at 
/usr/src/sys/kern/subr_prf.c:205
#2  0xc07decbc in trap (frame=0xdaa517c0) at 
/usr/src/sys/arch/i386/i386/trap.c:396
#3  0xc010cf48 in ?? () at /usr/src/sys/arch/i386/i386/vector.S:983
#4  0xc02857f0 in db_get_value (addr=56, size=4, is_signed=false) at 
/usr/src/sys/ddb/db_access.c:72
#5  0xc028a09a in db_nextframe (nextframe=0xdaa51b40, retaddr=0xdaa51b3c, 
arg0=0xdaa51b38, ip=0xdaa51b34, argp=0xdaa51d88, is_trap=0, pr=0xc07901b5 
printf) at /usr/src/sys/arch/i386/i386/db_machdep.c:308
#6  0xc028be2b in db_stack_trace_print (addr=optimized out, 
have_addr=true, count=65533, modif=0xc0bb44bf , pr=0xc07901b5 printf) at 
/usr/src/sys/arch/x86/x86/db_trace.c:275
#7  0xc07903cb in vpanic (fmt=0xc0b6ba76 testing, ap=0xdaa51d4c) at 
/usr/src/sys/kern/subr_prf.c:296
#8  0xc0790529 in panic (fmt=0xc0b6ba76 testing) at 
/usr/src/sys/kern/subr_prf.c:205
#9  0xc04e3d4f in ipintr () at /usr/src/sys/netinet/ip_input.c:369
#10 0xc054ac0d in softint_execute (s=optimized out, si=optimized out, 
l=optimized out) at /usr/src/sys/kern/kern_softint.c:543
#11 softint_dispatch (pinned=0xc4085560, s=4) at 
/usr/src/sys/kern/kern_softint.c:825
#12 0xc0100fdb in ?? () at /usr/src/sys/arch/i386/i386/spl.S:390
#13 0xc07d2e11 in tcp_usrreq (so=0xc40b0534, req=4, m=0x0, nam=0xc317ba00, 
control=0x0, l=0xc4085560) at /usr/src/sys/netinet/tcp_usrreq.c:615
#14 0xc04bb300 in tcp_usrreq_wrapper (a=0xc40b0534, b=4, c=0x0, 
d=0xc317ba00, e=0x0, f=0xc4085560) at /usr/src/sys/netinet/in_proto.c:164
#15 0xc0839006 in soconnect (so=0xc40b0534, nam=0xc317ba00, l=0xc4085560) 
at /usr/src/sys/kern/uipc_socket.c:821
#16 0xc083c4ce in do_sys_connect (l=0xc4085560, fd=4, nam=0xc317ba00) at 
/usr/src/sys/kern/uipc_syscalls.c:371
#17 0xc083dbeb in sys_connect (l=0xc4085560, uap=0xdbc27d00, 
retval=0xdbc27d28) at /usr/src/sys/kern/uipc_syscalls.c:350
#18 0xc07b1b4a in sy_call (rval=0xdbc27d28, uap=0xdbc27d00, l=0xc4085560, 
sy=0xc0c2f018) at /usr/src/sys/sys/syscallvar.h:61
#19 syscall (frame=0xdbc27d48) at /usr/src/sys/arch/x86/x86/syscall.c:179
#20 0xc010056d in ?? () at /usr/src/sys/arch/i386/i386/locore.S:1160
Backtrace stopped: previous frame inner to this frame (corrupt stack?)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/i386/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/i386/i386/db_machdep.c
diff -u src/sys/arch/i386/i386/db_machdep.c:1.4 src/sys/arch/i386/i386/db_machdep.c:1.5
--- src/sys/arch/i386/i386/db_machdep.c:1.4	Thu Jul 12 13:14:39 2012
+++ src/sys/arch/i386/i386/db_machdep.c	Sat Jan 11 12:11:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.4 2012/07/12 17:14:39 dsl Exp $	*/
+/*	$NetBSD: 

CVS commit: src/sys/arch/i386/i386

2014-01-10 Thread pedro martelletto
Module Name:src
Committed By:   pedro
Date:   Fri Jan 10 16:47:07 UTC 2014

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

Log Message:
Fix a comment describing the check performed by copyin(); the value
checked against VM_MAXUSER_ADDRESS is derived from the source address,
not the destination address. OK rmind@.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/i386/i386/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/i386/i386/copy.S
diff -u src/sys/arch/i386/i386/copy.S:1.22 src/sys/arch/i386/i386/copy.S:1.23
--- src/sys/arch/i386/i386/copy.S:1.22	Wed Jul  7 01:21:15 2010
+++ src/sys/arch/i386/i386/copy.S	Fri Jan 10 16:47:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: copy.S,v 1.22 2010/07/07 01:21:15 chs Exp $	*/
+/*	$NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $	*/
 /*	NetBSD: locore.S,v 1.34 2005/04/01 11:59:31 yamt Exp $	*/
 
 /*-
@@ -65,7 +65,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: copy.S,v 1.22 2010/07/07 01:21:15 chs Exp $);
+__KERNEL_RCSID(0, $NetBSD: copy.S,v 1.23 2014/01/10 16:47:07 pedro Exp $);
 
 #include assym.h
 
@@ -270,9 +270,9 @@ ENTRY(copyin)
 	movl	16(%esp),%edi
 	movl	20(%esp),%eax
 	/*
-	 * We check that the end of the destination buffer is not past the end
-	 * of the user's address space.  If it's not, then we only need to
-	 * check that each page is readable, and the CPU will do that for us.
+	 * We check that the end of the source buffer is not past the end of
+	 * the user's address space.  If it's not, then we only need to check
+	 * that each page is readable, and the CPU will do that for us.
 	 */
 .Lcopyin_start:
 	movl	%esi,%edx



CVS commit: src/sys/arch/i386/i386

2013-11-21 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Fri Nov 22 01:07:20 UTC 2013

Modified Files:
src/sys/arch/i386/i386: i386_trap_ipkdb.S

Log Message:
Remove stray #ifdef leftover from file split.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/i386/i386/i386_trap_ipkdb.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/i386/i386/i386_trap_ipkdb.S
diff -u src/sys/arch/i386/i386/i386_trap_ipkdb.S:1.1 src/sys/arch/i386/i386/i386_trap_ipkdb.S:1.2
--- src/sys/arch/i386/i386/i386_trap_ipkdb.S:1.1	Tue Jun 25 00:27:22 2013
+++ src/sys/arch/i386/i386/i386_trap_ipkdb.S	Fri Nov 22 01:07:20 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386_trap_ipkdb.S,v 1.1 2013/06/25 00:27:22 uebayasi Exp $	*/
+/*	$NetBSD: i386_trap_ipkdb.S,v 1.2 2013/11/22 01:07:20 riz Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -66,7 +66,7 @@
 
 #if 0
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: i386_trap_ipkdb.S,v 1.1 2013/06/25 00:27:22 uebayasi Exp $);
+__KERNEL_RCSID(0, $NetBSD: i386_trap_ipkdb.S,v 1.2 2013/11/22 01:07:20 riz Exp $);
 #endif
 
 #ifdef IPKDB
@@ -156,6 +156,3 @@ fault:
 	iret
 END(ipkdbsbyte)
 #endif	/* IPKDB */
-
-#ifdef XEN
-



CVS commit: src/sys/arch/i386/i386

2013-11-21 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Fri Nov 22 01:09:11 UTC 2013

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

Log Message:
Include i386_trap_ipkdb.S so the ALL kernel links.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/i386/i386/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/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.62 src/sys/arch/i386/i386/vector.S:1.63
--- src/sys/arch/i386/i386/vector.S:1.62	Tue Jun 25 00:27:22 2013
+++ src/sys/arch/i386/i386/vector.S	Fri Nov 22 01:09:11 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.62 2013/06/25 00:27:22 uebayasi Exp $	*/
+/*	$NetBSD: vector.S,v 1.63 2013/11/22 01:09:11 riz Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: vector.S,v 1.62 2013/06/25 00:27:22 uebayasi Exp $);
+__KERNEL_RCSID(0, $NetBSD: vector.S,v 1.63 2013/11/22 01:09:11 riz Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -734,6 +734,9 @@ END(xenev_stubs)
 #endif /* XEN */
 
 #include i386_trap.S
+#ifdef IPKDB
+#include i386_trap_ipkdb.S
+#endif
 
 #ifdef XEN
 



CVS commit: src/sys/arch/i386/i386

2013-11-21 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Nov 21 22:04:41 UTC 2013

Modified Files:
src/sys/arch/i386/i386: pmc.c

Log Message:
CPUID2FAMILY was renamed to CPUID_TO_FAMILY, apparently this usage was
missed.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/i386/i386/pmc.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/i386/i386/pmc.c
diff -u src/sys/arch/i386/i386/pmc.c:1.20 src/sys/arch/i386/i386/pmc.c:1.21
--- src/sys/arch/i386/i386/pmc.c:1.20	Mon Jan 30 21:35:22 2012
+++ src/sys/arch/i386/i386/pmc.c	Thu Nov 21 22:04:40 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmc.c,v 1.20 2012/01/30 21:35:22 rmind Exp $	*/
+/*	$NetBSD: pmc.c,v 1.21 2013/11/21 22:04:40 riz Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmc.c,v 1.20 2012/01/30 21:35:22 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmc.c,v 1.21 2013/11/21 22:04:40 riz Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -104,7 +104,7 @@ pmc_init(void)
 			 * we're missing Pentium 4 support.
 			 */
 			if (cpuid_level == -1 ||
-			CPUID2FAMILY(ci-ci_signature) == CPU_FAMILY_P4)
+			CPUID_TO_FAMILY(ci-ci_signature) == CPU_FAMILY_P4)
 break;
 
 			pmc_type = PMC_TYPE_I686;



CVS commit: src/sys/arch/i386/i386

2012-12-08 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Dec  8 14:40:11 UTC 2012

Modified Files:
src/sys/arch/i386/i386: db_interface.c

Log Message:
lapic.h provides NLAPIC, not LAPIC.  makes i386 kernels build again.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/i386/i386/db_interface.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/i386/i386/db_interface.c
diff -u src/sys/arch/i386/i386/db_interface.c:1.69 src/sys/arch/i386/i386/db_interface.c:1.70
--- src/sys/arch/i386/i386/db_interface.c:1.69	Sat Dec  8 12:36:30 2012
+++ src/sys/arch/i386/i386/db_interface.c	Sat Dec  8 14:40:10 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_interface.c,v 1.69 2012/12/08 12:36:30 kiyohara Exp $	*/
+/*	$NetBSD: db_interface.c,v 1.70 2012/12/08 14:40:10 jakllsch Exp $	*/
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.69 2012/12/08 12:36:30 kiyohara Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_interface.c,v 1.70 2012/12/08 14:40:10 jakllsch Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -59,7 +59,7 @@ __KERNEL_RCSID(0, $NetBSD: db_interface
 #if NIOAPIC  0
 #include machine/i82093var.h
 #endif
-#if LAPIC  0
+#if NLAPIC  0
 #include machine/i82489reg.h
 #include machine/i82489var.h
 #endif



CVS commit: src/sys/arch/i386/i386

2012-12-06 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Dec  7 04:49:08 UTC 2012

Modified Files:
src/sys/arch/i386/i386: multiboot.c

Log Message:
Fix off by one.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/i386/multiboot.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/i386/i386/multiboot.c
diff -u src/sys/arch/i386/i386/multiboot.c:1.21 src/sys/arch/i386/i386/multiboot.c:1.22
--- src/sys/arch/i386/i386/multiboot.c:1.21	Tue Jan 11 12:24:37 2011
+++ src/sys/arch/i386/i386/multiboot.c	Fri Dec  7 04:49:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: multiboot.c,v 1.21 2011/01/11 12:24:37 gsutre Exp $	*/
+/*	$NetBSD: multiboot.c,v 1.22 2012/12/07 04:49:08 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: multiboot.c,v 1.21 2011/01/11 12:24:37 gsutre Exp $);
+__KERNEL_RCSID(0, $NetBSD: multiboot.c,v 1.22 2012/12/07 04:49:08 msaitoh Exp $);
 
 #include opt_multiboot.h
 
@@ -506,7 +506,7 @@ setup_bootpath(struct multiboot_info *mi
 		*cl2 = '\0';
 		memcpy(bi.bootpath, cl, MIN(sizeof(bi.bootpath), len));
 		*cl2 = old;
-		bi.bootpath[MIN(sizeof(bi.bootpath), len)] = '\0';
+		bi.bootpath[MIN(sizeof(bi.bootpath) - 1, len)] = '\0';
 
 		bootinfo_add((struct btinfo_common *)bi, BTINFO_BOOTPATH,
 		sizeof(struct btinfo_bootpath));



CVS commit: src/sys/arch/i386/i386

2012-10-26 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Oct 26 14:46:44 UTC 2012

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

Log Message:
in osyscall, set the PSL_I bit into the correct field of the trapframe.
it was going into tf_eip instead of tf_eflags, which would sometimes
corrupt %eip and always return to user mode with interrupts disabled.
this was found with a netbsd 1.0 binary, and dsl@ points out that
this should also fix PR 41342.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.102 src/sys/arch/i386/i386/locore.S:1.103
--- src/sys/arch/i386/i386/locore.S:1.102	Sat Sep  1 23:19:46 2012
+++ src/sys/arch/i386/i386/locore.S	Fri Oct 26 14:46:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $	*/
+/*	$NetBSD: locore.S,v 1.103 2012/10/26 14:46:44 chs Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.103 2012/10/26 14:46:44 chs Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -1130,7 +1130,7 @@ IDTVEC(osyscall)
 #endif
 	pushfl			# set eflags in trap frame
 	popl	8(%esp)
-	orl	$PSL_I,(%esp)	# re-enable ints on return to user
+	orl	$PSL_I,8(%esp)	# re-enable ints on return to user
 	pushl	$7		# size of instruction for restart
 	jmp	syscall1
 IDTVEC_END(osyscall)



CVS commit: src/sys/arch/i386/i386

2012-09-30 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Sep 30 20:54:52 UTC 2012

Modified Files:
src/sys/arch/i386/i386: genassym.cf machdep.c mainbus.c

Log Message:
Fix build.
I've removed 'option apmbios' so config no longer generates apmbios.h
Not to be confused with dev/apm/apmbios.h :-)


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.731 -r1.732 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.95 -r1.96 src/sys/arch/i386/i386/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/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.93 src/sys/arch/i386/i386/genassym.cf:1.94
--- src/sys/arch/i386/i386/genassym.cf:1.93	Sun Sep 30 20:19:51 2012
+++ src/sys/arch/i386/i386/genassym.cf	Sun Sep 30 20:54:52 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.93 2012/09/30 20:19:51 dsl Exp $
+#	$NetBSD: genassym.cf,v 1.94 2012/09/30 20:54:52 dsl Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -104,9 +104,6 @@ endif
 
 if defined(_KERNEL)  defined(_KERNEL_OPT)
 include ioapic.h
-ifndef XEN
-include apmbios.h
-endif
 endif
 
 include compat/sys/signal.h

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.731 src/sys/arch/i386/i386/machdep.c:1.732
--- src/sys/arch/i386/i386/machdep.c:1.731	Sun Sep 30 20:19:51 2012
+++ src/sys/arch/i386/i386/machdep.c	Sun Sep 30 20:54:52 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.731 2012/09/30 20:19:51 dsl Exp $	*/
+/*	$NetBSD: machdep.c,v 1.732 2012/09/30 20:54:52 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.731 2012/09/30 20:19:51 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.732 2012/09/30 20:54:52 dsl Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -177,7 +177,6 @@ __KERNEL_RCSID(0, $NetBSD: machdep.c,v 
 #endif
 
 #include acpica.h
-#include apmbios.h
 #include bioscall.h
 
 #if NBIOSCALL  0

Index: src/sys/arch/i386/i386/mainbus.c
diff -u src/sys/arch/i386/i386/mainbus.c:1.95 src/sys/arch/i386/i386/mainbus.c:1.96
--- src/sys/arch/i386/i386/mainbus.c:1.95	Sun Sep 30 20:19:52 2012
+++ src/sys/arch/i386/i386/mainbus.c	Sun Sep 30 20:54:52 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.95 2012/09/30 20:19:52 dsl Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.96 2012/09/30 20:54:52 dsl Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.95 2012/09/30 20:19:52 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.96 2012/09/30 20:54:52 dsl Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -50,7 +50,6 @@ __KERNEL_RCSID(0, $NetBSD: mainbus.c,v 
 #include isa.h
 #include isadma.h
 #include mca.h
-#include apmbios.h
 #include pnpbios.h
 #include acpica.h
 #include ipmi.h



CVS commit: src/sys/arch/i386/i386

2012-09-01 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sat Sep  1 23:19:47 UTC 2012

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

Log Message:
Restrict export of the tmpgdt symbol to XEN kernels

Spotted by uwe@


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.101 src/sys/arch/i386/i386/locore.S:1.102
--- src/sys/arch/i386/i386/locore.S:1.101	Wed Jun 27 00:37:08 2012
+++ src/sys/arch/i386/i386/locore.S	Sat Sep  1 23:19:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.101 2012/06/27 00:37:08 jym Exp $	*/
+/*	$NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.101 2012/06/27 00:37:08 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.102 2012/09/01 23:19:46 cherry Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -233,10 +233,10 @@ _C_LABEL(tablesize):	.long	0
 tmpstk:
 #ifdef XEN
 	.align 		PAGE_SIZE, 0x0	# Align on page boundary
+	.globl tmpgdt
 _C_LABEL(tmpgdt):
 	.space 		PAGE_SIZE	# Xen expects a page
 #endif /* XEN */
-	.globl tmpgdt
 #ifndef XEN
 #define	_RELOC(x)	((x) - KERNBASE)
 #else



CVS commit: src/sys/arch/i386/i386

2012-08-29 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Wed Aug 29 22:43:35 UTC 2012

Modified Files:
src/sys/arch/i386/i386: i386func.S

Log Message:
tlbflushg/i386: test for the PGE feature flag first, before checking the %cr4.
Add a comment explaining why need to check both and in such order.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/i386/i386/i386func.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/i386/i386/i386func.S
diff -u src/sys/arch/i386/i386/i386func.S:1.16 src/sys/arch/i386/i386/i386func.S:1.17
--- src/sys/arch/i386/i386/i386func.S:1.16	Sun Jun 12 03:35:42 2011
+++ src/sys/arch/i386/i386/i386func.S	Wed Aug 29 22:43:35 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: i386func.S,v 1.16 2011/06/12 03:35:42 rmind Exp $	*/
+/*	$NetBSD: i386func.S,v 1.17 2012/08/29 22:43:35 rmind Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: i386func.S,v 1.16 2011/06/12 03:35:42 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: i386func.S,v 1.17 2012/08/29 22:43:35 rmind Exp $);
 
 #include machine/specialreg.h
 #include machine/segments.h
@@ -99,9 +99,13 @@ END(lcr3)
  *
  * (the alternatives not quoted above are not an option here.)
  *
- * If PGE is not in use, we reload CR3.
+ * If PGE is not in use, we reload CR3.  Check for the PGE feature
+ * first since i486 does not have CR4.  Note: the feature flag may
+ * be present while the actual PGE functionality not yet enabled.
  */
 ENTRY(tlbflushg)
+	testl	$CPUID_PGE, _C_LABEL(cpu_feature)
+	jz	1f
 	movl	%cr4, %eax
 	testl	$CR4_PGE, %eax
 	jz	1f



CVS commit: src/sys/arch/i386/i386

2012-07-12 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Jul 12 17:26:42 UTC 2012

Modified Files:
src/sys/arch/i386/i386: freebsd_syscall.c ibcs2_syscall.c
svr4_syscall.c

Log Message:
No point in having separate xxx_syscall_fancy() and xxx_syscall_plain().
Remove the 'plain' ones.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/i386/i386/freebsd_syscall.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/i386/i386/ibcs2_syscall.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/i386/i386/svr4_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/i386/i386/freebsd_syscall.c
diff -u src/sys/arch/i386/i386/freebsd_syscall.c:1.37 src/sys/arch/i386/i386/freebsd_syscall.c:1.38
--- src/sys/arch/i386/i386/freebsd_syscall.c:1.37	Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/freebsd_syscall.c	Thu Jul 12 17:26:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_syscall.c,v 1.37 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: freebsd_syscall.c,v 1.38 2012/07/12 17:26:42 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.37 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.38 2012/07/12 17:26:42 dsl Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -50,17 +50,13 @@ __KERNEL_RCSID(0, $NetBSD: freebsd_sysc
 #include machine/freebsd_machdep.h
 #include compat/freebsd/freebsd_syscall.h
 
-void freebsd_syscall_plain(struct trapframe *);
-void freebsd_syscall_fancy(struct trapframe *);
+void freebsd_syscall(struct trapframe *);
 
 void
 freebsd_syscall_intern(struct proc *p)
 {
 
-	if (trace_is_enabled(p))
-		p-p_md.md_syscall = freebsd_syscall_fancy;
-	else
-		p-p_md.md_syscall = freebsd_syscall_plain;
+	p-p_md.md_syscall = freebsd_syscall;
 }
 
 /*
@@ -69,87 +65,7 @@ freebsd_syscall_intern(struct proc *p)
  * Like trap(), argument is call by reference.
  */
 void
-freebsd_syscall_plain(struct trapframe *frame)
-{
-	char *params;
-	const struct sysent *callp;
-	struct lwp *l;
-	struct proc *p;
-	int error;
-	size_t argsize;
-	register_t code, args[8], rval[2];
-
-	l = curlwp;
-	p = l-l_proc;
-	LWP_CACHE_CREDS(l, p);
-
-	code = frame-tf_eax;
-	callp = p-p_emul-e_sysent;
-	params = (char *)frame-tf_esp + sizeof(int);
-
-	switch (code) {
-	case SYS_syscall:
-		/*
-		 * Code is first argument, followed by actual args.
-		 */
-		code = fuword(params);
-		params += sizeof(int);
-		break;
-	case SYS___syscall:
-		/*
-		 * Like syscall, but code is a quad, so as to maintain
-		 * quad alignment for the rest of the arguments.
-		 */
-		code = fuword(params + _QUAD_LOWWORD * sizeof(int));
-		params += sizeof(quad_t);
-		break;
-	default:
-		break;
-	}
-
-	code = (FREEBSD_SYS_NSYSENT - 1);
-	callp += code;
-	argsize = callp-sy_argsize;
-	if (argsize) {
-		error = copyin(params, (void *)args, argsize);
-		if (error)
-			goto bad;
-	}
-
-	rval[0] = 0;
-	rval[1] = frame-tf_edx; /* need to keep edx for shared FreeBSD bins */
-
-	error = sy_call(callp, l, args, rval);
-
-	switch (error) {
-	case 0:
-		frame-tf_eax = rval[0];
-		frame-tf_edx = rval[1];
-		frame-tf_eflags = ~PSL_C;	/* carry bit */
-		break;
-	case ERESTART:
-		/*
-		 * The offset to adjust the PC by depends on whether we entered
-		 * the kernel through the trap or call gate.  We pushed the
-		 * size of the instruction into tf_err on entry.
-		 */
-		frame-tf_eip -= frame-tf_err;
-		break;
-	case EJUSTRETURN:
-		/* nothing to do */
-		break;
-	default:
-	bad:
-		frame-tf_eax = error;
-		frame-tf_eflags |= PSL_C;	/* carry bit */
-		break;
-	}
-
-	userret(l);
-}
-
-void
-freebsd_syscall_fancy(struct trapframe *frame)
+freebsd_syscall(struct trapframe *frame)
 {
 	char *params;
 	const struct sysent *callp;

Index: src/sys/arch/i386/i386/ibcs2_syscall.c
diff -u src/sys/arch/i386/i386/ibcs2_syscall.c:1.46 src/sys/arch/i386/i386/ibcs2_syscall.c:1.47
--- src/sys/arch/i386/i386/ibcs2_syscall.c:1.46	Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/ibcs2_syscall.c	Thu Jul 12 17:26:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_syscall.c,v 1.46 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: ibcs2_syscall.c,v 1.47 2012/07/12 17:26:42 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.46 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.47 2012/07/12 17:26:42 dsl Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -54,18 +54,14 @@ __KERNEL_RCSID(0, $NetBSD: ibcs2_syscal
 #include compat/ibcs2/ibcs2_syscall.h
 #include machine/ibcs2_machdep.h
 
-void ibcs2_syscall_plain(struct trapframe *);
-void ibcs2_syscall_fancy(struct trapframe *);
+void ibcs2_syscall(struct trapframe *);
 extern struct sysent ibcs2_sysent[];
 
 void
 

CVS commit: src/sys/arch/i386/i386

2012-07-12 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Thu Jul 12 18:13:08 UTC 2012

Modified Files:
src/sys/arch/i386/i386: freebsd_syscall.c ibcs2_syscall.c
svr4_syscall.c

Log Message:
Fix previous - syscall_fancy() didn't contain the check for p_trace_anabled.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/i386/i386/freebsd_syscall.c
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/i386/i386/ibcs2_syscall.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/i386/i386/svr4_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/i386/i386/freebsd_syscall.c
diff -u src/sys/arch/i386/i386/freebsd_syscall.c:1.38 src/sys/arch/i386/i386/freebsd_syscall.c:1.39
--- src/sys/arch/i386/i386/freebsd_syscall.c:1.38	Thu Jul 12 17:26:42 2012
+++ src/sys/arch/i386/i386/freebsd_syscall.c	Thu Jul 12 18:13:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: freebsd_syscall.c,v 1.38 2012/07/12 17:26:42 dsl Exp $	*/
+/*	$NetBSD: freebsd_syscall.c,v 1.39 2012/07/12 18:13:08 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.38 2012/07/12 17:26:42 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: freebsd_syscall.c,v 1.39 2012/07/12 18:13:08 dsl Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -112,7 +112,8 @@ freebsd_syscall(struct trapframe *frame)
 			goto bad;
 	}
 
-	if ((error = trace_enter(code, args, callp-sy_narg)) == 0) {
+	if (!__predict_false(p-p_trace_enabled)
+	|| (error = trace_enter(code, args, callp-sy_narg)) == 0) {
 		rval[0] = 0;
 		rval[1] = frame-tf_edx; /* need to keep edx for shared FreeBSD bins */
 		error = sy_call(callp, l, args, rval);
@@ -142,7 +143,8 @@ freebsd_syscall(struct trapframe *frame)
 		break;
 	}
 
-	trace_exit(code, rval, error);
+	if (__predict_false(p-p_trace_enabled))
+		trace_exit(code, rval, error);
 
 	userret(l);
 }

Index: src/sys/arch/i386/i386/ibcs2_syscall.c
diff -u src/sys/arch/i386/i386/ibcs2_syscall.c:1.47 src/sys/arch/i386/i386/ibcs2_syscall.c:1.48
--- src/sys/arch/i386/i386/ibcs2_syscall.c:1.47	Thu Jul 12 17:26:42 2012
+++ src/sys/arch/i386/i386/ibcs2_syscall.c	Thu Jul 12 18:13:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibcs2_syscall.c,v 1.47 2012/07/12 17:26:42 dsl Exp $	*/
+/*	$NetBSD: ibcs2_syscall.c,v 1.48 2012/07/12 18:13:08 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.47 2012/07/12 17:26:42 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: ibcs2_syscall.c,v 1.48 2012/07/12 18:13:08 dsl Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -75,12 +75,14 @@ ibcs2_syscall(struct trapframe *frame)
 	char * params;
 	const struct sysent *callp;
 	struct lwp *l;
+	struct proc *p;
 	int error;
 	size_t argsize;
 	register_t code, args[8], rval[2];
 
 	l = curlwp;
-	LWP_CACHE_CREDS(l, l-l_proc);
+	p = l-l_proc;
+	LWP_CACHE_CREDS(l, p);
 
 	code = frame-tf_eax;
 	if (IBCS2_HIGH_SYSCALL(code))
@@ -109,7 +111,8 @@ ibcs2_syscall(struct trapframe *frame)
 			goto bad;
 	}
 
-	if ((error = trace_enter(code, args, callp-sy_narg)) == 0) {
+	if (!__predict_false(p-p_trace_enabled)
+	|| (error = trace_enter(code, args, callp-sy_narg)) == 0) {
 		rval[0] = 0;
 		rval[1] = 0;
 		error = sy_call(callp, l, args, rval);
@@ -140,7 +143,8 @@ ibcs2_syscall(struct trapframe *frame)
 		break;
 	}
 
-	trace_exit(code, rval, error);
+	if (__predict_false(p-p_trace_enabled))
+		trace_exit(code, rval, error);
 
 	userret(l);
 }

Index: src/sys/arch/i386/i386/svr4_syscall.c
diff -u src/sys/arch/i386/i386/svr4_syscall.c:1.46 src/sys/arch/i386/i386/svr4_syscall.c:1.47
--- src/sys/arch/i386/i386/svr4_syscall.c:1.46	Thu Jul 12 17:26:42 2012
+++ src/sys/arch/i386/i386/svr4_syscall.c	Thu Jul 12 18:13:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: svr4_syscall.c,v 1.46 2012/07/12 17:26:42 dsl Exp $	*/
+/*	$NetBSD: svr4_syscall.c,v 1.47 2012/07/12 18:13:08 dsl Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: svr4_syscall.c,v 1.46 2012/07/12 17:26:42 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: svr4_syscall.c,v 1.47 2012/07/12 18:13:08 dsl Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -74,12 +74,14 @@ svr4_syscall(struct trapframe *frame)
 	char *params;
 	const struct sysent *callp;
 	struct lwp *l;
+	struct proc *p;
 	int error;
 	size_t argsize;
 	register_t code, args[8], rval[2];
 
 	l = curlwp;
-	LWP_CACHE_CREDS(l, l-l_proc);
+	p = l-l_proc;
+	LWP_CACHE_CREDS(l, p);
 
 	code = frame-tf_eax;
 	callp = svr4_sysent;
@@ -106,7 +108,8 @@ svr4_syscall(struct trapframe *frame)
 			goto bad;
 	}
 
-	if ((error = trace_enter(code, args, callp-sy_narg)) == 0) {
+	if (!__predict_false(p-p_trace_enabled)
+	|| (error = trace_enter(code, args, 

CVS commit: src/sys/arch/i386/i386

2012-06-15 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Fri Jun 15 14:09:26 UTC 2012

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

Log Message:
update a comment


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/i386/i386/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/i386/i386/spl.S
diff -u src/sys/arch/i386/i386/spl.S:1.36 src/sys/arch/i386/i386/spl.S:1.37
--- src/sys/arch/i386/i386/spl.S:1.36	Fri Mar 18 15:18:16 2011
+++ src/sys/arch/i386/i386/spl.S	Fri Jun 15 14:09:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: spl.S,v 1.36 2011/03/18 15:18:16 joerg Exp $	*/
+/*	$NetBSD: spl.S,v 1.37 2012/06/15 14:09:26 yamt Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: spl.S,v 1.36 2011/03/18 15:18:16 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: spl.S,v 1.37 2012/06/15 14:09:26 yamt Exp $);
 
 #include opt_vm86.h
 #include opt_ddb.h
@@ -73,7 +73,7 @@ END(splraise)
  * void spllower(int s);
  *
  * spllower() for i486 and Pentium.  Must be the same size as
- * i686_spllower().  This must use pushf/cli/popf as it is used
+ * cx8_spllower().  This must use pushf/cli/popf as it is used
  * early in boot where interrupts are disabled via eflags/IE.
  */
 ENTRY(spllower)



CVS commit: src/sys/arch/i386/i386

2012-06-15 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Fri Jun 15 14:23:46 UTC 2012

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

Log Message:
whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/i386/i386/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/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.59 src/sys/arch/i386/i386/vector.S:1.60
--- src/sys/arch/i386/i386/vector.S:1.59	Sun Jun 12 03:35:42 2011
+++ src/sys/arch/i386/i386/vector.S	Fri Jun 15 14:23:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: vector.S,v 1.59 2011/06/12 03:35:42 rmind Exp $	*/
+/*	$NetBSD: vector.S,v 1.60 2012/06/15 14:23:46 yamt Exp $	*/
 
 /*
  * Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: vector.S,v 1.59 2011/06/12 03:35:42 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: vector.S,v 1.60 2012/06/15 14:23:46 yamt Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -282,7 +282,7 @@ IDTVEC(intr_ ## name ## num)		;\
 	pushl	$T_ASTFLT		/* trap # for doing ASTs */	;\
 	INTRENTRY			;\
 	movl	CPUVAR(ISOURCES) + (num) * 4, %ebp			;\
-	mask(num)		/* mask it in hardware */		;\
+	mask(num)			/* mask it in hardware */	;\
 	early_ack(num)			/* and allow other intrs */	;\
 	testl	%ebp,%ebp		;\
 	jz	9f			/* stray */			;\



CVS commit: src/sys/arch/i386/i386

2012-06-15 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Jun 15 23:01:16 UTC 2012

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

Log Message:
Don't use an empty body on the same line for the for loop.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/i386/i386/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/i386/i386/bios32.c
diff -u src/sys/arch/i386/i386/bios32.c:1.28 src/sys/arch/i386/i386/bios32.c:1.29
--- src/sys/arch/i386/i386/bios32.c:1.28	Tue Nov 17 23:45:39 2009
+++ src/sys/arch/i386/i386/bios32.c	Fri Jun 15 23:01:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bios32.c,v 1.28 2009/11/17 23:45:39 dyoung Exp $	*/
+/*	$NetBSD: bios32.c,v 1.29 2012/06/15 23:01:16 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -86,7 +86,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: bios32.c,v 1.28 2009/11/17 23:45:39 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: bios32.c,v 1.29 2012/06/15 23:01:16 joerg Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -175,8 +175,8 @@ bios32_init(void)
 		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/i386/i386

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

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

Log Message:
For correctness: do not forget VA_SIGN_NEG().


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/i386/i386/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/i386/i386/db_memrw.c
diff -u src/sys/arch/i386/i386/db_memrw.c:1.29 src/sys/arch/i386/i386/db_memrw.c:1.30
--- src/sys/arch/i386/i386/db_memrw.c:1.29	Mon May  7 12:12:03 2012
+++ src/sys/arch/i386/i386/db_memrw.c	Mon May  7 12:23:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.29 2012/05/07 12:12:03 jym Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.30 2012/05/07 12:23:05 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.29 2012/05/07 12:12:03 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.30 2012/05/07 12:23:05 jym Exp $);
 
 #include opt_xen.h
 
@@ -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((vaddr_t)dst);
 



CVS commit: src/sys/arch/i386/i386

2012-05-06 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Mon May  7 02:12:35 UTC 2012

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

Log Message:
I am not quite sure that __data_start (set through location counter) is
a char... declare it as int, like amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/i386/i386/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/i386/i386/db_memrw.c
diff -u src/sys/arch/i386/i386/db_memrw.c:1.25 src/sys/arch/i386/i386/db_memrw.c:1.26
--- src/sys/arch/i386/i386/db_memrw.c:1.25	Tue Mar 10 20:05:30 2009
+++ src/sys/arch/i386/i386/db_memrw.c	Mon May  7 02:12:35 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.25 2009/03/10 20:05:30 bouyer Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.26 2012/05/07 02:12:35 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.25 2009/03/10 20:05:30 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.26 2012/05/07 02:12:35 jym Exp $);
 
 #include opt_xen.h
 
@@ -186,7 +186,7 @@ db_write_text(vaddr_t addr, size_t size,
 void
 db_write_bytes(vaddr_t addr, size_t size, const char *data)
 {
-	extern char __data_start;
+	extern int __data_start;
 	char *dst;
 
 	dst = (char *)addr;



CVS commit: src/sys/arch/i386/i386

2012-05-06 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Mon May  7 02:15:34 UTC 2012

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

Log Message:
Remove XXXSMP comment and explain why no TLB shootdown is required here.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/i386/i386/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/i386/i386/db_memrw.c
diff -u src/sys/arch/i386/i386/db_memrw.c:1.26 src/sys/arch/i386/i386/db_memrw.c:1.27
--- src/sys/arch/i386/i386/db_memrw.c:1.26	Mon May  7 02:12:35 2012
+++ src/sys/arch/i386/i386/db_memrw.c	Mon May  7 02:15:34 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.26 2012/05/07 02:12:35 jym Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.27 2012/05/07 02:15:34 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.26 2012/05/07 02:12:35 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.27 2012/05/07 02:15:34 jym Exp $);
 
 #include opt_xen.h
 
@@ -161,22 +161,13 @@ db_write_text(vaddr_t addr, size_t size,
 		 */
 		pmap_pte_set(pte, oldpte);
 		pmap_pte_flush();
-#if 0 
+		pmap_update_pg(pgva);
 		/*
-		 * XXXSMP Not clear if this is needed for 100% correctness.
+		 * MULTIPROCESSOR: no shootdown required as all other CPUs
+		 * should be in CPUF_PAUSE state and will not cache the PTE
+		 * with the write access set.
 		 */
-		{
-			int cpumask = 0;
-			/*
-			 * shoot down in case other CPU mistakenly caches page.
-			 */
-			pmap_tlb_shootdown(pmap_kernel(), pgva, 0, PG_G);
-			pmap_tlb_shootwait();
-		}
-#else
-		pmap_update_pg(pgva);
-#endif
-		
+
 	} while (size != 0);
 }
 



CVS commit: src/sys/arch/i386/i386

2012-05-06 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Mon May  7 02:32:09 UTC 2012

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

Log Message:
Use pmap_pte_*bits macros to set/clear bits in a PTE. Remove pmap_pte_flush
calls as these operations are synchronously flushed under Xen; they should
not be cached.

XXX the code can be shared between i386 and amd64, but I will merge
them once I figure out why db_write_text() can cause page faults for
certain CPUs in long mode (code looks correct, but single stepping or
adding debug printf's makes the bug magically disappear... sigh)

Bug reported by David Laight on port-amd64@ when attempting to set
breakpoints through ddb(4).


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/i386/i386/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/i386/i386/db_memrw.c
diff -u src/sys/arch/i386/i386/db_memrw.c:1.27 src/sys/arch/i386/i386/db_memrw.c:1.28
--- src/sys/arch/i386/i386/db_memrw.c:1.27	Mon May  7 02:15:34 2012
+++ src/sys/arch/i386/i386/db_memrw.c	Mon May  7 02:32:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_memrw.c,v 1.27 2012/05/07 02:15:34 jym Exp $	*/
+/*	$NetBSD: db_memrw.c,v 1.28 2012/05/07 02:32:09 jym Exp $	*/
 
 /*-
  * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc.
@@ -49,7 +49,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.27 2012/05/07 02:15:34 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: db_memrw.c,v 1.28 2012/05/07 02:32:09 jym Exp $);
 
 #include opt_xen.h
 
@@ -97,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;
@@ -111,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;
 		}
@@ -122,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((vaddr_t)dst);
@@ -132,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);
@@ -140,9 +140,11 @@ db_write_text(vaddr_t addr, size_t size,
 			limit = size;
 		size -= limit;
 
-		tmppte = (oldpte  ~PG_KR) | PG_KW;
-		pmap_pte_set(pte, tmppte);
-		pmap_pte_flush();
+		/*
+		 * Make the kernel text page writable.
+		 */
+		pmap_pte_clearbits(ppte, PG_KR);
+		pmap_pte_setbits(ppte, PG_KW);
 		pmap_update_pg(pgva);
 		/*
 		 * MULTIPROCESSOR: no shootdown required as the PTE continues to
@@ -157,10 +159,10 @@ db_write_text(vaddr_t addr, size_t size,
 			*dst++ = *data++;
 
 		/*
-		 * Restore the old PTE.
+		 * Turn the page back to read-only.
 		 */
-		pmap_pte_set(pte, oldpte);
-		pmap_pte_flush();
+		pmap_pte_clearbits(ppte, PG_KW);
+		pmap_pte_setbits(ppte, PG_KR);
 		pmap_update_pg(pgva);
 		/*
 		 * MULTIPROCESSOR: no shootdown required as all other CPUs



CVS commit: src/sys/arch/i386/i386

2012-04-22 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Apr 22 20:36:52 UTC 2012

Modified Files:
src/sys/arch/i386/i386: compat_16_machdep.c

Log Message:
From Bob Lee [glee at force10networks dot com], Preserve the have fpu context
bit for compat_16 signals, because the old 1.6 context does not deal with the
fpu.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/i386/i386/compat_16_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/i386/i386/compat_16_machdep.c
diff -u src/sys/arch/i386/i386/compat_16_machdep.c:1.21 src/sys/arch/i386/i386/compat_16_machdep.c:1.22
--- src/sys/arch/i386/i386/compat_16_machdep.c:1.21	Sat Nov  6 07:40:24 2010
+++ src/sys/arch/i386/i386/compat_16_machdep.c	Sun Apr 22 16:36:52 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_16_machdep.c,v 1.21 2010/11/06 11:40:24 uebayasi Exp $	*/
+/*	$NetBSD: compat_16_machdep.c,v 1.22 2012/04/22 20:36:52 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: compat_16_machdep.c,v 1.21 2010/11/06 11:40:24 uebayasi Exp $);
+__KERNEL_RCSID(0, $NetBSD: compat_16_machdep.c,v 1.22 2012/04/22 20:36:52 christos Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_vm86.h
@@ -260,7 +260,9 @@ sendsig_sigcontext(const ksiginfo_t *ksi
 		/* NOTREACHED */
 	}
 
+	int svufpu = l-l_md.md_flags  MDL_USEDFPU;
 	buildcontext(l, sel, catcher, fp);
+	l-l_md.md_flags |= svufpu;
 
 	/* Remember that we're now on the signal stack. */
 	if (onstack)



CVS commit: src/sys/arch/i386/i386

2012-04-19 Thread Jean-Yves Migeon
Module Name:src
Committed By:   jym
Date:   Thu Apr 19 18:07:05 UTC 2012

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

Log Message:
Mirror what is done for amd64 boot and ACPI wakeup code by setting
CR0_WP (write protection bit) early on boot. Although it is set later via
cpu_init(), this can help tracking down invalid writes to pages mapped
as read only from ring 0.

No regression observed when booting under anita (QEMU) or a P4 host.

Depending on your hardware or setup, you may trigger code paths I have
overlooked. So if your machine does not start properly, or you get
page faults early during boot, please report them to me.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/i386/i386/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/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.98 src/sys/arch/i386/i386/locore.S:1.99
--- src/sys/arch/i386/i386/locore.S:1.98	Thu Apr 19 18:00:35 2012
+++ src/sys/arch/i386/i386/locore.S	Thu Apr 19 18:07:05 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.98 2012/04/19 18:00:35 jym Exp $	*/
+/*	$NetBSD: locore.S,v 1.99 2012/04/19 18:07:05 jym Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include machine/asm.h
-__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.98 2012/04/19 18:00:35 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: locore.S,v 1.99 2012/04/19 18:07:05 jym Exp $);
 
 #include opt_compat_oldboot.h
 #include opt_ddb.h
@@ -682,7 +682,7 @@ try586:	/* Use the `cpuid' instruction. 
  	 */
 	movl	%cr0,%eax		# get control word
 	# enable paging  NPX emulation
-	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_AM),%eax
+	orl	$(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP|CR0_AM),%eax
 	movl	%eax,%cr0		# and page NOW!
 
 	pushl	$begin			# jump to high mem



CVS commit: src/sys/arch/i386/i386

2012-03-04 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Mar  4 15:56:09 UTC 2012

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

Log Message:
cast xen_start_info.nr_pages to paddr_t, so that ctob() won't truncate
the addresses to 32bits. Fix avail memory when allocating more than 4GB
to a XEN3PAE domU.


To generate a diff of this commit:
cvs rdiff -u -r1.724 -r1.725 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.724 src/sys/arch/i386/i386/machdep.c:1.725
--- src/sys/arch/i386/i386/machdep.c:1.724	Sat Mar  3 23:43:17 2012
+++ src/sys/arch/i386/i386/machdep.c	Sun Mar  4 15:56:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.724 2012/03/03 23:43:17 mrg Exp $	*/
+/*	$NetBSD: machdep.c,v 1.725 2012/03/04 15:56:09 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.724 2012/03/03 23:43:17 mrg Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.725 2012/03/04 15:56:09 bouyer Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1364,9 +1364,9 @@ init386(paddr_t first_avail)
 	/* Make sure the end of the space used by the kernel is rounded. */
 	first_avail = round_page(first_avail);
 	avail_start = first_avail;
-	avail_end = ctob(xen_start_info.nr_pages) + XPMAP_OFFSET;
+	avail_end = ctob((paddr_t)xen_start_info.nr_pages) + XPMAP_OFFSET;
 	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
-	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
+	pmap_pa_end = pmap_pa_start + ctob((paddr_t)xen_start_info.nr_pages);
 	mem_clusters[0].start = avail_start;
 	mem_clusters[0].size = avail_end - avail_start;
 	mem_cluster_cnt++;
@@ -1419,9 +1419,10 @@ init386(paddr_t first_avail)
 	initx86_load_memmap(first_avail);
 
 #else /* !XEN */
-	XENPRINTK((load the memory cluster %p(%d) - %p(%ld)\n,
-	(void *)(long)avail_start, (int)atop(avail_start),
-	(void *)(long)avail_end, (int)atop(avail_end)));
+	XENPRINTK((load the memory cluster 0x% PRIx64  (% PRId64 ) - 
+	0x% PRIx64  (% PRId64 )\n,
+	(uint64_t)avail_start, (uint64_t)atop(avail_start),
+	(uint64_t)avail_end, (uint64_t)atop(avail_end)));
 	uvm_page_physload(atop(avail_start), atop(avail_end),
 	atop(avail_start), atop(avail_end),
 	VM_FREELIST_DEFAULT);



CVS commit: src/sys/arch/i386/i386

2012-03-04 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sun Mar  4 20:44:17 UTC 2012

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

Log Message:
Don't try to uvm_page_physload() the tmpgdt page: this always fails because
only one physical segment is configured for Xen, and it's probably not
worth it to create a second physseg with a single page (uvm has optimisations
for the VM_PHYSSEG_MAX == 1 case)


To generate a diff of this commit:
cvs rdiff -u -r1.725 -r1.726 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.725 src/sys/arch/i386/i386/machdep.c:1.726
--- src/sys/arch/i386/i386/machdep.c:1.725	Sun Mar  4 15:56:09 2012
+++ src/sys/arch/i386/i386/machdep.c	Sun Mar  4 20:44:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.725 2012/03/04 15:56:09 bouyer Exp $	*/
+/*	$NetBSD: machdep.c,v 1.726 2012/03/04 20:44:17 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.725 2012/03/04 15:56:09 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.726 2012/03/04 20:44:17 bouyer Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1440,10 +1440,6 @@ init386(paddr_t first_avail)
 		}
 	}
 
-	uvm_page_physload(atop((vaddr_t)tmpgdt), atop((vaddr_t)tmpgdt + PAGE_SIZE),
-	atop((vaddr_t)tmpgdt), atop((vaddr_t)tmpgdt + PAGE_SIZE),
-	VM_FREELIST_DEFAULT);
-
 #endif /* !XEN */
 
 	init386_msgbuf();



CVS commit: src/sys/arch/i386/i386

2012-02-27 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Mon Feb 27 19:52:59 UTC 2012

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

Log Message:
Do not special-case XEN and always use the proper selectors for %fs and %gs
in buildcontext() and setregs(). The consequence was that signal handlers
would have the wrong %fs/%gs. Found by running atf tests under Xen/i386.


To generate a diff of this commit:
cvs rdiff -u -r1.721 -r1.722 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.721 src/sys/arch/i386/i386/machdep.c:1.722
--- src/sys/arch/i386/i386/machdep.c:1.721	Fri Feb 24 08:06:07 2012
+++ src/sys/arch/i386/i386/machdep.c	Mon Feb 27 19:52:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.721 2012/02/24 08:06:07 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.722 2012/02/27 19:52:59 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.721 2012/02/24 08:06:07 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.722 2012/02/27 19:52:59 bouyer Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -723,13 +723,8 @@ buildcontext(struct lwp *l, int sel, voi
 {
 	struct trapframe *tf = l-l_md.md_regs;
 
-#ifndef XEN
 	tf-tf_gs = GSEL(GUGS_SEL, SEL_UPL);
 	tf-tf_fs = GSEL(GUFS_SEL, SEL_UPL);
-#else
-	tf-tf_gs = GSEL(GUDATA_SEL, SEL_UPL);
-	tf-tf_fs = GSEL(GUDATA_SEL, SEL_UPL);
-#endif
 	tf-tf_es = GSEL(GUDATA_SEL, SEL_UPL);
 	tf-tf_ds = GSEL(GUDATA_SEL, SEL_UPL);
 	tf-tf_eip = (int)catcher;
@@ -970,13 +965,8 @@ setregs(struct lwp *l, struct exec_packa
 	memcpy(pcb-pcb_gsd, gdt[GUDATA_SEL], sizeof(pcb-pcb_gsd));
 
 	tf = l-l_md.md_regs;
-#ifndef XEN
 	tf-tf_gs = GSEL(GUGS_SEL, SEL_UPL);
 	tf-tf_fs = GSEL(GUFS_SEL, SEL_UPL);
-#else
-	tf-tf_gs = LSEL(LUDATA_SEL, SEL_UPL);
-	tf-tf_fs = LSEL(LUDATA_SEL, SEL_UPL);
-#endif
 	tf-tf_es = LSEL(LUDATA_SEL, SEL_UPL);
 	tf-tf_ds = LSEL(LUDATA_SEL, SEL_UPL);
 	tf-tf_edi = 0;



CVS commit: src/sys/arch/i386/i386

2012-02-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Feb 22 18:35:26 UTC 2012

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

Log Message:
i386_switch_context(): mimic code in cpu_switchto() and compare pcb-pcb_fpcpu
against ci to decide if we need to turn off FPU. Fix FPU corruption, e.g.
paranoia occasionally reporting flaws on Xen/MP systems.

XXX is ci_fpused still needed at all ?


To generate a diff of this commit:
cvs rdiff -u -r1.718 -r1.719 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.718 src/sys/arch/i386/i386/machdep.c:1.719
--- src/sys/arch/i386/i386/machdep.c:1.718	Sun Feb 19 21:06:08 2012
+++ src/sys/arch/i386/i386/machdep.c	Wed Feb 22 18:35:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.718 2012/02/19 21:06:08 rmind Exp $	*/
+/*	$NetBSD: machdep.c,v 1.719 2012/02/22 18:35:26 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.718 2012/02/19 21:06:08 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.719 2012/02/22 18:35:26 bouyer Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -542,9 +542,8 @@ i386_switch_context(lwp_t *l)
 
 	pcb = lwp_getpcb(l);
 	ci = curcpu();
-	if (ci-ci_fpused) {
+	if (pcb-pcb_fpcpu != ci) {
 		HYPERVISOR_fpu_taskswitch(1);
-		ci-ci_fpused = 0;
 	}
 
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb-pcb_esp0);



CVS commit: src/sys/arch/i386/i386

2012-02-07 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Tue Feb  7 16:34:44 UTC 2012

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

Log Message:
Initialize pcibus_attach_args.pba_sub to 255.  Note in a comment that
this needs some improvement for machines with 1 Host-PCI bridge, but
that it doesn't cause any practical problems at this time.

Ok releng@.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/i386/i386/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/i386/i386/mainbus.c
diff -u src/sys/arch/i386/i386/mainbus.c:1.93 src/sys/arch/i386/i386/mainbus.c:1.94
--- src/sys/arch/i386/i386/mainbus.c:1.93	Wed Jan 18 21:34:38 2012
+++ src/sys/arch/i386/i386/mainbus.c	Tue Feb  7 16:34:44 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.93 2012/01/18 21:34:38 drochner Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.94 2012/02/07 16:34:44 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.93 2012/01/18 21:34:38 drochner Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.94 2012/02/07 16:34:44 dyoung Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -406,6 +406,13 @@ mainbus_rescan(device_t self, const char
 		mba.mba_pba.pba_pc = NULL;
 		mba.mba_pba.pba_flags = pci_bus_flags();
 		mba.mba_pba.pba_bus = 0;
+		/* XXX On those machines with 1 Host-PCI bridge,
+		 * XXX not every bus  pba_bus is subordinate to pba_bus,
+		 * XXX but this works on many machines, and pba_sub is
+		 * XXX not used today by any critical code, so it is safe
+		 * XXX to be so inclusive at this time.
+		 */
+		mba.mba_pba.pba_sub = 255;
 		mba.mba_pba.pba_bridgetag = NULL;
 #if NACPICA  0  defined(ACPI_SCANPCI)
 		if (npcibus == 0  sc-sc_mpacpi_active)



CVS commit: src/sys/arch/i386/i386

2012-01-30 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Mon Jan 30 21:35:22 UTC 2012

Modified Files:
src/sys/arch/i386/i386: pmc.c

Log Message:
pmc_init: check ncpu instead of cpus_attached.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/i386/i386/pmc.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/i386/i386/pmc.c
diff -u src/sys/arch/i386/i386/pmc.c:1.19 src/sys/arch/i386/i386/pmc.c:1.20
--- src/sys/arch/i386/i386/pmc.c:1.19	Tue Apr 27 18:41:52 2010
+++ src/sys/arch/i386/i386/pmc.c	Mon Jan 30 21:35:22 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmc.c,v 1.19 2010/04/27 18:41:52 dyoung Exp $	*/
+/*	$NetBSD: pmc.c,v 1.20 2012/01/30 21:35:22 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2000 Zembu Labs, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pmc.c,v 1.19 2010/04/27 18:41:52 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmc.c,v 1.20 2012/01/30 21:35:22 rmind Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -79,7 +79,7 @@ pmc_init(void)
 
 #ifdef MULTIPROCESSOR
 	/* XXX */
-	if (cpus_attached  1)
+	if (ncpu  1)
 		goto done;
 #endif
 



CVS commit: src/sys/arch/i386/i386

2012-01-18 Thread Matthias Drochner
Module Name:src
Committed By:   drochner
Date:   Wed Jan 18 21:34:38 UTC 2012

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

Log Message:
revert previous, the assumption all buses 1 and up must be subordinate
to pci0 doesn't even hold on i386 -- there are server-class chipsets
with multiple primary PCI buses, see arch/x86/pci/pchb.c for examples


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/arch/i386/i386/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/i386/i386/mainbus.c
diff -u src/sys/arch/i386/i386/mainbus.c:1.92 src/sys/arch/i386/i386/mainbus.c:1.93
--- src/sys/arch/i386/i386/mainbus.c:1.92	Fri Oct 21 21:35:28 2011
+++ src/sys/arch/i386/i386/mainbus.c	Wed Jan 18 21:34:38 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mainbus.c,v 1.92 2011/10/21 21:35:28 dyoung Exp $	*/
+/*	$NetBSD: mainbus.c,v 1.93 2012/01/18 21:34:38 drochner Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.92 2011/10/21 21:35:28 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: mainbus.c,v 1.93 2012/01/18 21:34:38 drochner Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -406,7 +406,6 @@ mainbus_rescan(device_t self, const char
 		mba.mba_pba.pba_pc = NULL;
 		mba.mba_pba.pba_flags = pci_bus_flags();
 		mba.mba_pba.pba_bus = 0;
-		mba.mba_pba.pba_sub = 255;
 		mba.mba_pba.pba_bridgetag = NULL;
 #if NACPICA  0  defined(ACPI_SCANPCI)
 		if (npcibus == 0  sc-sc_mpacpi_active)



CVS commit: src/sys/arch/i386/i386

2012-01-12 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Jan 12 19:37:46 UTC 2012

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

Log Message:
re-order call to x86_bus_space_init() until after %fs is initialised via 
initgdt().

x86_bus_space_init() uses mutex(9) since it uses extent(9), which requires %fs 
to be setup before use.


To generate a diff of this commit:
cvs rdiff -u -r1.715 -r1.716 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.715 src/sys/arch/i386/i386/machdep.c:1.716
--- src/sys/arch/i386/i386/machdep.c:1.715	Fri Dec 30 17:57:49 2011
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan 12 19:37:45 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.715 2011/12/30 17:57:49 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.716 2012/01/12 19:37:45 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1354,9 +1354,6 @@ init386(paddr_t first_avail)
 	cpu_info_primary.ci_pae_l3_pdir = (pd_entry_t *)(rcr3() + KERNBASE);
 #endif /* PAE  !XEN */
 
-#if NISA  0 || NPCI  0
-	x86_bus_space_init();
-#endif
 #ifdef XEN
 	xen_parse_cmdline(XEN_PARSE_BOOTFLAGS, NULL);
 #endif
@@ -1412,6 +1409,11 @@ init386(paddr_t first_avail)
 	 */
 	initgdt(NULL);
 #endif /* XEN */
+
+#if NISA  0 || NPCI  0
+	x86_bus_space_init();
+#endif /* NISA  0 || NPCI  0 */
+	
 	consinit();	/* XXX SHOULD NOT BE DONE HERE */
 
 #ifdef DEBUG_MEMLOAD



CVS commit: src/sys/arch/i386/i386

2011-11-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 29 11:12:27 UTC 2011

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

Log Message:
Explicitly cast the result of ptoa() to unsigned long for printf,
to fix build failure on xen.


To generate a diff of this commit:
cvs rdiff -u -r1.713 -r1.714 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.713 src/sys/arch/i386/i386/machdep.c:1.714
--- src/sys/arch/i386/i386/machdep.c:1.713	Fri Nov 18 22:18:08 2011
+++ src/sys/arch/i386/i386/machdep.c	Tue Nov 29 11:12:26 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.713 2011/11/18 22:18:08 jmcneill Exp $	*/
+/*	$NetBSD: machdep.c,v 1.714 2011/11/29 11:12:26 martin Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.713 2011/11/18 22:18:08 jmcneill Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.714 2011/11/29 11:12:26 martin Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1622,7 +1622,7 @@ init386(paddr_t first_avail)
 		   have %lu bytes, want %lu bytes\n
 		   running in degraded mode\n
 		   press a key to confirm\n\n,
-		   ptoa(physmem), 2*1024*1024UL);
+		   (unsigned long)ptoa(physmem), 2*1024*1024UL);
 		cngetc();
 	}
 



CVS commit: src/sys/arch/i386/i386

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

Modified Files:
src/sys/arch/i386/i386: dumpsys.c

Log Message:
revert dumpsys.c rev. 1.13 because it was reported to cause a problem.
http://mail-index.NetBSD.org/source-changes-d/2011/11/19/msg004283.html


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/i386/i386/dumpsys.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/i386/i386/dumpsys.c
diff -u src/sys/arch/i386/i386/dumpsys.c:1.14 src/sys/arch/i386/i386/dumpsys.c:1.15
--- src/sys/arch/i386/i386/dumpsys.c:1.14	Thu Nov 10 03:45:40 2011
+++ src/sys/arch/i386/i386/dumpsys.c	Sun Nov 20 18:41:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpsys.c,v 1.14 2011/11/10 03:45:40 riz Exp $	*/
+/*	$NetBSD: dumpsys.c,v 1.15 2011/11/20 18:41:12 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.14 2011/11/10 03:45:40 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.15 2011/11/20 18:41:12 yamt Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -668,7 +668,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/i386/i386

2011-11-09 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Nov 10 03:45:40 UTC 2011

Modified Files:
src/sys/arch/i386/i386: dumpsys.c

Log Message:
i386_use_pae is now just use_pae.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/i386/i386/dumpsys.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/i386/i386/dumpsys.c
diff -u src/sys/arch/i386/i386/dumpsys.c:1.13 src/sys/arch/i386/i386/dumpsys.c:1.14
--- src/sys/arch/i386/i386/dumpsys.c:1.13	Mon Oct 31 12:42:53 2011
+++ src/sys/arch/i386/i386/dumpsys.c	Thu Nov 10 03:45:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpsys.c,v 1.13 2011/10/31 12:42:53 yamt Exp $	*/
+/*	$NetBSD: dumpsys.c,v 1.14 2011/11/10 03:45:40 riz Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.13 2011/10/31 12:42:53 yamt Exp $);
+__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.14 2011/11/10 03:45:40 riz Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -627,7 +627,7 @@ cpu_dump(void)
 	 * Add the machine-dependent header info.
 	 */
 	cpuhdr.pdppaddr = PDPpaddr;
-	if (i386_use_pae == 1)
+	if (use_pae == 1)
 		cpuhdr.pdppaddr |= I386_KCORE_PAE;
 	cpuhdr.nmemsegs = dump_nmemsegs;
 	(void)dump_header_addbytes(cpuhdr, ALIGN(sizeof(cpuhdr)));



CVS commit: src/sys/arch/i386/i386

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

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

Log Message:
DTRT when initialising pmap_pa_end.


To generate a diff of this commit:
cvs rdiff -u -r1.710 -r1.711 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.710 src/sys/arch/i386/i386/machdep.c:1.711
--- src/sys/arch/i386/i386/machdep.c:1.710	Sun Nov  6 11:40:46 2011
+++ src/sys/arch/i386/i386/machdep.c	Sun Nov  6 15:35:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.710 2011/11/06 11:40:46 cherry Exp $	*/
+/*	$NetBSD: machdep.c,v 1.711 2011/11/06 15:35:29 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.710 2011/11/06 11:40:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.711 2011/11/06 15:35:29 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -1440,7 +1440,7 @@ init386(paddr_t first_avail)
 	avail_start = first_avail;
 	avail_end = ctob(xen_start_info.nr_pages) + XPMAP_OFFSET;
 	pmap_pa_start = (KERNTEXTOFF - KERNBASE);
-	pmap_pa_end = avail_end;
+	pmap_pa_end = pmap_pa_start + ctob(xen_start_info.nr_pages);
 	mem_clusters[0].start = avail_start;
 	mem_clusters[0].size = avail_end - avail_start;
 	mem_cluster_cnt++;



CVS commit: src/sys/arch/i386/i386

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

Modified Files:
src/sys/arch/i386/i386: dumpsys.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/i386/i386/dumpsys.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/i386/i386/dumpsys.c
diff -u src/sys/arch/i386/i386/dumpsys.c:1.12 src/sys/arch/i386/i386/dumpsys.c:1.13
--- src/sys/arch/i386/i386/dumpsys.c:1.12	Sat Nov  6 11:40:25 2010
+++ src/sys/arch/i386/i386/dumpsys.c	Mon Oct 31 12:42:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpsys.c,v 1.12 2010/11/06 11:40:25 uebayasi Exp $	*/
+/*	$NetBSD: dumpsys.c,v 1.13 2011/10/31 12:42:53 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.12 2010/11/06 11:40:25 uebayasi Exp $);
+__KERNEL_RCSID(0, $NetBSD: dumpsys.c,v 1.13 2011/10/31 12:42:53 yamt Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -668,6 +668,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/i386/i386

2011-10-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Oct 23 13:02:32 UTC 2011

Modified Files:
src/sys/arch/i386/i386: longrun.c

Log Message:
PR #32894: protection fault trap in tmx86_get_longrun_mode

Use rdmsr_safe in tmx86_init_longrun to verify that the MSRs are present.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/i386/longrun.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/i386/i386/longrun.c
diff -u src/sys/arch/i386/i386/longrun.c:1.3 src/sys/arch/i386/i386/longrun.c:1.4
--- src/sys/arch/i386/i386/longrun.c:1.3	Wed Feb 27 20:18:56 2008
+++ src/sys/arch/i386/i386/longrun.c	Sun Oct 23 13:02:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: longrun.c,v 1.3 2008/02/27 20:18:56 xtraeme Exp $	*/
+/*	$NetBSD: longrun.c,v 1.4 2011/10/23 13:02:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2001 Tamotsu Hattori.
@@ -35,7 +35,7 @@
  *
  */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: longrun.c,v 1.3 2008/02/27 20:18:56 xtraeme Exp $);
+__KERNEL_RCSID(0, $NetBSD: longrun.c,v 1.4 2011/10/23 13:02:32 jmcneill Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -92,6 +92,11 @@ void
 tmx86_init_longrun(void)
 {
 	const struct sysctlnode *mnode;
+	uint64_t msr;
+
+	/* PR #32894, make sure the longrun MSR is present */
+	if (rdmsr_safe(MSR_TMx86_LONGRUN, msr) == EFAULT)
+		return;
 
 	/* create the sysctl machdep.tm_longrun_* nodes */
 sysctl_createv(NULL, 0, NULL, mnode, CTLFLAG_PERMANENT,



CVS commit: src/sys/arch/i386/i386

2011-09-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Sep 28 17:27:21 UTC 2011

Modified Files:
src/sys/arch/i386/i386: linux_syscall.c

Log Message:
syscall (setcontext) can alter eax, so don't attempt to get code again from it
in order to avoid register spills.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/i386/i386/linux_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/i386/i386/linux_syscall.c
diff -u src/sys/arch/i386/i386/linux_syscall.c:1.50 src/sys/arch/i386/i386/linux_syscall.c:1.51
--- src/sys/arch/i386/i386/linux_syscall.c:1.50	Fri Nov 20 22:11:00 2009
+++ src/sys/arch/i386/i386/linux_syscall.c	Wed Sep 28 13:27:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_syscall.c,v 1.50 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: linux_syscall.c,v 1.51 2011/09/28 17:27:21 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: linux_syscall.c,v 1.50 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: linux_syscall.c,v 1.51 2011/09/28 17:27:21 christos Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_vm86.h
@@ -103,7 +103,6 @@ linux_syscall(struct trapframe *frame)
 		error = trace_enter(code, args, callp-sy_narg);
 		if (__predict_true(error == 0)) {
 			error = sy_call(callp, l, args, rval);
-			code = frame-tf_eax  (LINUX_SYS_NSYSENT - 1);
 			trace_exit(code, rval, error);
 		}
 	} else



CVS commit: src/sys/arch/i386/i386

2011-09-07 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Wed Sep  7 09:24:55 UTC 2011

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

Log Message:
Fix the illegal instruction return address. It was using the value of the
cpu's %cr2 register but thats not valid:

CR2 Contains a value called Page Fault Linear Address (PFLA). When a page
fault occurs, the address the program attempted to access is stored in the CR2
register.

And this is thus NOT the illegal instruction address!


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/sys/arch/i386/i386/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/i386/i386/trap.c
diff -u src/sys/arch/i386/i386/trap.c:1.261 src/sys/arch/i386/i386/trap.c:1.262
--- src/sys/arch/i386/i386/trap.c:1.261	Sun Apr  3 22:29:26 2011
+++ src/sys/arch/i386/i386/trap.c	Wed Sep  7 09:24:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.261 2011/04/03 22:29:26 dyoung Exp $	*/
+/*	$NetBSD: trap.c,v 1.262 2011/09/07 09:24:55 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.261 2011/04/03 22:29:26 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: trap.c,v 1.262 2011/09/07 09:24:55 reinoud Exp $);
 
 #include opt_ddb.h
 #include opt_kgdb.h
@@ -542,7 +542,7 @@
 	case T_FPOPFLT|T_USER:		/* coprocessor operand fault */
 		KSI_INIT_TRAP(ksi);
 		ksi.ksi_signo = SIGILL;
-		ksi.ksi_addr = (void *)rcr2();
+		ksi.ksi_addr = (void *) frame-tf_eip;
 		switch (type) {
 		case T_PRIVINFLT|T_USER:
 			ksi.ksi_code = ILL_PRVOPC;



CVS commit: src/sys/arch/i386/i386

2011-08-11 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug 11 11:01:31 UTC 2011

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

Log Message:
per-cpu gdt support for xen


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/i386/i386/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/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.50 src/sys/arch/i386/i386/gdt.c:1.51
--- src/sys/arch/i386/i386/gdt.c:1.50	Sat Nov 21 03:11:00 2009
+++ src/sys/arch/i386/i386/gdt.c	Thu Aug 11 11:01:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $	*/
+/*	$NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.50 2009/11/21 03:11:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: gdt.c,v 1.51 2011/08/11 11:01:30 cherry Exp $);
 
 #include opt_multiprocessor.h
 #include opt_xen.h
@@ -207,17 +207,28 @@
 		KASSERT(va = VM_MIN_KERNEL_ADDRESS);
 		ptp = kvtopte(va);
 		frames[f] = *ptp  PAGE_SHIFT;
-		pmap_pte_clearbits(ptp, PG_RW);
+		{ 
+		   /* 
+		* pmap_pte_clearbits(ptp, PG_RW);
+		* but without spl(), since %fs is not setup
+		* properly yet, ie; curcpu() won't work at this
+		* point and spl() will break.
+		*/
+		   xpq_queue_lock();
+		   xpq_queue_pte_update(xpmap_ptetomach(ptp),
+	*ptp  ~PG_RW);
+		   xpq_flush_queue();
+		   xpq_queue_unlock();
+		}
 	}
-	/* printk(loading gdt %x, %d entries, %d pages, */
-	/* frames[0]  PAGE_SHIFT, gdt_size[0], len  PAGE_SHIFT); */
+
 	if (HYPERVISOR_set_gdt(frames, gdt_size[0]))
 		panic(HYPERVISOR_set_gdt failed!\n);
 	lgdt_finish();
 #endif
 }
 
-#ifdef MULTIPROCESSOR
+#if defined(MULTIPROCESSOR)  !defined(XEN)
 
 void
 gdt_reload_cpu(struct cpu_info *ci)
@@ -255,15 +266,17 @@
 			gdt_size[which] = MINGDTSIZ;
 			new_len = gdt_size[which] * sizeof(gdt[0]);
 		}
-		for(va = (vaddr_t)(cpu_info_primary.ci_gdt) + old_len + max_len;
-		va  (vaddr_t)(cpu_info_primary.ci_gdt) + new_len + max_len;
-		va += PAGE_SIZE) {
-			while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
-			== NULL) {
-uvm_wait(gdt_grow);
+		for (CPU_INFO_FOREACH(cii, ci)) {
+			for(va = (vaddr_t)(ci-ci_gdt) + old_len + max_len;
+			va  (vaddr_t)(ci-ci_gdt) + new_len + max_len;
+			va += PAGE_SIZE) {
+while ((pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_ZERO))
+   == NULL) {
+	uvm_wait(gdt_grow);
+}
+pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
+	   VM_PROT_READ | VM_PROT_WRITE, 0);
 			}
-			pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pg),
-			VM_PROT_READ | VM_PROT_WRITE, 0);
 		}
 		return;
 	}



CVS commit: src/sys/arch/i386/i386

2011-08-10 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Wed Aug 10 06:38:02 UTC 2011

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

Log Message:
tweak the xen specific startup path to not use %fs before it is setup. Minor 
refactoring. Use Xen specific ipi calls.


To generate a diff of this commit:
cvs rdiff -u -r1.706 -r1.707 src/sys/arch/i386/i386/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/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.706 src/sys/arch/i386/i386/machdep.c:1.707
--- src/sys/arch/i386/i386/machdep.c:1.706	Fri Jul  1 18:14:15 2011
+++ src/sys/arch/i386/i386/machdep.c	Wed Aug 10 06:38:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.706 2011/07/01 18:14:15 dyoung Exp $	*/
+/*	$NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.706 2011/07/01 18:14:15 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: machdep.c,v 1.707 2011/08/10 06:38:02 cherry Exp $);
 
 #include opt_beep.h
 #include opt_compat_ibcs2.h
@@ -560,6 +560,12 @@
 
 	HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb-pcb_esp0);
 
+	/* Update TLS segment pointers */
+	update_descriptor(ci-ci_gdt[GUFS_SEL],
+			  (union descriptor *) pcb-pcb_fsd);
+	update_descriptor(ci-ci_gdt[GUGS_SEL], 
+			  (union descriptor *) pcb-pcb_gsd);
+
 	physop.cmd = PHYSDEVOP_SET_IOPL;
 	physop.u.set_iopl.iopl = pcb-pcb_iopl;
 	HYPERVISOR_physdev_op(physop);
@@ -949,8 +955,12 @@
 	}
 
 #ifdef MULTIPROCESSOR
+#ifdef XEN
+	xen_broadcast_ipi(XEN_IPI_HALT);
+#else /* XEN */
 	x86_broadcast_ipi(X86_IPI_HALT);
-#endif
+#endif /* XEN */
+#endif /* MULTIPROCESSOR */
 
 	if (howto  RB_HALT) {
 #if NACPICA  0
@@ -1123,14 +1133,18 @@
 int xen_idt_idx;
 #endif
 
-#ifndef XEN
 void cpu_init_idt(void)
 {
+#ifndef XEN
 	struct region_descriptor region;
 	setregion(region, pentium_idt, NIDT * sizeof(idt[0]) - 1);
 	lidt(region);
-}
+#else /* XEN */
+	XENPRINTF((HYPERVISOR_set_trap_table %p\n, xen_idt));
+	if (HYPERVISOR_set_trap_table(xen_idt))
+		panic(HYPERVISOR_set_trap_table %p failed\n, xen_idt);
 #endif /* !XEN */
+}
 
 void
 initgdt(union descriptor *tgdt)
@@ -1166,7 +1180,28 @@
 	lgdt(region);
 #else /* !XEN */
 	frames[0] = xpmap_ptom((uint32_t)gdt - KERNBASE)  PAGE_SHIFT;
-	pmap_kenter_pa((vaddr_t)gdt, (uint32_t)gdt - KERNBASE, VM_PROT_READ, 0);
+	{	/*
+		 * Enter the gdt page RO into the kernel map. We can't
+		 * use pmap_kenter_pa() here, because %fs is not
+		 * usable until the gdt is loaded, and %fs is used as
+		 * the base pointer for curcpu() and curlwp(), both of
+		 * which are in the callpath of pmap_kenter_pa().
+		 * So we mash up our own - this is MD code anyway.
+		 *
+		 * XXX: review this once we have finegrained locking
+		 * for xpq.
+		 */
+		pt_entry_t *pte, npte;
+		pt_entry_t pg_nx = (cpu_feature[2]  CPUID_NOX ? PG_NX : 0);
+
+		pte = kvtopte((vaddr_t)gdt);
+		npte = pmap_pa2pte((vaddr_t)gdt - KERNBASE);
+		npte |= PG_RO | pg_nx | PG_V;
+
+		xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
+		xpq_flush_queue();
+	}
+
 	XENPRINTK((loading gdt %lx, %d entries\n, frames[0]  PAGE_SHIFT,
 	NGDT));
 	if (HYPERVISOR_set_gdt(frames, NGDT /* XXX is it right ? */))
@@ -1579,10 +1614,7 @@
 	xen_idt[xen_idt_idx].address = (uint32_t)IDTVEC(svr4_fasttrap);
 	xen_idt_idx++;
 	lldt(GSEL(GLDT_SEL, SEL_KPL));
-
-	XENPRINTF((HYPERVISOR_set_trap_table %p\n, xen_idt));
-	if (HYPERVISOR_set_trap_table(xen_idt))
-		panic(HYPERVISOR_set_trap_table %p failed\n, xen_idt);
+	cpu_init_idt();
 #endif /* XEN */
 
 	init386_ksyms();



  1   2   >