[Midnightbsd-cvs] src [9993] trunk/sys/i386: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat May 26 18:09:12 EDT 2018


Revision: 9993
          http://svnweb.midnightbsd.org/src/?rev=9993
Author:   laffer1
Date:     2018-05-26 18:09:11 -0400 (Sat, 26 May 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sys/i386/include/_align.h
    trunk/sys/i386/include/_bus.h
    trunk/sys/i386/include/_inttypes.h
    trunk/sys/i386/include/_limits.h
    trunk/sys/i386/include/_stdint.h
    trunk/sys/i386/include/_types.h
    trunk/sys/i386/include/acpica_machdep.h
    trunk/sys/i386/include/apicvar.h
    trunk/sys/i386/include/apm_bios.h
    trunk/sys/i386/include/apm_segments.h
    trunk/sys/i386/include/asm.h
    trunk/sys/i386/include/asmacros.h
    trunk/sys/i386/include/atomic.h
    trunk/sys/i386/include/bootinfo.h
    trunk/sys/i386/include/bus.h
    trunk/sys/i386/include/bus_dma.h
    trunk/sys/i386/include/clock.h
    trunk/sys/i386/include/cpu.h
    trunk/sys/i386/include/cpufunc.h
    trunk/sys/i386/include/cputypes.h
    trunk/sys/i386/include/cserial.h
    trunk/sys/i386/include/db_machdep.h
    trunk/sys/i386/include/elan_mmcr.h
    trunk/sys/i386/include/elf.h
    trunk/sys/i386/include/endian.h
    trunk/sys/i386/include/exec.h
    trunk/sys/i386/include/float.h
    trunk/sys/i386/include/floatingpoint.h
    trunk/sys/i386/include/frame.h
    trunk/sys/i386/include/gdb_machdep.h
    trunk/sys/i386/include/ieeefp.h
    trunk/sys/i386/include/if_wl_wavelan.h
    trunk/sys/i386/include/in_cksum.h
    trunk/sys/i386/include/intr_machdep.h
    trunk/sys/i386/include/ioctl_bt848.h
    trunk/sys/i386/include/ioctl_meteor.h
    trunk/sys/i386/include/iodev.h
    trunk/sys/i386/include/kdb.h
    trunk/sys/i386/include/legacyvar.h
    trunk/sys/i386/include/limits.h
    trunk/sys/i386/include/md_var.h
    trunk/sys/i386/include/memdev.h
    trunk/sys/i386/include/metadata.h
    trunk/sys/i386/include/minidump.h
    trunk/sys/i386/include/mp_watchdog.h
    trunk/sys/i386/include/nexusvar.h
    trunk/sys/i386/include/npx.h
    trunk/sys/i386/include/param.h
    trunk/sys/i386/include/pc/bios.h
    trunk/sys/i386/include/pc/display.h
    trunk/sys/i386/include/pcaudioio.h
    trunk/sys/i386/include/pcb.h
    trunk/sys/i386/include/pcb_ext.h
    trunk/sys/i386/include/pci_cfgreg.h
    trunk/sys/i386/include/pcpu.h
    trunk/sys/i386/include/perfmon.h
    trunk/sys/i386/include/pmap.h
    trunk/sys/i386/include/pmc_mdep.h
    trunk/sys/i386/include/ppireg.h
    trunk/sys/i386/include/privatespace.h
    trunk/sys/i386/include/proc.h
    trunk/sys/i386/include/profile.h
    trunk/sys/i386/include/psl.h
    trunk/sys/i386/include/ptrace.h
    trunk/sys/i386/include/reg.h
    trunk/sys/i386/include/reloc.h
    trunk/sys/i386/include/resource.h
    trunk/sys/i386/include/runq.h
    trunk/sys/i386/include/segments.h
    trunk/sys/i386/include/setjmp.h
    trunk/sys/i386/include/sf_buf.h
    trunk/sys/i386/include/sigframe.h
    trunk/sys/i386/include/signal.h
    trunk/sys/i386/include/smapi.h
    trunk/sys/i386/include/smp.h
    trunk/sys/i386/include/speaker.h
    trunk/sys/i386/include/specialreg.h
    trunk/sys/i386/include/stack.h
    trunk/sys/i386/include/stdarg.h
    trunk/sys/i386/include/sysarch.h
    trunk/sys/i386/include/timerreg.h
    trunk/sys/i386/include/trap.h
    trunk/sys/i386/include/tss.h
    trunk/sys/i386/include/ucontext.h
    trunk/sys/i386/include/varargs.h
    trunk/sys/i386/include/vdso.h
    trunk/sys/i386/include/vm.h
    trunk/sys/i386/include/vm86.h
    trunk/sys/i386/include/vmparam.h
    trunk/sys/i386/include/xbox.h
    trunk/sys/i386/include/xen/features.h
    trunk/sys/i386/include/xen/hypercall.h
    trunk/sys/i386/include/xen/synch_bitops.h
    trunk/sys/i386/include/xen/xen-os.h
    trunk/sys/i386/include/xen/xen_clock_util.h
    trunk/sys/i386/include/xen/xenfunc.h
    trunk/sys/i386/include/xen/xenpmap.h
    trunk/sys/i386/include/xen/xenstored.h
    trunk/sys/i386/include/xen/xenvar.h
    trunk/sys/i386/isa/ccbque.h
    trunk/sys/i386/isa/elink.c
    trunk/sys/i386/isa/elink.h
    trunk/sys/i386/isa/npx.c
    trunk/sys/i386/isa/pmtimer.c
    trunk/sys/i386/isa/prof_machdep.c
    trunk/sys/i386/isa/spic.c
    trunk/sys/i386/isa/spicreg.h
    trunk/sys/i386/pci/pci_bus.c
    trunk/sys/i386/pci/pci_cfgreg.c
    trunk/sys/i386/pci/pci_pir.c

Modified: trunk/sys/i386/include/_align.h
===================================================================
--- trunk/sys/i386/include/_align.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_align.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/_align.h 215856 2010-11-26 10:59:20Z tijl $ */
 
 #include <x86/_align.h>

Modified: trunk/sys/i386/include/_bus.h
===================================================================
--- trunk/sys/i386/include/_bus.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_bus.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 M. Warner Losh.
  * All rights reserved.
@@ -25,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/_bus.h 145253 2005-04-18 21:45:34Z imp $
  */
 
 #ifndef I386_INCLUDE__BUS_H

Modified: trunk/sys/i386/include/_inttypes.h
===================================================================
--- trunk/sys/i386/include/_inttypes.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_inttypes.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/_inttypes.h 217157 2011-01-08 18:09:48Z tijl $ */
 
 #include <x86/_inttypes.h>

Modified: trunk/sys/i386/include/_limits.h
===================================================================
--- trunk/sys/i386/include/_limits.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_limits.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,87 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1988, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)limits.h	8.3 (Berkeley) 1/4/94
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/_limits.h 232262 2012-02-28 18:24:28Z tijl $ */
 
-#ifndef _MACHINE__LIMITS_H_
-#define	_MACHINE__LIMITS_H_
-
-/*
- * According to ANSI (section 2.2.4.2), the values below must be usable by
- * #if preprocessing directives.  Additionally, the expression must have the
- * same type as would an expression that is an object of the corresponding
- * type converted according to the integral promotions.  The subtraction for
- * INT_MIN, etc., is so the value is not unsigned; e.g., 0x80000000 is an
- * unsigned int for 32-bit two's complement ANSI compilers (section 3.1.3.2).
- */
-
-#define	__CHAR_BIT	8		/* number of bits in a char */
-
-#define	__SCHAR_MAX	0x7f		/* max value for a signed char */
-#define	__SCHAR_MIN	(-0x7f - 1)	/* min value for a signed char */
-
-#define	__UCHAR_MAX	0xff		/* max value for an unsigned char */
-
-#define	__USHRT_MAX	0xffff		/* max value for an unsigned short */
-#define	__SHRT_MAX	0x7fff		/* max value for a short */
-#define	__SHRT_MIN	(-0x7fff - 1)	/* min value for a short */
-
-#define	__UINT_MAX	0xffffffff	/* max value for an unsigned int */
-#define	__INT_MAX	0x7fffffff	/* max value for an int */
-#define	__INT_MIN	(-0x7fffffff - 1)	/* min value for an int */
-
-#define	__ULONG_MAX	0xffffffffUL	/* max value for an unsigned long */
-#define	__LONG_MAX	0x7fffffffL	/* max value for a long */
-#define	__LONG_MIN	(-0x7fffffffL - 1)	/* min value for a long */
-
-			/* max value for an unsigned long long */
-#define	__ULLONG_MAX	0xffffffffffffffffULL
-#define	__LLONG_MAX	0x7fffffffffffffffLL	/* max value for a long long */
-#define	__LLONG_MIN	(-0x7fffffffffffffffLL - 1)  /* min for a long long */
-
-#define	__SSIZE_MAX	__INT_MAX	/* max value for a ssize_t */
-
-#define	__SIZE_T_MAX	__UINT_MAX	/* max value for a size_t */
-
-#define	__OFF_MAX	__LLONG_MAX	/* max value for an off_t */
-#define	__OFF_MIN	__LLONG_MIN	/* min value for an off_t */
-
-/* Quads and long longs are the same size.  Ensure they stay in sync. */
-#define	__UQUAD_MAX	__ULLONG_MAX	/* max value for a uquad_t */
-#define	__QUAD_MAX	__LLONG_MAX	/* max value for a quad_t */
-#define	__QUAD_MIN	__LLONG_MIN	/* min value for a quad_t */
-
-#define	__LONG_BIT	32
-#define	__WORD_BIT	32
-
-/* Minimum signal stack size. */
-#define	__MINSIGSTKSZ	(512 * 4)
-
-#endif /* !_MACHINE__LIMITS_H_ */
+#include <x86/_limits.h>

Modified: trunk/sys/i386/include/_stdint.h
===================================================================
--- trunk/sys/i386/include/_stdint.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_stdint.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,171 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2001, 2002 Mike Barcroft <mike at FreeBSD.org>
- * Copyright (c) 2001 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Klaus Klein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/_stdint.h 232264 2012-02-28 18:38:33Z tijl $ */
 
-#ifndef _MACHINE__STDINT_H_
-#define	_MACHINE__STDINT_H_
-
-#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
-
-#define	INT8_C(c)		(c)
-#define	INT16_C(c)		(c)
-#define	INT32_C(c)		(c)
-#define	INT64_C(c)		(c ## LL)
-
-#define	UINT8_C(c)		(c)
-#define	UINT16_C(c)		(c)
-#define	UINT32_C(c)		(c ## U)
-#define	UINT64_C(c)		(c ## ULL)
-
-#define	INTMAX_C(c)		INT64_C(c)
-#define	UINTMAX_C(c)		UINT64_C(c)
-
-#endif /* !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) */
-
-#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.2.1 Limits of exact-width integer types
- */
-/* Minimum values of exact-width signed integer types. */
-#define	INT8_MIN	(-0x7f-1)
-#define	INT16_MIN	(-0x7fff-1)
-#define	INT32_MIN	(-0x7fffffff-1)
-#define	INT64_MIN	(-0x7fffffffffffffffLL-1)
-
-/* Maximum values of exact-width signed integer types. */
-#define	INT8_MAX	0x7f
-#define	INT16_MAX	0x7fff
-#define	INT32_MAX	0x7fffffff
-#define	INT64_MAX	0x7fffffffffffffffLL
-
-/* Maximum values of exact-width unsigned integer types. */
-#define	UINT8_MAX	0xff
-#define	UINT16_MAX	0xffff
-#define	UINT32_MAX	0xffffffffU
-#define	UINT64_MAX	0xffffffffffffffffULL
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.2.2  Limits of minimum-width integer types
- */
-/* Minimum values of minimum-width signed integer types. */
-#define	INT_LEAST8_MIN	INT8_MIN
-#define	INT_LEAST16_MIN	INT16_MIN
-#define	INT_LEAST32_MIN	INT32_MIN
-#define	INT_LEAST64_MIN	INT64_MIN
-
-/* Maximum values of minimum-width signed integer types. */
-#define	INT_LEAST8_MAX	INT8_MAX
-#define	INT_LEAST16_MAX	INT16_MAX
-#define	INT_LEAST32_MAX	INT32_MAX
-#define	INT_LEAST64_MAX	INT64_MAX
-
-/* Maximum values of minimum-width unsigned integer types. */
-#define	UINT_LEAST8_MAX	 UINT8_MAX
-#define	UINT_LEAST16_MAX UINT16_MAX
-#define	UINT_LEAST32_MAX UINT32_MAX
-#define	UINT_LEAST64_MAX UINT64_MAX
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.2.3  Limits of fastest minimum-width integer types
- */
-/* Minimum values of fastest minimum-width signed integer types. */
-#define	INT_FAST8_MIN	INT32_MIN
-#define	INT_FAST16_MIN	INT32_MIN
-#define	INT_FAST32_MIN	INT32_MIN
-#define	INT_FAST64_MIN	INT64_MIN
-
-/* Maximum values of fastest minimum-width signed integer types. */
-#define	INT_FAST8_MAX	INT32_MAX
-#define	INT_FAST16_MAX	INT32_MAX
-#define	INT_FAST32_MAX	INT32_MAX
-#define	INT_FAST64_MAX	INT64_MAX
-
-/* Maximum values of fastest minimum-width unsigned integer types. */
-#define	UINT_FAST8_MAX	UINT32_MAX
-#define	UINT_FAST16_MAX	UINT32_MAX
-#define	UINT_FAST32_MAX	UINT32_MAX
-#define	UINT_FAST64_MAX	UINT64_MAX
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.2.4  Limits of integer types capable of holding object pointers
- */
-#define	INTPTR_MIN	INT32_MIN
-#define	INTPTR_MAX	INT32_MAX
-#define	UINTPTR_MAX	UINT32_MAX
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.2.5  Limits of greatest-width integer types
- */
-#define	INTMAX_MIN	INT64_MIN
-#define	INTMAX_MAX	INT64_MAX
-#define	UINTMAX_MAX	UINT64_MAX
-
-/*
- * ISO/IEC 9899:1999
- * 7.18.3  Limits of other integer types
- */
-/* Limits of ptrdiff_t. */
-#define	PTRDIFF_MIN	INT32_MIN	
-#define	PTRDIFF_MAX	INT32_MAX
-
-/* Limits of sig_atomic_t. */
-#define	SIG_ATOMIC_MIN	INT32_MIN
-#define	SIG_ATOMIC_MAX	INT32_MAX
-
-/* Limit of size_t. */
-#define	SIZE_MAX	UINT32_MAX
-
-#ifndef WCHAR_MIN /* Also possibly defined in <wchar.h> */
-/* Limits of wchar_t. */
-#define	WCHAR_MIN	INT32_MIN
-#define	WCHAR_MAX	INT32_MAX
-#endif
-
-/* Limits of wint_t. */
-#define	WINT_MIN	INT32_MIN
-#define	WINT_MAX	INT32_MAX
-
-#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
-
-#endif /* !_MACHINE__STDINT_H_ */
+#include <x86/_stdint.h>

Modified: trunk/sys/i386/include/_types.h
===================================================================
--- trunk/sys/i386/include/_types.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/_types.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,128 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2002 Mike Barcroft <mike at FreeBSD.org>
- * Copyright (c) 1990, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	From: @(#)ansi.h	8.2 (Berkeley) 1/4/94
- *	From: @(#)types.h	8.3 (Berkeley) 1/5/94
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/_types.h 232261 2012-02-28 18:15:28Z tijl $ */
 
-#ifndef _MACHINE__TYPES_H_
-#define	_MACHINE__TYPES_H_
-
-#ifndef _SYS_CDEFS_H_
-#error this file needs sys/cdefs.h as a prerequisite
-#endif
-
-#define __NO_STRICT_ALIGNMENT
-
-/*
- * Basic types upon which most other types are built.
- */
-typedef	__signed char		__int8_t;
-typedef	unsigned char		__uint8_t;
-typedef	short			__int16_t;
-typedef	unsigned short		__uint16_t;
-typedef	int			__int32_t;
-typedef	unsigned int		__uint32_t;
-#ifndef lint
-__extension__
-#endif
-/* LONGLONG */
-typedef	long long		__int64_t;
-#ifndef lint
-__extension__
-#endif
-/* LONGLONG */
-typedef	unsigned long long	__uint64_t;
-
-/*
- * Standard type definitions.
- */
-typedef	unsigned long	__clock_t;		/* clock()... */
-typedef	__int32_t	__critical_t;
-typedef	long double	__double_t;
-typedef	long double	__float_t;
-typedef	__int32_t	__intfptr_t;
-typedef	__int64_t	__intmax_t;
-typedef	__int32_t	__intptr_t;
-typedef	__int32_t	__int_fast8_t;
-typedef	__int32_t	__int_fast16_t;
-typedef	__int32_t	__int_fast32_t;
-typedef	__int64_t	__int_fast64_t;
-typedef	__int8_t	__int_least8_t;
-typedef	__int16_t	__int_least16_t;
-typedef	__int32_t	__int_least32_t;
-typedef	__int64_t	__int_least64_t;
-typedef	__int32_t	__ptrdiff_t;		/* ptr1 - ptr2 */
-typedef	__int32_t	__register_t;
-typedef	__int32_t	__segsz_t;		/* segment size (in pages) */
-typedef	__uint32_t	__size_t;		/* sizeof() */
-typedef	__int32_t	__ssize_t;		/* byte count or error */
-typedef	__int32_t	__time_t;		/* time()... */
-typedef	__uint32_t	__uintfptr_t;
-typedef	__uint64_t	__uintmax_t;
-typedef	__uint32_t	__uintptr_t;
-typedef	__uint32_t	__uint_fast8_t;
-typedef	__uint32_t	__uint_fast16_t;
-typedef	__uint32_t	__uint_fast32_t;
-typedef	__uint64_t	__uint_fast64_t;
-typedef	__uint8_t	__uint_least8_t;
-typedef	__uint16_t	__uint_least16_t;
-typedef	__uint32_t	__uint_least32_t;
-typedef	__uint64_t	__uint_least64_t;
-typedef	__uint32_t	__u_register_t;
-typedef	__uint32_t	__vm_offset_t;
-typedef	__int64_t	__vm_ooffset_t;
-#ifdef PAE
-typedef	__uint64_t	__vm_paddr_t;
-#else
-typedef	__uint32_t	__vm_paddr_t;
-#endif
-typedef	__uint64_t	__vm_pindex_t;
-typedef	__uint32_t	__vm_size_t;
-
-/*
- * Unusual type definitions.
- */
-#ifdef __GNUCLIKE_BUILTIN_VARARGS
-typedef __builtin_va_list	__va_list;	/* internally known to gcc */
-#else
-typedef	char *			__va_list;
-#endif /* __GNUCLIKE_BUILTIN_VARARGS */
-#if defined(__GNUC_VA_LIST_COMPATIBILITY) && !defined(__GNUC_VA_LIST) \
-    && !defined(__NO_GNUC_VA_LIST)
-#define __GNUC_VA_LIST
-typedef __va_list		__gnuc_va_list;	/* compatibility w/GNU headers*/
-#endif
-
-#endif /* !_MACHINE__TYPES_H_ */
+#include <x86/_types.h>

Modified: trunk/sys/i386/include/acpica_machdep.h
===================================================================
--- trunk/sys/i386/include/acpica_machdep.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/acpica_machdep.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,104 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2002 Mitsuru IWASAKI
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/acpica_machdep.h 254305 2013-08-13 22:05:10Z jkim $ */
 
-/******************************************************************************
- *
- * Name: acpica_machdep.h - arch-specific defines, etc.
- *       $Revision: 1.4 $
- *
- *****************************************************************************/
-
-#ifndef __ACPICA_MACHDEP_H__
-#define	__ACPICA_MACHDEP_H__
-
-#ifdef _KERNEL
-/*
- * Calling conventions:
- *
- * ACPI_SYSTEM_XFACE        - Interfaces to host OS (handlers, threads)
- * ACPI_EXTERNAL_XFACE      - External ACPI interfaces 
- * ACPI_INTERNAL_XFACE      - Internal ACPI interfaces
- * ACPI_INTERNAL_VAR_XFACE  - Internal variable-parameter list interfaces
- */
-#define	ACPI_SYSTEM_XFACE
-#define	ACPI_EXTERNAL_XFACE
-#define	ACPI_INTERNAL_XFACE
-#define	ACPI_INTERNAL_VAR_XFACE
-
-/* Asm macros */
-
-#define	ACPI_ASM_MACROS
-#define	BREAKPOINT3
-#define	ACPI_DISABLE_IRQS() disable_intr()
-#define	ACPI_ENABLE_IRQS()  enable_intr()
-
-#define	ACPI_FLUSH_CPU_CACHE()	wbinvd()
-
-/* Section 5.2.9.1:  global lock acquire/release functions */
-extern int	acpi_acquire_global_lock(uint32_t *lock);
-extern int	acpi_release_global_lock(uint32_t *lock);
-#define	ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq)	do {			\
-	(Acq) = acpi_acquire_global_lock(&((GLptr)->GlobalLock));	\
-} while (0)
-#define	ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq)	do {			\
-	(Acq) = acpi_release_global_lock(&((GLptr)->GlobalLock));	\
-} while (0)
-
-/*! [Begin] no source code translation
- *
- * Math helper asm macros
- */
-#define	asm         __asm
-#define	ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \
-        asm("divl %2;"        \
-        :"=a"(q32), "=d"(r32) \
-        :"r"(d32),            \
-        "0"(n_lo), "1"(n_hi))
-
-
-#define	ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \
-    asm("shrl   $1,%2;"             \
-        "rcrl   $1,%3;"             \
-        :"=r"(n_hi), "=r"(n_lo)     \
-        :"0"(n_hi), "1"(n_lo))
-
-/*! [End] no source code translation !*/
-#endif /* _KERNEL */
-
-#define	ACPI_MACHINE_WIDTH             32
-#define	COMPILER_DEPENDENT_INT64       long long
-#define	COMPILER_DEPENDENT_UINT64      unsigned long long
-#define	ACPI_USE_NATIVE_DIVIDE
-
-void	acpi_SetDefaultIntrModel(int model);
-void	acpi_cpu_c1(void);
-void	*acpi_map_table(vm_paddr_t pa, const char *sig);
-void	acpi_unmap_table(void *table);
-vm_paddr_t acpi_find_table(const char *sig);
-
-#endif /* __ACPICA_MACHDEP_H__ */
+#include <x86/acpica_machdep.h>

Modified: trunk/sys/i386/include/apicvar.h
===================================================================
--- trunk/sys/i386/include/apicvar.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/apicvar.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 John Baldwin <jhb at FreeBSD.org>
  * All rights reserved.
@@ -10,9 +11,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the names of any co-contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -26,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/apicvar.h 302165 2016-06-24 01:20:33Z sephe $
  */
 
 #ifndef _MACHINE_APICVAR_H_
@@ -103,8 +101,6 @@
  */ 
 
 /* Interrupts for local APIC LVT entries other than the timer. */
-#ifdef XEN
-/* These are the Xen i386 APIC definitions */
 #define	APIC_LOCAL_INTS	240
 #define	APIC_ERROR_INT	APIC_LOCAL_INTS
 #define	APIC_THERMAL_INT (APIC_LOCAL_INTS + 1)
@@ -111,34 +107,6 @@
 #define	APIC_CMC_INT	(APIC_LOCAL_INTS + 2)
 #define	APIC_IPI_INTS	(APIC_LOCAL_INTS + 3)
 
-#define	IPI_RENDEZVOUS		(APIC_IPI_INTS)	/* Inter-CPU rendezvous. */
-#define	IPI_INVLTLB		(APIC_IPI_INTS + 1)	/* TLB Shootdown IPIs */
-#define	IPI_INVLPG		(APIC_IPI_INTS + 2)
-#define	IPI_INVLRNG		(APIC_IPI_INTS + 3)
-#define	IPI_INVLCACHE		(APIC_IPI_INTS + 4)
-#define	IPI_LAZYPMAP		(APIC_IPI_INTS + 5)	/* Lazy pmap release. */
-/* Vector to handle bitmap based IPIs */
-#define	IPI_BITMAP_VECTOR	(APIC_IPI_INTS + 6)
-
-/* IPIs handled by IPI_BITMAPED_VECTOR  (XXX ups is there a better place?) */
-#define	IPI_AST		0 	/* Generate software trap. */
-#define IPI_PREEMPT     1
-#define IPI_HARDCLOCK   2 
-#define IPI_BITMAP_LAST IPI_HARDCLOCK
-#define IPI_IS_BITMAPED(x) ((x) <= IPI_BITMAP_LAST)
-
-#define	IPI_STOP	(APIC_IPI_INTS + 7)	/* Stop CPU until restarted. */
-#define	IPI_SUSPEND	(APIC_IPI_INTS + 8)	/* Suspend CPU until restarted. */
-#define	IPI_STOP_HARD	(APIC_IPI_INTS + 9)	/* Stop CPU with a NMI. */
-
-#else /* XEN */
-/* These are the normal i386 APIC definitions */
-#define	APIC_LOCAL_INTS	240
-#define	APIC_ERROR_INT	APIC_LOCAL_INTS
-#define	APIC_THERMAL_INT (APIC_LOCAL_INTS + 1)
-#define	APIC_CMC_INT	(APIC_LOCAL_INTS + 2)
-#define	APIC_IPI_INTS	(APIC_LOCAL_INTS + 3)
-
 #define	IPI_RENDEZVOUS	(APIC_IPI_INTS)		/* Inter-CPU rendezvous. */
 #define	IPI_INVLTLB	(APIC_IPI_INTS + 1)	/* TLB Shootdown IPIs */
 #define	IPI_INVLPG	(APIC_IPI_INTS + 2)
@@ -158,7 +126,6 @@
 #define	IPI_STOP	(APIC_IPI_INTS + 7)	/* Stop CPU until restarted. */
 #define	IPI_SUSPEND	(APIC_IPI_INTS + 8)	/* Suspend CPU until restarted. */
 #define	IPI_STOP_HARD	(APIC_IPI_INTS + 9)	/* Stop CPU with a NMI. */
-#endif /* XEN */
 
 /*
  * The spurious interrupt can share the priority class with the IPIs since
@@ -166,15 +133,6 @@
  */
 #define	APIC_SPURIOUS_INT 255
 
-#define	LVT_LINT0	0
-#define	LVT_LINT1	1
-#define	LVT_TIMER	2
-#define	LVT_ERROR	3
-#define	LVT_PMC		4
-#define	LVT_THERMAL	5
-#define	LVT_CMCI	6
-#define	LVT_MAX		LVT_CMCI
-
 #ifndef LOCORE
 
 #define	APIC_IPI_DEST_SELF	-1
@@ -257,6 +215,7 @@
 	    enum intr_trigger trigger);
 void	lapic_set_tpr(u_int vector);
 void	lapic_setup(int boot);
+void	xen_intr_handle_upcall(struct trapframe *frame);
 
 #endif /* !LOCORE */
 #endif /* _MACHINE_APICVAR_H_ */

Modified: trunk/sys/i386/include/apm_bios.h
===================================================================
--- trunk/sys/i386/include/apm_bios.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/apm_bios.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/apm_bios.h 215140 2010-11-11 19:36:21Z jkim $ */
 
 #include <x86/apm_bios.h>

Modified: trunk/sys/i386/include/apm_segments.h
===================================================================
--- trunk/sys/i386/include/apm_segments.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/apm_segments.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * LP (Laptop Package)
  *
@@ -12,7 +13,7 @@
  *
  * Sep., 1994	Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/apm_segments.h 139790 2005-01-06 22:18:23Z imp $
  */
 
 #ifndef _MACHINE_APM_SEGMENTS_H

Modified: trunk/sys/i386/include/asm.h
===================================================================
--- trunk/sys/i386/include/asm.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/asm.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)DEFS.h	5.1 (Berkeley) 4/23/90
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/asm.h 254463 2013-08-17 19:24:58Z jilles $
  */
 
 #ifndef _MACHINE_ASM_H_
@@ -49,11 +50,12 @@
 	popl	%ebx
 #define	PIC_PLT(x)	x at PLT
 #define	PIC_GOT(x)	x at GOT(%ebx)
+#define	PIC_GOTOFF(x)	x at GOTOFF(%ebx)
 #else
 #define	PIC_PROLOGUE
 #define	PIC_EPILOGUE
 #define	PIC_PLT(x)	x
-#define	PIC_GOT(x)	x
+#define	PIC_GOTOFF(x)	x
 #endif
 
 /*
@@ -89,6 +91,20 @@
 #define	ENTRY(x)	_ENTRY(x)
 #endif
 
+/*
+ * WEAK_ALIAS: create a weak alias.
+ */
+#define	WEAK_ALIAS(alias,sym)						\
+	.weak alias;							\
+	alias = sym
+
+/*
+ * STRONG_ALIAS: create a strong alias.
+ */
+#define	STRONG_ALIAS(alias,sym)						\
+	.globl alias;							\
+	alias = sym
+
 #define RCSID(x)	.text; .asciz x
 
 #undef __FBSDID

Modified: trunk/sys/i386/include/asmacros.h
===================================================================
--- trunk/sys/i386/include/asmacros.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/asmacros.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1993 The Regents of the University of California.
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/asmacros.h 290668 2015-11-11 01:32:35Z jhb $
  */
 
 #ifndef _MACHINE_ASMACROS_H_
@@ -146,9 +147,12 @@
 	pushl	$0 ;		/* dummy error code */			\
 	pushl	$0 ;		/* dummy trap type */			\
 	pushal ;		/* 8 ints */				\
-	pushl	%ds ;		/* save data and extra segments ... */	\
-	pushl	%es ;							\
-	pushl	%fs
+	pushl	$0 ;		/* save data and extra segments ... */	\
+	movw	%ds,(%esp) ;						\
+	pushl	$0 ;							\
+	movw	%es,(%esp) ;						\
+	pushl	$0 ;							\
+	movw	%fs,(%esp)
 	
 #define	POP_FRAME							\
 	popl	%fs ;							\

Modified: trunk/sys/i386/include/atomic.h
===================================================================
--- trunk/sys/i386/include/atomic.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/atomic.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1998 Doug Rabson
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/atomic.h 326515 2017-12-04 09:46:08Z hselasky $
  */
 #ifndef _MACHINE_ATOMIC_H_
 #define	_MACHINE_ATOMIC_H_
@@ -32,6 +33,11 @@
 #error this file needs sys/cdefs.h as a prerequisite
 #endif
 
+#ifdef _KERNEL
+#include <machine/md_var.h>
+#include <machine/specialreg.h>
+#endif
+
 #define	mb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory", "cc")
 #define	wmb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory", "cc")
 #define	rmb()	__asm __volatile("lock; addl $0,(%%esp)" : : : "memory", "cc")
@@ -54,6 +60,7 @@
  * atomic_clear_int(P, V)	(*(u_int *)(P) &= ~(V))
  * atomic_add_int(P, V)		(*(u_int *)(P) += (V))
  * atomic_subtract_int(P, V)	(*(u_int *)(P) -= (V))
+ * atomic_swap_int(P, V)	(return (*(u_int *)(P)); *(u_int *)(P) = (V);)
  * atomic_readandclear_int(P)	(return (*(u_int *)(P)); *(u_int *)(P) = 0;)
  *
  * atomic_set_long(P, V)	(*(u_long *)(P) |= (V))
@@ -60,6 +67,7 @@
  * atomic_clear_long(P, V)	(*(u_long *)(P) &= ~(V))
  * atomic_add_long(P, V)	(*(u_long *)(P) += (V))
  * atomic_subtract_long(P, V)	(*(u_long *)(P) -= (V))
+ * atomic_swap_long(P, V)	(return (*(u_long *)(P)); *(u_long *)(P) = (V);)
  * atomic_readandclear_long(P)	(return (*(u_long *)(P)); *(u_long *)(P) = 0;)
  */
 
@@ -78,6 +86,8 @@
 
 int	atomic_cmpset_int(volatile u_int *dst, u_int expect, u_int src);
 u_int	atomic_fetchadd_int(volatile u_int *p, u_int v);
+int	atomic_testandset_int(volatile u_int *p, u_int v);
+int	atomic_testandclear_int(volatile u_int *p, u_int v);
 
 #define	ATOMIC_LOAD(TYPE, LOP)					\
 u_##TYPE	atomic_load_acq_##TYPE(volatile u_##TYPE *p)
@@ -84,6 +94,12 @@
 #define	ATOMIC_STORE(TYPE)					\
 void		atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)
 
+int		atomic_cmpset_64(volatile uint64_t *, uint64_t, uint64_t);
+uint64_t	atomic_load_acq_64(volatile uint64_t *);
+void		atomic_store_rel_64(volatile uint64_t *, uint64_t);
+uint64_t	atomic_swap_64(volatile uint64_t *, uint64_t);
+uint64_t	atomic_fetchadd_64(volatile uint64_t *, uint64_t);
+
 #else /* !KLD_MODULE && __GNUCLIKE_ASM */
 
 /*
@@ -106,8 +122,8 @@
 atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "cc");					\
 }							\
 							\
@@ -115,93 +131,12 @@
 atomic_##NAME##_barr_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
 	__asm __volatile(MPLOCKED OP			\
-	: "=m" (*p)					\
-	: CONS (V), "m" (*p)				\
+	: "+m" (*p)					\
+	: CONS (V)					\
 	: "memory", "cc");				\
 }							\
 struct __hack
 
-#if defined(_KERNEL) && !defined(WANT_FUNCTIONS)
-
-/* I486 does not support SMP or CMPXCHG8B. */
-static __inline uint64_t
-atomic_load_acq_64_i386(volatile uint64_t *p)
-{
-	volatile uint32_t *high, *low;
-	uint64_t res;
-
-	low = (volatile uint32_t *)p;
-	high = (volatile uint32_t *)p + 1;
-	__asm __volatile(
-	"	pushfl ;		"
-	"	cli ;			"
-	"	movl %1,%%eax ;		"
-	"	movl %2,%%edx ;		"
-	"	popfl"
-	: "=&A" (res)			/* 0 */
-	: "m" (*low),			/* 1 */
-	  "m" (*high)			/* 2 */
-	: "memory");
-
-	return (res);
-}
-
-static __inline void
-atomic_store_rel_64_i386(volatile uint64_t *p, uint64_t v)
-{
-	volatile uint32_t *high, *low;
-
-	low = (volatile uint32_t *)p;
-	high = (volatile uint32_t *)p + 1;
-	__asm __volatile(
-	"	pushfl ;		"
-	"	cli ;			"
-	"	movl %%eax,%0 ;		"
-	"	movl %%edx,%1 ;		"
-	"	popfl"
-	: "=m" (*low),			/* 0 */
-	  "=m" (*high)			/* 1 */
-	: "A" (v)			/* 2 */
-	: "memory");
-}
-
-static __inline uint64_t
-atomic_load_acq_64_i586(volatile uint64_t *p)
-{
-	uint64_t res;
-
-	__asm __volatile(
-	"	movl %%ebx,%%eax ;	"
-	"	movl %%ecx,%%edx ;	"
-	"	" MPLOCKED "		"
-	"	cmpxchg8b %2"
-	: "=&A" (res),			/* 0 */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "memory", "cc");
-
-	return (res);
-}
-
-static __inline void
-atomic_store_rel_64_i586(volatile uint64_t *p, uint64_t v)
-{
-
-	__asm __volatile(
-	"	movl %%eax,%%ebx ;	"
-	"	movl %%edx,%%ecx ;	"
-	"1:				"
-	"	" MPLOCKED "		"
-	"	cmpxchg8b %2 ;		"
-	"	jne 1b"
-	: "=m" (*p),			/* 0 */
-	  "+A" (v)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "ebx", "ecx", "memory", "cc");
-}
-
-#endif /* _KERNEL && !WANT_FUNCTIONS */
-
 /*
  * Atomic compare and set, used by the mutex functions
  *
@@ -220,7 +155,7 @@
 	__asm __volatile(
 	"	pushfl ;		"
 	"	cli ;			"
-	"	cmpl	%3,%4 ;		"
+	"	cmpl	%3,%1 ;		"
 	"	jne	1f ;		"
 	"	movl	%2,%1 ;		"
 	"1:				"
@@ -228,12 +163,10 @@
 	"	popfl ;			"
 	"# atomic_cmpset_int"
 	: "=q" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
+	  "+m" (*dst)			/* 1 */
 	: "r" (src),			/* 2 */
-	  "r" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	  "r" (expect)			/* 3 */
 	: "memory");
-
 	return (res);
 }
 
@@ -246,17 +179,14 @@
 
 	__asm __volatile(
 	"	" MPLOCKED "		"
-	"	cmpxchgl %2,%1 ;	"
+	"	cmpxchgl %3,%1 ;	"
 	"       sete	%0 ;		"
-	"1:				"
 	"# atomic_cmpset_int"
-	: "=a" (res),			/* 0 */
-	  "=m" (*dst)			/* 1 */
-	: "r" (src),			/* 2 */
-	  "a" (expect),			/* 3 */
-	  "m" (*dst)			/* 4 */
+	: "=q" (res),			/* 0 */
+	  "+m" (*dst),			/* 1 */
+	  "+a" (expect)			/* 2 */
+	: "r" (src)			/* 3 */
 	: "memory", "cc");
-
 	return (res);
 }
 
@@ -272,15 +202,48 @@
 
 	__asm __volatile(
 	"	" MPLOCKED "		"
-	"	xaddl	%0, %1 ;	"
+	"	xaddl	%0,%1 ;		"
 	"# atomic_fetchadd_int"
-	: "+r" (v),			/* 0 (result) */
-	  "=m" (*p)			/* 1 */
-	: "m" (*p)			/* 2 */
-	: "cc");
+	: "+r" (v),			/* 0 */
+	  "+m" (*p)			/* 1 */
+	: : "cc");
 	return (v);
 }
 
+static __inline int
+atomic_testandset_int(volatile u_int *p, u_int v)
+{
+	u_char res;
+
+	__asm __volatile(
+	"	" MPLOCKED "		"
+	"	btsl	%2,%1 ;		"
+	"	setc	%0 ;		"
+	"# atomic_testandset_int"
+	: "=q" (res),			/* 0 */
+	  "+m" (*p)			/* 1 */
+	: "Ir" (v & 0x1f)		/* 2 */
+	: "cc");
+	return (res);
+}
+
+static __inline int
+atomic_testandclear_int(volatile u_int *p, u_int v)
+{
+	u_char res;
+
+	__asm __volatile(
+	"	" MPLOCKED "		"
+	"	btrl	%2,%1 ;		"
+	"	setc	%0 ;		"
+	"# atomic_testandclear_int"
+	: "=q" (res),			/* 0 */
+	  "+m" (*p)			/* 1 */
+	: "Ir" (v & 0x1f)		/* 2 */
+	: "cc");
+	return (res);
+}
+
 /*
  * We assume that a = b will do atomic loads and stores.  Due to the
  * IA32 memory model, a simple store guarantees release semantics.
@@ -296,7 +259,7 @@
 static __inline void					\
 atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
 {							\
-	__asm __volatile("" : : : "memory");		\
+	__compiler_membar();				\
 	*p = v;						\
 }							\
 struct __hack
@@ -310,7 +273,7 @@
 	u_##TYPE tmp;					\
 							\
 	tmp = *p;					\
-	__asm __volatile("" : : : "memory");		\
+	__compiler_membar();				\
 	return (tmp);					\
 }							\
 struct __hack
@@ -325,10 +288,8 @@
 							\
 	__asm __volatile(MPLOCKED LOP			\
 	: "=a" (res),			/* 0 */		\
-	  "=m" (*p)			/* 1 */		\
-	: "m" (*p)			/* 2 */		\
-	: "memory", "cc");				\
-							\
+	  "+m" (*p)			/* 1 */		\
+	: : "memory", "cc");				\
 	return (res);					\
 }							\
 struct __hack
@@ -335,6 +296,230 @@
 
 #endif /* _KERNEL && !SMP */
 
+#ifdef _KERNEL
+
+#ifdef WANT_FUNCTIONS
+int		atomic_cmpset_64_i386(volatile uint64_t *, uint64_t, uint64_t);
+int		atomic_cmpset_64_i586(volatile uint64_t *, uint64_t, uint64_t);
+uint64_t	atomic_load_acq_64_i386(volatile uint64_t *);
+uint64_t	atomic_load_acq_64_i586(volatile uint64_t *);
+void		atomic_store_rel_64_i386(volatile uint64_t *, uint64_t);
+void		atomic_store_rel_64_i586(volatile uint64_t *, uint64_t);
+uint64_t	atomic_swap_64_i386(volatile uint64_t *, uint64_t);
+uint64_t	atomic_swap_64_i586(volatile uint64_t *, uint64_t);
+#endif
+
+/* I486 does not support SMP or CMPXCHG8B. */
+static __inline int
+atomic_cmpset_64_i386(volatile uint64_t *dst, uint64_t expect, uint64_t src)
+{
+	volatile uint32_t *p;
+	u_char res;
+
+	p = (volatile uint32_t *)dst;
+	__asm __volatile(
+	"	pushfl ;		"
+	"	cli ;			"
+	"	xorl	%1,%%eax ;	"
+	"	xorl	%2,%%edx ;	"
+	"	orl	%%edx,%%eax ;	"
+	"	jne	1f ;		"
+	"	movl	%4,%1 ;		"
+	"	movl	%5,%2 ;		"
+	"1:				"
+	"	sete	%3 ;		"
+	"	popfl"
+	: "+A" (expect),		/* 0 */
+	  "+m" (*p),			/* 1 */
+	  "+m" (*(p + 1)),		/* 2 */
+	  "=q" (res)			/* 3 */
+	: "r" ((uint32_t)src),		/* 4 */
+	  "r" ((uint32_t)(src >> 32))	/* 5 */
+	: "memory", "cc");
+	return (res);
+}
+
+static __inline uint64_t
+atomic_load_acq_64_i386(volatile uint64_t *p)
+{
+	volatile uint32_t *q;
+	uint64_t res;
+
+	q = (volatile uint32_t *)p;
+	__asm __volatile(
+	"	pushfl ;		"
+	"	cli ;			"
+	"	movl	%1,%%eax ;	"
+	"	movl	%2,%%edx ;	"
+	"	popfl"
+	: "=&A" (res)			/* 0 */
+	: "m" (*q),			/* 1 */
+	  "m" (*(q + 1))		/* 2 */
+	: "memory");
+	return (res);
+}
+
+static __inline void
+atomic_store_rel_64_i386(volatile uint64_t *p, uint64_t v)
+{
+	volatile uint32_t *q;
+
+	q = (volatile uint32_t *)p;
+	__asm __volatile(
+	"	pushfl ;		"
+	"	cli ;			"
+	"	movl	%%eax,%0 ;	"
+	"	movl	%%edx,%1 ;	"
+	"	popfl"
+	: "=m" (*q),			/* 0 */
+	  "=m" (*(q + 1))		/* 1 */
+	: "A" (v)			/* 2 */
+	: "memory");
+}
+
+static __inline uint64_t
+atomic_swap_64_i386(volatile uint64_t *p, uint64_t v)
+{
+	volatile uint32_t *q;
+	uint64_t res;
+
+	q = (volatile uint32_t *)p;
+	__asm __volatile(
+	"	pushfl ;		"
+	"	cli ;			"
+	"	movl	%1,%%eax ;	"
+	"	movl	%2,%%edx ;	"
+	"	movl	%4,%2 ;		"
+	"	movl	%3,%1 ;		"
+	"	popfl"
+	: "=&A" (res),			/* 0 */
+	  "+m" (*q),			/* 1 */
+	  "+m" (*(q + 1))		/* 2 */
+	: "r" ((uint32_t)v),		/* 3 */
+	  "r" ((uint32_t)(v >> 32)));	/* 4 */
+	return (res);
+}
+
+static __inline int
+atomic_cmpset_64_i586(volatile uint64_t *dst, uint64_t expect, uint64_t src)
+{
+	u_char res;
+
+	__asm __volatile(
+	"	" MPLOCKED "		"
+	"	cmpxchg8b %1 ;		"
+	"	sete	%0"
+	: "=q" (res),			/* 0 */
+	  "+m" (*dst),			/* 1 */
+	  "+A" (expect)			/* 2 */
+	: "b" ((uint32_t)src),		/* 3 */
+	  "c" ((uint32_t)(src >> 32))	/* 4 */
+	: "memory", "cc");
+	return (res);
+}
+
+static __inline uint64_t
+atomic_load_acq_64_i586(volatile uint64_t *p)
+{
+	uint64_t res;
+
+	__asm __volatile(
+	"	movl	%%ebx,%%eax ;	"
+	"	movl	%%ecx,%%edx ;	"
+	"	" MPLOCKED "		"
+	"	cmpxchg8b %1"
+	: "=&A" (res),			/* 0 */
+	  "+m" (*p)			/* 1 */
+	: : "memory", "cc");
+	return (res);
+}
+
+static __inline void
+atomic_store_rel_64_i586(volatile uint64_t *p, uint64_t v)
+{
+
+	__asm __volatile(
+	"	movl	%%eax,%%ebx ;	"
+	"	movl	%%edx,%%ecx ;	"
+	"1:				"
+	"	" MPLOCKED "		"
+	"	cmpxchg8b %0 ;		"
+	"	jne	1b"
+	: "+m" (*p),			/* 0 */
+	  "+A" (v)			/* 1 */
+	: : "ebx", "ecx", "memory", "cc");
+}
+
+static __inline uint64_t
+atomic_swap_64_i586(volatile uint64_t *p, uint64_t v)
+{
+
+	__asm __volatile(
+	"	movl	%%eax,%%ebx ;	"
+	"	movl	%%edx,%%ecx ;	"
+	"1:				"
+	"	" MPLOCKED "		"
+	"	cmpxchg8b %0 ;		"
+	"	jne	1b"
+	: "+m" (*p),			/* 0 */
+	  "+A" (v)			/* 1 */
+	: : "ebx", "ecx", "memory", "cc");
+	return (v);
+}
+
+static __inline int
+atomic_cmpset_64(volatile uint64_t *dst, uint64_t expect, uint64_t src)
+{
+
+	if ((cpu_feature & CPUID_CX8) == 0)
+		return (atomic_cmpset_64_i386(dst, expect, src));
+	else
+		return (atomic_cmpset_64_i586(dst, expect, src));
+}
+
+static __inline uint64_t
+atomic_load_acq_64(volatile uint64_t *p)
+{
+
+	if ((cpu_feature & CPUID_CX8) == 0)
+		return (atomic_load_acq_64_i386(p));
+	else
+		return (atomic_load_acq_64_i586(p));
+}
+
+static __inline void
+atomic_store_rel_64(volatile uint64_t *p, uint64_t v)
+{
+
+	if ((cpu_feature & CPUID_CX8) == 0)
+		atomic_store_rel_64_i386(p, v);
+	else
+		atomic_store_rel_64_i586(p, v);
+}
+
+static __inline uint64_t
+atomic_swap_64(volatile uint64_t *p, uint64_t v)
+{
+
+	if ((cpu_feature & CPUID_CX8) == 0)
+		return (atomic_swap_64_i386(p, v));
+	else
+		return (atomic_swap_64_i586(p, v));
+}
+
+static __inline uint64_t
+atomic_fetchadd_64(volatile uint64_t *p, uint64_t v)
+{
+
+	for (;;) {
+		uint64_t t = *p;
+		if (atomic_cmpset_64(p, t, t + v))
+			return (t);
+	}
+}
+
+#endif /* _KERNEL */
+
 #endif /* KLD_MODULE || !__GNUCLIKE_ASM */
 
 ATOMIC_ASM(set,	     char,  "orb %b1,%0",  "iq",  v);
@@ -373,11 +558,6 @@
 
 #ifndef WANT_FUNCTIONS
 
-#ifdef _KERNEL
-extern uint64_t (*atomic_load_acq_64)(volatile uint64_t *);
-extern void (*atomic_store_rel_64)(volatile uint64_t *, uint64_t);
-#endif
-
 static __inline int
 atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src)
 {
@@ -393,45 +573,46 @@
 	return (atomic_fetchadd_int((volatile u_int *)p, (u_int)v));
 }
 
-/* Read the current value and store a zero in the destination. */
+static __inline int
+atomic_testandset_long(volatile u_long *p, u_int v)
+{
+
+	return (atomic_testandset_int((volatile u_int *)p, v));
+}
+
+static __inline int
+atomic_testandclear_long(volatile u_long *p, u_int v)
+{
+
+	return (atomic_testandclear_int((volatile u_int *)p, v));
+}
+
+/* Read the current value and store a new value in the destination. */
 #ifdef __GNUCLIKE_ASM
 
 static __inline u_int
-atomic_readandclear_int(volatile u_int *addr)
+atomic_swap_int(volatile u_int *p, u_int v)
 {
-	u_int res;
 
-	res = 0;
 	__asm __volatile(
 	"	xchgl	%1,%0 ;		"
-	"# atomic_readandclear_int"
-	: "+r" (res),			/* 0 */
-	  "=m" (*addr)			/* 1 */
-	: "m" (*addr));
-
-	return (res);
+	"# atomic_swap_int"
+	: "+r" (v),			/* 0 */
+	  "+m" (*p));			/* 1 */
+	return (v);
 }
 
 static __inline u_long
-atomic_readandclear_long(volatile u_long *addr)
+atomic_swap_long(volatile u_long *p, u_long v)
 {
-	u_long res;
 
-	res = 0;
-	__asm __volatile(
-	"	xchgl	%1,%0 ;		"
-	"# atomic_readandclear_long"
-	: "+r" (res),			/* 0 */
-	  "=m" (*addr)			/* 1 */
-	: "m" (*addr));
-
-	return (res);
+	return (atomic_swap_int((volatile u_int *)p, (u_int)v));
 }
 
 #else /* !__GNUCLIKE_ASM */
 
-u_int	atomic_readandclear_int(volatile u_int *addr);
-u_long	atomic_readandclear_long(volatile u_long *addr);
+u_int	atomic_swap_int(volatile u_int *p, u_int v);
+u_long	atomic_swap_long(volatile u_long *p, u_long v);
 
 #endif /* __GNUCLIKE_ASM */
 
@@ -475,6 +656,9 @@
 #define	atomic_cmpset_acq_long		atomic_cmpset_long
 #define	atomic_cmpset_rel_long		atomic_cmpset_long
 
+#define	atomic_readandclear_int(p)	atomic_swap_int(p, 0)
+#define	atomic_readandclear_long(p)	atomic_swap_long(p, 0)
+
 /* Operations on 8-bit bytes. */
 #define	atomic_set_8		atomic_set_char
 #define	atomic_set_acq_8	atomic_set_acq_char
@@ -525,8 +709,11 @@
 #define	atomic_cmpset_32	atomic_cmpset_int
 #define	atomic_cmpset_acq_32	atomic_cmpset_acq_int
 #define	atomic_cmpset_rel_32	atomic_cmpset_rel_int
+#define	atomic_swap_32		atomic_swap_int
 #define	atomic_readandclear_32	atomic_readandclear_int
 #define	atomic_fetchadd_32	atomic_fetchadd_int
+#define	atomic_testandset_32	atomic_testandset_int
+#define	atomic_testandclear_32	atomic_testandclear_int
 
 /* Operations on pointers. */
 #define	atomic_set_ptr(p, v) \
@@ -565,6 +752,8 @@
 #define	atomic_cmpset_rel_ptr(dst, old, new) \
 	atomic_cmpset_rel_int((volatile u_int *)(dst), (u_int)(old), \
 	    (u_int)(new))
+#define	atomic_swap_ptr(p, v) \
+	atomic_swap_int((volatile u_int *)(p), (u_int)(v))
 #define	atomic_readandclear_ptr(p) \
 	atomic_readandclear_int((volatile u_int *)(p))
 

Modified: trunk/sys/i386/include/bootinfo.h
===================================================================
--- trunk/sys/i386/include/bootinfo.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/bootinfo.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 1994 by Rodney W. Grimes, Milwaukie, Oregon  97222
  * All rights reserved.
@@ -29,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/bootinfo.h 235391 2012-05-13 09:25:39Z avg $
  */
 
 #ifndef	_MACHINE_BOOTINFO_H_

Modified: trunk/sys/i386/include/bus.h
===================================================================
--- trunk/sys/i386/include/bus.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/bus.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/bus.h 244191 2012-12-13 21:27:20Z jimharris $ */
 
 #include <x86/bus.h>

Modified: trunk/sys/i386/include/bus_dma.h
===================================================================
--- trunk/sys/i386/include/bus_dma.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/bus_dma.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 Scott Long
  * All rights reserved.
@@ -24,7 +25,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/bus_dma.h 143598 2005-03-14 16:46:28Z scottl $ */
 
 #ifndef _I386_BUS_DMA_H_
 #define _I386_BUS_DMA_H_

Modified: trunk/sys/i386/include/clock.h
===================================================================
--- trunk/sys/i386/include/clock.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/clock.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,9 +1,10 @@
+/* $MidnightBSD$ */
 /*-
  * Kernel interface to machine-dependent clock driver.
  * Garrett Wollman, September 1994.
  * This file is in the public domain.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/clock.h 221703 2011-05-09 17:34:00Z jkim $
  */
 
 #ifndef _MACHINE_CLOCK_H_

Modified: trunk/sys/i386/include/cpu.h
===================================================================
--- trunk/sys/i386/include/cpu.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/cpu.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)cpu.h	5.4 (Berkeley) 5/9/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/cpu.h 255744 2013-09-20 22:59:22Z gibbs $
  */
 
 #ifndef _MACHINE_CPU_H_
@@ -54,6 +55,19 @@
 #define	TRAPF_PC(framep)	((framep)->tf_eip)
 
 #ifdef _KERNEL
+/*
+ * Struct containing pointers to CPU management functions whose
+ * implementation is run time selectable.  Selection can be made,
+ * for example, based on detection of a particular CPU variant or
+ * hypervisor environment.
+ */
+struct cpu_ops {
+	void (*cpu_init)(void);
+	void (*cpu_resume)(void);
+	void (*ipi_vectored)(u_int, int);
+};
+
+extern struct	cpu_ops cpu_ops;
 extern char	btext[];
 extern char	etext[];
 

Modified: trunk/sys/i386/include/cpufunc.h
===================================================================
--- trunk/sys/i386/include/cpufunc.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/cpufunc.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1993 The Regents of the University of California.
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/cpufunc.h 313150 2017-02-03 12:20:44Z kib $
  */
 
 /*
@@ -97,6 +98,13 @@
 }
 
 static __inline void
+clflushopt(u_long addr)
+{
+
+	__asm __volatile(".byte 0x66;clflush %0" : : "m" (*(char *)addr));
+}
+
+static __inline void
 clts(void)
 {
 
@@ -168,6 +176,13 @@
 	__asm __volatile("mfence" : : : "memory");
 }
 
+static __inline void
+sfence(void)
+{
+
+	__asm __volatile("sfence" : : : "memory");
+}
+
 #ifdef _KERNEL
 
 #define	HAVE_INLINE_FFS
@@ -184,6 +199,14 @@
 	 return (mask == 0 ? mask : (int)bsfl((u_int)mask) + 1);
 }
 
+#define	HAVE_INLINE_FFSL
+
+static __inline int
+ffsl(long mask)
+{
+	return (ffs((int)mask));
+}
+
 #define	HAVE_INLINE_FLS
 
 static __inline int
@@ -192,6 +215,14 @@
 	return (mask == 0 ? mask : (int)bsrl((u_int)mask) + 1);
 }
 
+#define	HAVE_INLINE_FLSL
+
+static __inline int
+flsl(long mask)
+{
+	return (fls((int)mask));
+}
+
 #endif /* _KERNEL */
 
 static __inline void
@@ -441,6 +472,25 @@
 	return (data);
 }
 
+static __inline uint64_t
+rxcr(u_int reg)
+{
+	u_int low, high;
+
+	__asm __volatile("xgetbv" : "=a" (low), "=d" (high) : "c" (reg));
+	return (low | ((uint64_t)high << 32));
+}
+
+static __inline void
+load_xcr(u_int reg, uint64_t val)
+{
+	u_int low, high;
+
+	low = val;
+	high = val >> 32;
+	__asm __volatile("xsetbv" : : "c" (reg), "a" (low), "d" (high));
+}
+
 /*
  * Global TLB flush (except for thise for pages marked PG_G)
  */

Modified: trunk/sys/i386/include/cputypes.h
===================================================================
--- trunk/sys/i386/include/cputypes.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/cputypes.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1993 Christopher G. Demetriou
  * All rights reserved.
@@ -24,7 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/cputypes.h 185341 2008-11-26 19:25:13Z jkim $
  */
 
 #ifndef _MACHINE_CPUTYPES_H_

Modified: trunk/sys/i386/include/cserial.h
===================================================================
--- trunk/sys/i386/include/cserial.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/cserial.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Ioctl interface to Cronyx serial drivers.
  *
@@ -18,7 +19,7 @@
  * all derivative works or modified versions.
  *
  * Cronyx Id: cserial.h,v 1.4.2.2 2005/11/09 13:01:35 rik Exp $
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/cserial.h 155049 2006-01-30 13:34:57Z rik $
  */
 
 /*

Modified: trunk/sys/i386/include/db_machdep.h
===================================================================
--- trunk/sys/i386/include/db_machdep.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/db_machdep.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Mach Operating System
  * Copyright (c) 1991,1990 Carnegie Mellon University
@@ -23,7 +24,7 @@
  * any improvements or extensions that they make and grant Carnegie Mellon
  * the rights to redistribute these changes.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/db_machdep.h 139790 2005-01-06 22:18:23Z imp $
  */
 
 #ifndef _MACHINE_DB_MACHDEP_H_

Modified: trunk/sys/i386/include/elan_mmcr.h
===================================================================
--- trunk/sys/i386/include/elan_mmcr.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/elan_mmcr.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 John Birrell
  * All rights reserved.
@@ -32,7 +33,7 @@
  * bytes. Ignore fields with the 'pad' prefix - they are only present for
  * alignment purposes.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/elan_mmcr.h 139788 2005-01-06 22:05:28Z imp $
  */
 
 #ifndef _MACHINE_ELAN_MMCR_H_

Modified: trunk/sys/i386/include/elf.h
===================================================================
--- trunk/sys/i386/include/elf.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/elf.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,118 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1996-1997 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/elf.h 247047 2013-02-20 17:39:52Z kib $ */
 
-#ifndef _MACHINE_ELF_H_
-#define	_MACHINE_ELF_H_ 1
-
-/*
- * ELF definitions for the i386 architecture.
- */
-
-#include <sys/elf32.h>	/* Definitions common to all 32 bit architectures. */
-#if defined(__ELF_WORD_SIZE) && __ELF_WORD_SIZE == 64
-#include <sys/elf64.h>	/* Definitions common to all 64 bit architectures. */
-#endif
-
-#ifndef __ELF_WORD_SIZE
-#define	__ELF_WORD_SIZE	32	/* Used by <sys/elf_generic.h> */
-#endif
-
-#include <sys/elf_generic.h>
-
-#define	ELF_ARCH	EM_386
-
-#define	ELF_MACHINE_OK(x) ((x) == EM_386 || (x) == EM_486)
-
-/*
- * Auxiliary vector entries for passing information to the interpreter.
- *
- * The i386 supplement to the SVR4 ABI specification names this "auxv_t",
- * but POSIX lays claim to all symbols ending with "_t".
- */
-
-typedef struct {	/* Auxiliary vector entry on initial stack */
-	int	a_type;			/* Entry type. */
-	union {
-		long	a_val;		/* Integer value. */
-		void	*a_ptr;		/* Address. */
-		void	(*a_fcn)(void);	/* Function pointer (not used). */
-	} a_un;
-} Elf32_Auxinfo;
-
-#if __ELF_WORD_SIZE == 64
-/* Fake for amd64 loader support */
-typedef struct {
-	int fake;
-} Elf64_Auxinfo;
-#endif
-
-__ElfType(Auxinfo);
-
-/* Values for a_type. */
-#define	AT_NULL		0	/* Terminates the vector. */
-#define	AT_IGNORE	1	/* Ignored entry. */
-#define	AT_EXECFD	2	/* File descriptor of program to load. */
-#define	AT_PHDR		3	/* Program header of program already loaded. */
-#define	AT_PHENT	4	/* Size of each program header entry. */
-#define	AT_PHNUM	5	/* Number of program header entries. */
-#define	AT_PAGESZ	6	/* Page size in bytes. */
-#define	AT_BASE		7	/* Interpreter's base address. */
-#define	AT_FLAGS	8	/* Flags (unused for i386). */
-#define	AT_ENTRY	9	/* Where interpreter should transfer control. */
-#define	AT_NOTELF	10	/* Program is not ELF ?? */
-#define	AT_UID		11	/* Real uid. */
-#define	AT_EUID		12	/* Effective uid. */
-#define	AT_GID		13	/* Real gid. */
-#define	AT_EGID		14	/* Effective gid. */
-#define	AT_EXECPATH	15	/* Path to the executable. */
-#define	AT_CANARY	16	/* Canary for SSP. */
-#define	AT_CANARYLEN	17	/* Length of the canary. */
-#define	AT_OSRELDATE	18	/* OSRELDATE. */
-#define	AT_NCPUS	19	/* Number of CPUs. */
-#define	AT_PAGESIZES	20	/* Pagesizes. */
-#define	AT_PAGESIZESLEN	21	/* Number of pagesizes. */
-#define	AT_TIMEKEEP	22	/* Pointer to timehands. */
-#define	AT_STACKPROT	23	/* Initial stack protection. */
-
-#define	AT_COUNT	24	/* Count of defined aux entry types. */
-
-/*
- * Relocation types.
- */
-
-#define	R_386_COUNT	38	/* Count of defined relocation types. */
-
-/* Define "machine" characteristics */
-#define	ELF_TARG_CLASS	ELFCLASS32
-#define	ELF_TARG_DATA	ELFDATA2LSB
-#define	ELF_TARG_MACH	EM_386
-#define	ELF_TARG_VER	1
-
-#define	ET_DYN_LOAD_ADDR 0x01001000
-
-#endif /* !_MACHINE_ELF_H_ */
+#include <x86/elf.h>

Modified: trunk/sys/i386/include/endian.h
===================================================================
--- trunk/sys/i386/include/endian.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/endian.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,145 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1987, 1991 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)endian.h	7.8 (Berkeley) 4/3/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/endian.h 232266 2012-02-28 19:39:54Z tijl $ */
 
-#ifndef _MACHINE_ENDIAN_H_
-#define	_MACHINE_ENDIAN_H_
-
-#include <sys/cdefs.h>
-#include <sys/_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Define the order of 32-bit words in 64-bit words.
- */
-#define	_QUAD_HIGHWORD 1
-#define	_QUAD_LOWWORD 0
-
-/*
- * Definitions for byte order, according to byte significance from low
- * address to high.
- */
-#define	_LITTLE_ENDIAN	1234	/* LSB first: i386, vax */
-#define	_BIG_ENDIAN	4321	/* MSB first: 68000, ibm, net */
-#define	_PDP_ENDIAN	3412	/* LSB first in word, MSW first in long */
-
-#define	_BYTE_ORDER	_LITTLE_ENDIAN
-
-/*
- * Deprecated variants that don't have enough underscores to be useful in more
- * strict namespaces.
- */
-#if __BSD_VISIBLE
-#define	LITTLE_ENDIAN	_LITTLE_ENDIAN
-#define	BIG_ENDIAN	_BIG_ENDIAN
-#define	PDP_ENDIAN	_PDP_ENDIAN
-#define	BYTE_ORDER	_BYTE_ORDER
-#endif
-
-#if defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE_BUILTIN_CONSTANT_P)
-
-#define	__bswap64_const(_x)			\
-	(((_x) >> 56) |				\
-	(((_x) >> 40) & (0xffULL << 8)) |	\
-	(((_x) >> 24) & (0xffULL << 16)) |	\
-	(((_x) >> 8) & (0xffULL << 24)) |	\
-	(((_x) << 8) & (0xffULL << 32)) |	\
-	(((_x) << 24) & (0xffULL << 40)) |	\
-	(((_x) << 40) & (0xffULL << 48)) |	\
-	((_x) << 56))
-
-#define	__bswap32_const(_x)			\
-	(((_x) >> 24) |				\
-	(((_x) & (0xff << 16)) >> 8) |		\
-	(((_x) & (0xff << 8)) << 8) |		\
-	((_x) << 24))
-
-#define __bswap16_const(_x)	(__uint16_t)((_x) << 8 | (_x) >> 8)
-
-static __inline __uint64_t
-__bswap64_var(__uint64_t __x)
-{
-
-	return __bswap64_const(__x);
-}
-
-
-static __inline __uint32_t
-__bswap32_var(__uint32_t _x)
-{
-
-	__asm ("bswap %0" : "+r" (_x));
-	return (_x);
-}
-
-static __inline __uint16_t
-__bswap16_var(__uint16_t _x)
-{
-
-	return (__bswap16_const(_x));
-}
-
-#define	__bswap64(_x)					\
-	(__builtin_constant_p(_x) ?			\
-	    __bswap64_const((__uint64_t)(_x)) : __bswap64_var(_x))
-
-#define	__bswap32(_x)					\
-	(__builtin_constant_p(_x) ?			\
-	    __bswap32_const((__uint32_t)(_x)) : __bswap32_var(_x))
-
-#define	__bswap16(_x)					\
-	((__uint16_t)(__builtin_constant_p(_x) ?	\
-	    __bswap16_const((__uint16_t)(_x)) : __bswap16_var(_x)))
-
-#define	__htonl(x)	__bswap32(x)
-#define	__htons(x)	__bswap16(x)
-#define	__ntohl(x)	__bswap32(x)
-#define	__ntohs(x)	__bswap16(x)
-
-#else /* !(__GNUCLIKE_ASM && __GNUCLIKE_BUILTIN_CONSTANT_P) */
-
-/*
- * No optimizations are available for this compiler.  Fall back to
- * non-optimized functions by defining the constant usually used to prevent
- * redefinition.
- */
-#define	_BYTEORDER_FUNC_DEFINED
-
-#endif /* __GNUCLIKE_ASM && __GNUCLIKE_BUILTIN_CONSTANT_P */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !_MACHINE_ENDIAN_H_ */
+#include <x86/endian.h>

Modified: trunk/sys/i386/include/exec.h
===================================================================
--- trunk/sys/i386/include/exec.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/exec.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)exec.h	8.1 (Berkeley) 6/11/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/exec.h 142107 2005-02-19 21:16:48Z ru $
  */
 
 #ifndef	_MACHINE_EXEC_H_

Modified: trunk/sys/i386/include/float.h
===================================================================
--- trunk/sys/i386/include/float.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/float.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,78 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1989 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)float.h	7.1 (Berkeley) 5/8/90
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/float.h 232491 2012-03-04 14:00:32Z tijl $ */
 
-#ifndef _MACHINE_FLOAT_H_
-#define _MACHINE_FLOAT_H_ 1
-
-#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-extern int __flt_rounds(void);
-__END_DECLS
-
-#define FLT_RADIX	2		/* b */
-#define FLT_ROUNDS	__flt_rounds()
-#if __ISO_C_VISIBLE >= 1999
-#define	FLT_EVAL_METHOD	(-1)		/* i387 semantics are...interesting */
-#define	DECIMAL_DIG	21		/* max precision in decimal digits */
-#endif
-
-#define FLT_MANT_DIG	24		/* p */
-#define FLT_EPSILON	1.19209290E-07F	/* b**(1-p) */
-#define FLT_DIG		6		/* floor((p-1)*log10(b))+(b == 10) */
-#define FLT_MIN_EXP	(-125)		/* emin */
-#define FLT_MIN		1.17549435E-38F	/* b**(emin-1) */
-#define FLT_MIN_10_EXP	(-37)		/* ceil(log10(b**(emin-1))) */
-#define FLT_MAX_EXP	128		/* emax */
-#define FLT_MAX		3.40282347E+38F	/* (1-b**(-p))*b**emax */
-#define FLT_MAX_10_EXP	38		/* floor(log10((1-b**(-p))*b**emax)) */
-
-#define DBL_MANT_DIG	53
-#define DBL_EPSILON	2.2204460492503131E-16
-#define DBL_DIG		15
-#define DBL_MIN_EXP	(-1021)
-#define DBL_MIN		2.2250738585072014E-308
-#define DBL_MIN_10_EXP	(-307)
-#define DBL_MAX_EXP	1024
-#define DBL_MAX		1.7976931348623157E+308
-#define DBL_MAX_10_EXP	308
-
-#define LDBL_MANT_DIG	64
-#define LDBL_EPSILON	1.0842021724855044340E-19L
-#define LDBL_DIG	18
-#define LDBL_MIN_EXP	(-16381)
-#define LDBL_MIN	3.3621031431120935063E-4932L
-#define LDBL_MIN_10_EXP	(-4931)
-#define LDBL_MAX_EXP	16384
-#define LDBL_MAX	1.1897314953572317650E+4932L
-#define LDBL_MAX_10_EXP	4932
-#endif /* _MACHINE_FLOAT_H_ */
+#include <x86/float.h>

Modified: trunk/sys/i386/include/floatingpoint.h
===================================================================
--- trunk/sys/i386/include/floatingpoint.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/floatingpoint.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1993 Andrew Moore, Talke Studio
  * All rights reserved.
@@ -31,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#) floatingpoint.h	1.0 (Berkeley) 9/23/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/floatingpoint.h 144544 2005-04-02 17:31:42Z netchild $
  */
 
 #ifndef _FLOATINGPOINT_H_

Modified: trunk/sys/i386/include/frame.h
===================================================================
--- trunk/sys/i386/include/frame.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/frame.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,100 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)frame.h	5.2 (Berkeley) 1/18/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/frame.h 247047 2013-02-20 17:39:52Z kib $ */
 
-#ifndef _MACHINE_FRAME_H_
-#define _MACHINE_FRAME_H_ 1
-
-/*
- * System stack frames.
- */
-
-/*
- * Exception/Trap Stack Frame
- */
-
-struct trapframe {
-	int	tf_fs;
-	int	tf_es;
-	int	tf_ds;
-	int	tf_edi;
-	int	tf_esi;
-	int	tf_ebp;
-	int	tf_isp;
-	int	tf_ebx;
-	int	tf_edx;
-	int	tf_ecx;
-	int	tf_eax;
-	int	tf_trapno;
-	/* below portion defined in 386 hardware */
-	int	tf_err;
-	int	tf_eip;
-	int	tf_cs;
-	int	tf_eflags;
-	/* below only when crossing rings (e.g. user to kernel) */
-	int	tf_esp;
-	int	tf_ss;
-};
-
-/* Superset of trap frame, for traps from virtual-8086 mode */
-
-struct trapframe_vm86 {
-	int	tf_fs;
-	int	tf_es;
-	int	tf_ds;
-	int	tf_edi;
-	int	tf_esi;
-	int	tf_ebp;
-	int	tf_isp;
-	int	tf_ebx;
-	int	tf_edx;
-	int	tf_ecx;
-	int	tf_eax;
-	int	tf_trapno;
-	/* below portion defined in 386 hardware */
-	int	tf_err;
-	int	tf_eip;
-	int	tf_cs;
-	int	tf_eflags;
-	/* below only when crossing rings (e.g. user to kernel) */
-	int	tf_esp;
-	int	tf_ss;
-	/* below only when switching out of VM86 mode */
-	int	tf_vm86_es;
-	int	tf_vm86_ds;
-	int	tf_vm86_fs;
-	int	tf_vm86_gs;
-};
-
-#endif /* _MACHINE_FRAME_H_ */
+#include <x86/frame.h>

Modified: trunk/sys/i386/include/gdb_machdep.h
===================================================================
--- trunk/sys/i386/include/gdb_machdep.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/gdb_machdep.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Marcel Moolenaar
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/gdb_machdep.h 290734 2015-11-13 00:50:34Z jhb $
  */
 
 #ifndef _MACHINE_GDB_MACHDEP_H_
@@ -30,7 +31,7 @@
 #define	_MACHINE_GDB_MACHDEP_H_
 
 #define	GDB_BUFSZ	400
-#define	GDB_NREGS	14
+#define	GDB_NREGS	16
 #define	GDB_REG_PC	8
 
 static __inline size_t

Modified: trunk/sys/i386/include/ieeefp.h
===================================================================
--- trunk/sys/i386/include/ieeefp.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ieeefp.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 Peter Wemm.
  * Copyright (c) 1990 Andrew Moore, Talke Studio
@@ -32,7 +33,7 @@
  * SUCH DAMAGE.
  *
  * 	from: @(#) ieeefp.h 	1.0 (Berkeley) 9/23/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/ieeefp.h 226607 2011-10-21 06:41:46Z das $
  */
 
 #ifndef _MACHINE_IEEEFP_H_
@@ -39,6 +40,8 @@
 #define _MACHINE_IEEEFP_H_
 
 /*
+ * Deprecated historical FPU control interface
+ *
  * IEEE floating point type, constant and function definitions.
  * XXX: FP*FLD and FP*OFF are undocumented pollution.
  */
@@ -253,7 +256,4 @@
 
 #endif /* __GNUCLIKE_ASM */
 
-/* Suppress prototypes in the MI header. */
-#define	_IEEEFP_INLINED_	1
-
 #endif /* !_MACHINE_IEEEFP_H_ */

Modified: trunk/sys/i386/include/if_wl_wavelan.h
===================================================================
--- trunk/sys/i386/include/if_wl_wavelan.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/if_wl_wavelan.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,4 +1,5 @@
-/* $FreeBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/if_wl_wavelan.h 139790 2005-01-06 22:18:23Z imp $ */
 /*-
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions

Modified: trunk/sys/i386/include/in_cksum.h
===================================================================
--- trunk/sys/i386/include/in_cksum.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/in_cksum.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -29,7 +30,7 @@
  *	from tahoe:	in_cksum.c	1.2	86/01/05
  *	from:		@(#)in_cksum.c	1.3 (Berkeley) 1/19/91
  *	from: Id: in_cksum.c,v 1.8 1995/12/03 18:35:19 bde Exp
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/in_cksum.h 235941 2012-05-24 22:00:48Z bz $
  */
 
 #ifndef _MACHINE_IN_CKSUM_H_

Modified: trunk/sys/i386/include/intr_machdep.h
===================================================================
--- trunk/sys/i386/include/intr_machdep.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/intr_machdep.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 John Baldwin <jhb at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/intr_machdep.h 305672 2016-09-09 19:57:32Z jhb $
  */
 
 #ifndef __MACHINE_INTR_MACHDEP_H__
@@ -44,12 +45,30 @@
  * allocate IDT vectors.
  *
  * The first 255 IRQs (0 - 254) are reserved for ISA IRQs and PCI intline IRQs.
- * IRQ values beyond 256 are used by MSI.  We leave 255 unused to avoid
- * confusion since 255 is used in PCI to indicate an invalid IRQ.
+ * IRQ values from 256 to 767 are used by MSI.  When running under the Xen
+ * Hypervisor, IRQ values from 768 to 4863 are available for binding to
+ * event channel events.  We leave 255 unused to avoid confusion since 255 is
+ * used in PCI to indicate an invalid IRQ.
  */
 #define	NUM_MSI_INTS	512
 #define	FIRST_MSI_INT	256
-#define	NUM_IO_INTS	(FIRST_MSI_INT + NUM_MSI_INTS)
+#ifdef XENHVM
+#include <xen/xen-os.h>
+#define	NUM_EVTCHN_INTS	NR_EVENT_CHANNELS
+#define	FIRST_EVTCHN_INT \
+    (FIRST_MSI_INT + NUM_MSI_INTS)
+#define	LAST_EVTCHN_INT \
+    (FIRST_EVTCHN_INT + NUM_EVTCHN_INTS - 1)
+#elif defined(XEN)
+#include <xen/xen-os.h>
+#define	NUM_EVTCHN_INTS	NR_EVENT_CHANNELS
+#define	FIRST_EVTCHN_INT 0
+#define	LAST_EVTCHN_INT \
+    (FIRST_EVTCHN_INT + NUM_EVTCHN_INTS - 1)
+#else /* !XEN && !XENHVM */
+#define	NUM_EVTCHN_INTS	0
+#endif
+#define	NUM_IO_INTS	(FIRST_MSI_INT + NUM_MSI_INTS + NUM_EVTCHN_INTS)
 
 /*
  * Default base address for MSI messages on x86 platforms.
@@ -90,7 +109,7 @@
 	int (*pic_vector)(struct intsrc *);
 	int (*pic_source_pending)(struct intsrc *);
 	void (*pic_suspend)(struct pic *);
-	void (*pic_resume)(struct pic *);
+	void (*pic_resume)(struct pic *, bool suspend_cancelled);
 	int (*pic_config_intr)(struct intsrc *, enum intr_trigger,
 	    enum intr_polarity);
 	int (*pic_assign_cpu)(struct intsrc *, u_int apic_id);
@@ -122,6 +141,9 @@
 
 extern struct mtx icu_lock;
 extern int elcr_found;
+#ifdef SMP
+extern int msix_disable_migration;
+#endif
 
 #ifndef DEV_ATPIC
 void	atpic_reset(void);
@@ -131,7 +153,9 @@
 enum intr_trigger elcr_read_trigger(u_int irq);
 void	elcr_resume(void);
 void	elcr_write_trigger(u_int irq, enum intr_trigger trigger);
+#ifdef SMP
 void	intr_add_cpu(u_int cpu);
+#endif
 int	intr_add_handler(const char *name, int vector, driver_filter_t filter,
     driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep);
 #ifdef SMP
@@ -146,7 +170,7 @@
 int	intr_register_pic(struct pic *pic);
 int	intr_register_source(struct intsrc *isrc);
 int	intr_remove_handler(void *cookie);
-void	intr_resume(void);
+void	intr_resume(bool suspend_cancelled);
 void	intr_suspend(void);
 void	intrcnt_add(const char *name, u_long **countp);
 void	nexus_add_irq(u_long irq);

Modified: trunk/sys/i386/include/ioctl_bt848.h
===================================================================
--- trunk/sys/i386/include/ioctl_bt848.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ioctl_bt848.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 David O'Brien
  * All rights reserved.
@@ -23,7 +24,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/ioctl_bt848.h 143063 2005-03-02 21:33:29Z joerg $
  */
 
 #ifndef	_MACHINE_IOCTL_BT848_H_

Modified: trunk/sys/i386/include/ioctl_meteor.h
===================================================================
--- trunk/sys/i386/include/ioctl_meteor.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ioctl_meteor.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 David O'Brien
  * All rights reserved.
@@ -23,7 +24,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/ioctl_meteor.h 143063 2005-03-02 21:33:29Z joerg $
  */
 
 #ifndef	_MACHINE_IOCTL_METEOR_H_

Modified: trunk/sys/i386/include/iodev.h
===================================================================
--- trunk/sys/i386/include/iodev.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/iodev.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Mark R V Murray
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/iodev.h 207329 2010-04-28 15:38:01Z attilio $
  */
 #ifndef _MACHINE_IODEV_H_
 #define	_MACHINE_IODEV_H_

Modified: trunk/sys/i386/include/kdb.h
===================================================================
--- trunk/sys/i386/include/kdb.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/kdb.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Marcel Moolenaar
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/kdb.h 170473 2007-06-09 21:55:17Z marcel $
  */
 
 #ifndef _MACHINE_KDB_H_

Modified: trunk/sys/i386/include/legacyvar.h
===================================================================
--- trunk/sys/i386/include/legacyvar.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/legacyvar.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Peter Wemm <peter at FreeBSD.org>
  * All rights reserved.

Modified: trunk/sys/i386/include/limits.h
===================================================================
--- trunk/sys/i386/include/limits.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/limits.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1988, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)limits.h	8.3 (Berkeley) 1/4/94
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/limits.h 143063 2005-03-02 21:33:29Z joerg $
  */
 
 #ifndef _MACHINE_LIMITS_H_

Modified: trunk/sys/i386/include/md_var.h
===================================================================
--- trunk/sys/i386/include/md_var.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/md_var.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1995 Bruce D. Evans.
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/md_var.h 322205 2017-08-07 22:30:18Z jkim $
  */
 
 #ifndef _MACHINE_MD_VAR_H_
@@ -48,15 +49,27 @@
 extern	u_int	via_feature_rng;
 extern	u_int	via_feature_xcrypt;
 extern	u_int	cpu_clflush_line_size;
+extern	u_int	cpu_stdext_feature;
+extern	u_int	cpu_stdext_feature2;
 extern	u_int	cpu_fxsr;
 extern	u_int	cpu_high;
 extern	u_int	cpu_id;
+extern	u_int	cpu_max_ext_state_size;
 extern	u_int	cpu_mxcsr_mask;
 extern	u_int	cpu_procinfo;
 extern	u_int	cpu_procinfo2;
 extern	char	cpu_vendor[];
 extern	u_int	cpu_vendor_id;
+extern	u_int	cpu_mon_mwait_flags;
+extern	u_int	cpu_mon_min_size;
+extern	u_int	cpu_mon_max_size;
+extern	u_int	cpu_maxphyaddr;
 extern	u_int	cyrix_did;
+#if defined(I586_CPU) && !defined(NO_F00F_HACK)
+extern	int	has_f00f_bug;
+#endif
+extern	u_int	hv_high;
+extern	char	hv_vendor[];
 extern	char	kstack[];
 extern	char	sigcode[];
 extern	int	szsigcode;
@@ -69,14 +82,36 @@
 extern	uint32_t *vm_page_dump;
 extern	int	vm_page_dump_size;
 extern	int	workaround_erratum383;
+extern	int	_udatasel;
+extern	int	_ucodesel;
+extern	int	use_xsave;
+extern	uint64_t xsave_mask;
 
 typedef void alias_for_inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
+struct	pcb;
+union	savefpu;
 struct	thread;
 struct	reg;
 struct	fpreg;
 struct  dbreg;
 struct	dumperinfo;
+struct	segment_descriptor;
 
+/*
+ * Returns the maximum physical address that can be used with the
+ * current system.
+ */
+static __inline vm_paddr_t
+cpu_getmaxphyaddr(void)
+{
+#if !defined(PAE)
+	return (0xffffffff);
+#else
+	return ((1ULL << cpu_maxphyaddr) - 1);
+#endif
+}
+
+void	*alloc_fpusave(int flags);
 void	bcopyb(const void *from, void *to, size_t len);
 void	busdma_swi(void);
 void	cpu_setregs(void);
@@ -91,9 +126,13 @@
 void	doreti_popl_fs_fault(void) __asm(__STRING(doreti_popl_fs_fault));
 void	dump_add_page(vm_paddr_t);
 void	dump_drop_page(vm_paddr_t);
+void	finishidentcpu(void);
+void	fillw(int /*u_short*/ pat, void *base, size_t cnt);
+void	fill_based_sd(struct segment_descriptor *sdp, uint32_t base);
+void	identify_hypervisor(void);
 void	initializecpu(void);
-void	enable_sse(void);
-void	fillw(int /*u_short*/ pat, void *base, size_t cnt);
+void	initializecpucache(void);
+bool	fix_cpuid(void);
 void	i686_pagezero(void *addr);
 void	sse2_pagezero(void *addr);
 void	init_AMD_Elan_sc520(void);
@@ -100,8 +139,14 @@
 int	is_physical_memory(vm_paddr_t addr);
 int	isa_nmi(int cd);
 vm_paddr_t kvtop(void *addr);
+void	panicifcpuunsupported(void);
+void	ppro_reenable_apic(void);
+void	printcpuinfo(void);
 void	setidt(int idx, alias_for_inthand_t *func, int typ, int dpl, int selec);
 int     user_dbreg_trap(void);
 void	minidumpsys(struct dumperinfo *);
+union savefpu *get_pcb_user_save_td(struct thread *td);
+union savefpu *get_pcb_user_save_pcb(struct pcb *pcb);
+struct pcb *get_pcb_td(struct thread *td);
 
 #endif /* !_MACHINE_MD_VAR_H_ */

Modified: trunk/sys/i386/include/memdev.h
===================================================================
--- trunk/sys/i386/include/memdev.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/memdev.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Mark R V Murray
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/memdev.h 217515 2011-01-17 22:58:28Z jkim $
  */
 
 #ifndef _MACHINE_MEMDEV_H_

Modified: trunk/sys/i386/include/metadata.h
===================================================================
--- trunk/sys/i386/include/metadata.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/metadata.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,35 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2003 Peter Wemm <peter at FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/metadata.h 294274 2016-01-18 15:52:07Z emaste $ */
 
-#ifndef _MACHINE_METADATA_H_
-#define	_MACHINE_METADATA_H_
-
-#define	MODINFOMD_SMAP		0x1001
-#define	MODINFOMD_SMAP_XATTR	0x1002
-
-#endif /* !_MACHINE_METADATA_H_ */
+#include <x86/metadata.h>

Modified: trunk/sys/i386/include/minidump.h
===================================================================
--- trunk/sys/i386/include/minidump.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/minidump.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 Peter Wemm
  * All rights reserved.
@@ -23,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/minidump.h 157909 2006-04-21 04:28:43Z peter $
  */
 
 #ifndef	_MACHINE_MINIDUMP_H_

Modified: trunk/sys/i386/include/mp_watchdog.h
===================================================================
--- trunk/sys/i386/include/mp_watchdog.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/mp_watchdog.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004 Robert N. M. Watson
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/mp_watchdog.h 133759 2004-08-15 18:02:09Z rwatson $
  */
 
 #ifndef	_MACHINE_MP_WATCHDOG_H_

Modified: trunk/sys/i386/include/nexusvar.h
===================================================================
--- trunk/sys/i386/include/nexusvar.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/nexusvar.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 1998 Massachusetts Institute of Technology
  *
@@ -26,7 +27,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/nexusvar.h 177157 2008-03-13 20:39:04Z jhb $
  */
 
 #ifndef _MACHINE_NEXUSVAR_H_

Modified: trunk/sys/i386/include/npx.h
===================================================================
--- trunk/sys/i386/include/npx.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/npx.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)npx.h	5.3 (Berkeley) 1/18/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/npx.h 276084 2014-12-22 21:32:39Z jhb $
  */
 
 /*
@@ -41,140 +42,29 @@
 #ifndef _MACHINE_NPX_H_
 #define	_MACHINE_NPX_H_
 
-/* Environment information of floating point unit */
-struct env87 {
-	long	en_cw;		/* control word (16bits) */
-	long	en_sw;		/* status word (16bits) */
-	long	en_tw;		/* tag word (16bits) */
-	long	en_fip;		/* floating point instruction pointer */
-	u_short	en_fcs;		/* floating code segment selector */
-	u_short	en_opcode;	/* opcode last executed (11 bits ) */
-	long	en_foo;		/* floating operand offset */
-	long	en_fos;		/* floating operand segment selector */
-};
+#include <x86/fpu.h>
 
-/* Contents of each floating point accumulator */
-struct fpacc87 {
-#ifdef dontdef /* too unportable */
-	u_long	fp_mantlo;	/* mantissa low (31:0) */
-	u_long	fp_manthi;	/* mantissa high (63:32) */
-	int	fp_exp:15;	/* exponent */
-	int	fp_sgn:1;	/* mantissa sign */
-#else
-	u_char	fp_bytes[10];
-#endif
-};
+#ifdef _KERNEL
 
-/* Floating point context */
-struct save87 {
-	struct	env87 sv_env;	/* floating point control/status */
-	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
-	u_char	sv_pad0[4];	/* padding for (now unused) saved status word */
-	/*
-	 * Bogus padding for emulators.  Emulators should use their own
-	 * struct and arrange to store into this struct (ending here)
-	 * before it is inspected for ptracing or for core dumps.  Some
-	 * emulators overwrite the whole struct.  We have no good way of
-	 * knowing how much padding to leave.  Leave just enough for the
-	 * GPL emulator's i387_union (176 bytes total).
-	 */
-	u_char	sv_pad[64];	/* padding; used by emulators */
-};
+struct fpu_kern_ctx;
 
-struct  envxmm {
-	u_int16_t	en_cw;		/* control word (16bits) */
-	u_int16_t	en_sw;		/* status word (16bits) */
-	u_int16_t	en_tw;		/* tag word (16bits) */
-	u_int16_t	en_opcode;	/* opcode last executed (11 bits ) */
-	u_int32_t	en_fip;		/* floating point instruction pointer */
-	u_int16_t	en_fcs;		/* floating code segment selector */
-	u_int16_t	en_pad0;	/* padding */
-	u_int32_t	en_foo;		/* floating operand offset */
-	u_int16_t	en_fos;		/* floating operand segment selector */
-	u_int16_t	en_pad1;	/* padding */
-	u_int32_t	en_mxcsr;	/* SSE control/status register */
-	u_int32_t	en_mxcsr_mask;	/* valid bits in mxcsr */
-};
+#define	PCB_USER_FPU(pcb) (((pcb)->pcb_flags & PCB_KERNNPX) == 0)
 
-/* Contents of each SSE extended accumulator */
-struct  xmmacc {
-	u_char	xmm_bytes[16];
-};
+#define	XSAVE_AREA_ALIGN	64
 
-/* Contents of the upper 16 bytes of each AVX extended accumulator */
-struct  ymmacc {
-	uint8_t  ymm_bytes[16];
-};
-
-struct  savexmm {
-	struct	envxmm	sv_env;
-	struct {
-		struct fpacc87	fp_acc;
-		u_char		fp_pad[6];      /* padding */
-	} sv_fp[8];
-	struct xmmacc	sv_xmm[8];
-	u_char sv_pad[224];
-} __aligned(16);
-
-union	savefpu {
-	struct	save87	sv_87;
-	struct	savexmm	sv_xmm;
-};
-
-struct xstate_hdr {
-	uint64_t xstate_bv;
-	uint8_t xstate_rsrv0[16];
-	uint8_t	xstate_rsrv[40];
-};
-
-struct savexmm_xstate {
-	struct xstate_hdr sx_hd;
-	struct ymmacc	sx_ymm[16];
-};
-
-struct savexmm_ymm {
-	struct	envxmm	sv_env;
-	struct {
-		struct fpacc87	fp_acc;
-		int8_t		fp_pad[6];      /* padding */
-	} sv_fp[8];
-	struct xmmacc	sv_xmm[16];
-	uint8_t sv_pad[96];
-	struct savexmm_xstate sv_xstate;
-} __aligned(64);
-
-/*
- * The hardware default control word for i387's and later coprocessors is
- * 0x37F, giving:
- *
- *	round to nearest
- *	64-bit precision
- *	all exceptions masked.
- *
- * We modify the affine mode bit and precision bits in this to give:
- *
- *	affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
- *	53-bit precision (2 in bitfield 3<<8)
- *
- * 64-bit precision often gives bad results with high level languages
- * because it makes the results of calculations depend on whether
- * intermediate values are stored in memory or in FPU registers.
- */
-#define	__INITIAL_NPXCW__	0x127F
-#define	__INITIAL_MXCSR__	0x1F80
-
-#ifdef _KERNEL
-
-#define	PCB_USER_FPU(pcb) (((pcb)->pcb_flags & PCB_KERNNPX) == 0)
-
 int	npxdna(void);
 void	npxdrop(void);
 void	npxexit(struct thread *td);
 int	npxformat(void);
 int	npxgetregs(struct thread *td);
-void	npxinit(void);
+void	npxinit(bool bsp);
+void	npxresume(union savefpu *addr);
 void	npxsave(union savefpu *addr);
-void	npxsetregs(struct thread *td, union savefpu *addr);
+int	npxsetregs(struct thread *td, union savefpu *addr,
+	    char *xfpustate, size_t xfpustate_size);
+int	npxsetxstate(struct thread *td, char *xfpustate,
+	    size_t xfpustate_size);
+void	npxsuspend(union savefpu *addr);
 int	npxtrap_x87(void);
 int	npxtrap_sse(void);
 void	npxuserinited(struct thread *);
@@ -186,11 +76,16 @@
 int	fpu_kern_thread(u_int flags);
 int	is_fpu_kern_thread(u_int flags);
 
+union savefpu	*fpu_save_area_alloc(void);
+void	fpu_save_area_free(union savefpu *fsa);
+void	fpu_save_area_reset(union savefpu *fsa);
+
 /*
- * Flags for fpu_kern_enter() and fpu_kern_thread().
+ * Flags for fpu_kern_alloc_ctx(), fpu_kern_enter() and fpu_kern_thread().
  */
 #define	FPU_KERN_NORMAL	0x0000
 #define	FPU_KERN_NOWAIT	0x0001
+#define	FPU_KERN_KTHR	0x0002
 
 #endif
 

Modified: trunk/sys/i386/include/param.h
===================================================================
--- trunk/sys/i386/include/param.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/param.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,31 +31,20 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)param.h	5.8 (Berkeley) 6/28/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/param.h 286878 2015-08-18 09:09:39Z kib $
  */
 
-#include <machine/_align.h>
 
 #ifndef _I386_INCLUDE_PARAM_H_
 #define	_I386_INCLUDE_PARAM_H_
 
+#include <machine/_align.h>
+
 /*
  * Machine dependent constants for Intel 386.
  */
 
-/*
- * Round p (pointer or byte index) up to a correctly-aligned value
- * for all data types (int, long, ...).   The result is unsigned int
- * and must be cast to any desired pointer type.
- */
-#ifndef _ALIGNBYTES
-#define _ALIGNBYTES	(sizeof(int) - 1)
-#endif
-#ifndef _ALIGN
-#define _ALIGN(p)	(((unsigned)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
-#endif
 
-
 #define __HAVE_ACPI
 #define	__HAVE_PIR
 #define __PCI_REROUTE_INTERRUPT
@@ -75,6 +65,10 @@
 #define MAXCPU		1
 #endif /* SMP || KLD_MODULE */
 
+#ifndef MAXMEMDOM
+#define	MAXMEMDOM	1
+#endif
+
 #define ALIGNBYTES	_ALIGNBYTES
 #define ALIGN(p)	_ALIGN(p)
 /*
@@ -97,7 +91,7 @@
 #define PAGE_MASK	(PAGE_SIZE-1)
 #define NPTEPG		(PAGE_SIZE/(sizeof (pt_entry_t)))
 
-#ifdef PAE
+#if defined(PAE) || defined(PAE_TABLES)
 #define NPGPTD		4
 #define PDRSHIFT	21		/* LOG2(NBPDR) */
 #define NPGPTD_SHIFT	9
@@ -121,6 +115,11 @@
 #define KSTACK_PAGES 2		/* Includes pcb! */
 #endif
 #define KSTACK_GUARD_PAGES 1	/* pages of kstack guard; 0 disables */
+#if KSTACK_PAGES < 4
+#define	TD0_KSTACK_PAGES 4
+#else
+#define	TD0_KSTACK_PAGES KSTACK_PAGES
+#endif
 
 /*
  * Ceiling on amount of swblock kva space, can be changed via
@@ -164,4 +163,7 @@
 
 #define	pgtok(x)		((x) * (PAGE_SIZE / 1024))
 
+#define INKERNEL(va)	(((vm_offset_t)(va)) >= VM_MAXUSER_ADDRESS && \
+    ((vm_offset_t)(va)) < VM_MAX_KERNEL_ADDRESS)
+
 #endif /* !_I386_INCLUDE_PARAM_H_ */

Modified: trunk/sys/i386/include/pc/bios.h
===================================================================
--- trunk/sys/i386/include/pc/bios.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pc/bios.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997 Michael Smith
  * Copyright (c) 1998 Jonathan Lemon
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pc/bios.h 272913 2014-10-10 20:47:23Z jhb $
  */
 
 #ifndef _MACHINE_PC_BIOS_H_
@@ -221,6 +222,14 @@
     u_int32_t	type;
 } __packed;
 
+/* Structure extended to include extended attribute field in ACPI 3.0. */
+struct bios_smap_xattr {
+    u_int64_t	base;
+    u_int64_t	length;
+    u_int32_t	type;
+    u_int32_t	xattr;
+} __packed;
+
 /*
  * System Management BIOS
  */

Modified: trunk/sys/i386/include/pc/display.h
===================================================================
--- trunk/sys/i386/include/pc/display.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pc/display.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,7 +1,8 @@
+/* $MidnightBSD$ */
 /*
  * IBM PC display definitions
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pc/display.h 145010 2005-04-13 13:12:12Z nyan $
  */
 
 /* Color attributes for foreground text */

Modified: trunk/sys/i386/include/pcaudioio.h
===================================================================
--- trunk/sys/i386/include/pcaudioio.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pcaudioio.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1994 S\xF8ren Schmidt
+ * Copyright (c) 1994 Søren Schmidt
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,7 +26,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pcaudioio.h 230132 2012-01-15 13:23:18Z uqs $
  */
 
 #ifndef	_MACHINE_PCAUDIOIO_H_

Modified: trunk/sys/i386/include/pcb.h
===================================================================
--- trunk/sys/i386/include/pcb.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pcb.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)pcb.h	5.10 (Berkeley) 5/12/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pcb.h 294283 2016-01-18 18:27:21Z jhb $
  */
 
 #ifndef _I386_PCB_H_
@@ -44,18 +45,28 @@
 #endif
 #include <machine/npx.h>
 
+/*
+ * NB: The fields marked with (*) are used by kernel debuggers.  Their
+ * ABI should be preserved.
+ */
 struct pcb {
+	int	pcb_edi;	/* (*) */
+	int	pcb_esi;	/* (*) */
+	int	pcb_ebp;	/* (*) */
+	int	pcb_esp;	/* (*) */
+	int	pcb_ebx;	/* (*) */
+	int	pcb_eip;	/* (*) */
+	struct segment_descriptor pcb_fsd;
+	struct segment_descriptor pcb_gsd;
+	int	pcb_ds;
+	int	pcb_es;
+	int	pcb_fs;
+	int	pcb_gs;
+	int	pcb_ss;
 	int	pcb_cr0;
 	int	pcb_cr2;
 	int	pcb_cr3;
 	int	pcb_cr4;
-	int	pcb_edi;
-	int	pcb_esi;
-	int	pcb_ebp;
-	int	pcb_esp;
-	int	pcb_ebx;
-	int	pcb_eip;
-
 	int     pcb_dr0;
 	int     pcb_dr1;
 	int     pcb_dr2;
@@ -63,10 +74,12 @@
 	int     pcb_dr6;
 	int     pcb_dr7;
 
-	union	savefpu	pcb_user_save;
-	uint16_t pcb_initial_npxcw;
+	struct region_descriptor pcb_gdt;
+	struct region_descriptor pcb_idt;
+	uint16_t	pcb_ldt;
+	uint16_t	pcb_tr;
+
 	u_int	pcb_flags;
-#define	FP_SOFTFP	0x01	/* process using software fltng pnt emulator */
 #define	PCB_DBREGS	0x02	/* process using debug registers */
 #define	PCB_NPXINITDONE	0x08	/* fpu state is initialized */
 #define	PCB_VM86CALL	0x10	/* in vm86 call */
@@ -73,32 +86,31 @@
 #define	PCB_NPXUSERINITDONE 0x20 /* user fpu state is initialized */
 #define	PCB_KERNNPX	0x40	/* kernel uses npx */
 
+	uint16_t pcb_initial_npxcw;
+
 	caddr_t	pcb_onfault;	/* copyin/out fault recovery */
-	int	pcb_ds;
-	int	pcb_es;
-	int	pcb_fs;
-	int	pcb_gs;
-	int	pcb_ss;
-	struct segment_descriptor pcb_fsd;
-	struct segment_descriptor pcb_gsd;
 	struct	pcb_ext	*pcb_ext;	/* optional pcb extension */
 	int	pcb_psl;	/* process status long */
 	u_long	pcb_vm86[2];	/* vm86bios scratch space */
 	union	savefpu *pcb_save;
 
-	struct region_descriptor pcb_gdt;
-	struct region_descriptor pcb_idt;
-	uint16_t	pcb_ldt;
-	uint16_t	pcb_tr;
+	uint32_t pcb_pad[10];
 };
 
+/* Per-CPU state saved during suspend and resume. */
+struct susppcb {
+	struct pcb	sp_pcb;
+
+	/* fpu context for suspend/resume */
+	void		*sp_fpususpend;
+};
+
 #ifdef _KERNEL
 struct trapframe;
 
 void	makectx(struct trapframe *, struct pcb *);
-void	savectx(struct pcb *) __returns_twice;
-int	suspendctx(struct pcb *) __returns_twice;
-void	resumectx(struct pcb *);
+int	savectx(struct pcb *) __returns_twice;
+void	resumectx(struct pcb *) __fastcall;
 #endif
 
 #endif /* _I386_PCB_H_ */

Modified: trunk/sys/i386/include/pcb_ext.h
===================================================================
--- trunk/sys/i386/include/pcb_ext.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pcb_ext.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997 Jonathan Lemon
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pcb_ext.h 150173 2005-09-15 17:30:08Z jhb $
  */
 
 #ifndef _I386_PCB_EXT_H_

Modified: trunk/sys/i386/include/pci_cfgreg.h
===================================================================
--- trunk/sys/i386/include/pci_cfgreg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pci_cfgreg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/pci_cfgreg.h 223440 2011-06-22 21:04:13Z jhb $ */
 
 #include <x86/pci_cfgreg.h>

Modified: trunk/sys/i386/include/pcpu.h
===================================================================
--- trunk/sys/i386/include/pcpu.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pcpu.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) Peter Wemm
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pcpu.h 256073 2013-10-05 23:11:01Z gibbs $
  */
 
 #ifndef _MACHINE_PCPU_H_
@@ -44,15 +45,6 @@
  * other processors"
  */
 
-#if defined(XEN) || defined(XENHVM)
-#ifndef NR_VIRQS
-#define	NR_VIRQS	24
-#endif
-#ifndef NR_IPIS
-#define	NR_IPIS		2
-#endif
-#endif
-
 #if defined(XEN)
 
 /* These are peridically updated in shared_info, and then copied here. */
@@ -71,22 +63,14 @@
 	vm_paddr_t *pc_pdir_shadow;					\
 	uint64_t pc_processed_system_time;				\
 	struct shadow_time_info pc_shadow_time;				\
-	int	pc_resched_irq;						\
-	int	pc_callfunc_irq;					\
-	int	pc_virq_to_irq[NR_VIRQS];				\
-	int	pc_ipi_to_irq[NR_IPIS]	
+	char	__pad[185]
 
-#elif defined(XENHVM)
+#else /* !XEN */
 
-#define	PCPU_XEN_FIELDS							\
+#define PCPU_XEN_FIELDS							\
 	;								\
-	unsigned int pc_last_processed_l1i;				\
-	unsigned int pc_last_processed_l2i
+	char	__pad[233]
 
-#else /* !XEN && !XENHVM */
-
-#define PCPU_XEN_FIELDS
-
 #endif
 
 #define	PCPU_MD_FIELDS							\
@@ -101,7 +85,8 @@
 	u_int   pc_acpi_id;		/* ACPI CPU id */		\
 	u_int	pc_apic_id;						\
 	int	pc_private_tss;		/* Flag indicating private tss*/\
-	u_int	pc_cmci_mask		/* MCx banks for CMCI */	\
+	u_int	pc_cmci_mask;		/* MCx banks for CMCI */	\
+	u_int	pc_vcpu_id		/* Xen vCPU ID */		\
 	PCPU_XEN_FIELDS
 
 #ifdef _KERNEL

Modified: trunk/sys/i386/include/perfmon.h
===================================================================
--- trunk/sys/i386/include/perfmon.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/perfmon.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright 1996 Massachusetts Institute of Technology
  *
@@ -26,7 +27,7 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/perfmon.h 139790 2005-01-06 22:18:23Z imp $
  */
 
 /*

Modified: trunk/sys/i386/include/pmap.h
===================================================================
--- trunk/sys/i386/include/pmap.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pmap.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1991 Regents of the University of California.
  * All rights reserved.
@@ -38,7 +39,7 @@
  *
  *	from: hp300: @(#)pmap.h	7.2 (Berkeley) 12/16/90
  *	from: @(#)pmap.h	7.4 (Berkeley) 5/12/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pmap.h 320432 2017-06-28 04:23:20Z alc $
  */
 
 #ifndef _MACHINE_PMAP_H_
@@ -63,7 +64,7 @@
 #define	PG_AVAIL2	0x400	/*   <	programmers use		*/
 #define	PG_AVAIL3	0x800	/*    \				*/
 #define	PG_PDE_PAT	0x1000	/* PAT	PAT index		*/
-#ifdef PAE
+#if defined(PAE) || defined(PAE_TABLES)
 #define	PG_NX		(1ull<<63) /* No-execute */
 #endif
 
@@ -71,7 +72,8 @@
 /* Our various interpretations of the above */
 #define PG_W		PG_AVAIL1	/* "Wired" pseudoflag */
 #define	PG_MANAGED	PG_AVAIL2
-#ifdef PAE
+#define	PG_PROMOTED	PG_AVAIL3	/* PDE only */
+#if defined(PAE) || defined(PAE_TABLES)
 #define	PG_FRAME	(0x000ffffffffff000ull)
 #define	PG_PS_FRAME	(0x000fffffffe00000ull)
 #else
@@ -110,7 +112,7 @@
  * is 1 Gigabyte.  Double everything.  It must be a multiple of 8 for PAE.
  */
 #ifndef KVA_PAGES
-#ifdef PAE
+#if defined(PAE) || defined(PAE_TABLES)
 #define KVA_PAGES	512
 #else
 #define KVA_PAGES	256
@@ -122,13 +124,21 @@
  */
 #define VADDR(pdi, pti) ((vm_offset_t)(((pdi)<<PDRSHIFT)|((pti)<<PAGE_SHIFT)))
 
-/* Initial number of kernel page tables. */
+/*
+ * The initial number of kernel page table pages that are constructed
+ * by locore must be sufficient to map vm_page_array.  That number can
+ * be calculated as follows:
+ *     max_phys / PAGE_SIZE * sizeof(struct vm_page) / NBPDR
+ * PAE:      max_phys 16G, sizeof(vm_page) 76, NBPDR 2M, 152 page table pages.
+ * PAE_TABLES: max_phys 4G,  sizeof(vm_page) 68, NBPDR 2M, 36 page table pages.
+ * Non-PAE:  max_phys 4G,  sizeof(vm_page) 68, NBPDR 4M, 18 page table pages.
+ */
 #ifndef NKPT
-#ifdef PAE
-/* 152 page tables needed to map 16G (76B "struct vm_page", 2M page tables). */
+#if defined(PAE)
 #define	NKPT		240
+#elif defined(PAE_TABLES)
+#define	NKPT		60
 #else
-/* 18 page tables needed to map 4G (72B "struct vm_page", 4M page tables). */
 #define	NKPT		30
 #endif
 #endif
@@ -159,8 +169,10 @@
 #include <sys/_lock.h>
 #include <sys/_mutex.h>
 
-#ifdef PAE
+#include <vm/_vm_radix.h>
 
+#if defined(PAE) || defined(PAE_TABLES)
+
 typedef uint64_t pdpt_entry_t;
 typedef uint64_t pd_entry_t;
 typedef uint64_t pt_entry_t;
@@ -186,7 +198,7 @@
 extern pd_entry_t PTD[];
 extern pd_entry_t PTDpde[];
 
-#ifdef PAE
+#if defined(PAE) || defined(PAE_TABLES)
 extern pdpt_entry_t *IdlePDPT;
 #endif
 extern pd_entry_t *IdlePTD;	/* physical address of "Idle" state directory */
@@ -211,7 +223,9 @@
 
 #if defined(XEN)
 #include <sys/param.h>
-#include <machine/xen/xen-os.h>
+
+#include <xen/xen-os.h>
+
 #include <machine/xen/xenvar.h>
 #include <machine/xen/xenpmap.h>
 
@@ -322,100 +336,29 @@
 #define PT_UPDATES_FLUSH()
 #endif
 
-#if defined(PAE) && !defined(XEN)
+#if (defined(PAE) || defined(PAE_TABLES)) && !defined(XEN)
 
-#define	pde_cmpset(pdep, old, new) \
-				atomic_cmpset_64((pdep), (old), (new))
+#define	pde_cmpset(pdep, old, new)	atomic_cmpset_64_i586(pdep, old, new)
+#define	pte_load_store(ptep, pte)	atomic_swap_64_i586(ptep, pte)
+#define	pte_load_clear(ptep)		atomic_swap_64_i586(ptep, 0)
+#define	pte_store(ptep, pte)		atomic_store_rel_64_i586(ptep, pte)
 
-static __inline pt_entry_t
-pte_load(pt_entry_t *ptep)
-{
-	pt_entry_t r;
-
-	__asm __volatile(
-	    "lock; cmpxchg8b %1"
-	    : "=A" (r)
-	    : "m" (*ptep), "a" (0), "d" (0), "b" (0), "c" (0));
-	return (r);
-}
-
-static __inline pt_entry_t
-pte_load_store(pt_entry_t *ptep, pt_entry_t v)
-{
-	pt_entry_t r;
-
-	r = *ptep;
-	__asm __volatile(
-	    "1:\n"
-	    "\tlock; cmpxchg8b %1\n"
-	    "\tjnz 1b"
-	    : "+A" (r)
-	    : "m" (*ptep), "b" ((uint32_t)v), "c" ((uint32_t)(v >> 32)));
-	return (r);
-}
-
-/* XXXRU move to atomic.h? */
-static __inline int
-atomic_cmpset_64(volatile uint64_t *dst, uint64_t exp, uint64_t src)
-{
-	int64_t res = exp;
-
-	__asm __volatile (
-	"	lock ;			"
-	"	cmpxchg8b %2 ;		"
-	"	setz	%%al ;		"
-	"	movzbl	%%al,%0 ;	"
-	"# atomic_cmpset_64"
-	: "+A" (res),			/* 0 (result) */
-	  "=m" (*dst)			/* 1 */
-	: "m" (*dst),			/* 2 */
-	  "b" ((uint32_t)src),
-	  "c" ((uint32_t)(src >> 32)));
-
-	return (res);
-}
-
-#define	pte_load_clear(ptep)	pte_load_store((ptep), (pt_entry_t)0ULL)
-
-#define	pte_store(ptep, pte)	pte_load_store((ptep), (pt_entry_t)pte)
-
 extern pt_entry_t pg_nx;
 
-#elif !defined(PAE) && !defined (XEN)
+#elif !defined(PAE) && !defined(PAE_TABLES) && !defined(XEN)
 
-#define	pde_cmpset(pdep, old, new) \
-				atomic_cmpset_int((pdep), (old), (new))
+#define	pde_cmpset(pdep, old, new)	atomic_cmpset_int(pdep, old, new)
+#define	pte_load_store(ptep, pte)	atomic_swap_int(ptep, pte)
+#define	pte_load_clear(ptep)		atomic_swap_int(ptep, 0)
+#define	pte_store(ptep, pte) do { \
+	*(u_int *)(ptep) = (u_int)(pte); \
+} while (0)
 
-static __inline pt_entry_t
-pte_load(pt_entry_t *ptep)
-{
-	pt_entry_t r;
-
-	r = *ptep;
-	return (r);
-}
-
-static __inline pt_entry_t
-pte_load_store(pt_entry_t *ptep, pt_entry_t pte)
-{
-	__asm volatile("xchgl %0, %1" : "+m" (*ptep), "+r" (pte));
-	return (pte);
-}
-
-#define	pte_load_clear(pte)	atomic_readandclear_int(pte)
-
-static __inline void
-pte_store(pt_entry_t *ptep, pt_entry_t pte)
-{
-
-	*ptep = pte;
-}
-
 #endif /* PAE */
 
-#define	pte_clear(ptep)		pte_store((ptep), (pt_entry_t)0ULL)
+#define	pte_clear(ptep)			pte_store(ptep, 0)
 
-#define	pde_store(pdep, pde)	pte_store((pdep), (pde))
+#define	pde_store(pdep, pde)		pte_store(pdep, pde)
 
 #endif /* _KERNEL */
 
@@ -437,11 +380,11 @@
 	cpuset_t		pm_active;	/* active on cpus */
 	struct pmap_statistics	pm_stats;	/* pmap statistics */
 	LIST_ENTRY(pmap) 	pm_list;	/* List of all pmaps */
-#ifdef PAE
-	pdpt_entry_t		*pm_pdpt;	/* KVA of page director pointer
+#if defined(PAE) || defined(PAE_TABLES)
+	pdpt_entry_t		*pm_pdpt;	/* KVA of page directory pointer
 						   table */
 #endif
-	vm_page_t		pm_root;	/* spare page table pages */
+	struct vm_radix		pm_root;	/* spare page table pages */
 };
 
 typedef struct pmap	*pmap_t;
@@ -468,7 +411,7 @@
  */
 typedef struct pv_entry {
 	vm_offset_t	pv_va;		/* virtual address for mapping */
-	TAILQ_ENTRY(pv_entry)	pv_list;
+	TAILQ_ENTRY(pv_entry)	pv_next;
 } *pv_entry_t;
 
 /*
@@ -487,8 +430,8 @@
 
 #ifdef	_KERNEL
 
-extern caddr_t	CADDR1;
-extern pt_entry_t *CMAP1;
+extern caddr_t	CADDR3;
+extern pt_entry_t *CMAP3;
 extern vm_paddr_t phys_avail[];
 extern vm_paddr_t dump_avail[];
 extern int pseflag;
@@ -525,7 +468,8 @@
 void	pmap_invalidate_all(pmap_t);
 void	pmap_invalidate_cache(void);
 void	pmap_invalidate_cache_pages(vm_page_t *pages, int count);
-void	pmap_invalidate_cache_range(vm_offset_t sva, vm_offset_t eva);
+void	pmap_invalidate_cache_range(vm_offset_t sva, vm_offset_t eva,
+	    boolean_t force);
 
 #endif /* _KERNEL */
 

Modified: trunk/sys/i386/include/pmc_mdep.h
===================================================================
--- trunk/sys/i386/include/pmc_mdep.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/pmc_mdep.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003-2005,2008 Joseph Koshy
  * Copyright (c) 2007 The FreeBSD Foundation
@@ -27,7 +28,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/pmc_mdep.h 286305 2015-08-05 07:21:44Z kib $
  */
 
 #ifndef _MACHINE_PMC_MDEP_H
@@ -138,8 +139,7 @@
 
 #define	PMC_IN_KERNEL_STACK(S,START,END)		\
 	((S) >= (START) && (S) < (END))
-#define	PMC_IN_KERNEL(va) (((va) >= USRSTACK) &&	\
-	((va) < VM_MAX_KERNEL_ADDRESS))
+#define	PMC_IN_KERNEL(va)	INKERNEL(va)
 
 #define	PMC_IN_USERSPACE(va) ((va) <= VM_MAXUSER_ADDRESS)
 

Modified: trunk/sys/i386/include/ppireg.h
===================================================================
--- trunk/sys/i386/include/ppireg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ppireg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2005 TAKAHASHI Yoshihiro. All rights reserved.
  *
@@ -22,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/ppireg.h 146211 2005-05-14 09:10:02Z nyan $
  */
 
 #ifndef _MACHINE_PPIREG_H_

Modified: trunk/sys/i386/include/privatespace.h
===================================================================
--- trunk/sys/i386/include/privatespace.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/privatespace.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) Peter Wemm
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/privatespace.h 158501 2006-05-12 22:38:53Z peter $
  */
 
 #ifndef _MACHINE_PRIVATESPACE_H_

Modified: trunk/sys/i386/include/proc.h
===================================================================
--- trunk/sys/i386/include/proc.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/proc.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1991 Regents of the University of California.
  * All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)proc.h	7.1 (Berkeley) 5/15/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/proc.h 233291 2012-03-22 04:52:51Z alc $
  */
 
 #ifndef _MACHINE_PROC_H_

Modified: trunk/sys/i386/include/profile.h
===================================================================
--- trunk/sys/i386/include/profile.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/profile.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)profile.h	8.1 (Berkeley) 6/11/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/profile.h 214346 2010-10-25 15:28:03Z jhb $
  */
 
 #ifndef _MACHINE_PROFILE_H_

Modified: trunk/sys/i386/include/psl.h
===================================================================
--- trunk/sys/i386/include/psl.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/psl.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,84 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)psl.h	5.2 (Berkeley) 1/18/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/psl.h 233204 2012-03-19 21:29:57Z tijl $ */
 
-#ifndef _MACHINE_PSL_H_
-#define	_MACHINE_PSL_H_
-
-/*
- * 386 processor status longword.
- */
-#define	PSL_C		0x00000001	/* carry bit */
-#define	PSL_PF		0x00000004	/* parity bit */
-#define	PSL_AF		0x00000010	/* bcd carry bit */
-#define	PSL_Z		0x00000040	/* zero bit */
-#define	PSL_N		0x00000080	/* negative bit */
-#define	PSL_T		0x00000100	/* trace enable bit */
-#define	PSL_I		0x00000200	/* interrupt enable bit */
-#define	PSL_D		0x00000400	/* string instruction direction bit */
-#define	PSL_V		0x00000800	/* overflow bit */
-#define	PSL_IOPL	0x00003000	/* i/o privilege level */
-#define	PSL_NT		0x00004000	/* nested task bit */
-#define	PSL_RF		0x00010000	/* resume flag bit */
-#define	PSL_VM		0x00020000	/* virtual 8086 mode bit */
-#define	PSL_AC		0x00040000	/* alignment checking */
-#define	PSL_VIF		0x00080000	/* virtual interrupt enable */
-#define	PSL_VIP		0x00100000	/* virtual interrupt pending */
-#define	PSL_ID		0x00200000	/* identification bit */
-
-/*
- * The i486 manual says that we are not supposed to change reserved flags,
- * but this is too much trouble since the reserved flags depend on the cpu
- * and setting them to their historical values works in practice.
- */
-#define	PSL_RESERVED_DEFAULT	0x00000002
-
-/*
- * Initial flags for kernel and user mode.  The kernel later inherits
- * PSL_I and some other flags from user mode.
- */
-#define	PSL_KERNEL	PSL_RESERVED_DEFAULT
-#define	PSL_USER	(PSL_RESERVED_DEFAULT | PSL_I)
-
-/*
- * Bits that can be changed in user mode on 486's.  We allow these bits
- * to be changed using ptrace(), sigreturn() and procfs.  Setting PS_NT
- * is undesirable but it may as well be allowed since users can inflict
- * it on the kernel directly.  Changes to PSL_AC are silently ignored on
- * 386's.
- */
-#define	PSL_USERCHANGE (PSL_C | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_T \
-			| PSL_D | PSL_V | PSL_NT | PSL_AC | PSL_ID)
-
-#endif /* !_MACHINE_PSL_H_ */
+#include <x86/psl.h>

Modified: trunk/sys/i386/include/ptrace.h
===================================================================
--- trunk/sys/i386/include/ptrace.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ptrace.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,43 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)ptrace.h	8.1 (Berkeley) 6/11/93
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/ptrace.h 232520 2012-03-04 20:24:28Z tijl $ */
 
-#ifndef _MACHINE_PTRACE_H_
-#define _MACHINE_PTRACE_H_
-
-#define	__HAVE_PTRACE_MACHDEP
-
-#define PT_GETXMMREGS	(PT_FIRSTMACH + 0)
-#define PT_SETXMMREGS	(PT_FIRSTMACH + 1)
-#define PT_GETXSTATE	(PT_FIRSTMACH + 2)
-#define PT_SETXSTATE	(PT_FIRSTMACH + 3)
-
-#endif
+#include <x86/ptrace.h>

Modified: trunk/sys/i386/include/reg.h
===================================================================
--- trunk/sys/i386/include/reg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/reg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,172 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)reg.h	5.5 (Berkeley) 1/18/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/reg.h 233124 2012-03-18 19:06:38Z tijl $ */
 
-#ifndef _MACHINE_REG_H_
-#define	_MACHINE_REG_H_
-
-/*
- * Indices for registers in `struct trapframe' and `struct regs'.
- *
- * This interface is deprecated.  In the kernel, it is only used in FPU
- * emulators to convert from register numbers encoded in instructions to
- * register values.  Everything else just accesses the relevant struct
- * members.  In userland, debuggers tend to abuse this interface since
- * they don't understand that `struct regs' is a struct.  I hope they have
- * stopped accessing the registers in the trap frame via PT_{READ,WRITE}_U
- * and we can stop supporting the user area soon.
- */
-#define	tFS	(0)
-#define	tES	(1)
-#define	tDS	(2)
-#define	tEDI	(3)
-#define	tESI	(4)
-#define	tEBP	(5)
-#define	tISP	(6)
-#define	tEBX	(7)
-#define	tEDX	(8)
-#define	tECX	(9)
-#define	tEAX	(10)
-#define	tERR	(12)
-#define	tEIP	(13)
-#define	tCS	(14)
-#define	tEFLAGS	(15)
-#define	tESP	(16)
-#define	tSS	(17)
-
-/*
- * Indices for registers in `struct regs' only.
- *
- * Some registers live in the pcb and are only in an "array" with the
- * other registers in application interfaces that copy all the registers
- * to or from a `struct regs'.
- */
-#define	tGS	(18)
-
-/*
- * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS.
- */
-struct reg {
-	unsigned int	r_fs;
-	unsigned int	r_es;
-	unsigned int	r_ds;
-	unsigned int	r_edi;
-	unsigned int	r_esi;
-	unsigned int	r_ebp;
-	unsigned int	r_isp;
-	unsigned int	r_ebx;
-	unsigned int	r_edx;
-	unsigned int	r_ecx;
-	unsigned int	r_eax;
-	unsigned int	r_trapno;
-	unsigned int	r_err;
-	unsigned int	r_eip;
-	unsigned int	r_cs;
-	unsigned int	r_eflags;
-	unsigned int	r_esp;
-	unsigned int	r_ss;
-	unsigned int	r_gs;
-};
-
-/*
- * Register set accessible via /proc/$pid/fpregs.
- */
-struct fpreg {
-	/*
-	 * XXX should get struct from npx.h.  Here we give a slightly
-	 * simplified struct.  This may be too much detail.  Perhaps
-	 * an array of unsigned longs is best.
-	 */
-	unsigned long	fpr_env[7];
-	unsigned char	fpr_acc[8][10];
-	unsigned long	fpr_ex_sw;
-	unsigned char	fpr_pad[64];
-};
-
-struct xmmreg {
-	/*
-	 * XXX should get struct from npx.h.  Here we give a slightly
-	 * simplified struct.  This may be too much detail.  Perhaps
-	 * an array of unsigned longs is best.
-	 */
-	unsigned long	xmm_env[8];
-	unsigned char	xmm_acc[8][16];
-	unsigned char	xmm_reg[8][16];
-	unsigned char	xmm_pad[224];
-};
-
-/*
- * Register set accessible via /proc/$pid/dbregs.
- */
-struct dbreg {
-	unsigned int  dr[8];	/* debug registers */
-				/* Index 0-3: debug address registers */
-				/* Index 4-5: reserved */
-				/* Index 6: debug status */
-				/* Index 7: debug control */
-};
-
-#define	DBREG_DR7_LOCAL_ENABLE	0x01
-#define	DBREG_DR7_GLOBAL_ENABLE	0x02
-#define	DBREG_DR7_LEN_1		0x00	/* 1 byte length          */
-#define	DBREG_DR7_LEN_2		0x01
-#define	DBREG_DR7_LEN_4		0x03
-#define	DBREG_DR7_EXEC		0x00	/* break on execute       */
-#define	DBREG_DR7_WRONLY	0x01	/* break on write         */
-#define	DBREG_DR7_RDWR		0x03	/* break on read or write */
-#define	DBREG_DR7_MASK(i)	(0xf << ((i) * 4 + 16) | 0x3 << (i) * 2)
-#define	DBREG_DR7_SET(i, len, access, enable)				\
-	(((len) << 2 | (access)) << ((i) * 4 + 16) | (enable) << (i) * 2)
-#define	DBREG_DR7_GD		0x2000
-#define	DBREG_DR7_ENABLED(d, i)	(((d) & 0x3 << (i) * 2) != 0)
-#define	DBREG_DR7_ACCESS(d, i)	((d) >> ((i) * 4 + 16) & 0x3)
-#define	DBREG_DR7_LEN(d, i)	((d) >> ((i) * 4 + 18) & 0x3)
-
-#define	DBREG_DRX(d,x)	((d)->dr[(x)])	/* reference dr0 - dr7 by
-					   register number */
-
-#ifdef _KERNEL
-/*
- * XXX these interfaces are MI, so they should be declared in a MI place.
- */
-int	fill_regs(struct thread *, struct reg *);
-int	fill_frame_regs(struct trapframe *, struct reg *);
-int	set_regs(struct thread *, struct reg *);
-int	fill_fpregs(struct thread *, struct fpreg *);
-int	set_fpregs(struct thread *, struct fpreg *);
-int	fill_dbregs(struct thread *, struct dbreg *);
-int	set_dbregs(struct thread *, struct dbreg *);
-#endif
-
-#endif /* !_MACHINE_REG_H_ */
+#include <x86/reg.h>

Modified: trunk/sys/i386/include/reloc.h
===================================================================
--- trunk/sys/i386/include/reloc.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/reloc.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1992, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,7 +28,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)reloc.h	8.1 (Berkeley) 6/10/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/reloc.h 128019 2004-04-07 20:46:16Z imp $
  */
 
 #ifndef _I386_MACHINE_RELOC_H_

Modified: trunk/sys/i386/include/resource.h
===================================================================
--- trunk/sys/i386/include/resource.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/resource.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,4 +1,5 @@
-/* $FreeBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/resource.h 280970 2015-04-01 21:48:54Z jhb $ */
 /*-
  * Copyright 1998 Massachusetts Institute of Technology
  *
@@ -40,5 +41,8 @@
 #define	SYS_RES_DRQ	2	/* isa dma lines */
 #define	SYS_RES_MEMORY	3	/* i/o memory */
 #define	SYS_RES_IOPORT	4	/* i/o ports */
+#ifdef NEW_PCIB
+#define	PCI_RES_BUS	5	/* PCI bus numbers */
+#endif
 
 #endif /* !_MACHINE_RESOURCE_H_ */

Modified: trunk/sys/i386/include/runq.h
===================================================================
--- trunk/sys/i386/include/runq.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/runq.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Jake Burkholder <jake at FreeBSD.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/runq.h 139790 2005-01-06 22:18:23Z imp $
  */
 
 #ifndef	_MACHINE_RUNQ_H_

Modified: trunk/sys/i386/include/segments.h
===================================================================
--- trunk/sys/i386/include/segments.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/segments.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1989, 1990 William F. Jolitz
  * Copyright (c) 1990 The Regents of the University of California.
@@ -31,7 +32,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)segments.h	7.1 (Berkeley) 5/9/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/segments.h 233203 2012-03-19 21:24:50Z tijl $
  */
 
 #ifndef _MACHINE_SEGMENTS_H_
@@ -42,105 +43,9 @@
  *	William F. Jolitz (william at ernie.berkeley.edu) 6/20/1989
  */
 
-/*
- * Selectors
- */
+#include <x86/segments.h>
 
-#define	ISPL(s)	((s)&3)		/* what is the priority level of a selector */
-#ifdef XEN
-#define	SEL_KPL	1		/* kernel priority level */
-#else
-#define	SEL_KPL	0		/* kernel priority level */
-#endif
-#define	SEL_UPL	3		/* user priority level */
-#define	ISLDT(s)	((s)&SEL_LDT)	/* is it local or global */
-#define	SEL_LDT	4		/* local descriptor table */
-#define	IDXSEL(s)	(((s)>>3) & 0x1fff)		/* index of selector */
-#define	LSEL(s,r)	(((s)<<3) | SEL_LDT | r)	/* a local selector */
-#define	GSEL(s,r)	(((s)<<3) | r)			/* a global selector */
-
 /*
- * Memory and System segment descriptors
- */
-struct	segment_descriptor	{
-	unsigned sd_lolimit:16 ;	/* segment extent (lsb) */
-	unsigned sd_lobase:24 __packed;	/* segment base address (lsb) */
-	unsigned sd_type:5 ;		/* segment type */
-	unsigned sd_dpl:2 ;		/* segment descriptor priority level */
-	unsigned sd_p:1 ;		/* segment descriptor present */
-	unsigned sd_hilimit:4 ;		/* segment extent (msb) */
-	unsigned sd_xx:2 ;		/* unused */
-	unsigned sd_def32:1 ;		/* default 32 vs 16 bit size */
-	unsigned sd_gran:1 ;		/* limit granularity (byte/page units)*/
-	unsigned sd_hibase:8 ;		/* segment base address  (msb) */
-} ;
-
-#define	USD_GETBASE(sd)		(((sd)->sd_lobase) | (sd)->sd_hibase << 24) 
-#define	USD_SETBASE(sd, b)	(sd)->sd_lobase = (b);  \
-				(sd)->sd_hibase = ((b) >> 24);
-#define	USD_GETLIMIT(sd)	(((sd)->sd_lolimit) | (sd)->sd_hilimit << 16)
-#define	USD_SETLIMIT(sd, l)	(sd)->sd_lolimit = (l); \
-				(sd)->sd_hilimit = ((l) >> 16);
-
-/*
- * Gate descriptors (e.g. indirect descriptors)
- */
-struct	gate_descriptor	{
-	unsigned gd_looffset:16 ;	/* gate offset (lsb) */
-	unsigned gd_selector:16 ;	/* gate segment selector */
-	unsigned gd_stkcpy:5 ;		/* number of stack wds to cpy */
-	unsigned gd_xx:3 ;		/* unused */
-	unsigned gd_type:5 ;		/* segment type */
-	unsigned gd_dpl:2 ;		/* segment descriptor priority level */
-	unsigned gd_p:1 ;		/* segment descriptor present */
-	unsigned gd_hioffset:16 ;	/* gate offset (msb) */
-} ;
-
-/*
- * Generic descriptor
- */
-union	descriptor	{
-	struct	segment_descriptor sd;
-	struct	gate_descriptor gd;
-};
-
-	/* system segments and gate types */
-#define	SDT_SYSNULL	 0	/* system null */
-#define	SDT_SYS286TSS	 1	/* system 286 TSS available */
-#define	SDT_SYSLDT	 2	/* system local descriptor table */
-#define	SDT_SYS286BSY	 3	/* system 286 TSS busy */
-#define	SDT_SYS286CGT	 4	/* system 286 call gate */
-#define	SDT_SYSTASKGT	 5	/* system task gate */
-#define	SDT_SYS286IGT	 6	/* system 286 interrupt gate */
-#define	SDT_SYS286TGT	 7	/* system 286 trap gate */
-#define	SDT_SYSNULL2	 8	/* system null again */
-#define	SDT_SYS386TSS	 9	/* system 386 TSS available */
-#define	SDT_SYSNULL3	10	/* system null again */
-#define	SDT_SYS386BSY	11	/* system 386 TSS busy */
-#define	SDT_SYS386CGT	12	/* system 386 call gate */
-#define	SDT_SYSNULL4	13	/* system null again */
-#define	SDT_SYS386IGT	14	/* system 386 interrupt gate */
-#define	SDT_SYS386TGT	15	/* system 386 trap gate */
-
-	/* memory segment types */
-#define	SDT_MEMRO	16	/* memory read only */
-#define	SDT_MEMROA	17	/* memory read only accessed */
-#define	SDT_MEMRW	18	/* memory read write */
-#define	SDT_MEMRWA	19	/* memory read write accessed */
-#define	SDT_MEMROD	20	/* memory read only expand dwn limit */
-#define	SDT_MEMRODA	21	/* memory read only expand dwn limit accessed */
-#define	SDT_MEMRWD	22	/* memory read write expand dwn limit */
-#define	SDT_MEMRWDA	23	/* memory read write expand dwn limit accessed */
-#define	SDT_MEME	24	/* memory execute only */
-#define	SDT_MEMEA	25	/* memory execute only accessed */
-#define	SDT_MEMER	26	/* memory execute read */
-#define	SDT_MEMERA	27	/* memory execute read accessed */
-#define	SDT_MEMEC	28	/* memory execute only conforming */
-#define	SDT_MEMEAC	29	/* memory execute only accessed conforming */
-#define	SDT_MEMERC	30	/* memory execute read conforming */
-#define	SDT_MEMERAC	31	/* memory execute read accessed conforming */
-
-/*
  * Software definitions are in this convenient format,
  * which are translated into inconvenient segment descriptors
  * when needed to be used by the 386 hardware
@@ -176,84 +81,6 @@
 				/* other bits are affected descriptor index */
 #define SEGEX_IDX(s)	(((s)>>3)&0x1fff)
 
-/*
- * Size of IDT table
- */
-
-#define	NIDT	256		/* 32 reserved, 0x80 syscall, most are h/w */
-#define	NRSVIDT	32		/* reserved entries for cpu exceptions */
-
-/*
- * Entries in the Interrupt Descriptor Table (IDT)
- */
-#define	IDT_DE		0	/* #DE: Divide Error */
-#define	IDT_DB		1	/* #DB: Debug */
-#define	IDT_NMI		2	/* Nonmaskable External Interrupt */
-#define	IDT_BP		3	/* #BP: Breakpoint */
-#define	IDT_OF		4	/* #OF: Overflow */
-#define	IDT_BR		5	/* #BR: Bound Range Exceeded */
-#define	IDT_UD		6	/* #UD: Undefined/Invalid Opcode */
-#define	IDT_NM		7	/* #NM: No Math Coprocessor */
-#define	IDT_DF		8	/* #DF: Double Fault */
-#define	IDT_FPUGP	9	/* Coprocessor Segment Overrun */
-#define	IDT_TS		10	/* #TS: Invalid TSS */
-#define	IDT_NP		11	/* #NP: Segment Not Present */
-#define	IDT_SS		12	/* #SS: Stack Segment Fault */
-#define	IDT_GP		13	/* #GP: General Protection Fault */
-#define	IDT_PF		14	/* #PF: Page Fault */
-#define	IDT_MF		16	/* #MF: FPU Floating-Point Error */
-#define	IDT_AC		17	/* #AC: Alignment Check */
-#define	IDT_MC		18	/* #MC: Machine Check */
-#define	IDT_XF		19	/* #XF: SIMD Floating-Point Exception */
-#define	IDT_IO_INTS	NRSVIDT	/* Base of IDT entries for I/O interrupts. */
-#define	IDT_SYSCALL	0x80	/* System Call Interrupt Vector */
-#define	IDT_DTRACE_RET	0x92	/* DTrace pid provider Interrupt Vector */
-
-/*
- * Entries in the Global Descriptor Table (GDT)
- * Note that each 4 entries share a single 32 byte L1 cache line.
- * Some of the fast syscall instructions require a specific order here.
- */
-#define	GNULL_SEL	0	/* Null Descriptor */
-#define	GPRIV_SEL	1	/* SMP Per-Processor Private Data */
-#define	GUFS_SEL	2	/* User %fs Descriptor (order critical: 1) */
-#define	GUGS_SEL	3	/* User %gs Descriptor (order critical: 2) */
-#define	GCODE_SEL	4	/* Kernel Code Descriptor (order critical: 1) */
-#define	GDATA_SEL	5	/* Kernel Data Descriptor (order critical: 2) */
-#define	GUCODE_SEL	6	/* User Code Descriptor (order critical: 3) */
-#define	GUDATA_SEL	7	/* User Data Descriptor (order critical: 4) */
-#define	GBIOSLOWMEM_SEL	8	/* BIOS low memory access (must be entry 8) */
-#define	GPROC0_SEL	9	/* Task state process slot zero and up */
-#define	GLDT_SEL	10	/* Default User LDT */
-#define	GUSERLDT_SEL	11	/* User LDT */
-#define	GPANIC_SEL	12	/* Task state to consider panic from */
-#define	GBIOSCODE32_SEL	13	/* BIOS interface (32bit Code) */
-#define	GBIOSCODE16_SEL	14	/* BIOS interface (16bit Code) */
-#define	GBIOSDATA_SEL	15	/* BIOS interface (Data) */
-#define	GBIOSUTIL_SEL	16	/* BIOS interface (Utility) */
-#define	GBIOSARGS_SEL	17	/* BIOS interface (Arguments) */
-#define	GNDIS_SEL	18	/* For the NDIS layer */
-
-#ifdef XEN
-#define	NGDT 		9
-#else
-#define	NGDT 		19
-#endif
-
-/*
- * Entries in the Local Descriptor Table (LDT)
- */
-#define	LSYS5CALLS_SEL	0	/* forced by intel BCS */
-#define	LSYS5SIGR_SEL	1
-#define	L43BSDCALLS_SEL	2	/* notyet */
-#define	LUCODE_SEL	3
-#define LSOL26CALLS_SEL	4	/* Solaris >= 2.6 system call gate */
-#define	LUDATA_SEL	5
-/* separate stack, es,fs,gs sels ? */
-/* #define	LPOSIXCALLS_SEL	5*/	/* notyet */
-#define LBSDICALLS_SEL	16	/* BSDI system call gate */
-#define NLDT		(LBSDICALLS_SEL + 1)
-
 #ifdef _KERNEL
 extern int	_default_ldt;
 #ifdef XEN

Modified: trunk/sys/i386/include/setjmp.h
===================================================================
--- trunk/sys/i386/include/setjmp.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/setjmp.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,50 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1998 John Birrell <jb at cimlogic.com.au>.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the author nor the names of any co-contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/setjmp.h 232275 2012-02-28 22:17:52Z tijl $ */
 
-#ifndef _MACHINE_SETJMP_H_
-#define	_MACHINE_SETJMP_H_
-
-#include <sys/cdefs.h>
-
-#define	_JBLEN	11		/* Size of the jmp_buf on x86. */
-
-/*
- * jmp_buf and sigjmp_buf are encapsulated in different structs to force
- * compile-time diagnostics for mismatches.  The structs are the same
- * internally to avoid some run-time errors for mismatches.
- */
-#if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE
-typedef	struct _sigjmp_buf { int _sjb[_JBLEN + 1]; } sigjmp_buf[1];
-#endif
-
-typedef	struct _jmp_buf { int _jb[_JBLEN + 1]; } jmp_buf[1];
-
-#endif /* !_MACHINE_SETJMP_H_ */
+#include <x86/setjmp.h>

Modified: trunk/sys/i386/include/sf_buf.h
===================================================================
--- trunk/sys/i386/include/sf_buf.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/sf_buf.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003, 2005 Alan L. Cox <alc at cs.rice.edu>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/sf_buf.h 255318 2013-09-06 17:44:13Z glebius $
  */
 
 #ifndef _MACHINE_SF_BUF_H_
@@ -45,6 +46,9 @@
 #endif
 };
 
+struct sf_buf * sf_buf_alloc(struct vm_page *m, int flags);
+void sf_buf_free(struct sf_buf *sf);
+
 static __inline vm_offset_t
 sf_buf_kva(struct sf_buf *sf)
 {

Modified: trunk/sys/i386/include/sigframe.h
===================================================================
--- trunk/sys/i386/include/sigframe.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/sigframe.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Marcel Moolenaar
  * All rights reserved.
@@ -25,7 +26,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/sigframe.h 247047 2013-02-20 17:39:52Z kib $
  */
 
 #ifndef _MACHINE_SIGFRAME_H_
@@ -89,25 +90,6 @@
 #endif
 #endif
 
-struct sigframe {
-	/*
-	 * The first four members may be used by applications.
-	 *
-	 * NOTE: The 4th argument is undocumented, ill commented
-	 * on and seems to be somewhat BSD "standard".  Handlers
-	 * installed with sigvec may be using it.
-	 */
-	register_t	sf_signum;
-	register_t	sf_siginfo;	/* code or pointer to sf_si */
-	register_t	sf_ucontext;	/* points to sf_uc */
-	register_t	sf_addr;	/* undocumented 4th arg */
+#include <x86/sigframe.h>
 
-	union {
-		__siginfohandler_t	*sf_action;
-		__sighandler_t		*sf_handler;
-	} sf_ahu;
-	ucontext_t	sf_uc;		/* = *sf_ucontext */
-	siginfo_t	sf_si;		/* = *sf_siginfo (SA_SIGINFO case) */
-};
-
 #endif /* !_MACHINE_SIGFRAME_H_ */

Modified: trunk/sys/i386/include/signal.h
===================================================================
--- trunk/sys/i386/include/signal.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/signal.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1986, 1989, 1991, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -27,32 +28,14 @@
  * SUCH DAMAGE.
  *
  *	@(#)signal.h	8.1 (Berkeley) 6/11/93
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/signal.h 247047 2013-02-20 17:39:52Z kib $
  */
 
 #ifndef _MACHINE_SIGNAL_H_
 #define	_MACHINE_SIGNAL_H_
 
-#include <sys/cdefs.h>
-#include <sys/_sigset.h>
+#include <x86/signal.h>
 
-/*
- * Machine-dependent signal definitions
- */
-
-typedef int sig_atomic_t;
-
-#if __BSD_VISIBLE
-#include <machine/trap.h>	/* codes for SIGILL, SIGFPE */
-
-/*
- * Information pushed on stack when a signal is delivered.
- * This is used by the kernel to restore state following
- * execution of the signal handler.  It is also made available
- * to the handler to allow it to restore state properly if
- * a non-standard exit is performed.
- */
-
 #if defined(_KERNEL) && defined(COMPAT_43)
 /*
  * Only the kernel should need these old type definitions.
@@ -82,57 +65,4 @@
 };
 #endif
 
-/*
- * The sequence of the fields/registers in struct sigcontext should match
- * those in mcontext_t and struct trapframe.
- */
-struct sigcontext {
-	struct __sigset sc_mask;	/* signal mask to restore */
-	int	sc_onstack;		/* sigstack state to restore */
-	int	sc_gs;			/* machine state (struct trapframe) */
-	int	sc_fs;
-	int	sc_es;
-	int	sc_ds;
-	int	sc_edi;
-	int	sc_esi;
-	int	sc_ebp;
-	int	sc_isp;
-	int	sc_ebx;
-	int	sc_edx;
-	int	sc_ecx;
-	int	sc_eax;
-	int	sc_trapno;
-	int	sc_err;
-	int	sc_eip;
-	int	sc_cs;
-	int	sc_efl;
-	int	sc_esp;
-	int	sc_ss;
-	int	sc_len;			/* sizeof(mcontext_t) */
-	/*
-	 * See <machine/ucontext.h> and <machine/npx.h> for
-	 * the following fields.
-	 */
-	int	sc_fpformat;
-	int	sc_ownedfp;
-	int	sc_flags;
-	int	sc_fpstate[128] __aligned(16);
-
-	int	sc_fsbase;
-	int	sc_gsbase;
-
-	int	sc_xfpustate;
-	int	sc_xfpustate_len;
-
-	int	sc_spare2[4];
-};
-
-#define	sc_sp		sc_esp
-#define	sc_fp		sc_ebp
-#define	sc_pc		sc_eip
-#define	sc_ps		sc_efl
-#define	sc_eflags	sc_efl
-
-#endif /* __BSD_VISIBLE */
-
 #endif /* !_MACHINE_SIGNAL_H_ */

Modified: trunk/sys/i386/include/smapi.h
===================================================================
--- trunk/sys/i386/include/smapi.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/smapi.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003 Matthew N. Dodd <winter at freebsd.org>
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/smapi.h 112558 2003-03-24 20:44:39Z mdodd $
  */
 
 #ifndef _MACHINE_SMAPI_H_

Modified: trunk/sys/i386/include/smp.h
===================================================================
--- trunk/sys/i386/include/smp.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/smp.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * ----------------------------------------------------------------------------
  * "THE BEER-WARE LICENSE" (Revision 42):
@@ -6,7 +7,7 @@
  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
  * ----------------------------------------------------------------------------
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/smp.h 264118 2014-04-04 14:54:54Z royger $
  *
  */
 
@@ -63,7 +64,12 @@
 #ifndef XEN
 void	cpususpend_handler(void);
 #endif
+void	invltlb_handler(void);
+void	invlpg_handler(void);
+void	invlrng_handler(void);
+void	invlcache_handler(void);
 void	init_secondary(void);
+void	ipi_startup(int apic_id, int vector);
 void	ipi_all_but_self(u_int ipi);
 #ifndef XEN
 void 	ipi_bitmap_handler(struct trapframe frame);
@@ -83,11 +89,6 @@
 
 #ifdef XEN
 void ipi_to_irq_init(void);
-
-#define RESCHEDULE_VECTOR	0
-#define CALL_FUNCTION_VECTOR	1
-#define NR_IPIS			2
-
 #endif
 #endif /* !LOCORE */
 #endif /* SMP */

Modified: trunk/sys/i386/include/speaker.h
===================================================================
--- trunk/sys/i386/include/speaker.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/speaker.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/speaker.h 152306 2005-11-11 09:57:32Z ru $
  */
 
 #ifndef	_MACHINE_SPEAKER_H_

Modified: trunk/sys/i386/include/specialreg.h
===================================================================
--- trunk/sys/i386/include/specialreg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/specialreg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,636 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)specialreg.h	7.1 (Berkeley) 5/9/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/specialreg.h 233207 2012-03-19 21:34:11Z tijl $ */
 
-#ifndef _MACHINE_SPECIALREG_H_
-#define	_MACHINE_SPECIALREG_H_
-
-/*
- * Bits in 386 special registers:
- */
-#define	CR0_PE	0x00000001	/* Protected mode Enable */
-#define	CR0_MP	0x00000002	/* "Math" (fpu) Present */
-#define	CR0_EM	0x00000004	/* EMulate FPU instructions. (trap ESC only) */
-#define	CR0_TS	0x00000008	/* Task Switched (if MP, trap ESC and WAIT) */
-#define	CR0_PG	0x80000000	/* PaGing enable */
-
-/*
- * Bits in 486 special registers:
- */
-#define	CR0_NE	0x00000020	/* Numeric Error enable (EX16 vs IRQ13) */
-#define	CR0_WP	0x00010000	/* Write Protect (honor page protect in
-							   all modes) */
-#define	CR0_AM	0x00040000	/* Alignment Mask (set to enable AC flag) */
-#define	CR0_NW  0x20000000	/* Not Write-through */
-#define	CR0_CD  0x40000000	/* Cache Disable */
-
-/*
- * Bits in PPro special registers
- */
-#define	CR4_VME	0x00000001	/* Virtual 8086 mode extensions */
-#define	CR4_PVI	0x00000002	/* Protected-mode virtual interrupts */
-#define	CR4_TSD	0x00000004	/* Time stamp disable */
-#define	CR4_DE	0x00000008	/* Debugging extensions */
-#define	CR4_PSE	0x00000010	/* Page size extensions */
-#define	CR4_PAE	0x00000020	/* Physical address extension */
-#define	CR4_MCE	0x00000040	/* Machine check enable */
-#define	CR4_PGE	0x00000080	/* Page global enable */
-#define	CR4_PCE	0x00000100	/* Performance monitoring counter enable */
-#define	CR4_FXSR 0x00000200	/* Fast FPU save/restore used by OS */
-#define	CR4_XMM	0x00000400	/* enable SIMD/MMX2 to use except 16 */
-#define	CR4_XSAVE 0x00040000	/* XSETBV/XGETBV */
-
-/*
- * Bits in AMD64 special registers.  EFER is 64 bits wide.
- */
-#define	EFER_NXE 0x000000800	/* PTE No-Execute bit enable (R/W) */
-
-/*
- * CPUID instruction features register
- */
-#define	CPUID_FPU	0x00000001
-#define	CPUID_VME	0x00000002
-#define	CPUID_DE	0x00000004
-#define	CPUID_PSE	0x00000008
-#define	CPUID_TSC	0x00000010
-#define	CPUID_MSR	0x00000020
-#define	CPUID_PAE	0x00000040
-#define	CPUID_MCE	0x00000080
-#define	CPUID_CX8	0x00000100
-#define	CPUID_APIC	0x00000200
-#define	CPUID_B10	0x00000400
-#define	CPUID_SEP	0x00000800
-#define	CPUID_MTRR	0x00001000
-#define	CPUID_PGE	0x00002000
-#define	CPUID_MCA	0x00004000
-#define	CPUID_CMOV	0x00008000
-#define	CPUID_PAT	0x00010000
-#define	CPUID_PSE36	0x00020000
-#define	CPUID_PSN	0x00040000
-#define	CPUID_CLFSH	0x00080000
-#define	CPUID_B20	0x00100000
-#define	CPUID_DS	0x00200000
-#define	CPUID_ACPI	0x00400000
-#define	CPUID_MMX	0x00800000
-#define	CPUID_FXSR	0x01000000
-#define	CPUID_SSE	0x02000000
-#define	CPUID_XMM	0x02000000
-#define	CPUID_SSE2	0x04000000
-#define	CPUID_SS	0x08000000
-#define	CPUID_HTT	0x10000000
-#define	CPUID_TM	0x20000000
-#define	CPUID_IA64	0x40000000
-#define	CPUID_PBE	0x80000000
-
-#define	CPUID2_SSE3	0x00000001
-#define	CPUID2_PCLMULQDQ 0x00000002
-#define	CPUID2_DTES64	0x00000004
-#define	CPUID2_MON	0x00000008
-#define	CPUID2_DS_CPL	0x00000010
-#define	CPUID2_VMX	0x00000020
-#define	CPUID2_SMX	0x00000040
-#define	CPUID2_EST	0x00000080
-#define	CPUID2_TM2	0x00000100
-#define	CPUID2_SSSE3	0x00000200
-#define	CPUID2_CNXTID	0x00000400
-#define	CPUID2_FMA	0x00001000
-#define	CPUID2_CX16	0x00002000
-#define	CPUID2_XTPR	0x00004000
-#define	CPUID2_PDCM	0x00008000
-#define	CPUID2_PCID	0x00020000
-#define	CPUID2_DCA	0x00040000
-#define	CPUID2_SSE41	0x00080000
-#define	CPUID2_SSE42	0x00100000
-#define	CPUID2_X2APIC	0x00200000
-#define	CPUID2_MOVBE	0x00400000
-#define	CPUID2_POPCNT	0x00800000
-#define	CPUID2_TSCDLT	0x01000000
-#define	CPUID2_AESNI	0x02000000
-#define	CPUID2_XSAVE	0x04000000
-#define	CPUID2_OSXSAVE	0x08000000
-#define	CPUID2_AVX	0x10000000
-#define	CPUID2_F16C	0x20000000
-#define	CPUID2_RDRAND	0x40000000
-#define	CPUID2_HV	0x80000000
-
-/*
- * Important bits in the Thermal and Power Management flags
- * CPUID.6 EAX and ECX.
- */
-#define	CPUTPM1_SENSOR	0x00000001
-#define	CPUTPM1_TURBO	0x00000002
-#define	CPUTPM1_ARAT	0x00000004
-#define	CPUTPM2_EFFREQ	0x00000001
-
-/*
- * Important bits in the AMD extended cpuid flags
- */
-#define	AMDID_SYSCALL	0x00000800
-#define	AMDID_MP	0x00080000
-#define	AMDID_NX	0x00100000
-#define	AMDID_EXT_MMX	0x00400000
-#define	AMDID_FFXSR	0x01000000
-#define	AMDID_PAGE1GB	0x04000000
-#define	AMDID_RDTSCP	0x08000000
-#define	AMDID_LM	0x20000000
-#define	AMDID_EXT_3DNOW	0x40000000
-#define	AMDID_3DNOW	0x80000000
-
-#define	AMDID2_LAHF	0x00000001
-#define	AMDID2_CMP	0x00000002
-#define	AMDID2_SVM	0x00000004
-#define	AMDID2_EXT_APIC	0x00000008
-#define	AMDID2_CR8	0x00000010
-#define	AMDID2_ABM	0x00000020
-#define	AMDID2_SSE4A	0x00000040
-#define	AMDID2_MAS	0x00000080
-#define	AMDID2_PREFETCH	0x00000100
-#define	AMDID2_OSVW	0x00000200
-#define	AMDID2_IBS	0x00000400
-#define	AMDID2_XOP	0x00000800
-#define	AMDID2_SKINIT	0x00001000
-#define	AMDID2_WDT	0x00002000
-#define	AMDID2_LWP	0x00008000
-#define	AMDID2_FMA4	0x00010000
-#define	AMDID2_NODE_ID	0x00080000
-#define	AMDID2_TBM	0x00200000
-#define	AMDID2_TOPOLOGY	0x00400000
-
-/*
- * CPUID instruction 1 eax info
- */
-#define	CPUID_STEPPING		0x0000000f
-#define	CPUID_MODEL		0x000000f0
-#define	CPUID_FAMILY		0x00000f00
-#define	CPUID_EXT_MODEL		0x000f0000
-#define	CPUID_EXT_FAMILY	0x0ff00000
-#define	CPUID_TO_MODEL(id) \
-    ((((id) & CPUID_MODEL) >> 4) | \
-    ((((id) & CPUID_FAMILY) >= 0x600) ? \
-    (((id) & CPUID_EXT_MODEL) >> 12) : 0))
-#define	CPUID_TO_FAMILY(id) \
-    ((((id) & CPUID_FAMILY) >> 8) + \
-    ((((id) & CPUID_FAMILY) == 0xf00) ? \
-    (((id) & CPUID_EXT_FAMILY) >> 20) : 0))
-
-/*
- * CPUID instruction 1 ebx info
- */
-#define	CPUID_BRAND_INDEX	0x000000ff
-#define	CPUID_CLFUSH_SIZE	0x0000ff00
-#define	CPUID_HTT_CORES		0x00ff0000
-#define	CPUID_LOCAL_APIC_ID	0xff000000
-
-/*
- * CPUID instruction 6 ecx info
- */
-#define	CPUID_PERF_STAT		0x00000001
-#define	CPUID_PERF_BIAS		0x00000008
-
-/* 
- * CPUID instruction 0xb ebx info.
- */
-#define	CPUID_TYPE_INVAL	0
-#define	CPUID_TYPE_SMT		1
-#define	CPUID_TYPE_CORE		2
-
-/*
- * CPUID instruction 0xd Processor Extended State Enumeration Sub-leaf 1
- */
-#define	CPUID_EXTSTATE_XSAVEOPT	0x00000001
-
-/*
- * AMD extended function 8000_0007h edx info
- */
-#define	AMDPM_TS		0x00000001
-#define	AMDPM_FID		0x00000002
-#define	AMDPM_VID		0x00000004
-#define	AMDPM_TTP		0x00000008
-#define	AMDPM_TM		0x00000010
-#define	AMDPM_STC		0x00000020
-#define	AMDPM_100MHZ_STEPS	0x00000040
-#define	AMDPM_HW_PSTATE		0x00000080
-#define	AMDPM_TSC_INVARIANT	0x00000100
-#define	AMDPM_CPB		0x00000200
-
-/*
- * AMD extended function 8000_0008h ecx info
- */
-#define	AMDID_CMP_CORES		0x000000ff
-#define	AMDID_COREID_SIZE	0x0000f000
-#define	AMDID_COREID_SIZE_SHIFT	12
-
-/*
- * CPUID manufacturers identifiers
- */
-#define	AMD_VENDOR_ID		"AuthenticAMD"
-#define	CENTAUR_VENDOR_ID	"CentaurHauls"
-#define	CYRIX_VENDOR_ID		"CyrixInstead"
-#define	INTEL_VENDOR_ID		"GenuineIntel"
-#define	NEXGEN_VENDOR_ID	"NexGenDriven"
-#define	NSC_VENDOR_ID		"Geode by NSC"
-#define	RISE_VENDOR_ID		"RiseRiseRise"
-#define	SIS_VENDOR_ID		"SiS SiS SiS "
-#define	TRANSMETA_VENDOR_ID	"GenuineTMx86"
-#define	UMC_VENDOR_ID		"UMC UMC UMC "
-
-/*
- * Model-specific registers for the i386 family
- */
-#define	MSR_P5_MC_ADDR		0x000
-#define	MSR_P5_MC_TYPE		0x001
-#define	MSR_TSC			0x010
-#define	MSR_P5_CESR		0x011
-#define	MSR_P5_CTR0		0x012
-#define	MSR_P5_CTR1		0x013
-#define	MSR_IA32_PLATFORM_ID	0x017
-#define	MSR_APICBASE		0x01b
-#define	MSR_EBL_CR_POWERON	0x02a
-#define	MSR_TEST_CTL		0x033
-#define	MSR_BIOS_UPDT_TRIG	0x079
-#define	MSR_BBL_CR_D0		0x088
-#define	MSR_BBL_CR_D1		0x089
-#define	MSR_BBL_CR_D2		0x08a
-#define	MSR_BIOS_SIGN		0x08b
-#define	MSR_PERFCTR0		0x0c1
-#define	MSR_PERFCTR1		0x0c2
-#define	MSR_MPERF		0x0e7
-#define	MSR_APERF		0x0e8
-#define	MSR_IA32_EXT_CONFIG	0x0ee	/* Undocumented. Core Solo/Duo only */
-#define	MSR_MTRRcap		0x0fe
-#define	MSR_BBL_CR_ADDR		0x116
-#define	MSR_BBL_CR_DECC		0x118
-#define	MSR_BBL_CR_CTL		0x119
-#define	MSR_BBL_CR_TRIG		0x11a
-#define	MSR_BBL_CR_BUSY		0x11b
-#define	MSR_BBL_CR_CTL3		0x11e
-#define	MSR_SYSENTER_CS_MSR	0x174
-#define	MSR_SYSENTER_ESP_MSR	0x175
-#define	MSR_SYSENTER_EIP_MSR	0x176
-#define	MSR_MCG_CAP		0x179
-#define	MSR_MCG_STATUS		0x17a
-#define	MSR_MCG_CTL		0x17b
-#define	MSR_EVNTSEL0		0x186
-#define	MSR_EVNTSEL1		0x187
-#define	MSR_THERM_CONTROL	0x19a
-#define	MSR_THERM_INTERRUPT	0x19b
-#define	MSR_THERM_STATUS	0x19c
-#define	MSR_IA32_MISC_ENABLE	0x1a0
-#define	MSR_IA32_TEMPERATURE_TARGET	0x1a2
-#define	MSR_DEBUGCTLMSR		0x1d9
-#define	MSR_LASTBRANCHFROMIP	0x1db
-#define	MSR_LASTBRANCHTOIP	0x1dc
-#define	MSR_LASTINTFROMIP	0x1dd
-#define	MSR_LASTINTTOIP		0x1de
-#define	MSR_ROB_CR_BKUPTMPDR6	0x1e0
-#define	MSR_MTRRVarBase		0x200
-#define	MSR_MTRR64kBase		0x250
-#define	MSR_MTRR16kBase		0x258
-#define	MSR_MTRR4kBase		0x268
-#define	MSR_PAT			0x277
-#define	MSR_MC0_CTL2		0x280
-#define	MSR_MTRRdefType		0x2ff
-#define	MSR_MC0_CTL		0x400
-#define	MSR_MC0_STATUS		0x401
-#define	MSR_MC0_ADDR		0x402
-#define	MSR_MC0_MISC		0x403
-#define	MSR_MC1_CTL		0x404
-#define	MSR_MC1_STATUS		0x405
-#define	MSR_MC1_ADDR		0x406
-#define	MSR_MC1_MISC		0x407
-#define	MSR_MC2_CTL		0x408
-#define	MSR_MC2_STATUS		0x409
-#define	MSR_MC2_ADDR		0x40a
-#define	MSR_MC2_MISC		0x40b
-#define	MSR_MC3_CTL		0x40c
-#define	MSR_MC3_STATUS		0x40d
-#define	MSR_MC3_ADDR		0x40e
-#define	MSR_MC3_MISC		0x40f
-#define	MSR_MC4_CTL		0x410
-#define	MSR_MC4_STATUS		0x411
-#define	MSR_MC4_ADDR		0x412
-#define	MSR_MC4_MISC		0x413
-
-/*
- * Constants related to MSR's.
- */
-#define	APICBASE_RESERVED	0x000006ff
-#define	APICBASE_BSP		0x00000100
-#define	APICBASE_ENABLED	0x00000800
-#define	APICBASE_ADDRESS	0xfffff000
-
-/*
- * PAT modes.
- */
-#define	PAT_UNCACHEABLE		0x00
-#define	PAT_WRITE_COMBINING	0x01
-#define	PAT_WRITE_THROUGH	0x04
-#define	PAT_WRITE_PROTECTED	0x05
-#define	PAT_WRITE_BACK		0x06
-#define	PAT_UNCACHED		0x07
-#define	PAT_VALUE(i, m)		((long long)(m) << (8 * (i)))
-#define	PAT_MASK(i)		PAT_VALUE(i, 0xff)
-
-/*
- * Constants related to MTRRs
- */
-#define	MTRR_UNCACHEABLE	0x00
-#define	MTRR_WRITE_COMBINING	0x01
-#define	MTRR_WRITE_THROUGH	0x04
-#define	MTRR_WRITE_PROTECTED	0x05
-#define	MTRR_WRITE_BACK		0x06
-#define	MTRR_N64K		8	/* numbers of fixed-size entries */
-#define	MTRR_N16K		16
-#define	MTRR_N4K		64
-#define	MTRR_CAP_WC		0x0000000000000400
-#define	MTRR_CAP_FIXED		0x0000000000000100
-#define	MTRR_CAP_VCNT		0x00000000000000ff
-#define	MTRR_DEF_ENABLE		0x0000000000000800
-#define	MTRR_DEF_FIXED_ENABLE	0x0000000000000400
-#define	MTRR_DEF_TYPE		0x00000000000000ff
-#define	MTRR_PHYSBASE_PHYSBASE	0x000ffffffffff000
-#define	MTRR_PHYSBASE_TYPE	0x00000000000000ff
-#define	MTRR_PHYSMASK_PHYSMASK	0x000ffffffffff000
-#define	MTRR_PHYSMASK_VALID	0x0000000000000800
-
-/*
- * Cyrix configuration registers, accessible as IO ports.
- */
-#define	CCR0			0xc0	/* Configuration control register 0 */
-#define	CCR0_NC0		0x01	/* First 64K of each 1M memory region is
-								   non-cacheable */
-#define	CCR0_NC1		0x02	/* 640K-1M region is non-cacheable */
-#define	CCR0_A20M		0x04	/* Enables A20M# input pin */
-#define	CCR0_KEN		0x08	/* Enables KEN# input pin */
-#define	CCR0_FLUSH		0x10	/* Enables FLUSH# input pin */
-#define	CCR0_BARB		0x20	/* Flushes internal cache when entering hold
-								   state */
-#define	CCR0_CO			0x40	/* Cache org: 1=direct mapped, 0=2x set
-								   assoc */
-#define	CCR0_SUSPEND	0x80	/* Enables SUSP# and SUSPA# pins */
-
-#define	CCR1			0xc1	/* Configuration control register 1 */
-#define	CCR1_RPL		0x01	/* Enables RPLSET and RPLVAL# pins */
-#define	CCR1_SMI		0x02	/* Enables SMM pins */
-#define	CCR1_SMAC		0x04	/* System management memory access */
-#define	CCR1_MMAC		0x08	/* Main memory access */
-#define	CCR1_NO_LOCK	0x10	/* Negate LOCK# */
-#define	CCR1_SM3		0x80	/* SMM address space address region 3 */
-
-#define	CCR2			0xc2
-#define	CCR2_WB			0x02	/* Enables WB cache interface pins */
-#define	CCR2_SADS		0x02	/* Slow ADS */
-#define	CCR2_LOCK_NW	0x04	/* LOCK NW Bit */
-#define	CCR2_SUSP_HLT	0x08	/* Suspend on HALT */
-#define	CCR2_WT1		0x10	/* WT region 1 */
-#define	CCR2_WPR1		0x10	/* Write-protect region 1 */
-#define	CCR2_BARB		0x20	/* Flushes write-back cache when entering
-								   hold state. */
-#define	CCR2_BWRT		0x40	/* Enables burst write cycles */
-#define	CCR2_USE_SUSP	0x80	/* Enables suspend pins */
-
-#define	CCR3			0xc3
-#define	CCR3_SMILOCK	0x01	/* SMM register lock */
-#define	CCR3_NMI		0x02	/* Enables NMI during SMM */
-#define	CCR3_LINBRST	0x04	/* Linear address burst cycles */
-#define	CCR3_SMMMODE	0x08	/* SMM Mode */
-#define	CCR3_MAPEN0		0x10	/* Enables Map0 */
-#define	CCR3_MAPEN1		0x20	/* Enables Map1 */
-#define	CCR3_MAPEN2		0x40	/* Enables Map2 */
-#define	CCR3_MAPEN3		0x80	/* Enables Map3 */
-
-#define	CCR4			0xe8
-#define	CCR4_IOMASK		0x07
-#define	CCR4_MEM		0x08	/* Enables momory bypassing */
-#define	CCR4_DTE		0x10	/* Enables directory table entry cache */
-#define	CCR4_FASTFPE	0x20	/* Fast FPU exception */
-#define	CCR4_CPUID		0x80	/* Enables CPUID instruction */
-
-#define	CCR5			0xe9
-#define	CCR5_WT_ALLOC	0x01	/* Write-through allocate */
-#define	CCR5_SLOP		0x02	/* LOOP instruction slowed down */
-#define	CCR5_LBR1		0x10	/* Local bus region 1 */
-#define	CCR5_ARREN		0x20	/* Enables ARR region */
-
-#define	CCR6			0xea
-
-#define	CCR7			0xeb
-
-/* Performance Control Register (5x86 only). */
-#define	PCR0			0x20
-#define	PCR0_RSTK		0x01	/* Enables return stack */
-#define	PCR0_BTB		0x02	/* Enables branch target buffer */
-#define	PCR0_LOOP		0x04	/* Enables loop */
-#define	PCR0_AIS		0x08	/* Enables all instrcutions stalled to
-								   serialize pipe. */
-#define	PCR0_MLR		0x10	/* Enables reordering of misaligned loads */
-#define	PCR0_BTBRT		0x40	/* Enables BTB test register. */
-#define	PCR0_LSSER		0x80	/* Disable reorder */
-
-/* Device Identification Registers */
-#define	DIR0			0xfe
-#define	DIR1			0xff
-
-/*
- * Machine Check register constants.
- */
-#define	MCG_CAP_COUNT		0x000000ff
-#define	MCG_CAP_CTL_P		0x00000100
-#define	MCG_CAP_EXT_P		0x00000200
-#define	MCG_CAP_CMCI_P		0x00000400
-#define	MCG_CAP_TES_P		0x00000800
-#define	MCG_CAP_EXT_CNT		0x00ff0000
-#define	MCG_CAP_SER_P		0x01000000
-#define	MCG_STATUS_RIPV		0x00000001
-#define	MCG_STATUS_EIPV		0x00000002
-#define	MCG_STATUS_MCIP		0x00000004
-#define	MCG_CTL_ENABLE		0xffffffffffffffff
-#define	MCG_CTL_DISABLE		0x0000000000000000
-#define	MSR_MC_CTL(x)		(MSR_MC0_CTL + (x) * 4)
-#define	MSR_MC_STATUS(x)	(MSR_MC0_STATUS + (x) * 4)
-#define	MSR_MC_ADDR(x)		(MSR_MC0_ADDR + (x) * 4)
-#define	MSR_MC_MISC(x)		(MSR_MC0_MISC + (x) * 4)
-#define	MSR_MC_CTL2(x)		(MSR_MC0_CTL2 + (x))	/* If MCG_CAP_CMCI_P */
-#define	MC_STATUS_MCA_ERROR	0x000000000000ffff
-#define	MC_STATUS_MODEL_ERROR	0x00000000ffff0000
-#define	MC_STATUS_OTHER_INFO	0x01ffffff00000000
-#define	MC_STATUS_COR_COUNT	0x001fffc000000000	/* If MCG_CAP_CMCI_P */
-#define	MC_STATUS_TES_STATUS	0x0060000000000000	/* If MCG_CAP_TES_P */
-#define	MC_STATUS_AR		0x0080000000000000	/* If MCG_CAP_TES_P */
-#define	MC_STATUS_S		0x0100000000000000	/* If MCG_CAP_TES_P */
-#define	MC_STATUS_PCC		0x0200000000000000
-#define	MC_STATUS_ADDRV		0x0400000000000000
-#define	MC_STATUS_MISCV		0x0800000000000000
-#define	MC_STATUS_EN		0x1000000000000000
-#define	MC_STATUS_UC		0x2000000000000000
-#define	MC_STATUS_OVER		0x4000000000000000
-#define	MC_STATUS_VAL		0x8000000000000000
-#define	MC_MISC_RA_LSB		0x000000000000003f	/* If MCG_CAP_SER_P */
-#define	MC_MISC_ADDRESS_MODE	0x00000000000001c0	/* If MCG_CAP_SER_P */
-#define	MC_CTL2_THRESHOLD	0x0000000000007fff
-#define	MC_CTL2_CMCI_EN		0x0000000040000000
-
-/*
- * The following four 3-byte registers control the non-cacheable regions.
- * These registers must be written as three separate bytes.
- *
- * NCRx+0: A31-A24 of starting address
- * NCRx+1: A23-A16 of starting address
- * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx.
- *
- * The non-cacheable region's starting address must be aligned to the
- * size indicated by the NCR_SIZE_xx field.
- */
-#define	NCR1	0xc4
-#define	NCR2	0xc7
-#define	NCR3	0xca
-#define	NCR4	0xcd
-
-#define	NCR_SIZE_0K	0
-#define	NCR_SIZE_4K	1
-#define	NCR_SIZE_8K	2
-#define	NCR_SIZE_16K	3
-#define	NCR_SIZE_32K	4
-#define	NCR_SIZE_64K	5
-#define	NCR_SIZE_128K	6
-#define	NCR_SIZE_256K	7
-#define	NCR_SIZE_512K	8
-#define	NCR_SIZE_1M	9
-#define	NCR_SIZE_2M	10
-#define	NCR_SIZE_4M	11
-#define	NCR_SIZE_8M	12
-#define	NCR_SIZE_16M	13
-#define	NCR_SIZE_32M	14
-#define	NCR_SIZE_4G	15
-
-/*
- * The address region registers are used to specify the location and
- * size for the eight address regions.
- *
- * ARRx + 0: A31-A24 of start address
- * ARRx + 1: A23-A16 of start address
- * ARRx + 2: A15-A12 of start address | ARR_SIZE_xx
- */
-#define	ARR0	0xc4
-#define	ARR1	0xc7
-#define	ARR2	0xca
-#define	ARR3	0xcd
-#define	ARR4	0xd0
-#define	ARR5	0xd3
-#define	ARR6	0xd6
-#define	ARR7	0xd9
-
-#define	ARR_SIZE_0K		0
-#define	ARR_SIZE_4K		1
-#define	ARR_SIZE_8K		2
-#define	ARR_SIZE_16K	3
-#define	ARR_SIZE_32K	4
-#define	ARR_SIZE_64K	5
-#define	ARR_SIZE_128K	6
-#define	ARR_SIZE_256K	7
-#define	ARR_SIZE_512K	8
-#define	ARR_SIZE_1M		9
-#define	ARR_SIZE_2M		10
-#define	ARR_SIZE_4M		11
-#define	ARR_SIZE_8M		12
-#define	ARR_SIZE_16M	13
-#define	ARR_SIZE_32M	14
-#define	ARR_SIZE_4G		15
-
-/*
- * The region control registers specify the attributes associated with
- * the ARRx addres regions.
- */
-#define	RCR0	0xdc
-#define	RCR1	0xdd
-#define	RCR2	0xde
-#define	RCR3	0xdf
-#define	RCR4	0xe0
-#define	RCR5	0xe1
-#define	RCR6	0xe2
-#define	RCR7	0xe3
-
-#define	RCR_RCD	0x01	/* Disables caching for ARRx (x = 0-6). */
-#define	RCR_RCE	0x01	/* Enables caching for ARR7. */
-#define	RCR_WWO	0x02	/* Weak write ordering. */
-#define	RCR_WL	0x04	/* Weak locking. */
-#define	RCR_WG	0x08	/* Write gathering. */
-#define	RCR_WT	0x10	/* Write-through. */
-#define	RCR_NLB	0x20	/* LBA# pin is not asserted. */
-
-/* AMD Write Allocate Top-Of-Memory and Control Register */
-#define	AMD_WT_ALLOC_TME	0x40000	/* top-of-memory enable */
-#define	AMD_WT_ALLOC_PRE	0x20000	/* programmable range enable */
-#define	AMD_WT_ALLOC_FRE	0x10000	/* fixed (A0000-FFFFF) range enable */
-
-/* AMD64 MSR's */
-#define	MSR_EFER		0xc0000080	/* extended features */
-#define	MSR_HWCR		0xc0010015
-#define	MSR_K8_UCODE_UPDATE	0xc0010020	/* update microcode */
-#define	MSR_MC0_CTL_MASK	0xc0010044
-
-/* VIA ACE crypto featureset: for via_feature_rng */
-#define	VIA_HAS_RNG		1	/* cpu has RNG */
-
-/* VIA ACE crypto featureset: for via_feature_xcrypt */
-#define	VIA_HAS_AES		1	/* cpu has AES */
-#define	VIA_HAS_SHA		2	/* cpu has SHA1 & SHA256 */
-#define	VIA_HAS_MM		4	/* cpu has RSA instructions */
-#define	VIA_HAS_AESCTR		8	/* cpu has AES-CTR instructions */
-
-/* Centaur Extended Feature flags */
-#define	VIA_CPUID_HAS_RNG	0x000004
-#define	VIA_CPUID_DO_RNG	0x000008
-#define	VIA_CPUID_HAS_ACE	0x000040
-#define	VIA_CPUID_DO_ACE	0x000080
-#define	VIA_CPUID_HAS_ACE2	0x000100
-#define	VIA_CPUID_DO_ACE2	0x000200
-#define	VIA_CPUID_HAS_PHE	0x000400
-#define	VIA_CPUID_DO_PHE	0x000800
-#define	VIA_CPUID_HAS_PMM	0x001000
-#define	VIA_CPUID_DO_PMM	0x002000
-
-/* VIA ACE xcrypt-* instruction context control options */
-#define	VIA_CRYPT_CWLO_ROUND_M		0x0000000f
-#define	VIA_CRYPT_CWLO_ALG_M		0x00000070
-#define	VIA_CRYPT_CWLO_ALG_AES		0x00000000
-#define	VIA_CRYPT_CWLO_KEYGEN_M		0x00000080
-#define	VIA_CRYPT_CWLO_KEYGEN_HW	0x00000000
-#define	VIA_CRYPT_CWLO_KEYGEN_SW	0x00000080
-#define	VIA_CRYPT_CWLO_NORMAL		0x00000000
-#define	VIA_CRYPT_CWLO_INTERMEDIATE	0x00000100
-#define	VIA_CRYPT_CWLO_ENCRYPT		0x00000000
-#define	VIA_CRYPT_CWLO_DECRYPT		0x00000200
-#define	VIA_CRYPT_CWLO_KEY128		0x0000000a	/* 128bit, 10 rds */
-#define	VIA_CRYPT_CWLO_KEY192		0x0000040c	/* 192bit, 12 rds */
-#define	VIA_CRYPT_CWLO_KEY256		0x0000080e	/* 256bit, 15 rds */
-
-#endif /* !_MACHINE_SPECIALREG_H_ */
+#include <x86/specialreg.h>

Modified: trunk/sys/i386/include/stack.h
===================================================================
--- trunk/sys/i386/include/stack.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/stack.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Mach Operating System
  * Copyright (c) 1991,1990 Carnegie Mellon University
@@ -23,7 +24,7 @@
  * any improvements or extensions that they make and grant Carnegie the
  * rights to redistribute these changes.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/stack.h 286305 2015-08-05 07:21:44Z kib $
  */
 
 #ifndef _MACHINE_STACK_H_
@@ -32,8 +33,6 @@
 /*
  * Stack trace.
  */
-#define INKERNEL(va)	(((vm_offset_t)(va)) >= USRSTACK && \
-	    ((vm_offset_t)(va)) < VM_MAX_KERNEL_ADDRESS)
 
 struct i386_frame {
 	struct i386_frame	*f_frame;

Modified: trunk/sys/i386/include/stdarg.h
===================================================================
--- trunk/sys/i386/include/stdarg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/stdarg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,90 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
- * Copyright (c) 1991, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)stdarg.h	8.1 (Berkeley) 6/10/93
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/stdarg.h 232276 2012-02-28 22:30:58Z tijl $ */
 
-#ifndef _MACHINE_STDARG_H_
-#define	_MACHINE_STDARG_H_
-
-#include <sys/cdefs.h>
-#include <sys/_types.h>
-
-#ifndef _VA_LIST_DECLARED
-#define	_VA_LIST_DECLARED
-typedef	__va_list	va_list;
-#endif
-
-#ifdef __GNUCLIKE_BUILTIN_STDARG
-
-#define	va_start(ap, last) \
-	__builtin_va_start((ap), (last))
-
-#define	va_arg(ap, type) \
-	__builtin_va_arg((ap), type)
-
-#if __ISO_C_VISIBLE >= 1999
-#define	va_copy(dest, src) \
-	__builtin_va_copy((dest), (src))
-#endif
-
-#define	va_end(ap) \
-	__builtin_va_end(ap)
-
-#else	/* !__GNUCLIKE_BUILTIN_STDARG */
-
-#define	__va_size(type) \
-	(((sizeof(type) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
-
-#ifdef __GNUCLIKE_BUILTIN_NEXT_ARG
-#define va_start(ap, last) \
-	((ap) = (va_list)__builtin_next_arg(last))
-#else	/* !__GNUCLIKE_BUILTIN_NEXT_ARG */
-#define	va_start(ap, last) \
-	((ap) = (va_list)&(last) + __va_size(last))
-#endif	/* __GNUCLIKE_BUILTIN_NEXT_ARG */
-
-#define	va_arg(ap, type) \
-	(*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
-
-#if __ISO_C_VISIBLE >= 1999
-#define	va_copy(dest, src) \
-	((dest) = (src))
-#endif
-
-#define	va_end(ap)
-
-#endif /* __GNUCLIKE_BUILTIN_STDARG */
-
-#endif /* !_MACHINE_STDARG_H_ */
+#include <x86/stdarg.h>

Modified: trunk/sys/i386/include/sysarch.h
===================================================================
--- trunk/sys/i386/include/sysarch.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/sysarch.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,115 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/sysarch.h 233209 2012-03-19 21:57:31Z tijl $ */
 
-/*
- * Architecture specific syscalls (i386)
- */
-#ifndef _MACHINE_SYSARCH_H_
-#define _MACHINE_SYSARCH_H_
-
-#define I386_GET_LDT	0
-#define I386_SET_LDT	1
-#define	LDT_AUTO_ALLOC	0xffffffff
-				/* I386_IOPL */
-#define I386_GET_IOPERM	3
-#define I386_SET_IOPERM	4
-				/* xxxxx */
-#define I386_VM86	6
-#define I386_GET_FSBASE	7
-#define I386_SET_FSBASE	8
-#define I386_GET_GSBASE	9
-#define I386_SET_GSBASE	10
-#define	I386_GET_XFPUSTATE 11
-
-/* These four only exist when running an i386 binary on amd64 */
-#define	_AMD64_GET_FSBASE	128
-#define	_AMD64_SET_FSBASE	129
-#define	_AMD64_GET_GSBASE	130
-#define	_AMD64_SET_GSBASE	131
-
-struct i386_ldt_args {
-	unsigned int start;
-	union	descriptor *descs;
-	unsigned int num;
-}; 
-
-struct i386_ioperm_args {
-	unsigned int start;
-	unsigned int length;
-	int	enable;
-};
-
-struct i386_vm86_args {
-	int	sub_op;			/* sub-operation to perform */
-	char	*sub_args;		/* args */
-};
-
-struct i386_get_xfpustate {
-	void *addr;
-	int len;
-};
-
-#ifndef _KERNEL
-#include <sys/cdefs.h>
-
-union descriptor;
-struct dbreg;
-
-__BEGIN_DECLS
-/* These four only exist when running an i386 binary on amd64 */
-int _amd64_get_fsbase(void **);
-int _amd64_get_gsbase(void **);
-int _amd64_set_fsbase(void *);
-int _amd64_set_gsbase(void *);
-int i386_get_ldt(int, union descriptor *, int);
-int i386_set_ldt(int, union descriptor *, int);
-int i386_get_ioperm(unsigned int, unsigned int *, int *);
-int i386_set_ioperm(unsigned int, unsigned int, int);
-int i386_vm86(int, void *);
-int i386_get_fsbase(void **);
-int i386_get_gsbase(void **);
-int i386_set_fsbase(void *);
-int i386_set_gsbase(void *);
-int i386_set_watch(int, unsigned int, int, int, struct dbreg *);
-int i386_clr_watch(int, struct dbreg *);
-int sysarch(int, void *);
-__END_DECLS
-#else
-struct thread;
-union descriptor;
-
-int i386_get_ldt(struct thread *, struct i386_ldt_args *);
-int i386_set_ldt(struct thread *, struct i386_ldt_args *, union descriptor *);
-int i386_get_ioperm(struct thread *, struct i386_ioperm_args *);
-int i386_set_ioperm(struct thread *, struct i386_ioperm_args *);
-#endif
-
-#endif /* !_MACHINE_SYSARCH_H_ */
+#include <x86/sysarch.h>

Modified: trunk/sys/i386/include/timerreg.h
===================================================================
--- trunk/sys/i386/include/timerreg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/timerreg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (C) 2005 TAKAHASHI Yoshihiro. All rights reserved.
  *
@@ -22,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/timerreg.h 177642 2008-03-26 20:09:21Z phk $
  */
 
 /*

Modified: trunk/sys/i386/include/trap.h
===================================================================
--- trunk/sys/i386/include/trap.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/trap.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,95 +1,7 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	from: @(#)trap.h	5.4 (Berkeley) 5/9/91
- * $FreeBSD$
+ * This file is in the public domain.
  */
+/* $FreeBSD: stable/10/sys/i386/include/trap.h 232492 2012-03-04 14:12:57Z tijl $ */
 
-#ifndef _MACHINE_TRAP_H_
-#define	_MACHINE_TRAP_H_
-
-/*
- * Trap type values
- * also known in trap.c for name strings
- */
-
-#define	T_PRIVINFLT	1	/* privileged instruction */
-#define	T_BPTFLT	3	/* breakpoint instruction */
-#define	T_ARITHTRAP	6	/* arithmetic trap */
-#define	T_PROTFLT	9	/* protection fault */
-#define	T_TRCTRAP	10	/* debug exception (sic) */
-#define	T_PAGEFLT	12	/* page fault */
-#define	T_ALIGNFLT	14	/* alignment fault */
-
-#define	T_DIVIDE	18	/* integer divide fault */
-#define	T_NMI		19	/* non-maskable trap */
-#define	T_OFLOW		20	/* overflow trap */
-#define	T_BOUND		21	/* bound instruction fault */
-#define	T_DNA		22	/* device not available fault */
-#define	T_DOUBLEFLT	23	/* double fault */
-#define	T_FPOPFLT	24	/* fp coprocessor operand fetch fault */
-#define	T_TSSFLT	25	/* invalid tss fault */
-#define	T_SEGNPFLT	26	/* segment not present fault */
-#define	T_STKFLT	27	/* stack fault */
-#define	T_MCHK		28	/* machine check trap */
-#define	T_XMMFLT	29	/* SIMD floating-point exception */
-#define	T_RESERVED	30	/* reserved (unknown) */
-#define	T_DTRACE_RET	32	/* DTrace pid return */
-#define	T_DTRACE_PROBE	33	/* DTrace fasttrap probe */
-
-/* XXX most of the following codes aren't used, but could be. */
-
-/* definitions for <sys/signal.h> */
-#define	    ILL_RESAD_FAULT	T_RESADFLT
-#define	    ILL_PRIVIN_FAULT	T_PRIVINFLT
-#define	    ILL_RESOP_FAULT	T_RESOPFLT
-#define	    ILL_ALIGN_FAULT	T_ALIGNFLT
-#define	    ILL_FPOP_FAULT	T_FPOPFLT	/* coprocessor operand fault */
-
-/* old FreeBSD macros, deprecated */
-#define	FPE_INTOVF_TRAP	0x1	/* integer overflow */
-#define	FPE_INTDIV_TRAP	0x2	/* integer divide by zero */
-#define	FPE_FLTDIV_TRAP	0x3	/* floating/decimal divide by zero */
-#define	FPE_FLTOVF_TRAP	0x4	/* floating overflow */
-#define	FPE_FLTUND_TRAP	0x5	/* floating underflow */
-#define	FPE_FPU_NP_TRAP	0x6	/* floating point unit not present  */
-#define	FPE_SUBRNG_TRAP	0x7	/* subrange out of bounds */
-
-/* codes for SIGBUS */
-#define	    BUS_PAGE_FAULT	T_PAGEFLT	/* page fault protection base */
-#define	    BUS_SEGNP_FAULT	T_SEGNPFLT	/* segment not present */
-#define	    BUS_STK_FAULT	T_STKFLT	/* stack segment */
-#define	    BUS_SEGM_FAULT	T_RESERVED	/* segment protection base */
-
-/* Trap's coming from user mode */
-#define	T_USER	0x100
-
-#endif /* !_MACHINE_TRAP_H_ */
+#include <x86/trap.h>

Modified: trunk/sys/i386/include/tss.h
===================================================================
--- trunk/sys/i386/include/tss.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/tss.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -30,7 +31,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)tss.h	5.4 (Berkeley) 1/18/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/tss.h 128019 2004-04-07 20:46:16Z imp $
  */
 
 #ifndef _MACHINE_TSS_H_

Modified: trunk/sys/i386/include/ucontext.h
===================================================================
--- trunk/sys/i386/include/ucontext.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/ucontext.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1999 Marcel Moolenaar
  * All rights reserved.
@@ -25,70 +26,12 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/ucontext.h 247047 2013-02-20 17:39:52Z kib $
  */
 
 #ifndef _MACHINE_UCONTEXT_H_
 #define	_MACHINE_UCONTEXT_H_
 
-/* Keep _MC_* values similar to amd64 */
-#define	_MC_HASSEGS	0x1
-#define	_MC_HASBASES	0x2
-#define	_MC_HASFPXSTATE	0x4
-#define	_MC_FLAG_MASK	(_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE)
-
-typedef struct __mcontext {
-	/*
-	 * The definition of mcontext_t must match the layout of
-	 * struct sigcontext after the sc_mask member.  This is so
-	 * that we can support sigcontext and ucontext_t at the same
-	 * time.
-	 */
-	__register_t	mc_onstack;	/* XXX - sigcontext compat. */
-	__register_t	mc_gs;		/* machine state (struct trapframe) */
-	__register_t	mc_fs;
-	__register_t	mc_es;
-	__register_t	mc_ds;
-	__register_t	mc_edi;
-	__register_t	mc_esi;
-	__register_t	mc_ebp;
-	__register_t	mc_isp;
-	__register_t	mc_ebx;
-	__register_t	mc_edx;
-	__register_t	mc_ecx;
-	__register_t	mc_eax;
-	__register_t	mc_trapno;
-	__register_t	mc_err;
-	__register_t	mc_eip;
-	__register_t	mc_cs;
-	__register_t	mc_eflags;
-	__register_t	mc_esp;
-	__register_t	mc_ss;
-
-	int	mc_len;			/* sizeof(mcontext_t) */
-#define	_MC_FPFMT_NODEV		0x10000	/* device not present or configured */
-#define	_MC_FPFMT_387		0x10001
-#define	_MC_FPFMT_XMM		0x10002
-	int	mc_fpformat;
-#define	_MC_FPOWNED_NONE	0x20000	/* FP state not used */
-#define	_MC_FPOWNED_FPU		0x20001	/* FP state came from FPU */
-#define	_MC_FPOWNED_PCB		0x20002	/* FP state came from PCB */
-	int	mc_ownedfp;
-	__register_t mc_flags;
-	/*
-	 * See <machine/npx.h> for the internals of mc_fpstate[].
-	 */
-	int	mc_fpstate[128] __aligned(16);
-
-	__register_t mc_fsbase;
-	__register_t mc_gsbase;
-
-	__register_t mc_xfpustate;
-	__register_t mc_xfpustate_len;
-
-	int	mc_spare2[4];
-} mcontext_t;
-
 #if defined(_KERNEL) && defined(COMPAT_FREEBSD4)
 struct mcontext4 {
 	__register_t	mc_onstack;	/* XXX - sigcontext compat. */
@@ -116,4 +59,6 @@
 };
 #endif
 
+#include <x86/ucontext.h>
+
 #endif /* !_MACHINE_UCONTEXT_H_ */

Modified: trunk/sys/i386/include/varargs.h
===================================================================
--- trunk/sys/i386/include/varargs.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/varargs.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2002 David E. O'Brien.  All rights reserved.
  * Copyright (c) 1990, 1993
@@ -33,7 +34,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)varargs.h	8.2 (Berkeley) 3/22/94
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/varargs.h 143063 2005-03-02 21:33:29Z joerg $
  */
 
 #ifndef _MACHINE_VARARGS_H_

Modified: trunk/sys/i386/include/vdso.h
===================================================================
--- trunk/sys/i386/include/vdso.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/vdso.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,6 +1,7 @@
+/* $MidnightBSD$ */
 /*-
  * This file is in the public domain.
  */
-/* $FreeBSD$ */
+/* $FreeBSD: stable/10/sys/i386/include/vdso.h 237433 2012-06-22 07:06:40Z kib $ */
 
 #include <x86/vdso.h>

Modified: trunk/sys/i386/include/vm.h
===================================================================
--- trunk/sys/i386/include/vm.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/vm.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
 /*-
- * Copyright (c) 2009 Advanced Computing Technologies LLC
+ * Copyright (c) 2009 Hudson River Trading LLC
  * Written by: John H. Baldwin <jhb at FreeBSD.org>
  * All rights reserved.
  *
@@ -24,7 +25,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/vm.h 283927 2015-06-02 19:20:39Z jhb $
  */
 
 #ifndef _MACHINE_VM_H_
@@ -39,7 +40,6 @@
 #define	VM_MEMATTR_WRITE_PROTECTED	((vm_memattr_t)PAT_WRITE_PROTECTED)
 #define	VM_MEMATTR_WRITE_BACK		((vm_memattr_t)PAT_WRITE_BACK)
 #define	VM_MEMATTR_WEAK_UNCACHEABLE	((vm_memattr_t)PAT_UNCACHED)
-#define	VM_MEMATTR_UNCACHED		VM_MEMATTR_WEAK_UNCACHEABLE
 
 #define	VM_MEMATTR_DEFAULT		VM_MEMATTR_WRITE_BACK
 

Modified: trunk/sys/i386/include/vm86.h
===================================================================
--- trunk/sys/i386/include/vm86.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/vm86.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997 Jonathan Lemon
  * All rights reserved.
@@ -26,7 +27,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/vm86.h 258559 2013-11-25 15:58:48Z emaste $
  */
 
 #ifndef _MACHINE_VM86_H_
@@ -113,7 +114,7 @@
 	} pmap[VM86_PMAPSIZE];
 };
 
-#define VM_USERCHANGE   (PSL_USERCHANGE | PSL_RF)
+#define VM_USERCHANGE   (PSL_USERCHANGE)
 #define VME_USERCHANGE  (VM_USERCHANGE | PSL_VIP | PSL_VIF)
 
 struct vm86_kernel {

Modified: trunk/sys/i386/include/vmparam.h
===================================================================
--- trunk/sys/i386/include/vmparam.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/vmparam.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
  * All rights reserved.
@@ -32,7 +33,7 @@
  * SUCH DAMAGE.
  *
  *	from: @(#)vmparam.h	5.9 (Berkeley) 5/12/91
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/vmparam.h 282065 2015-04-27 08:02:12Z kib $
  */
 
 
@@ -64,9 +65,15 @@
 #endif
 
 /*
- * The physical address space is densely populated.
+ * Choose between DENSE and SPARSE based on whether lower execution time or
+ * lower kernel address space consumption is desired.  Under PAE, kernel
+ * address space is often in short supply.
  */
+#ifdef PAE
+#define	VM_PHYSSEG_SPARSE
+#else
 #define	VM_PHYSSEG_DENSE
+#endif
 
 /*
  * The number of PHYSSEG entries must be one greater than the number
@@ -107,13 +114,6 @@
 #endif
 
 /*
- * Only one memory domain.
- */
-#ifndef VM_NDOMAIN
-#define	VM_NDOMAIN		1
-#endif
-
-/*
  * Enable superpage reservations: 1 level.
  */
 #ifndef	VM_NRESERVLEVEL
@@ -121,11 +121,11 @@
 #endif
 
 /*
- * Level 0 reservations consist of 512 pages under PAE and 1024 pages
- * otherwise.
+ * Level 0 reservations consist of 512 pages when PAE pagetables are
+ * used, and 1024 pages otherwise.
  */
 #ifndef	VM_LEVEL_0_ORDER
-#ifdef PAE
+#if defined(PAE) || defined(PAE_TABLES)
 #define	VM_LEVEL_0_ORDER	9
 #else
 #define	VM_LEVEL_0_ORDER	10
@@ -171,16 +171,8 @@
 #define VM_MAX_ADDRESS		VADDR(PTDPTDI, PTDPTDI)
 #define VM_MIN_ADDRESS		((vm_offset_t)0)
 
-/* virtual sizes (bytes) for various kernel submaps */
-#ifndef VM_KMEM_SIZE
-#define VM_KMEM_SIZE		(12 * 1024 * 1024)
-#endif
-
 /*
- * How many physical pages per KVA page allocated.
- * min(max(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE),
- *     VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX)
- * is the total KVA space allocated for kmem_map.
+ * How many physical pages per kmem arena virtual page.
  */
 #ifndef VM_KMEM_SIZE_SCALE
 #define	VM_KMEM_SIZE_SCALE	(3)
@@ -187,9 +179,16 @@
 #endif
 
 /*
- * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space
- * rounded to the nearest multiple of the superpage size.
+ * Optional floor (in bytes) on the size of the kmem arena.
  */
+#ifndef VM_KMEM_SIZE_MIN
+#define	VM_KMEM_SIZE_MIN	(12 * 1024 * 1024)
+#endif
+
+/*
+ * Optional ceiling (in bytes) on the size of the kmem arena: 40% of the
+ * kernel map rounded to the nearest multiple of the superpage size.
+ */
 #ifndef VM_KMEM_SIZE_MAX
 #define	VM_KMEM_SIZE_MAX	(((((VM_MAX_KERNEL_ADDRESS - \
     VM_MIN_KERNEL_ADDRESS) >> (PDRSHIFT - 2)) + 5) / 10) << PDRSHIFT)
@@ -202,4 +201,8 @@
 
 #define	ZERO_REGION_SIZE	(64 * 1024)	/* 64KB */
 
+#ifndef VM_MAX_AUTOTUNE_MAXUSERS
+#define VM_MAX_AUTOTUNE_MAXUSERS 384
+#endif
+
 #endif /* _MACHINE_VMPARAM_H_ */

Modified: trunk/sys/i386/include/xbox.h
===================================================================
--- trunk/sys/i386/include/xbox.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xbox.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2005 Rink Springer
  * All rights reserved.
@@ -24,7 +25,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/xbox.h 156243 2006-03-03 14:52:57Z rink $
  */
 #ifndef _MACHINE_XBOX_H_
 #define _MACHINE_XBOX_H_

Modified: trunk/sys/i386/include/xen/features.h
===================================================================
--- trunk/sys/i386/include/xen/features.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/features.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
  * features.h
  *
@@ -5,7 +6,7 @@
  *
  * Copyright (c) 2006, Ian Campbell
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/xen/features.h 181638 2008-08-12 19:41:11Z kmacy $
  */
 
 #ifndef __ASM_XEN_FEATURES_H__

Modified: trunk/sys/i386/include/xen/hypercall.h
===================================================================
--- trunk/sys/i386/include/xen/hypercall.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/hypercall.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /******************************************************************************
  * hypercall.h
  * 

Modified: trunk/sys/i386/include/xen/synch_bitops.h
===================================================================
--- trunk/sys/i386/include/xen/synch_bitops.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/synch_bitops.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 #ifndef __XEN_SYNCH_BITOPS_H__
 #define __XEN_SYNCH_BITOPS_H__
 

Modified: trunk/sys/i386/include/xen/xen-os.h
===================================================================
--- trunk/sys/i386/include/xen/xen-os.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xen-os.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,47 +1,62 @@
-/******************************************************************************
- * os.h
+/* $MidnightBSD$ */
+/*****************************************************************************
+ * i386/xen/xen-os.h
  * 
- * random collection of macros and definition
+ * Random collection of macros and definition
+ *
+ * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * $FreeBSD$
  */
 
-#ifndef _XEN_OS_H_
-#define _XEN_OS_H_
-#include <machine/param.h>
+#ifndef _MACHINE_XEN_XEN_OS_H_
+#define _MACHINE_XEN_XEN_OS_H_
 
 #ifdef PAE
 #define CONFIG_X86_PAE
 #endif
 
-#if !defined(__XEN_INTERFACE_VERSION__) 
-/* 
- * Can update to a more recent version when we implement 
- * the hypercall page 
- */ 
-#define  __XEN_INTERFACE_VERSION__ 0x00030204 
-#endif 
+/* Everything below this point is not included by assembler (.S) files. */
+#ifndef __ASSEMBLY__
 
-#include <xen/interface/xen.h>
+/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
+static inline void rep_nop(void)
+{
+    __asm__ __volatile__ ( "rep;nop" : : : "memory" );
+}
+#define cpu_relax() rep_nop()
 
-/* Force a proper event-channel callback from Xen. */
-void force_evtchn_callback(void);
+#ifndef XENHVM
+void xc_printf(const char *fmt, ...);
 
-#define likely(x)  __builtin_expect((x),1)
-#define unlikely(x)  __builtin_expect((x),0)
+#ifdef SMP
+extern int gdtset;
 
-#ifndef vtophys
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
-#endif
-
-extern int gdtset;
-#ifdef SMP
 #include <sys/time.h> /* XXX for pcpu.h */
 #include <sys/pcpu.h> /* XXX for PCPU_GET */
 static inline int 
 smp_processor_id(void)  
 {
-    if (likely(gdtset))
+    if (__predict_true(gdtset))
 	return PCPU_GET(cpuid);
     return 0;
 }
@@ -50,53 +65,16 @@
 #define smp_processor_id() 0
 #endif
 
-#ifndef NULL
-#define NULL (void *)0
-#endif
-
 #ifndef PANIC_IF
-#define PANIC_IF(exp) if (unlikely(exp)) {printk("panic - %s: %s:%d\n",#exp, __FILE__, __LINE__); panic("%s: %s:%d", #exp, __FILE__, __LINE__);} 
+#define PANIC_IF(exp) if (__predict_false(exp)) {printf("panic - %s: %s:%d\n",#exp, __FILE__, __LINE__); panic("%s: %s:%d", #exp, __FILE__, __LINE__);} 
 #endif
 
-extern shared_info_t *HYPERVISOR_shared_info;
-
-/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented
-   a mechanism by which the user can annotate likely branch directions and
-   expect the blocks to be reordered appropriately.  Define __builtin_expect
-   to nothing for earlier compilers.  */
-
-/* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */
-static inline void rep_nop(void)
-{
-    __asm__ __volatile__ ( "rep;nop" : : : "memory" );
-}
-#define cpu_relax() rep_nop()
-
-
-#if __GNUC__ == 2 && __GNUC_MINOR__ < 96
-#define __builtin_expect(x, expected_value) (x)
-#endif
-
-#define per_cpu(var, cpu)           (pcpu_find((cpu))->pc_ ## var)
-
-/* crude memory allocator for memory allocation early in 
- *  boot
+/*
+ * Crude memory allocator for memory allocation early in boot.
  */
 void *bootmem_alloc(unsigned int size);
 void bootmem_free(void *ptr, unsigned int size);
 
-
-/* Everything below this point is not included by assembler (.S) files. */
-#ifndef __ASSEMBLY__
-#include <sys/types.h>
-
-void printk(const char *fmt, ...);
-
-/* some function prototypes */
-void trap_init(void);
-
-#ifndef XENHVM
-
 /*
  * STI/CLI equivalents. These basically set and clear the virtual
  * event_enable flag in the shared_info structure. Note that when
@@ -104,7 +82,6 @@
  * We may therefore call into do_hypervisor_callback() directly.
  */
 
-
 #define __cli()                                                         \
 do {                                                                    \
         vcpu_info_t *_vcpu;                                             \
@@ -120,7 +97,7 @@
         _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
         _vcpu->evtchn_upcall_mask = 0;                                  \
         barrier(); /* unmask then check (avoid races) */                \
-        if ( unlikely(_vcpu->evtchn_upcall_pending) )                   \
+        if (__predict_false(_vcpu->evtchn_upcall_pending))              \
                 force_evtchn_callback();                                \
 } while (0)
 
@@ -131,7 +108,7 @@
         _vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; \
         if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {                   \
                 barrier(); /* unmask then check (avoid races) */        \
-                if ( unlikely(_vcpu->evtchn_upcall_pending) )           \
+                if (__predict_false(_vcpu->evtchn_upcall_pending))      \
                         force_evtchn_callback();                        \
         } 								\
 } while (0)
@@ -166,23 +143,8 @@
 #define spin_lock_irqsave mtx_lock_irqsave
 #define spin_unlock_irqrestore mtx_unlock_irqrestore
 
-#endif
+#endif /* !XENHVM */
 
-#ifdef SMP
-#define smp_mb() mb() 
-#define smp_rmb() rmb()
-#define smp_wmb() wmb()
-#define smp_read_barrier_depends()      read_barrier_depends()
-#define set_mb(var, value) do { xchg(&var, value); } while (0)
-#else
-#define smp_mb()        barrier()
-#define smp_rmb()       barrier()
-#define smp_wmb()       barrier()
-#define smp_read_barrier_depends()      do { } while(0)
-#define set_mb(var, value) do { var = value; barrier(); } while (0)
-#endif
-
-
 /* This is a barrier for the compiler only, NOT the processor! */
 #define barrier() __asm__ __volatile__("": : :"memory")
 
@@ -196,8 +158,6 @@
  */
 typedef struct { volatile int counter; } atomic_t;
 
-
-
 #define xen_xchg(ptr,v) \
         ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
 struct __xchg_dummy { unsigned long a[100]; };
@@ -324,33 +284,6 @@
 #define rdtscll(val) \
      __asm__ __volatile__("rdtsc" : "=A" (val))
 
-
-
-/*
- * Kernel pointers have redundant information, so we can use a
- * scheme where we can return either an error code or a dentry
- * pointer with the same return value.
- *
- * This should be a per-architecture thing, to allow different
- * error and pointer decisions.
- */
-#define IS_ERR_VALUE(x) unlikely((x) > (unsigned long)-1000L)
-
-static inline void *ERR_PTR(long error)
-{
-	return (void *) error;
-}
-
-static inline long PTR_ERR(const void *ptr)
-{
-	return (long) ptr;
-}
-
-static inline long IS_ERR(const void *ptr)
-{
-	return IS_ERR_VALUE((unsigned long)ptr);
-}
-
 #endif /* !__ASSEMBLY__ */
 
-#endif /* _OS_H_ */
+#endif /* _MACHINE_XEN_XEN_OS_H_ */

Modified: trunk/sys/i386/include/xen/xen_clock_util.h
===================================================================
--- trunk/sys/i386/include/xen/xen_clock_util.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xen_clock_util.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  *
  * Copyright (c) 2009 Adrian Chadd

Modified: trunk/sys/i386/include/xen/xenfunc.h
===================================================================
--- trunk/sys/i386/include/xen/xenfunc.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xenfunc.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2004, 2005 Kip Macy
  * All rights reserved.
@@ -23,16 +24,20 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/xen/xenfunc.h 255040 2013-08-29 19:52:18Z gibbs $
  */
 
 #ifndef _XEN_XENFUNC_H_
 #define _XEN_XENFUNC_H_
 
-#include <machine/xen/xen-os.h>
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
+
+#include <vm/pmap.h>
+
 #include <machine/xen/xenpmap.h>
 #include <machine/segments.h>
+
 #include <sys/pcpu.h>
 #define BKPT __asm__("int3");
 #define XPQ_CALL_DEPTH 5

Modified: trunk/sys/i386/include/xen/xenpmap.h
===================================================================
--- trunk/sys/i386/include/xen/xenpmap.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xenpmap.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  *
  * Copyright (c) 2004 Christian Limpach.
@@ -30,7 +31,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/xen/xenpmap.h 230916 2012-02-02 17:54:35Z ken $
  */
 
 #ifndef _XEN_XENPMAP_H_

Modified: trunk/sys/i386/include/xen/xenstored.h
===================================================================
--- trunk/sys/i386/include/xen/xenstored.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xenstored.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*
  * Simple prototyle Xen Store Daemon providing simple tree-like database.
  * Copyright (C) 2005 Rusty Russell IBM Corporation

Modified: trunk/sys/i386/include/xen/xenvar.h
===================================================================
--- trunk/sys/i386/include/xen/xenvar.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/include/xen/xenvar.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008 Kip Macy
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD$
+ * $FreeBSD: stable/10/sys/i386/include/xen/xenvar.h 255781 2013-09-22 00:54:22Z gibbs $
  */
 
 #ifndef XENVAR_H_
@@ -37,7 +38,8 @@
 #define XPMAP   0x2
 extern int xendebug_flags;
 #ifndef NOXENDEBUG
-#define XENPRINTF printk
+/* Print directly to the Xen console during debugging. */
+#define XENPRINTF xc_printf
 #else
 #define XENPRINTF printf
 #endif
@@ -93,7 +95,7 @@
 void xpq_init(void);
 
 #define BITS_PER_LONG 32
-#define NR_CPUS      MAX_VIRT_CPUS
+#define NR_CPUS      XEN_LEGACY_MAX_VCPUS
 
 #define BITS_TO_LONGS(bits) \
 	(((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
@@ -106,9 +108,7 @@
 
 #elif defined(XENHVM)
 
-#if !defined(PAE)
 #define	vtomach(va)	pmap_kextract((vm_offset_t) (va))
-#endif
 #define	PFNTOMFN(pa)	(pa)
 #define	MFNTOPFN(ma)	(ma)
 

Modified: trunk/sys/i386/isa/ccbque.h
===================================================================
--- trunk/sys/i386/isa/ccbque.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/ccbque.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD$	*/
 /*-
  * [NetBSD for NEC PC98 series]
@@ -27,7 +28,7 @@
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/i386/isa/ccbque.h 139790 2005-01-06 22:18:23Z imp $
  */
 /*
  * Common command control queue funcs.

Modified: trunk/sys/i386/isa/elink.c
===================================================================
--- trunk/sys/i386/isa/elink.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/elink.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
  *
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/isa/elink.c 241394 2012-10-10 08:36:38Z kevlo $");
 
 /*
  * Common code for dealing with 3COM ethernet cards.

Modified: trunk/sys/i386/isa/elink.h
===================================================================
--- trunk/sys/i386/isa/elink.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/elink.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
  *
@@ -26,7 +27,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/i386/isa/elink.h 139790 2005-01-06 22:18:23Z imp $
  */
 
 #ifdef PC98

Modified: trunk/sys/i386/isa/npx.c
===================================================================
--- trunk/sys/i386/isa/npx.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/npx.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1990 William Jolitz.
  * Copyright (c) 1991 The Regents of the University of California.
@@ -31,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/isa/npx.c 325543 2017-11-08 11:39:42Z kib $");
 
 #include "opt_cpu.h"
 #include "opt_isa.h"
@@ -55,6 +56,7 @@
 #include <sys/syslog.h>
 #endif
 #include <sys/signalvar.h>
+#include <vm/uma.h>
 
 #include <machine/asmacros.h>
 #include <machine/cputypes.h>
@@ -69,7 +71,7 @@
 
 #include <machine/intr_machdep.h>
 #ifdef XEN
-#include <machine/xen/xen-os.h>
+#include <xen/xen-os.h>
 #include <xen/hypervisor.h>
 #endif
 
@@ -99,7 +101,40 @@
 #ifdef CPU_ENABLE_SSE
 #define	fxrstor(addr)		__asm __volatile("fxrstor %0" : : "m" (*(addr)))
 #define	fxsave(addr)		__asm __volatile("fxsave %0" : "=m" (*(addr)))
+#define	ldmxcsr(csr)		__asm __volatile("ldmxcsr %0" : : "m" (csr))
 #define	stmxcsr(addr)		__asm __volatile("stmxcsr %0" : : "m" (*(addr)))
+
+static __inline void
+xrstor(char *addr, uint64_t mask)
+{
+	uint32_t low, hi;
+
+	low = mask;
+	hi = mask >> 32;
+	__asm __volatile("xrstor %0" : : "m" (*addr), "a" (low), "d" (hi));
+}
+
+static __inline void
+xsave(char *addr, uint64_t mask)
+{
+	uint32_t low, hi;
+
+	low = mask;
+	hi = mask >> 32;
+	__asm __volatile("xsave %0" : "=m" (*addr) : "a" (low), "d" (hi) :
+	    "memory");
+}
+
+static __inline void
+xsaveopt(char *addr, uint64_t mask)
+{
+	uint32_t low, hi;
+
+	low = mask;
+	hi = mask >> 32;
+	__asm __volatile("xsaveopt %0" : "=m" (*addr) : "a" (low), "d" (hi) :
+	    "memory");
+}
 #endif
 #else	/* !(__GNUCLIKE_ASM && !lint) */
 
@@ -114,7 +149,11 @@
 #ifdef CPU_ENABLE_SSE
 void	fxsave(caddr_t addr);
 void	fxrstor(caddr_t addr);
+void	ldmxcsr(u_int csr);
 void	stmxcsr(u_int *csr);
+void	xrstor(char *addr, uint64_t mask);
+void	xsave(char *addr, uint64_t mask);
+void	xsaveopt(char *addr, uint64_t mask);
 #endif
 
 #endif	/* __GNUCLIKE_ASM && !lint */
@@ -151,17 +190,30 @@
 	(savefpu)->sv_87.sv_env.en_cw = (value)
 #endif /* CPU_ENABLE_SSE */
 
-typedef u_char bool_t;
+#ifdef CPU_ENABLE_SSE
+CTASSERT(sizeof(union savefpu) == 512);
+CTASSERT(sizeof(struct xstate_hdr) == 64);
+CTASSERT(sizeof(struct savefpu_ymm) == 832);
 
-#ifdef CPU_ENABLE_SSE
+/*
+ * This requirement is to make it easier for asm code to calculate
+ * offset of the fpu save area from the pcb address. FPU save area
+ * must be 64-byte aligned.
+ */
+CTASSERT(sizeof(struct pcb) % XSAVE_AREA_ALIGN == 0);
+
+/*
+ * Ensure the copy of XCR0 saved in a core is contained in the padding
+ * area.
+ */
+CTASSERT(X86_XSTATE_XCR0_OFFSET >= offsetof(struct savexmm, sv_pad) &&
+    X86_XSTATE_XCR0_OFFSET + sizeof(uint64_t) <= sizeof(struct savexmm));
+
 static	void	fpu_clean_state(void);
 #endif
 
 static	void	fpusave(union savefpu *);
 static	void	fpurstor(union savefpu *);
-static	int	npx_attach(device_t dev);
-static	void	npx_identify(driver_t *driver, device_t parent);
-static	int	npx_probe(device_t dev);
 
 int	hw_float;
 
@@ -168,8 +220,23 @@
 SYSCTL_INT(_hw, HW_FLOATINGPT, floatingpoint, CTLFLAG_RD,
     &hw_float, 0, "Floating point instructions executed in hardware");
 
+#ifdef CPU_ENABLE_SSE
+int use_xsave;
+uint64_t xsave_mask;
+#endif
+static	uma_zone_t fpu_save_area_zone;
+static	union savefpu *npx_initialstate;
+
+#ifdef CPU_ENABLE_SSE
+struct xsave_area_elm_descr {
+	u_int	offset;
+	u_int	size;
+} *xsave_area_desc;
+
+static int use_xsaveopt;
+#endif
+
 static	volatile u_int		npx_traps_while_probing;
-static	union savefpu		npx_initialstate;
 
 alias_for_inthand_t probetrap;
 __asm("								\n\
@@ -184,32 +251,14 @@
 ");
 
 /*
- * Identify routine.  Create a connection point on our parent for probing.
+ * Determine if an FPU is present and how to use it.
  */
-static void
-npx_identify(driver, parent)
-	driver_t *driver;
-	device_t parent;
-{
-	device_t child;
-
-	child = BUS_ADD_CHILD(parent, 0, "npx", 0);
-	if (child == NULL)
-		panic("npx_identify");
-}
-
-/*
- * Probe routine.  Set flags to tell npxattach() what to do.  Set up an
- * interrupt handler if npx needs to use interrupts.
- */
 static int
-npx_probe(device_t dev)
+npx_probe(void)
 {
 	struct gate_descriptor save_idt_npxtrap;
 	u_short control, status;
 
-	device_set_desc(dev, "math processor");
-
 	/*
 	 * Modern CPUs all have an FPU that uses the INT16 interface
 	 * and provide a simple way to verify that, so handle the
@@ -217,8 +266,7 @@
 	 */
 	if (cpu_feature & CPUID_FPU) {
 		hw_float = 1;
-		device_quiet(dev);
-		return (0);
+		return (1);
 	}
 
 	save_idt_npxtrap = idt[IDT_MF];
@@ -272,7 +320,7 @@
 			 * accelerator board.
 			 */
 			hw_float = 1;
-			return (0);
+			return (1);
 #endif
 			npx_traps_while_probing = 0;
 			fp_divide_by_0();
@@ -283,7 +331,7 @@
 				hw_float = 1;
 				goto cleanup;
 			}
-			device_printf(dev,
+			printf(
 	"FPU does not use exception 16 for error reporting\n");
 			goto cleanup;
 		}
@@ -293,46 +341,74 @@
 	 * Probe failed.  Floating point simply won't work.
 	 * Notify user and disable FPU/MMX/SSE instruction execution.
 	 */
-	device_printf(dev, "WARNING: no FPU!\n");
+	printf("WARNING: no FPU!\n");
 	__asm __volatile("smsw %%ax; orb %0,%%al; lmsw %%ax" : :
 	    "n" (CR0_EM | CR0_MP) : "ax");
 
 cleanup:
 	idt[IDT_MF] = save_idt_npxtrap;
-	return (hw_float ? 0 : ENXIO);
+	return (hw_float);
 }
 
+#ifdef CPU_ENABLE_SSE
 /*
- * Attach routine - announce which it is, and wire into system
+ * Enable XSAVE if supported and allowed by user.
+ * Calculate the xsave_mask.
  */
-static int
-npx_attach(device_t dev)
+static void
+npxinit_bsp1(void)
 {
+	u_int cp[4];
+	uint64_t xsave_mask_user;
 
-	npxinit();
-	critical_enter();
-	stop_emulating();
-	fpusave(&npx_initialstate);
-	start_emulating();
+	if (cpu_fxsr && (cpu_feature2 & CPUID2_XSAVE) != 0) {
+		use_xsave = 1;
+		TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave);
+	}
+	if (!use_xsave)
+		return;
+
+	cpuid_count(0xd, 0x0, cp);
+	xsave_mask = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE;
+	if ((cp[0] & xsave_mask) != xsave_mask)
+		panic("CPU0 does not support X87 or SSE: %x", cp[0]);
+	xsave_mask = ((uint64_t)cp[3] << 32) | cp[0];
+	xsave_mask_user = xsave_mask;
+	TUNABLE_QUAD_FETCH("hw.xsave_mask", &xsave_mask_user);
+	xsave_mask_user |= XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE;
+	xsave_mask &= xsave_mask_user;
+	if ((xsave_mask & XFEATURE_AVX512) != XFEATURE_AVX512)
+		xsave_mask &= ~XFEATURE_AVX512;
+	if ((xsave_mask & XFEATURE_MPX) != XFEATURE_MPX)
+		xsave_mask &= ~XFEATURE_MPX;
+
+	cpuid_count(0xd, 0x1, cp);
+	if ((cp[0] & CPUID_EXTSTATE_XSAVEOPT) != 0)
+		use_xsaveopt = 1;
+}
+#endif
+/*
+
+ * Calculate the fpu save area size.
+ */
+static void
+npxinit_bsp2(void)
+{
 #ifdef CPU_ENABLE_SSE
-	if (cpu_fxsr) {
-		if (npx_initialstate.sv_xmm.sv_env.en_mxcsr_mask)
-			cpu_mxcsr_mask = 
-			    npx_initialstate.sv_xmm.sv_env.en_mxcsr_mask;
-		else
-			cpu_mxcsr_mask = 0xFFBF;
-		bzero(npx_initialstate.sv_xmm.sv_fp,
-		    sizeof(npx_initialstate.sv_xmm.sv_fp));
-		bzero(npx_initialstate.sv_xmm.sv_xmm,
-		    sizeof(npx_initialstate.sv_xmm.sv_xmm));
-		/* XXX might need even more zeroing. */
+	u_int cp[4];
+
+	if (use_xsave) {
+		cpuid_count(0xd, 0x0, cp);
+		cpu_max_ext_state_size = cp[1];
+
+		/*
+		 * Reload the cpu_feature2, since we enabled OSXSAVE.
+		 */
+		do_cpuid(1, cp);
+		cpu_feature2 = cp[2];
 	} else
 #endif
-		bzero(npx_initialstate.sv_87.sv_ac,
-		    sizeof(npx_initialstate.sv_87.sv_ac));
-	critical_exit();
-
-	return (0);
+		cpu_max_ext_state_size = sizeof(union savefpu);
 }
 
 /*
@@ -339,46 +415,161 @@
  * Initialize floating point unit.
  */
 void
-npxinit(void)
+npxinit(bool bsp)
 {
 	static union savefpu dummy;
 	register_t saveintr;
+#ifdef CPU_ENABLE_SSE
+	u_int mxcsr;
+#endif
 	u_short control;
 
-	if (!hw_float)
-		return;
+	if (bsp) {
+		if (!npx_probe())
+			return;
+#ifdef CPU_ENABLE_SSE
+		npxinit_bsp1();
+#endif
+	}
+
+#ifdef CPU_ENABLE_SSE
+	if (use_xsave) {
+		load_cr4(rcr4() | CR4_XSAVE);
+		load_xcr(XCR0, xsave_mask);
+	}
+#endif
+
 	/*
+	 * XCR0 shall be set up before CPU can report the save area size.
+	 */
+	if (bsp)
+		npxinit_bsp2();
+	
+	/*
 	 * fninit has the same h/w bugs as fnsave.  Use the detoxified
-	 * fnsave to throw away any junk in the fpu.  npxsave() initializes
-	 * the fpu and sets fpcurthread = NULL as important side effects.
+	 * fnsave to throw away any junk in the fpu.  fpusave() initializes
+	 * the fpu.
 	 *
 	 * It is too early for critical_enter() to work on AP.
 	 */
 	saveintr = intr_disable();
-	npxsave(&dummy);
 	stop_emulating();
 #ifdef CPU_ENABLE_SSE
-	/* XXX npxsave() doesn't actually initialize the fpu in the SSE case. */
 	if (cpu_fxsr)
 		fninit();
+	else
 #endif
+		fnsave(&dummy);
 	control = __INITIAL_NPXCW__;
 	fldcw(control);
+#ifdef CPU_ENABLE_SSE
+	if (cpu_fxsr) {
+		mxcsr = __INITIAL_MXCSR__;
+		ldmxcsr(mxcsr);
+	}
+#endif
 	start_emulating();
 	intr_restore(saveintr);
 }
 
 /*
+ * On the boot CPU we generate a clean state that is used to
+ * initialize the floating point unit when it is first used by a
+ * process.
+ */
+static void
+npxinitstate(void *arg __unused)
+{
+	register_t saveintr;
+#ifdef CPU_ENABLE_SSE
+	int cp[4], i, max_ext_n;
+#endif
+
+	if (!hw_float)
+		return;
+
+	npx_initialstate = malloc(cpu_max_ext_state_size, M_DEVBUF,
+	    M_WAITOK | M_ZERO);
+	saveintr = intr_disable();
+	stop_emulating();
+
+	fpusave(npx_initialstate);
+#ifdef CPU_ENABLE_SSE
+	if (cpu_fxsr) {
+		if (npx_initialstate->sv_xmm.sv_env.en_mxcsr_mask)
+			cpu_mxcsr_mask = 
+			    npx_initialstate->sv_xmm.sv_env.en_mxcsr_mask;
+		else
+			cpu_mxcsr_mask = 0xFFBF;
+
+		/*
+		 * The fninit instruction does not modify XMM
+		 * registers or x87 registers (MM/ST).  The fpusave
+		 * call dumped the garbage contained in the registers
+		 * after reset to the initial state saved.  Clear XMM
+		 * and x87 registers file image to make the startup
+		 * program state and signal handler XMM/x87 register
+		 * content predictable.
+		 */
+		bzero(npx_initialstate->sv_xmm.sv_fp,
+		    sizeof(npx_initialstate->sv_xmm.sv_fp));
+		bzero(npx_initialstate->sv_xmm.sv_xmm,
+		    sizeof(npx_initialstate->sv_xmm.sv_xmm));
+	} else
+#endif
+		bzero(npx_initialstate->sv_87.sv_ac,
+		    sizeof(npx_initialstate->sv_87.sv_ac));
+
+#ifdef CPU_ENABLE_SSE
+	/*
+	 * Create a table describing the layout of the CPU Extended
+	 * Save Area.
+	 */
+	if (use_xsave) {
+		if (xsave_mask >> 32 != 0)
+			max_ext_n = fls(xsave_mask >> 32) + 32;
+		else
+			max_ext_n = fls(xsave_mask);
+		xsave_area_desc = malloc(max_ext_n * sizeof(struct
+		    xsave_area_elm_descr), M_DEVBUF, M_WAITOK | M_ZERO);
+		/* x87 state */
+		xsave_area_desc[0].offset = 0;
+		xsave_area_desc[0].size = 160;
+		/* XMM */
+		xsave_area_desc[1].offset = 160;
+		xsave_area_desc[1].size = 288 - 160;
+
+		for (i = 2; i < max_ext_n; i++) {
+			cpuid_count(0xd, i, cp);
+			xsave_area_desc[i].offset = cp[1];
+			xsave_area_desc[i].size = cp[0];
+		}
+	}
+#endif
+
+	fpu_save_area_zone = uma_zcreate("FPU_save_area",
+	    cpu_max_ext_state_size, NULL, NULL, NULL, NULL,
+	    XSAVE_AREA_ALIGN - 1, 0);
+
+	start_emulating();
+	intr_restore(saveintr);
+}
+SYSINIT(npxinitstate, SI_SUB_DRIVERS, SI_ORDER_ANY, npxinitstate, NULL);
+
+/*
  * Free coprocessor (if we have it).
  */
 void
-npxexit(td)
-	struct thread *td;
+npxexit(struct thread *td)
 {
 
 	critical_enter();
-	if (curthread == PCPU_GET(fpcurthread))
-		npxsave(curpcb->pcb_save);
+	if (curthread == PCPU_GET(fpcurthread)) {
+		stop_emulating();
+		fpusave(curpcb->pcb_save);
+		start_emulating();
+		PCPU_SET(fpcurthread, NULL);
+	}
 	critical_exit();
 #ifdef NPX_DEBUG
 	if (hw_float) {
@@ -399,7 +590,7 @@
 }
 
 int
-npxformat()
+npxformat(void)
 {
 
 	if (!hw_float)
@@ -683,7 +874,7 @@
 	}
 	stop_emulating();
 	/*
-	 * Record new context early in case frstor causes an IRQ13.
+	 * Record new context early in case frstor causes a trap.
 	 */
 	PCPU_SET(fpcurthread, curthread);
 
@@ -697,8 +888,14 @@
 		 * This is the first time this thread has used the FPU or
 		 * the PCB doesn't contain a clean FPU state.  Explicitly
 		 * load an initial state.
+		 *
+		 * We prefer to restore the state from the actual save
+		 * area in PCB instead of directly loading from
+		 * npx_initialstate, to ignite the XSAVEOPT
+		 * tracking engine.
 		 */
-		fpurstor(&npx_initialstate);
+		bcopy(npx_initialstate, curpcb->pcb_save, cpu_max_ext_state_size);
+		fpurstor(curpcb->pcb_save);
 		if (curpcb->pcb_initial_npxcw != __INITIAL_NPXCW__)
 			fldcw(curpcb->pcb_initial_npxcw);
 		curpcb->pcb_flags |= PCB_NPXINITDONE;
@@ -705,20 +902,6 @@
 		if (PCB_USER_FPU(curpcb))
 			curpcb->pcb_flags |= PCB_NPXUSERINITDONE;
 	} else {
-		/*
-		 * The following fpurstor() may cause an IRQ13 when the
-		 * state being restored has a pending error.  The error will
-		 * appear to have been triggered by the current (npx) user
-		 * instruction even when that instruction is a no-wait
-		 * instruction that should not trigger an error (e.g.,
-		 * fnclex).  On at least one 486 system all of the no-wait
-		 * instructions are broken the same as frstor, so our
-		 * treatment does not amplify the breakage.  On at least
-		 * one 386/Cyrix 387 system, fnclex works correctly while
-		 * frstor and fnsave are broken, so our treatment breaks
-		 * fnclex if it is the first FPU instruction after a context
-		 * switch.
-		 */
 		fpurstor(curpcb->pcb_save);
 	}
 	critical_exit();
@@ -727,27 +910,12 @@
 }
 
 /*
- * Wrapper for fnsave instruction, partly to handle hardware bugs.  When npx
- * exceptions are reported via IRQ13, spurious IRQ13's may be triggered by
- * no-wait npx instructions.  See the Intel application note AP-578 for
- * details.  This doesn't cause any additional complications here.  IRQ13's
- * are inherently asynchronous unless the CPU is frozen to deliver them --
- * one that started in userland may be delivered many instructions later,
- * after the process has entered the kernel.  It may even be delivered after
- * the fnsave here completes.  A spurious IRQ13 for the fnsave is handled in
- * the same way as a very-late-arriving non-spurious IRQ13 from user mode:
- * it is normally ignored at first because we set fpcurthread to NULL; it is
- * normally retriggered in npxdna() after return to user mode.
+ * Wrapper for fpusave() called from context switch routines.
  *
  * npxsave() must be called with interrupts disabled, so that it clears
  * fpcurthread atomically with saving the state.  We require callers to do the
  * disabling, since most callers need to disable interrupts anyway to call
  * npxsave() atomically with checking fpcurthread.
- *
- * A previous version of npxsave() went to great lengths to excecute fnsave
- * with interrupts enabled in case executing it froze the CPU.  This case
- * can't happen, at least for Intel CPU/NPX's.  Spurious IRQ13's don't imply
- * spurious freezes.
  */
 void
 npxsave(addr)
@@ -755,15 +923,55 @@
 {
 
 	stop_emulating();
-	fpusave(addr);
-
+#ifdef CPU_ENABLE_SSE
+	if (use_xsaveopt)
+		xsaveopt((char *)addr, xsave_mask);
+	else
+#endif
+		fpusave(addr);
 	start_emulating();
 	PCPU_SET(fpcurthread, NULL);
 }
 
+/*
+ * Unconditionally save the current co-processor state across suspend and
+ * resume.
+ */
 void
-npxdrop()
+npxsuspend(union savefpu *addr)
 {
+	register_t cr0;
+
+	if (!hw_float)
+		return;
+	if (PCPU_GET(fpcurthread) == NULL) {
+		bcopy(npx_initialstate, addr, cpu_max_ext_state_size);
+		return;
+	}
+	cr0 = rcr0();
+	stop_emulating();
+	fpusave(addr);
+	load_cr0(cr0);
+}
+
+void
+npxresume(union savefpu *addr)
+{
+	register_t cr0;
+
+	if (!hw_float)
+		return;
+
+	cr0 = rcr0();
+	npxinit(false);
+	stop_emulating();
+	fpurstor(addr);
+	load_cr0(cr0);
+}
+
+void
+npxdrop(void)
+{
 	struct thread *td;
 
 	/*
@@ -792,6 +1000,12 @@
 npxgetregs(struct thread *td)
 {
 	struct pcb *pcb;
+#ifdef CPU_ENABLE_SSE
+	uint64_t *xstate_bv, bit;
+	char *sa;
+	int max_ext_n, i;
+#endif
+	int owned;
 
 	if (!hw_float)
 		return (_MC_FPOWNED_NONE);
@@ -798,15 +1012,15 @@
 
 	pcb = td->td_pcb;
 	if ((pcb->pcb_flags & PCB_NPXINITDONE) == 0) {
-		bcopy(&npx_initialstate, &pcb->pcb_user_save,
-		    sizeof(npx_initialstate));
-		SET_FPU_CW(&pcb->pcb_user_save, pcb->pcb_initial_npxcw);
+		bcopy(npx_initialstate, get_pcb_user_save_pcb(pcb),
+		    cpu_max_ext_state_size);
+		SET_FPU_CW(get_pcb_user_save_pcb(pcb), pcb->pcb_initial_npxcw);
 		npxuserinited(td);
 		return (_MC_FPOWNED_PCB);
 	}
 	critical_enter();
 	if (td == PCPU_GET(fpcurthread)) {
-		fpusave(&pcb->pcb_user_save);
+		fpusave(get_pcb_user_save_pcb(pcb));
 #ifdef CPU_ENABLE_SSE
 		if (!cpu_fxsr)
 #endif
@@ -816,12 +1030,36 @@
 			 * starts with a clean state next time.
 			 */
 			npxdrop();
-		critical_exit();
-		return (_MC_FPOWNED_FPU);
+		owned = _MC_FPOWNED_FPU;
 	} else {
-		critical_exit();
-		return (_MC_FPOWNED_PCB);
+		owned = _MC_FPOWNED_PCB;
 	}
+	critical_exit();
+#ifdef CPU_ENABLE_SSE
+	if (use_xsave) {
+		/*
+		 * Handle partially saved state.
+		 */
+		sa = (char *)get_pcb_user_save_pcb(pcb);
+		xstate_bv = (uint64_t *)(sa + sizeof(union savefpu) +
+		    offsetof(struct xstate_hdr, xstate_bv));
+		if (xsave_mask >> 32 != 0)
+			max_ext_n = fls(xsave_mask >> 32) + 32;
+		else
+			max_ext_n = fls(xsave_mask);
+		for (i = 0; i < max_ext_n; i++) {
+			bit = 1ULL << i;
+			if ((xsave_mask & bit) == 0 || (*xstate_bv & bit) != 0)
+				continue;
+			bcopy((char *)npx_initialstate +
+			    xsave_area_desc[i].offset,
+			    sa + xsave_area_desc[i].offset,
+			    xsave_area_desc[i].size);
+			*xstate_bv |= bit;
+		}
+	}
+#endif
+	return (owned);
 }
 
 void
@@ -835,34 +1073,89 @@
 	pcb->pcb_flags |= PCB_NPXUSERINITDONE;
 }
 
+#ifdef CPU_ENABLE_SSE
+int
+npxsetxstate(struct thread *td, char *xfpustate, size_t xfpustate_size)
+{
+	struct xstate_hdr *hdr, *ehdr;
+	size_t len, max_len;
+	uint64_t bv;
 
-void
-npxsetregs(struct thread *td, union savefpu *addr)
+	/* XXXKIB should we clear all extended state in xstate_bv instead ? */
+	if (xfpustate == NULL)
+		return (0);
+	if (!use_xsave)
+		return (EOPNOTSUPP);
+
+	len = xfpustate_size;
+	if (len < sizeof(struct xstate_hdr))
+		return (EINVAL);
+	max_len = cpu_max_ext_state_size - sizeof(union savefpu);
+	if (len > max_len)
+		return (EINVAL);
+
+	ehdr = (struct xstate_hdr *)xfpustate;
+	bv = ehdr->xstate_bv;
+
+	/*
+	 * Avoid #gp.
+	 */
+	if (bv & ~xsave_mask)
+		return (EINVAL);
+
+	hdr = (struct xstate_hdr *)(get_pcb_user_save_td(td) + 1);
+
+	hdr->xstate_bv = bv;
+	bcopy(xfpustate + sizeof(struct xstate_hdr),
+	    (char *)(hdr + 1), len - sizeof(struct xstate_hdr));
+
+	return (0);
+}
+#endif
+
+int
+npxsetregs(struct thread *td, union savefpu *addr, char *xfpustate,
+	size_t xfpustate_size)
 {
 	struct pcb *pcb;
+#ifdef CPU_ENABLE_SSE
+	int error;
+#endif
 
 	if (!hw_float)
-		return;
+		return (ENXIO);
 
+#ifdef CPU_ENABLE_SSE
+	if (cpu_fxsr)
+		addr->sv_xmm.sv_env.en_mxcsr &= cpu_mxcsr_mask;
+#endif
 	pcb = td->td_pcb;
 	critical_enter();
 	if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) {
 #ifdef CPU_ENABLE_SSE
+		error = npxsetxstate(td, xfpustate, xfpustate_size);
+		if (error != 0) {
+			critical_exit();
+			return (error);
+		}
 		if (!cpu_fxsr)
 #endif
 			fnclex();	/* As in npxdrop(). */
-		if (((uintptr_t)addr & 0xf) != 0) {
-			bcopy(addr, &pcb->pcb_user_save, sizeof(*addr));
-			fpurstor(&pcb->pcb_user_save);
-		} else
-			fpurstor(addr);
+		bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
+		fpurstor(get_pcb_user_save_td(td));
 		critical_exit();
 		pcb->pcb_flags |= PCB_NPXUSERINITDONE | PCB_NPXINITDONE;
 	} else {
 		critical_exit();
-		bcopy(addr, &pcb->pcb_user_save, sizeof(*addr));
+#ifdef CPU_ENABLE_SSE
+		error = npxsetxstate(td, xfpustate, xfpustate_size);
+		if (error != 0)
+			return (error);
+#endif
+		bcopy(addr, get_pcb_user_save_td(td), sizeof(*addr));
 		npxuserinited(td);
 	}
+	return (0);
 }
 
 static void
@@ -871,7 +1164,9 @@
 {
 	
 #ifdef CPU_ENABLE_SSE
-	if (cpu_fxsr)
+	if (use_xsave)
+		xsave((char *)addr, xsave_mask);
+	else if (cpu_fxsr)
 		fxsave(addr);
 	else
 #endif
@@ -912,12 +1207,13 @@
 #endif /* CPU_ENABLE_SSE */
 
 static void
-fpurstor(addr)
-	union savefpu *addr;
+fpurstor(union savefpu *addr)
 {
 
 #ifdef CPU_ENABLE_SSE
-	if (cpu_fxsr)
+	if (use_xsave)
+		xrstor((char *)addr, xsave_mask);
+	else if (cpu_fxsr)
 		fxrstor(addr);
 	else
 #endif
@@ -924,33 +1220,6 @@
 		frstor(addr);
 }
 
-static device_method_t npx_methods[] = {
-	/* Device interface */
-	DEVMETHOD(device_identify,	npx_identify),
-	DEVMETHOD(device_probe,		npx_probe),
-	DEVMETHOD(device_attach,	npx_attach),
-	DEVMETHOD(device_detach,	bus_generic_detach),
-	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
-	DEVMETHOD(device_suspend,	bus_generic_suspend),
-	DEVMETHOD(device_resume,	bus_generic_resume),
-	
-	{ 0, 0 }
-};
-
-static driver_t npx_driver = {
-	"npx",
-	npx_methods,
-	1,			/* no softc */
-};
-
-static devclass_t npx_devclass;
-
-/*
- * We prefer to attach to the root nexus so that the usual case (exception 16)
- * doesn't describe the processor as being `on isa'.
- */
-DRIVER_MODULE(npx, nexus, npx_driver, npx_devclass, 0, 0);
-
 #ifdef DEV_ISA
 /*
  * This sucks up the legacy ISA support assignments from PNPBIOS/ACPI.
@@ -1005,9 +1274,8 @@
 static MALLOC_DEFINE(M_FPUKERN_CTX, "fpukern_ctx",
     "Kernel contexts for FPU state");
 
-#define	XSAVE_AREA_ALIGN	64
-
 #define	FPU_KERN_CTX_NPXINITDONE 0x01
+#define	FPU_KERN_CTX_DUMMY	 0x02
 
 struct fpu_kern_ctx {
 	union savefpu *prev;
@@ -1022,7 +1290,7 @@
 	size_t sz;
 
 	sz = sizeof(struct fpu_kern_ctx) + XSAVE_AREA_ALIGN +
-	    sizeof(union savefpu);
+	    cpu_max_ext_state_size;
 	res = malloc(sz, M_FPUKERN_CTX, ((flags & FPU_KERN_NOWAIT) ?
 	    M_NOWAIT : M_WAITOK) | M_ZERO);
 	return (res);
@@ -1051,9 +1319,13 @@
 {
 	struct pcb *pcb;
 
+	if ((flags & FPU_KERN_KTHR) != 0 && is_fpu_kern_thread(0)) {
+		ctx->flags = FPU_KERN_CTX_DUMMY;
+		return (0);
+	}
 	pcb = td->td_pcb;
-	KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save == &pcb->pcb_user_save,
-	    ("mangled pcb_save"));
+	KASSERT(!PCB_USER_FPU(pcb) || pcb->pcb_save ==
+	    get_pcb_user_save_pcb(pcb), ("mangled pcb_save"));
 	ctx->flags = 0;
 	if ((pcb->pcb_flags & PCB_NPXINITDONE) != 0)
 		ctx->flags |= FPU_KERN_CTX_NPXINITDONE;
@@ -1070,6 +1342,8 @@
 {
 	struct pcb *pcb;
 
+	if (is_fpu_kern_thread(0) && (ctx->flags & FPU_KERN_CTX_DUMMY) != 0)
+		return (0);
 	pcb = td->td_pcb;
 	critical_enter();
 	if (curthread == PCPU_GET(fpcurthread))
@@ -1076,7 +1350,7 @@
 		npxdrop();
 	critical_exit();
 	pcb->pcb_save = ctx->prev;
-	if (pcb->pcb_save == &pcb->pcb_user_save) {
+	if (pcb->pcb_save == get_pcb_user_save_pcb(pcb)) {
 		if ((pcb->pcb_flags & PCB_NPXUSERINITDONE) != 0)
 			pcb->pcb_flags |= PCB_NPXINITDONE;
 		else
@@ -1095,12 +1369,10 @@
 int
 fpu_kern_thread(u_int flags)
 {
-	struct pcb *pcb;
 
-	pcb = curpcb;
 	KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0,
 	    ("Only kthread may use fpu_kern_thread"));
-	KASSERT(curpcb->pcb_save == &curpcb->pcb_user_save,
+	KASSERT(curpcb->pcb_save == get_pcb_user_save_pcb(curpcb),
 	    ("mangled pcb_save"));
 	KASSERT(PCB_USER_FPU(curpcb), ("recursive call"));
 
@@ -1116,3 +1388,27 @@
 		return (0);
 	return ((curpcb->pcb_flags & PCB_KERNNPX) != 0);
 }
+
+/*
+ * FPU save area alloc/free/init utility routines
+ */
+union savefpu *
+fpu_save_area_alloc(void)
+{
+
+	return (uma_zalloc(fpu_save_area_zone, 0));
+}
+
+void
+fpu_save_area_free(union savefpu *fsa)
+{
+
+	uma_zfree(fpu_save_area_zone, fsa);
+}
+
+void
+fpu_save_area_reset(union savefpu *fsa)
+{
+
+	bcopy(npx_initialstate, fsa, cpu_max_ext_state_size);
+}

Modified: trunk/sys/i386/isa/pmtimer.c
===================================================================
--- trunk/sys/i386/isa/pmtimer.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/pmtimer.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki at FreeBSD.org>
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/isa/pmtimer.c 247088 2013-02-21 07:16:40Z imp $");
 
 /*
  * Timer device driver for power management events.
@@ -82,14 +83,11 @@
 static int
 pmtimer_suspend(device_t dev)
 {
-	int	pl;
 
-	pl = splsoftclock();
 	microtime(&diff_time);
 	inittodr(0);
 	microtime(&suspend_time);
 	timevalsub(&diff_time, &suspend_time);
-	splx(pl);
 	return (0);
 }
 
@@ -96,12 +94,10 @@
 static int
 pmtimer_resume(device_t dev)
 {
-	int pl;
 	u_int second, minute, hour;
 	struct timeval resume_time, tmp_time;
 
 	/* modified for adjkerntz */
-	pl = splsoftclock();
 	timer_restore();		/* restore the all timers */
 	inittodr(0);			/* adjust time to RTC */
 	microtime(&resume_time);
@@ -118,16 +114,13 @@
 	timevalsub(&resume_time, &suspend_time);
 	/* Fixup the calltodo list with the delta time. */
 	adjust_timeout_calltodo(&resume_time);
-#endif /* PMTIMER_FIXUP_CALLTODOK */
-	splx(pl);
-#ifndef PMTIMER_FIXUP_CALLTODO
-	second = resume_time.tv_sec - suspend_time.tv_sec; 
-#else /* PMTIMER_FIXUP_CALLTODO */
 	/* 
 	 * We've already calculated resume_time to be the delta between 
 	 * the suspend and the resume. 
 	 */
 	second = resume_time.tv_sec; 
+#else /* !PMTIMER_FIXUP_CALLTODO */
+	second = resume_time.tv_sec - suspend_time.tv_sec; 
 #endif /* PMTIMER_FIXUP_CALLTODO */
 	hour = second / 3600;
 	second %= 3600;

Modified: trunk/sys/i386/isa/prof_machdep.c
===================================================================
--- trunk/sys/i386/isa/prof_machdep.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/prof_machdep.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1996 Bruce D. Evans.
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/isa/prof_machdep.c 220433 2011-04-07 23:28:28Z jkim $");
 
 #ifdef GUPROF
 #include "opt_i586_guprof.h"

Modified: trunk/sys/i386/isa/spic.c
===================================================================
--- trunk/sys/i386/isa/spic.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/spic.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000  Nick Sayer
  * All rights reserved.
@@ -34,7 +35,7 @@
  * and mouse button out of the jog dial. I suspect that this device will
  * end up having to support at least 2 different minor devices: One to be
  * the jog wheel device for moused to camp out on and the other to perform
- * all of the other miscelaneous functions of this device. But for now,
+ * all of the other miscellaneous functions of this device. But for now,
  * the jog wheel is all you get.
  *
  * At the moment, the data sent back by the device is rather primitive.
@@ -41,7 +42,7 @@
  * It sends a single character per event:
  * u = up, d = down -- that's the jog button
  * l = left, r = right -- that's the dial.
- * "left" and "right" are rather caprecious. They actually represent
+ * "left" and "right" are rather capricious. They actually represent
  * ccw and cw, respectively
  *
  * What documentation exists is thanks to Andrew Tridge, and his page at
@@ -50,7 +51,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/isa/spic.c 320923 2017-07-12 22:16:54Z jhb $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -346,6 +347,8 @@
 
 	/* There can be only one */
 	make_dev(&spic_cdevsw, 0, 0, 0, 0600, "jogdial");
+	device_printf(dev,
+	    "WARNING: This driver is deprecated and will be removed.\n");
 
 	return 0;
 }

Modified: trunk/sys/i386/isa/spicreg.h
===================================================================
--- trunk/sys/i386/isa/spicreg.h	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/isa/spicreg.h	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000  Nick Sayer
  * All rights reserved.
@@ -23,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sys/i386/isa/spicreg.h 139790 2005-01-06 22:18:23Z imp $
  *
  */
 

Modified: trunk/sys/i386/pci/pci_bus.c
===================================================================
--- trunk/sys/i386/pci/pci_bus.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/pci/pci_bus.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997, Stefan Esser <se at freebsd.org>
  * All rights reserved.

Modified: trunk/sys/i386/pci/pci_cfgreg.c
===================================================================
--- trunk/sys/i386/pci/pci_cfgreg.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/pci/pci_cfgreg.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997, Stefan Esser <se at freebsd.org>
  * Copyright (c) 2000, Michael Smith <msmith at freebsd.org>
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/pci/pci_cfgreg.c 261455 2014-02-04 03:36:42Z eadler $");
 
 #include "opt_xbox.h"
 
@@ -306,7 +307,7 @@
 		switch (cfgmech) {
 		case CFGMECH_PCIE:
 		case CFGMECH_1:
-			outl(CONF1_ADDR_PORT, (1 << 31)
+			outl(CONF1_ADDR_PORT, (1U << 31)
 			    | (bus << 16) | (slot << 11) 
 			    | (func << 8) | (reg & ~0x03));
 			dataport = CONF1_DATA_PORT + (reg & 0x03);
@@ -562,7 +563,7 @@
 		if (pcie_array == NULL)
 			return (0);
 
-		va = kmem_alloc_nofault(kernel_map, PCIE_CACHE * PAGE_SIZE);
+		va = kva_alloc(PCIE_CACHE * PAGE_SIZE);
 		if (va == 0) {
 			free(pcie_array, M_DEVBUF);
 			return (0);
@@ -610,25 +611,29 @@
 }
 #endif /* !XEN */
 
-#define PCIE_PADDR(bar, reg, bus, slot, func)	\
-	((bar)				|	\
-	(((bus) & 0xff) << 20)		|	\
+#define PCIE_PADDR(base, reg, bus, slot, func)	\
+	((base)				+	\
+	((((bus) & 0xff) << 20)		|	\
 	(((slot) & 0x1f) << 15)		|	\
 	(((func) & 0x7) << 12)		|	\
-	((reg) & 0xfff))
+	((reg) & 0xfff)))
 
-/*
- * Find an element in the cache that matches the physical page desired, or
- * create a new mapping from the least recently used element.
- * A very simple LRU algorithm is used here, does it need to be more
- * efficient?
- */
-static __inline struct pcie_cfg_elem *
-pciereg_findelem(vm_paddr_t papage)
+static __inline vm_offset_t
+pciereg_findaddr(int bus, unsigned slot, unsigned func, unsigned reg)
 {
 	struct pcie_cfg_list *pcielist;
 	struct pcie_cfg_elem *elem;
+	vm_paddr_t pa, papage;
 
+	pa = PCIE_PADDR(pcie_base, reg, bus, slot, func);
+	papage = pa & ~PAGE_MASK;
+
+	/*
+	 * Find an element in the cache that matches the physical page desired,
+	 * or create a new mapping from the least recently used element.
+	 * A very simple LRU algorithm is used here, does it need to be more
+	 * efficient?
+	 */
 	pcielist = &pcie_list[PCPU_GET(cpuid)];
 	TAILQ_FOREACH(elem, pcielist, elem) {
 		if (elem->papage == papage)
@@ -649,7 +654,7 @@
 		TAILQ_REMOVE(pcielist, elem, elem);
 		TAILQ_INSERT_HEAD(pcielist, elem, elem);
 	}
-	return (elem);
+	return (elem->vapage | (pa & PAGE_MASK));
 }
 
 /*
@@ -664,9 +669,7 @@
 pciereg_cfgread(int bus, unsigned slot, unsigned func, unsigned reg,
     unsigned bytes)
 {
-	struct pcie_cfg_elem *elem;
-	volatile vm_offset_t va;
-	vm_paddr_t pa, papage;
+	vm_offset_t va;
 	int data = -1;
 
 	if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX ||
@@ -674,23 +677,20 @@
 		return (-1);
 
 	critical_enter();
-	pa = PCIE_PADDR(pcie_base, reg, bus, slot, func);
-	papage = pa & ~PAGE_MASK;
-	elem = pciereg_findelem(papage);
-	va = elem->vapage | (pa & PAGE_MASK);
+	va = pciereg_findaddr(bus, slot, func, reg);
 
 	switch (bytes) {
 	case 4:
-		__asm __volatile("mov %1, %%eax" : "=a" (data)
-		    : "m" (*(uint32_t *)va));
+		__asm("movl %1, %0" : "=a" (data)
+		    : "m" (*(volatile uint32_t *)va));
 		break;
 	case 2:
-		__asm __volatile("movzwl %1, %%eax" : "=a" (data)
-		    : "m" (*(uint16_t *)va));
+		__asm("movzwl %1, %0" : "=a" (data)
+		    : "m" (*(volatile uint16_t *)va));
 		break;
 	case 1:
-		__asm __volatile("movzbl %1, %%eax" : "=a" (data)
-		    : "m" (*(uint8_t *)va));
+		__asm("movzbl %1, %0" : "=a" (data)
+		    : "m" (*(volatile uint8_t *)va));
 		break;
 	}
 
@@ -702,9 +702,7 @@
 pciereg_cfgwrite(int bus, unsigned slot, unsigned func, unsigned reg, int data,
     unsigned bytes)
 {
-	struct pcie_cfg_elem *elem;
-	volatile vm_offset_t va;
-	vm_paddr_t pa, papage;
+	vm_offset_t va;
 
 	if (bus < pcie_minbus || bus > pcie_maxbus || slot > PCI_SLOTMAX ||
 	    func > PCI_FUNCMAX || reg > PCIE_REGMAX)
@@ -711,23 +709,20 @@
 		return;
 
 	critical_enter();
-	pa = PCIE_PADDR(pcie_base, reg, bus, slot, func);
-	papage = pa & ~PAGE_MASK;
-	elem = pciereg_findelem(papage);
-	va = elem->vapage | (pa & PAGE_MASK);
+	va = pciereg_findaddr(bus, slot, func, reg);
 
 	switch (bytes) {
 	case 4:
-		__asm __volatile("mov %%eax, %0" : "=m" (*(uint32_t *)va)
+		__asm("movl %1, %0" : "=m" (*(volatile uint32_t *)va)
 		    : "a" (data));
 		break;
 	case 2:
-		__asm __volatile("mov %%ax, %0" : "=m" (*(uint16_t *)va)
-		    : "a" (data));
+		__asm("movw %1, %0" : "=m" (*(volatile uint16_t *)va)
+		    : "a" ((uint16_t)data));
 		break;
 	case 1:
-		__asm __volatile("mov %%al, %0" : "=m" (*(uint8_t *)va)
-		    : "a" (data));
+		__asm("movb %1, %0" : "=m" (*(volatile uint8_t *)va)
+		    : "a" ((uint8_t)data));
 		break;
 	}
 

Modified: trunk/sys/i386/pci/pci_pir.c
===================================================================
--- trunk/sys/i386/pci/pci_pir.c	2018-05-26 22:08:56 UTC (rev 9992)
+++ trunk/sys/i386/pci/pci_pir.c	2018-05-26 22:09:11 UTC (rev 9993)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 1997, Stefan Esser <se at freebsd.org>
  * Copyright (c) 2000, Michael Smith <msmith at freebsd.org>
@@ -28,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/i386/pci/pci_pir.c 181775 2008-08-15 20:51:31Z kmacy $");
 
 #include <sys/param.h>
 #include <sys/systm.h>



More information about the Midnightbsd-cvs mailing list