Home | History | Annotate | only in /src/sys/arch/i386/include
History log of /src/sys/arch/i386/include
RevisionDateAuthorComments
 1.53 30-Nov-2024  christos Create a new header lwp_private.h to contain _lwp_getprivate_fast,
_lwp_gettcb_fast, _lwp_settcb and remove them from mcontext.h, so that:
1. we don't need special hacks to hide them
2. we can include <lwp.h> where needed to get the necessary prototypes
without redefining them locally.
 1.52 04-Nov-2024  christos Undo previous lwp.h change.
 1.51 03-Nov-2024  christos Split __lwp_getprivate_fast and __lwp_*tcb from mcontext.h into a separate
lwp.h file.
 1.50 13-Sep-2019  manu branches: 1.50.32;
Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.49 12-Jul-2018  maxv branches: 1.49.4;
Remove the kernel PMC code. Sent yesterday on tech-kern@.

This change:

* Removes "options PERFCTRS", the associated includes, and the associated
ifdefs. In doing so, it removes several XXXSMPs in the MI code, which is
good.

* Removes the PMC code of ARM XSCALE.

* Removes all the pmc.h files. They were all empty, except for ARM XSCALE.

* Reorders the x86 PMC code not to rely on the legacy pmc.h file. The
definitions are put in sysarch.h.

* Removes the kern/sys_pmc.c file, and along with it, the sys_pmc_control
and sys_pmc_get_info syscalls. They are marked as OBSOL in kern,
netbsd32 and rump.

* Removes the pmc_evid_t and pmc_ctr_t types.

* Removes all the associated man pages. The sets are marked as obsolete.
 1.48 12-Aug-2017  maxv branches: 1.48.2; 1.48.4;
Remove vm86.

Pass 4.
 1.47 09-Aug-2017  maxv Remove ibcs2_machdep.h on i386, and don't install it.
 1.46 08-Aug-2017  maxv Move freebsd_machdep.h into sys/compat/freebsd, and don't install it. Now,
the compat_freebsd files are all contained in sys/compat/freebsd.
 1.45 29-Jul-2017  maxv Unlink svr4_machdep.h.
 1.44 27-Feb-2016  tls branches: 1.44.10;
Add cpu_rng, a framework for simple on-CPU random number generators.
 1.43 23-Jul-2014  alnsn branches: 1.43.4;
Rename sljitarch.h to sljit_machdep.h.
 1.42 12-Feb-2014  dsl branches: 1.42.2;
Change i386 to use x86/fpu.c instead of i386/isa/npx.c
This changes the trap10 and trap13 code to call directly into fpu.c,
removing all the code for T_ARITHTRAP, T_XMM and T_FPUNDA from i386/trap.c
Not all of the code thate appeared to handle fpu traps was ever called!
Most of the changes just replace the include of machine/npx.h with x86/fpu.h
(or remove it entirely).
 1.41 05-Nov-2012  alnsn branches: 1.41.2;
Build sljit test when MKSLJIT != no and set MKSLJIT to yes on amd64 and i386.
 1.40 08-Aug-2012  drochner branches: 1.40.2;
on x86, <machine/cpufunc.h> only pulls in <x86/cpufunc.h>. The latter
is not installed to userland and noone missed it, so the former ones
can not be useful either. Don't install them.
 1.39 17-Jul-2011  joerg branches: 1.39.2;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.38 17-Jul-2011  dyoung On i386, good-bye <machine/bus.h>.
 1.37 31-Jul-2010  joerg Add support for fenv.h interface for i386 and amd64.

Submitted by Stathis Kamperis as part of GSoC 2010 and ported from
FreeBSD.
 1.36 20-Dec-2007  ad branches: 1.36.10; 1.36.24; 1.36.30; 1.36.32;
- Make __cpu_simple_lock and similar real functions and patch at runtime.
- Remove old x86 atomic ops.
- Drop text alignment back to 16 on i386 (really, this time).
- Minor cleanup.
 1.35 14-Nov-2007  ad branches: 1.35.2; 1.35.6;
- Remove I486_CPU, I586_CPU, I686_CPU options. They buy us nothing and
clutter the code significantly.
- Remove pccons.
 1.34 09-Feb-2007  ad branches: 1.34.6; 1.34.12; 1.34.22; 1.34.24; 1.34.28; 1.34.30;
Merge newlock2 to head.
 1.33 26-Jul-2006  drochner branches: 1.33.4;
don't install <machine/db_machdep.h>, this is kernel only
 1.32 04-Feb-2006  jmmv branches: 1.32.2;
Revert yesterday's change that attempted to fix the detection of the
boot device when using a Multiboot boot loader. It couldn't work because
these boot loaders do not pass a checksum of the disk so matchbiosdisk()
cannot really find any matches. I should have gone to sleep before
commiting...

Found by xtraeme@.
 1.31 03-Feb-2006  jmmv branches: 1.31.2;
When booting an i386 kernel with Multiboot, properly detect the boot device
by looking it up in the x86_alldisks table (instead of trying to match it
to 'wd*' manually).

In order to do this, move the cpu_rootconf function from x86 common code
to amd64 and i386 specific one. This way, i386 can do an extra step (call
the appropriate Multiboot code) in the appropriate place (after
x86_matchbiosdisks and before findroot()).
 1.30 03-Feb-2006  jmmv Implement support for 'The Multiboot Specification' so that i386 kernels
can be booted directly from Multiboot-compliant boot loaders (e.g. GRUB).
See the added multiboot(8) manual page for more information.

No objections in tech-kern@; only positive comments.
 1.29 11-Dec-2005  christos branches: 1.29.2; 1.29.4;
merge ktrace-lwp.
 1.28 03-May-2005  tron branches: 1.28.2;
"loadfile_machdep.h" should not be installed as pointed out by
Izumi Tsutsui. This needs to be fixed in the build process.
 1.27 02-May-2005  tron Install "loadfile_machdep.h" to fix build of "libsa".
 1.26 08-May-2004  kleink Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 1.25 15-May-2003  wiz branches: 1.25.2;
Don't install machine/mouse.h on i386 and prep; there are no users for
the old busmouse interface any longer, we use wsmouse now.
 1.24 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.23 26-Nov-2002  lukem Remove KDIR=, since SYS_INCLUDE=symlinks and KDIR are not supported any more.
 1.22 23-Nov-2002  lha install intrdefs.h so it can be used by intr.h (and libkvm)
 1.21 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.20 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.19 12-Sep-2001  jmc branches: 1.19.2; 1.19.8; 1.19.12;
Add mtrr.h to INCS list to get installed on a make includes
 1.18 15-Apr-2001  kleink branches: 1.18.4; 1.18.6;
Add definitions of C99 integer format conversion macros.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.17 15-Apr-2001  kleink Add definitions of C99 specified-width integer type limits.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.16 14-Apr-2001  kleink Add definitions of C99 integer constant macros.
Tidy Makefiles up a little.
 1.15 14-Apr-2001  kleink Add definitions of C99 minimum-width and greatest-width integer types.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.14 05-Nov-2000  thorpej branches: 1.14.4;
Machine pmc.h
 1.13 26-Jun-2000  kleink Add <machine/int_types.h>, which provides namespace-pure definitions
of exact-width integer types.
 1.12 29-Apr-2000  thorpej Require that each each MACHINE/MACHINE_ARCH supply a lock.h. This file
contains the values __SIMPLELOCK_LOCKED and __SIMPLELOCK_UNLOCKED, which
replace the old SIMPLELOCK_LOCKED and SIMPLELOCK_UNLOCKED. These files
are also required to supply inline functions __cpu_simple_lock(),
__cpu_simple_lock_try(), and __cpu_simple_unlock() if locking is to be
supported on that platform (i.e. if MULTIPROCESSOR is defined in the
_KERNEL case). Change these functions to take an int * (&alp->lock_data)
rather than the struct simplelock * itself.

These changes make it possible for userland to use the locking primitives
by including <machine/lock.h>.
 1.11 17-Mar-2000  tron Install "endian_machdep.h" required for "sys/endian.h".
 1.10 23-Dec-1999  kleink C99: Define a NAN macro in <math.h> which evaulates to a constant expression of
a single-precision quiet NaN; only to be defined on platforms that do support
this value.
 1.9 25-Oct-1999  drochner Don't let loadfile_machdep.h make it to /usr/include - the i386
stand Makefiles already set up the compile environment so that
machine/loadfile_machdep.h can be found.
 1.8 17-Jun-1999  thorpej branches: 1.8.2; 1.8.4; 1.8.6;
PMAP_NEW is no longer optional on the i386; the old pmap's page table
allocation strategy no longer works at all. Move pmap.new.* to pmap.*.

To read the revision history of PMAP_NEW up until this merge, use cvs
rlog of the old pmap.new.* files.
 1.7 28-Apr-1999  christos MD defines for the MI loadfile
 1.6 10-Mar-1999  mycroft branches: 1.6.4;
Add an ieee.h.
 1.5 16-Jan-1999  tron Add missing backslashes between continued lines.
 1.4 16-Jan-1999  bouyer Oups, need byte_swap.h too. Pointed out by Robert V. Baron
 1.3 15-Jan-1999  bouyer Move the bswap functions from libutil to libc (this bups the
minor of libc and the major of libutil). For little-endian architectures
merge the bnswap() assembly versions with nto* and hton* using symbols
aliasing. Use symbol renaming for the bswap function in this case to avoid
namespace pollution.
Declare bswap* in machine/bswap.h, not machine/endian.h. For little-endian
machines, common code for inline macros go in machine/byte_swap.h
Sync libkern with libc.
Adjust #include in kernel sources for machine/bswap.h.
 1.2 01-Oct-1998  erh linux_machdep.h has moved.
 1.1 12-Jun-1998  cgd Rework the way kernel include files are installed. In the new method,
as with user-land programs, include files are installed by each directory
in the tree that has includes to install. (This allows more flexibility
as to what gets installed, makes 'partial installs' easier, and gives us
more options as to which machines' includes get installed at any given
time.) The old SYS_INCLUDES={symlinks,copies} behaviours are _both_
still supported, though at least one bug in the 'symlinks' case is
fixed by this change. Include files can't be build before installation,
so directories that have includes as targets (e.g. dev/pci) have to move
those targets into a different Makefile.
 1.6.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.8.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.4.1 15-Nov-1999  fvdl Sync with -current
 1.8.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.8.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.8.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.4.6 11-Dec-2002  thorpej Sync with HEAD.
 1.14.4.5 18-Oct-2002  nathanw Catch up to -current.
 1.14.4.4 17-Sep-2002  nathanw Catch up to -current.
 1.14.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.14.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.14.4.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.18.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.18.4.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.18.4.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.19.12.1 19-May-2002  gehenna Remove port-dependent conf.h.
 1.19.8.1 17-Mar-2002  thorpej Add first-cut mutex and rwlock implementation bits for the x86.
XXX Does not actually handle i386 CPUs yet, only i486 and later.
 1.19.2.2 11-Dec-2001  sommerfeld Install atomic.h for benefit of userland
 1.19.2.1 12-Sep-2001  sommerfeld file Makefile was added on branch sommerfeld_i386mp_1 on 2001-12-11 23:51:25 +0000
 1.25.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.25.2.1 03-Aug-2004  skrll Sync with HEAD
 1.28.2.5 21-Jan-2008  yamt sync with head
 1.28.2.4 15-Nov-2007  yamt sync with head.
 1.28.2.3 26-Feb-2007  yamt sync with head.
 1.28.2.2 30-Dec-2006  yamt sync with head.
 1.28.2.1 21-Jun-2006  yamt sync with head.
 1.29.4.1 09-Sep-2006  rpaulo sync with head
 1.29.2.1 18-Feb-2006  yamt sync with head.
 1.31.2.1 22-Apr-2006  simonb Sync with head.
 1.32.2.1 11-Aug-2006  yamt sync with head
 1.33.4.1 24-Oct-2006  ad Compile fixes
 1.34.30.2 27-Dec-2007  mjf Sync with HEAD.
 1.34.30.1 19-Nov-2007  mjf Sync with HEAD.
 1.34.28.1 18-Nov-2007  bouyer Sync with HEAD
 1.34.24.1 09-Jan-2008  matt sync with HEAD
 1.34.22.1 21-Nov-2007  joerg Sync with HEAD.
 1.34.12.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.34.6.1 03-Dec-2007  ad Sync with HEAD.
 1.35.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.35.2.1 26-Dec-2007  ad Sync with head.
 1.36.32.1 05-Mar-2011  rmind sync with head
 1.36.30.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.36.24.2 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.36.24.1 24-Oct-2010  jym Sync with HEAD
 1.36.10.1 11-Aug-2010  yamt sync with head.
 1.39.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.39.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.39.2.1 30-Oct-2012  yamt sync with head
 1.40.2.3 03-Dec-2017  jdolecek update from HEAD
 1.40.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.41.2.1 18-May-2014  rmind sync with head
 1.42.2.1 10-Aug-2014  tls Rebase.
 1.43.4.2 28-Aug-2017  skrll Sync with HEAD
 1.43.4.1 19-Mar-2016  skrll Sync with HEAD
 1.44.10.1 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.48.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.48.4.1 10-Jun-2019  christos Sync with HEAD
 1.48.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.49.4.1 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.50.32.1 02-Aug-2025  perseant Sync with HEAD
 1.3 19-Oct-2014  joerg Disable SSE and AVX for kernel modules too.
 1.2 24-May-2014  jakllsch branches: 1.2.2;
Now that GCC 4.8 on i486 has stolen the frame pointer, do like amd64 and
add -fno-omit-frame-pointer to kernel DEFCOPTS and modules CFLAGS.
 1.1 25-Nov-2009  tron branches: 1.1.4; 1.1.8; 1.1.22; 1.1.26; 1.1.40;
Enable SSP (Stack Smash Protection) in x86 kernels by default (except
in i386 *TINY kernels). The NetBSD/i386 "ALL" kernel is unconditionally
compiled with SSP enabled.

Change approved by the core team.
 1.1.40.1 10-Aug-2014  tls Rebase.
 1.1.26.2 03-Dec-2017  jdolecek update from HEAD
 1.1.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.22.1 10-Nov-2014  msaitoh Pull up following revision(s) (requested by joerg in ticket #1172):
sys/arch/amd64/include/Makefile.inc: revision 1.5
sys/arch/i386/include/Makefile.inc: revision 1.3 via patch
Disable SSE and AVX for kernel modules too.
 1.1.8.2 24-Oct-2010  jym Sync with HEAD
 1.1.8.1 25-Nov-2009  jym file Makefile.inc was added on branch jym-xensuspend on 2010-10-24 22:48:02 +0000
 1.1.4.2 11-Mar-2010  yamt sync with head
 1.1.4.1 25-Nov-2009  yamt file Makefile.inc was added on branch yamt-nfs-mp on 2010-03-11 15:02:29 +0000
 1.2.2.1 19-Oct-2014  martin Pull up following revision(s) (requested by joerg in ticket #152):
sys/arch/amd64/include/Makefile.inc: revision 1.5
sys/arch/i386/include/Makefile.inc: revision 1.3
Disable SSE and AVX for kernel modules too.
 1.11 24-May-2008  jmcneill MI implementation of AcpiAcquireGlobalLock and AcpiReleaseGlobalLock.
 1.10 24-May-2008  jmcneill Replace asm implementation of ACPI global lock functions with C equivalents.
 1.9 11-Apr-2008  jmcneill branches: 1.9.2; 1.9.4; 1.9.6;
Revert previous.
 1.8 11-Apr-2008  jmcneill Remove a nasty hack that slipped in during the ACPICA update that should
never have made it in-tree. How ACPI has ever worked since 4.99.42 is
beyond me.
 1.7 09-Dec-2007  jmcneill branches: 1.7.10;
Merge jmcneill-pm branch.
 1.6 24-Dec-2005  perry branches: 1.6.48; 1.6.50; 1.6.60; 1.6.62;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 11-Dec-2005  christos merge ktrace-lwp.
 1.4 13-Aug-2003  yamt branches: 1.4.16;
- leave a compiler which register is used for an asm argument.
- use correct asm constraints.
- eliminate usage of dummy variables.
 1.3 13-Aug-2003  yamt use correct asm operand indexes.
(previously 'GLptr' was used as mask.)
this long standing bug seems to be uncovered by
my previous change(rev.1.2) on some machines.

PR/22457 from Matthias Scheler, and tested by him.
 1.2 09-Aug-2003  yamt in ACPI_ACQUIRE_GLOBAL_LOCK,
don't assume that the reserved bits of the global lock are all zero.
it's actually needed for, at least, IBM Thinkpad X21 (2662-64J).
 1.1 11-May-2003  fvdl branches: 1.1.2;
Add a new include file with some ACPI MD macros, to move i386 specific
stuff out of acnetbsd.h
 1.1.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.1 03-Aug-2004  skrll Sync with HEAD
 1.4.16.2 21-Jan-2008  yamt sync with head
 1.4.16.1 21-Jun-2006  yamt sync with head.
 1.6.62.1 11-Dec-2007  yamt sync with head.
 1.6.60.1 26-Dec-2007  ad Sync with head.
 1.6.50.1 09-Jan-2008  matt sync with HEAD
 1.6.48.1 02-Oct-2007  jmcneill Update to ACPI-CA 20070320
 1.7.10.1 02-Jun-2008  mjf Sync with HEAD.
 1.9.6.2 23-Jun-2008  wrstuden Remove files removed on branch. Updating using patch has its
drawbacks. :-)
 1.9.6.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.4.1 04-May-2009  yamt sync with head.
 1.9.2.1 04-Jun-2008  yamt sync with head
 1.7 11-May-2003  fvdl Redirect to x86/.
 1.6 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.5 18-Jul-2002  kanaoka branches: 1.5.2;
- Disable Interrput before execute AcpiEnterSleepState().
- Add acpi_md_OsDisableInterrupt() for this.
 1.4 18-Jun-2002  tshiozak add MD support for ACPI sleep/wakeup.
 1.3 15-Jun-2002  thorpej Update for acpica-unix-20020612. From Takayoshi Kochi.
 1.2 28-Sep-2001  thorpej branches: 1.2.2; 1.2.4; 1.2.10; 1.2.18;
Bah, fix typo that crept in (tank you vi(1)).
 1.1 28-Sep-2001  thorpej Machine-dependent ACPI CA Osd routines for i386.
 1.2.18.3 21-Jul-2002  gehenna catch up with -current.
 1.2.18.2 16-Jul-2002  gehenna catch up with -current.
 1.2.18.1 14-Jul-2002  gehenna catch up with -current.
 1.2.10.4 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.10.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.2.10.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.10.1 28-Sep-2001  thorpej file acpi_machdep.h was added on branch kqueue on 2002-01-10 19:44:49 +0000
 1.2.4.5 07-Jan-2003  thorpej Sync with HEAD.
 1.2.4.4 01-Aug-2002  nathanw Catch up to -current.
 1.2.4.3 20-Jun-2002  nathanw Catch up to -current.
 1.2.4.2 08-Oct-2001  nathanw Catch up to -current.
 1.2.4.1 28-Sep-2001  nathanw file acpi_machdep.h was added on branch nathanw_sa on 2001-10-08 20:10:46 +0000
 1.2.2.2 01-Oct-2001  fvdl Catch up with -current.
 1.2.2.1 28-Sep-2001  fvdl file acpi_machdep.h was added on branch thorpej-devvp on 2001-10-01 12:39:58 +0000
 1.5.2.2 18-Jul-2002  kanaoka - Disable Interrput before execute AcpiEnterSleepState().
- Add acpi_md_OsDisableInterrupt() for this.
 1.5.2.1 18-Jul-2002  kanaoka file acpi_machdep.h was added on branch sommerfeld_i386mp_1 on 2002-07-18 12:05:13 +0000
 1.28 07-May-2019  kamil Switch all users (except ia64) of custom machine/ansi.h to common_ansi.h

Deduplicate the code among ports and poll definitions of types
directly from a compiler.

This fixes miscompilation of certain programs that instruct compilers
to generate code for different types. This bug has been detected with
-fshort-wchar in EFI firmware.

Proposed and discussed on a mailing list (twice).

Itanium uses custom !ELF fallback switch, temporarily leave it as it is.
 1.27 17-Jun-2015  martin branches: 1.27.18;
Make clock_t unsigned int everywhere.
Ok: matt@, mrg@
 1.26 09-Dec-2014  pooka On i386, prefer __WCHAR/WINT_TYPE__ where available instead of hardcoded
_BSD_WCHAR_T_ value.

This mimics some other ports, and more importantly fixes compilation with
i386 compilers which define __WCHAR_TYPE__ as "long int" instead of the
"int" we had in there. That superficial mismatch resulted in errors
such as:

lib/libc/gen/vis.c:109:1: error: array of inappropriate type initialized from string constant
static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~";

No change to NetBSD (our gcc does define __WCHAR_TYPE__, but it is
"int" ... as expected ... since the NetBSD build worked ;)
 1.25 17-Jul-2011  joerg branches: 1.25.12; 1.25.28; 1.25.30;
Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.24 27-Mar-2010  tnozaki 1. {wctype,wctrans,mbstate}_t: switch MD to MI like other
libc implementation (such as *BSD and glibc2).

2. don't typedef void * wc{type,trans}_t, suggested by soda@-san.
it may pass through compiler type check, it's harmful.
so i introduce dummy struct __tag_wc{type,trans}_t(iconv_t already does).

no ABI change was made.
 1.23 11-Jan-2009  christos branches: 1.23.2; 1.23.4; 1.23.6;
merge christos-time_t
 1.22 26-Oct-2008  mrg branches: 1.22.2;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.21 17-Oct-2007  garbled branches: 1.21.16; 1.21.18; 1.21.22; 1.21.28;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.20 03-Sep-2007  drochner clean up some definitions around rune_t which are not needed anymore
 1.19 04-Oct-2006  tnozaki branches: 1.19.8; 1.19.16; 1.19.22; 1.19.26; 1.19.28;
fix gcc -Werror -Wmissing-braces problem
mbstate_t(this is opaque object)'s initializer should be ``{ 0 }'',
so changed 1st field of union from character array to integer.
 1.18 11-Dec-2005  christos branches: 1.18.20; 1.18.22;
merge ktrace-lwp.
 1.17 07-Aug-2003  agc branches: 1.17.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.16 02-Mar-2003  tshiozak branches: 1.16.2;
add some ISO C 1995 I18N functions and types:
btowc, wctrans, towctrans, wcscoll, wcsxfrm, wctype_t and wctrans_t.
 1.15 03-Jan-2001  takemura branches: 1.15.2;
replace 'long long' with int64_t to compile stand alone program with
compiler other than GCC.
 1.14 26-Dec-2000  itojun make mbstate_t bigger (32 -> 128 bytes).
XXX if you have libc after citrus locale import, please recompile libc,
and your applications that use mbstate_t (rather rare). really sorry
for the mess.
 1.13 21-Dec-2000  itojun populate _BSD_MBSTATE_T_. add warning regarding to rune_t.
 1.12 27-Jun-2000  kleink G/c _BSD_INTPTR_T_ and _BSD_UINTPTR_T_.
 1.11 05-May-2000  thorpej branches: 1.11.2;
Use __GNUC_PREREQ__().
 1.10 03-May-2000  thorpej Make varargs and stdarg work with GCC 2.96 and later.
 1.9 27-Apr-1998  kleink branches: 1.9.14;
Provide definitions for intptr_t and uintptr_t, signed resp. unsigned integral
types large enough to hold any pointer.
 1.8 23-Nov-1997  kleink Add _BSD_SUSECONDS_T_ and _BSD_USECONDS_T_; do some space vs. tab formatting
cleanup
 1.7 15-Nov-1996  jtc Define _BSD_CLOCKID_T_ and _BSD_TIMER_T_
 1.6 16-Mar-1996  jtc Add _BSD_WINT_T_ definition so we can handle wint_t type added in NA1.
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 21-May-1994  cgd new way of naming things
 1.3 20-Dec-1993  mycroft branches: 1.3.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 14-Nov-1993  mycroft Add _SSIZE_T_.
 1.3.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.3.2.1 20-Dec-1993  mycroft file ansi.h was added on branch magnum on 1993-12-20 05:25:03 +0000
 1.9.14.2 05-Jan-2001  bouyer Sync with HEAD
 1.9.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.11.2.1 28-May-2000  minoura Citrus Project XPG4DL, an implementation of I18N (locale) framework,
is imported.
 1.15.2.2 03-Jan-2001  takemura replace 'long long' with int64_t to compile stand alone program with
compiler other than GCC.
 1.15.2.1 03-Jan-2001  takemura file ansi.h was added on branch sommerfeld_i386mp_1 on 2001-01-03 10:09:00 +0000
 1.16.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.2.1 03-Aug-2004  skrll Sync with HEAD
 1.17.16.2 27-Oct-2007  yamt sync with head.
 1.17.16.1 30-Dec-2006  yamt sync with head.
 1.18.22.1 22-Oct-2006  yamt sync with head
 1.18.20.1 18-Nov-2006  ad Sync with head.
 1.19.28.1 06-Nov-2007  matt sync with HEAD
 1.19.26.1 02-Oct-2007  joerg Sync with HEAD.
 1.19.22.1 10-Sep-2007  skrll Sync with HEAD.
 1.19.16.1 03-Oct-2007  garbled Sync with HEAD
 1.19.8.1 09-Oct-2007  ad Sync with head.
 1.21.28.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.21.22.2 11-Aug-2010  yamt sync with head.
 1.21.22.1 04-May-2009  yamt sync with head.
 1.21.18.4 01-Nov-2008  christos catch up with changes in head.
 1.21.18.3 01-Nov-2008  christos Sync with head.
 1.21.18.2 30-Mar-2008  christos time_t is now __int64_t
 1.21.18.1 29-Mar-2008  christos Welcome to the time_t=long long dev_t=uint64_t branch.
 1.21.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.22.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.23.6.1 30-May-2010  rmind sync with head
 1.23.4.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.23.2.2 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.23.2.1 24-Oct-2010  jym Sync with HEAD
 1.25.30.2 22-Sep-2015  skrll Sync with HEAD
 1.25.30.1 06-Apr-2015  skrll Sync with HEAD
 1.25.28.1 16-Jul-2015  riz Pull up following revision(s) (requested by martin in ticket #846):
sys/arch/mips/include/ansi.h: revision 1.29
sys/arch/sh3/include/ansi.h: revision 1.16
sys/arch/sparc64/include/ansi.h: revision 1.18
sys/arch/m68k/include/ansi.h: revision 1.24
sys/arch/powerpc/include/ansi.h: revision 1.30
sys/arch/hppa/include/ansi.h: revision 1.14
sys/arch/i386/include/ansi.h: revision 1.27
sys/arch/alpha/include/ansi.h: revision 1.25
sys/arch/usermode/include/ansi.h: revision 1.5
sys/arch/sparc/include/ansi.h: revision 1.24
Make _BSD_CLOCK_T_ unsigned int so it's the same for IPL32 and LP64
environments. We don't really have a powerpc64 native userland
and the mips64 native userland is IPL32 so this shouldn't affect anything.
Make clock_t unsigned
Make clock_t unsigned int everywhere.
Ok: matt@, mrg@
 1.25.12.1 03-Dec-2017  jdolecek update from HEAD
 1.27.18.1 10-Jun-2019  christos Sync with HEAD
 1.8 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.7 10-Dec-2002  thorpej Rename __LDPGSZ to AOUT_LDPGSZ, to accurately reflect what it is.
 1.6 27-Oct-1994  cgd branches: 1.6.42;
new RCS ID format.
 1.5 28-Jan-1994  jtc Fix spelling error in Copyright notice
 1.4 18-Oct-1993  pk Put definition of __LDPGSZ and `struct relocation_info' where they belong:
in <machine/exec.h>.
 1.3 18-Jun-1993  cgd branches: 1.3.4;
convert magic numbers to network byte order, and attendent changes
 1.2 03-Jun-1993  cgd add prototype for a function to be called from execve to check a_mid type
 1.1 02-Jun-1993  cgd machine-dependent exec stuff
 1.3.4.2 18-Oct-1993  mycroft Merge changes from trunk.
 1.3.4.1 15-Oct-1993  mycroft Define __LDPGSZ.
 1.6.42.1 11-Dec-2002  thorpej Sync with HEAD.
 1.4 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.3 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file apicvar.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.3 27-Feb-2000  sommerfeld Multiple-include protection
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld stuff shared between local and i/o apic drivers.
 1.2.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file apicvar.h was added on branch nathanw_sa on 2002-10-18 02:37:53 +0000
 1.26 01-Oct-2012  dsl Remove some definitions that were part of the APM bos interface.
 1.25 28-Apr-2008  martin branches: 1.25.34; 1.25.44;
Remove clause 3 and 4 from TNF licenses
 1.24 08-Jul-2006  christos branches: 1.24.58; 1.24.60; 1.24.62;
remove functions we don't use
and adjust to the new prototype.
 1.23 11-Dec-2005  christos branches: 1.23.4; 1.23.8; 1.23.16;
merge ktrace-lwp.
 1.22 01-Jun-2005  drochner branches: 1.22.2;
kill the "busname" attach arg for acpi, apm, pnpbios and vesabios,
and pass NULL "print" function pointers to their config_found functions
because they shouldn't be called anyway
 1.21 31-May-2005  drochner inspired by the last commit -- apm_attach_args aren't necessary at all,
kill them
being here fix cast-qual problems in debug code
 1.20 31-May-2005  christos PR/30387: Nicolas Joly: -current i386 GENERIC_LAPTOP kernel compilation failure
 1.19 25-Dec-2003  jmc Wrap some areas with #ifndef _LOCORE so assembly files can pick up some defs
from here. Needed for bioscall fixes in PR#14946
 1.18 27-Oct-2003  junyoung Nuke __P().
 1.17 02-Apr-2003  thorpej branches: 1.17.2;
Use PAGE_SIZE rather than NBPG.
 1.16 14-Oct-2002  takemura Moved MI APM definitions into dev/apm.
 1.15 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.14 10-Sep-2001  perry Make it possible to query each battery individually by making the
APM_IOC_GETPOWER ioctl read/write. Setting the batteryid in the passed
structure returns the data for just that battery. The old ioctl
remains for binary compatibility but has been renamed.

Itojun already did the hard work -- I just added a couple of lines.

reviewed by: thorpej
 1.13 22-Jul-2001  itojun branches: 1.13.2;
support multiple batteries (currently only # of batteris is visible -
need to tweak ioctl API more). PR 10545.
 1.12 21-May-2001  perry branches: 1.12.2;
remove needless externs in front of function prototypes
 1.11 24-Mar-2001  christos Some bios's when apm is disabled [or even some functions of it are disabled],
they keep giving error 0x30b. Unfortunately this keeps happening every second
making the console unusable. Keep track of the last error that occurred and
if the last 10 times apm was called the same error was returned, give up and
exit the apm thread.
 1.10 12-Jan-2001  simonb branches: 1.10.2;
Enable the APM_IOC_DEV_CTL ioctl. Works at least for turning off & on
a LCD screen on a Dell Inspiron 5000e (and probably many others).
 1.9 17-Aug-1999  drochner branches: 1.9.2; 1.9.10;
add some v1.2 bits, comment out the APM_IOC_DEV_CTL ioctl which I didn't
find a use for
 1.8 03-Oct-1998  jtk copyright has been assigned to TNF, update notice
 1.7 31-Aug-1998  jtk add 32-bit register support and beginnings of APM V1.2 support
 1.6 15-Oct-1997  jtk put in place a proper bioscall.h (sorry about that!)
finish up incomplete job of moving structure used by bioscall() to
<machine/bioscall.h>, with associated changes in include file strategy,
genassym stuff, etc.
 1.5 22-Nov-1996  jtk branches: 1.5.10;
add pre-probe step so that autoconfiguration does not print 'apm0 at
mainbus0 not configured' message if configured but not present in the
BIOS
 1.4 10-Sep-1996  jtk clean up missing prototype, extra variable
 1.3 08-Sep-1996  jtk change APM to use new almost-generalized BIOS trampoline:

/*
* void bioscall(int function, struct apmregs *regs):
* call the BIOS interrupt "function" from real mode with
* registers as specified in "regs"
* (for the flags, though, only these flags are passed to the BIOS;
* the remainder come from the flags register at the time of the call:
* (PSL_C|PSL_PF|PSL_AF|PSL_Z|PSL_N|PSL_D|PSL_V)
*
* Fills in *regs with registers as returned by BIOS.
*/

Thanks to Charles Hannum for complaining and inspiring me to hack this
together.
 1.2 30-Aug-1996  jtk make all constants use APM_ prefix, and some other minor cleanup so that
this can be the sole APM include file
 1.1 25-Aug-1996  jtk add Advanced Power Management driver
Includes bootstrap support from FreeBSD (Tatsumi HOSOKAWA and <ukai>)
 1.5.10.1 15-Oct-1997  thorpej Sync w/ trunk.
 1.9.10.5 22-Sep-2001  sommerfeld Merge branch with current, post ubcperf, MTRR, etc., etc.,
with the recent fifo_putpages fix to the trunk, GENERIC.MPDEBUG config
boots multiuser on my BP6.
 1.9.10.4 03-Sep-2001  sommerfeld Merge with -current once more.
 1.9.10.3 23-May-2001  sommerfeld Merge branch with tonight's current.
boots multiuser.
 1.9.10.2 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.9.10.1 23-Jan-2001  thorpej Sync with the trunk.
 1.9.2.2 27-Mar-2001  bouyer Sync with HEAD.
 1.9.2.1 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.10.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.10.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.10.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.10.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.10.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.12.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.12.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.12.2.1 03-Aug-2001  lukem update to -current
 1.13.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.17.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.17.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.17.2.1 03-Aug-2004  skrll Sync with HEAD
 1.22.2.1 30-Dec-2006  yamt sync with head.
 1.23.16.1 13-Jul-2006  gdamore Merge from HEAD.
 1.23.8.1 11-Aug-2006  yamt sync with head
 1.23.4.1 09-Sep-2006  rpaulo sync with head
 1.24.62.1 16-May-2008  yamt sync with head.
 1.24.60.1 18-May-2008  yamt sync with head.
 1.24.58.1 02-Jun-2008  mjf Sync with HEAD.
 1.25.44.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.25.34.1 30-Oct-2012  yamt sync with head
 1.47 05-Jan-2025  riastradh i386/asm.h: Missed a spot in previous concatenated-.asciz change.

PR toolchain/58960: Missing support for _NETBSD_REVISIONID on various
ports
 1.46 05-Jan-2025  riastradh x86 machine/asm.h: Avoid juxtaposition for concatenation.

clang asm doesn't seem to like it. Instead of `.asciz "foo" "bar"',
do `.ascii "foo"; .asciz "bar"'.

PR toolchain/58960: Missing support for _NETBSD_REVISIONID on various
ports
 1.45 09-Jun-2024  riastradh branches: 1.45.2;
i386/asm.h: Respect _NETBSD_REVISIONID.
 1.44 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.43 17-Apr-2020  joerg Mark the .ident section as mergable string section to avoid redundant
entries.
 1.42 15-May-2016  chs branches: 1.42.18; 1.42.28;
define ALTENTRY(), needed by dtrace.
 1.41 12-Sep-2013  joerg branches: 1.41.6;
Pass PICFLAGS down to cc-as-as and use __PIC__ to decide if it is small
vs big PIC mode. Retire -DPIC and -DBIGPIC.
 1.40 16-Jun-2011  joerg branches: 1.40.2; 1.40.12; 1.40.16;
Use minimal alignment for functions in standalone code.
 1.39 20-Dec-2010  joerg branches: 1.39.6;
Consistently use .gnu.warning with .pushsectio and .popsection on all
architectures instead of obsolete STABS frames for linker warnings.
 1.38 03-May-2008  yamt branches: 1.38.14; 1.38.22;
add macros to designate the end of asm functions. ok by Andrew Doran.
 1.37 20-Dec-2007  ad branches: 1.37.6; 1.37.8; 1.37.10;
- Make __cpu_simple_lock and similar real functions and patch at runtime.
- Remove old x86 atomic ops.
- Drop text alignment back to 16 on i386 (really, this time).
- Minor cleanup.
 1.36 12-Dec-2007  yamt restore section after RCSID.
 1.35 14-Nov-2007  ad branches: 1.35.2; 1.35.4; 1.35.6;
Drop _ALIGN_TEXT back to 16. 32 was a bit silly.
 1.34 17-Oct-2007  garbled branches: 1.34.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.33 05-Aug-2007  ad branches: 1.33.2; 1.33.6;
Keep alignment small for _STANDALONE.
 1.32 05-Aug-2007  ad - Align assembly routines on 32-byte boundaries.
- Don't bother doing anything special for CPUVAR() when !MULTIPROCESSOR.
 1.31 09-Feb-2007  ad branches: 1.31.6; 1.31.14; 1.31.16; 1.31.18; 1.31.22;
Merge newlock2 to head.
 1.30 20-Jan-2006  christos branches: 1.30.18;
Add a STRONG_ALIAS macro
 1.29 11-Dec-2005  christos branches: 1.29.2;
merge ktrace-lwp.
 1.28 13-May-2004  yamt branches: 1.28.12;
fix a compile error in the case DDB && !GPROF.
the problem pointed by Jaka Jejcic on current-users@ and
by several others privately.
 1.27 13-May-2004  yamt call mcount in Xspllower.
 1.26 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.25 02-May-2003  yamt branches: 1.25.2;
set symbol to be a function using .type directive in IDTVEC macro
so that ddb backtrace can pick them up after recent ksyms changes.

suggested by Matt Thomas on tech-kern.
ok'ed by Frank van der Linden.
 1.24 03-Mar-2003  fvdl Make CVAR asm reference macro CVAROFF, taking an offset.
 1.23 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.22 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.21 31-May-2002  thorpej branches: 1.21.2;
Move the IDTVEC() macro to <machine/asm.h>, and make it work with
an ISO C preprocessor.
 1.20 13-Jan-2002  drochner branches: 1.20.10;
for ELF, put RCSID string into .ident section,
add __KERNEL_RCSID macro which is undefined in case of NO_KERNEL_RCSIDS
 1.19 14-Dec-2000  mycroft branches: 1.19.4; 1.19.6;
Remove ALTENTRY(). It's dangerous and should not be used.
 1.18 23-Jun-2000  kleink Add a WEAK_ALIAS() macro.
 1.17 09-Nov-1999  marc branches: 1.17.6;
charles was on drugs. There's no such thing as #elifdef.
 1.16 07-Nov-1999  mycroft branches: 1.16.2;
Fix WARN_REFERENCES() here for the ELF case.
 1.15 27-Sep-1999  kleink branches: 1.15.2; 1.15.4; 1.15.6;
For ELF, rename the profiling entry from mcount to __mcount to avoid clashing
with the user's namespace, also within file scope; for binary compatibility,
define a weak alias for the previous name to cover our tracks.
 1.14 23-Aug-1999  kleink Unlike in an i386 a.out assembler, where in an .align n directive n is meant
to be the logarithm to base 2 of the alignment, in an ELF environment n is
the actual alignment boundary; thus, adjust the directives accordingly.

Albeit the wonderful i386 architecture doesn't mind the smaller alignment in
an obvious way, it is likely to have resulted in some performance penalty
during the a.out->ELF transition.
 1.13 23-Dec-1998  christos C_LABEL has no _ if __ELF__
 1.12 02-Dec-1998  thorpej Argh, fix the ANSI CPP version of the a.out WARN_REFERENCES().
 1.11 02-Dec-1998  thorpej Implement WARN_REFERENCES().
 1.10 05-Jul-1997  thorpej Define the ALTENTRY() macro here.
 1.9 04-Dec-1996  fvdl Change asm.h to make it usable for kernel profiling as well.
Make mcount() a prototype in profile.h
 1.8 30-Nov-1996  jtc PROF -> GPROF
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 02-Sep-1994  jtc Misc changes to make this file more like the asm.h headers used by other
architectures:
Renamed _C_FUNC() to _C_LABEL()
Renamed _ASM_FUNC() to _ASM_LABEL()
Merged _BEGIN_ENTRY with _ENTRY
Renamed _END_ENTRY to _PROF_PROLOGUE

When assembling with profiling enabled, set up stack frame before calling
mcount() in _PROF_PROLOGUE. Also omit emitting .long 0's, as they are no
longer used by the profiling code.
 1.5 12-Mar-1994  jtc branches: 1.5.2;
Added RCSID macro, for RCS ID's (what else?).
 1.4 07-Jan-1994  pk branches: 1.4.2;
Add .type directive to ENRTY().
Move PIC_ macros over here from SYS.h
 1.3 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2 08-Sep-1993  jtc branches: 1.2.2;
STDC -> __STDC__
 1.1 16-Jun-1993  mycroft Move asm.h from /usr/include/sys to /usr/include/machine.
 1.2.2.1 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.4.2.2 07-Jan-1994  pk Add .type directive to ENRTY().
Move PIC_ macros over here from SYS.h
 1.4.2.1 07-Jan-1994  pk file asm.h was added on branch magnum on 1994-01-07 00:46:21 +0000
 1.5.2.1 06-Oct-1994  mycroft Update from trunk.
 1.15.6.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.15.4.1 15-Nov-1999  fvdl Sync with -current
 1.15.2.2 05-Jan-2001  bouyer Sync with HEAD
 1.15.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.16.2.2 07-Nov-1999  mycroft Fix WARN_REFERENCES() here for the ELF case.
 1.16.2.1 07-Nov-1999  mycroft file asm.h was added on branch comdex-fall-1999 on 1999-11-07 07:20:27 +0000
 1.17.6.1 25-Jul-2000  kleink Pull up rev. 1.18 (approved by thorpej):
For ELF, add a WEAK_ALIAS() macro.
 1.19.6.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.19.6.1 11-Feb-2002  jdolecek Sync w/ -current.
 1.19.4.3 11-Dec-2002  thorpej Sync with HEAD.
 1.19.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.19.4.1 28-Feb-2002  nathanw Catch up to -current.
 1.20.10.1 14-Jul-2002  gehenna catch up with -current.
 1.21.2.2 31-May-2002  thorpej Move the IDTVEC() macro to <machine/asm.h>, and make it work with
an ISO C preprocessor.
 1.21.2.1 31-May-2002  thorpej file asm.h was added on branch sommerfeld_i386mp_1 on 2002-05-31 18:07:32 +0000
 1.25.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.25.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.25.2.1 03-Aug-2004  skrll Sync with HEAD
 1.28.12.5 21-Jan-2008  yamt sync with head
 1.28.12.4 15-Nov-2007  yamt sync with head.
 1.28.12.3 03-Sep-2007  yamt sync with head.
 1.28.12.2 26-Feb-2007  yamt sync with head.
 1.28.12.1 21-Jun-2006  yamt sync with head.
 1.29.2.1 01-Feb-2006  yamt sync with head.
 1.30.18.3 06-Feb-2007  ad Remove now unused SPLLOWER() macro.
 1.30.18.2 26-Jan-2007  ad Add a macro to define a global label.
 1.30.18.1 10-Sep-2006  ad Add updated locking primatives.
 1.31.22.2 21-Nov-2007  joerg Sync with HEAD.
 1.31.22.1 09-Aug-2007  jmcneill Sync with HEAD.
 1.31.18.1 15-Aug-2007  skrll Sync with HEAD.
 1.31.16.1 07-Aug-2007  matt Sync with HEAD.
 1.31.14.1 03-Oct-2007  garbled Sync with HEAD
 1.31.6.4 03-Dec-2007  ad Sync with HEAD.
 1.31.6.3 09-Oct-2007  ad Sync with head.
 1.31.6.2 20-Aug-2007  ad Sync with HEAD.
 1.31.6.1 29-Jul-2007  ad - When zeroing/copying pages, use SSE2 movtni to avoid polluting the cache.
- By default, align assembly routines on 32-byte starting boundaries.
- There are now 8 interrupt priority levels, half of which are softints.
Update intrdefs.h to match.
- Always clear/set spinlock words - removes lots of ifdefs.
- Remove the horrible ci_self150 hack that I introduced.
- Overhaul how TLB shootdown is performed. Inspired by a similar change in
OpenBSD but implemented quite differently. This should be a lot faster
but I have not benchmarked it yet.
 1.33.6.1 18-Nov-2007  bouyer Sync with HEAD
 1.33.2.2 09-Jan-2008  matt sync with HEAD
 1.33.2.1 06-Nov-2007  matt sync with HEAD
 1.34.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.34.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.35.6.2 02-Jan-2008  bouyer Sync with HEAD
 1.35.6.1 13-Dec-2007  bouyer Sync with HEAD
 1.35.4.1 13-Dec-2007  yamt sync with head.
 1.35.2.1 26-Dec-2007  ad Sync with head.
 1.37.10.1 16-May-2008  yamt sync with head.
 1.37.8.1 18-May-2008  yamt sync with head.
 1.37.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.38.22.1 05-Mar-2011  rmind sync with head
 1.38.14.2 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.38.14.1 10-Jan-2011  jym Sync with HEAD
 1.39.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.40.16.1 18-May-2014  rmind sync with head
 1.40.12.2 03-Dec-2017  jdolecek update from HEAD
 1.40.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.40.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.41.6.1 29-May-2016  skrll Sync with HEAD
 1.42.28.1 20-Apr-2020  bouyer Sync with HEAD
 1.42.18.1 21-Apr-2020  martin Sync with HEAD
 1.45.2.1 02-Aug-2025  perseant Sync with HEAD
 1.14 20-Dec-2007  ad - Make __cpu_simple_lock and similar real functions and patch at runtime.
- Remove old x86 atomic ops.
- Drop text alignment back to 16 on i386 (really, this time).
- Minor cleanup.
 1.13 17-Oct-2007  garbled branches: 1.13.2; 1.13.4; 1.13.8;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.12 03-Oct-2007  ad Make the atomics inline unless !__GNUC__.
 1.11 26-Sep-2007  ad Make build in userspace again.
 1.10 26-Sep-2007  ad x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.9 24-Mar-2007  christos branches: 1.9.2; 1.9.4; 1.9.12; 1.9.14; 1.9.16;
KNF, properly protect.
 1.8 09-Feb-2007  ad branches: 1.8.2; 1.8.6; 1.8.8; 1.8.10;
Merge newlock2 to head.
 1.7 28-Dec-2005  perry branches: 1.7.20;
inline -> __inline
 1.6 26-Dec-2005  perry u_intN_t -> uintN_t
 1.5 24-Dec-2005  perry __asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.4 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 26-Feb-2003  fvdl branches: 1.3.18;
Redirect some includes to x86/foo.h
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file atomic.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.6 03-May-2002  sommerfeld Lint.
 1.1.2.5 11-Dec-2001  sommerfeld Tweak to let this allow userland to build
 1.1.2.4 31-Dec-2000  sommerfeld Tweak i386_atomic_clearbits_l based on suggestions from mycroft
 1.1.2.3 18-Aug-2000  sommerfeld setbits/clearbits now take volatile u_int32_t *
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld Primitives for a few atomic operations.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file atomic.h was added on branch nathanw_sa on 2002-10-18 02:37:53 +0000
 1.3.18.5 21-Jan-2008  yamt sync with head
 1.3.18.4 27-Oct-2007  yamt sync with head.
 1.3.18.3 03-Sep-2007  yamt sync with head.
 1.3.18.2 26-Feb-2007  yamt sync with head.
 1.3.18.1 21-Jun-2006  yamt sync with head.
 1.7.20.2 27-Jan-2007  ad Work around gcc trying to use a register only available on x86_64. XXX
 1.7.20.1 29-Dec-2006  ad Checkpoint work in progress.
 1.8.10.1 29-Mar-2007  reinoud Pullup to -current
 1.8.8.1 11-Jul-2007  mjf Sync with head.
 1.8.6.2 09-Oct-2007  ad Sync with head.
 1.8.6.1 10-Apr-2007  ad Sync with head.
 1.8.2.1 15-Apr-2007  yamt sync with head.
 1.9.16.1 06-Oct-2007  yamt sync with head.
 1.9.14.2 23-Mar-2008  matt sync with HEAD
 1.9.14.1 06-Nov-2007  matt sync with HEAD
 1.9.12.2 04-Oct-2007  joerg Sync with HEAD.
 1.9.12.1 02-Oct-2007  joerg Sync with HEAD.
 1.9.4.1 03-Oct-2007  garbled Sync with HEAD
 1.9.2.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.13.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.13.4.1 26-Dec-2007  ad Sync with head.
 1.13.2.1 27-Dec-2007  mjf Sync with HEAD.
 1.3 18-Oct-2011  dyoung Define some optional routines that will help device_register() to
register ISA & PCI devices. Add stub implementations of the routines.
 1.2 04-Feb-2006  jmmv Revert yesterday's change that attempted to fix the detection of the
boot device when using a Multiboot boot loader. It couldn't work because
these boot loaders do not pass a checksum of the disk so matchbiosdisk()
cannot really find any matches. I should have gone to sleep before
commiting...

Found by xtraeme@.
 1.1 03-Feb-2006  jmmv branches: 1.1.2;
When booting an i386 kernel with Multiboot, properly detect the boot device
by looking it up in the x86_alldisks table (instead of trying to match it
to 'wd*' manually).

In order to do this, move the cpu_rootconf function from x86 common code
to amd64 and i386 specific one. This way, i386 can do an extra step (call
the appropriate Multiboot code) in the appropriate place (after
x86_matchbiosdisks and before findroot()).
 1.1.2.1 22-Apr-2006  simonb Sync with head.
 1.2 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.1 17-Nov-1999  thorpej branches: 1.1.2; 1.1.10;
Basic interface to BIOS32. Separated from UCHIYAMA Yasushi's PCI BIOS
patches and cleaned up a bit.
 1.1.10.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.10.1 17-Nov-1999  bouyer file bios32.h was added on branch thorpej_scsipi on 2000-11-20 20:09:25 +0000
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.11 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10 11-Dec-2005  christos branches: 1.10.74; 1.10.76; 1.10.78;
merge ktrace-lwp.
 1.9 27-Oct-2003  junyoung Nuke __P().
 1.8 02-Apr-2003  thorpej branches: 1.8.2;
Use PAGE_SIZE rather than NBPG.
 1.7 02-May-2001  jdolecek branches: 1.7.2;
Add support for getting %es value from the bios call.
 1.6 12-Jul-2000  thorpej branches: 1.6.4;
Clean up bios_reg a little, and add support for accessing
the byte variants of the registers (e.g. %ah, %al, etc.).
 1.5 03-Oct-1998  jtk branches: 1.5.12;
copyright has been assigned to TNF, update notice
 1.4 01-Oct-1998  jtk add prototype for bioscall()
 1.3 31-Aug-1998  jtk add 32-bit register support to BIOSCALL interface
 1.2 15-Oct-1997  jtk branches: 1.2.2;
put in place a proper bioscall.h (sorry about that!)
finish up incomplete job of moving structure used by bioscall() to
<machine/bioscall.h>, with associated changes in include file strategy,
genassym stuff, etc.
 1.1 14-Oct-1997  christos Someone [who will remain nameless] forgot this...
 1.2.2.3 15-Oct-1997  thorpej Sync w/ trunk.
 1.2.2.2 15-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.2.2.1 15-Oct-1997  thorpej file bioscall.h was added on branch marc-pcmcia on 1997-10-15 05:27:38 +0000
 1.5.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.6.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.7.2.2 02-May-2001  jdolecek Add support for getting %es value from the bios call.
 1.7.2.1 02-May-2001  jdolecek file bioscall.h was added on branch sommerfeld_i386mp_1 on 2001-05-02 13:12:47 +0000
 1.8.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.2.1 03-Aug-2004  skrll Sync with HEAD
 1.10.78.1 16-May-2008  yamt sync with head.
 1.10.76.1 18-May-2008  yamt sync with head.
 1.10.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.14 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.13 23-Feb-2003  fvdl For x86_64, split the bootinfo memory entry words to avoid growth of the
structure due to alignment.
 1.12 28-Dec-2002  kristerw The correct way to decorate objects with attributes is to use __attribute__
instead of the synonyms understood by gcc.
 1.11 30-Nov-2002  fvdl Make biosgeom struct packed, so that it works out on x86_64.
 1.10 29-Nov-2002  fvdl Think before committing.. previous wasn't actually needed, the values are
guaranteed to fit in 32 bits when loading the kernel into physmem,
and it avoids bootloader incompatibility.
 1.9 29-Nov-2002  fvdl Use long for ssym and esym in btinfo_symtab, so that it works out for
both i386 and x86_64.
 1.8 02-Jun-2000  thorpej branches: 1.8.4; 1.8.6;
Actually define the ACPI memory map entry (bi_memmap_entry).
 1.7 12-Mar-1999  fvdl branches: 1.7.8; 1.7.18;
Clean up the BIOS disk matching code a bit (better naming, one structure
and sysctl to export to userland). Also, only use total number of sectors
given in the extended parameters if the physical chs geometry is
marked invalid. Hopefully fixes a problem where BIOSs would not correctly
fill in this field.
 1.6 10-Mar-1999  fvdl Create a list of native disks too, and make it retrievable. It contains
all matching BIOS disks per entry, so that we have complete match info.
Enable the matching code.
 1.5 08-Mar-1999  drochner add a definition to pass the "memory map", ie the outcome of INT15/0xe820,
to the kernel
 1.4 08-Mar-1999  fvdl Add some fields to the already defined, but unused, bootinfo structure
for BIOS geometry. Define CPU_BIOS_GEOM sysctl value in cpu.h.
 1.3 28-Jan-1999  christos Add btinfo_symtab, to pass symbol table information.
Actually the current ddb_init interface sucks, since there is no
magic number for a.out and it applies heuristics. It would be nice
if the boot blocks passed more info.
 1.2 27-Jan-1999  thorpej Use the MI <sys/disklabel_mbr.h>, not our own machine-dependent
definitions.
 1.1 20-Sep-1997  drochner branches: 1.1.2;
Data structures passed from the boot loader to the kernel.
 1.1.2.2 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 20-Sep-1997  thorpej file bootinfo.h was added on branch marc-pcmcia on 1997-09-22 06:31:09 +0000
 1.7.18.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.7.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.6.2 29-Dec-2002  thorpej Sync with HEAD.
 1.8.6.1 11-Dec-2002  thorpej Sync with HEAD.
 1.8.4.2 02-Jun-2000  thorpej Actually define the ACPI memory map entry (bi_memmap_entry).
 1.8.4.1 02-Jun-2000  thorpej file bootinfo.h was added on branch sommerfeld_i386mp_1 on 2000-06-02 18:27:48 +0000
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 09-Jan-1994  cgd branches: 1.1.2;
LBL "/dev/audio" include file.
probably will need to be hacked if "the right things" are done to bsd_audio.c
 1.1.2.2 09-Jan-1994  cgd LBL "/dev/audio" include file.
probably will need to be hacked if "the right things" are done to bsd_audio.c
 1.1.2.1 09-Jan-1994  cgd file bsd_audioio.h was added on branch magnum on 1994-01-09 19:30:18 +0000
 1.4 26-Oct-2008  mrg - use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.3 31-Jan-2006  dsl branches: 1.3.72; 1.3.76; 1.3.82;
Change sys/arch/xxx/include/bswap.h to #include machine/byte_swap.h then
sys/bswap.h in order to pick up the MD inline routines and the constant
folding definitions in the right order.
Code can include either sys/bswap.h or machine/bswap.h with the same effect.
 1.2 21-Aug-1999  simonb branches: 1.2.54; 1.2.66;
Include <sys/bswap.h> for function prototypes. i386, pc532 and vax
still include <machine/byte_swap.h> and define macros for some of
the bswap*() functions.
 1.1 15-Jan-1999  bouyer Move the bswap functions from libutil to libc (this bups the
minor of libc and the major of libutil). For little-endian architectures
merge the bnswap() assembly versions with nto* and hton* using symbols
aliasing. Use symbol renaming for the bswap function in this case to avoid
namespace pollution.
Declare bswap* in machine/bswap.h, not machine/endian.h. For little-endian
machines, common code for inline macros go in machine/byte_swap.h
Sync libkern with libc.
Adjust #include in kernel sources for machine/bswap.h.
 1.2.66.1 01-Feb-2006  yamt sync with head.
 1.2.54.1 21-Jun-2006  yamt sync with head.
 1.3.82.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.3.76.1 04-May-2009  yamt sync with head.
 1.3.72.1 17-Jan-2009  mjf Sync with HEAD.
 1.42 17-Jul-2011  dyoung On i386, good-bye <machine/bus.h>.
 1.41 26-Feb-2003  fvdl branches: 1.41.122;
Redirect some includes to x86/foo.h
 1.40 28-Jan-2003  kent Introduce BUS_DMA_NOCACHE, and bus_dmamem_map() of i386 supports it.
 1.39 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.38 10-Nov-2001  perry trivially rename some macro parameters to avoid lint warnings.
 1.37 23-Sep-2001  jdolecek branches: 1.37.2;
fix typo
 1.36 04-Sep-2001  thorpej branches: 1.36.2;
Implement bus_space_mmap().
 1.35 19-Jul-2001  thorpej Add BUS_DMA_READ and BUS_DMA_WRITE flags, that hint the back-end
at dmamap load time that the mapping will be used for a unidirectional
transfer of the specified direction.
 1.34 30-Apr-2001  lukem branches: 1.34.2;
remove some lint, including ansifying some inlines
 1.33 25-Apr-2001  thorpej Move _i386_memio_unmap() into bus_machdep.c; the ACPI code wants it.
 1.32 10-Apr-2001  fvdl Fix bus_space_write_multi_* in the memory case; the asm constraints
were wrong.
 1.31 07-Mar-2001  thorpej Add the BUS_DMA_STREAMING flag.
 1.30 31-Jul-2000  briggs branches: 1.30.2; 1.30.4;
Define bus_space_*_stream_N functions as their non-stream counterparts.
 1.29 26-Jun-2000  simonb Change the kernel mmap interface so that the offset to map is an
"off_t" and the return value is a "paddr_t" to allow mappings
at offsets past 2^31 bytes. Somewhat inspired by FreeBSD, which
only changed the offset to a "vm_offset_t".

Includes updates for the i386, pc532 and sh3 mmmmap from Jason Thorpe.
 1.28 17-Apr-2000  drochner branches: 1.28.6;
implement bus_space_vaddr()
 1.27 15-Mar-2000  drochner explicitely #include <sys/systm.h> #if BUS_SPACE_DEBUG to get a printf()
prototype
 1.26 13-Mar-2000  kristerw Make the inline asm conform to what gcc thinks they should look like (per
discussions in http://gcc.gnu.org/ml/gcc-patches/1998-11/msg00004.html)

Approved by fvdl.
 1.25 25-Jan-2000  drochner define a "BUS_SPACE_MAP_PREFETCHABLE" flag which basically means that
device accesses are idempotent (but should not be cached by the CPU)
 1.24 18-Jun-1999  cgd branches: 1.24.2;
nuke current definitions provided by __BUS_SPACE_COMPAT_OLDDEFS.
I'll do what I can to make new ones soon. 8-)
 1.23 23-Mar-1999  drochner branches: 1.23.4;
Add a macro to check for sufficient pointer alignment in bus.h context,
"BUS_SPACE_ALIGNED_POINTER()".
Equal to the param.h "ALIGNED_POINTER()" normally, but obeys additional
requirements of the bus_space_xxx_n() macros. (BUS_SPACE_DEBUG)
 1.22 03-Oct-1998  thorpej Add a private bounce threshold to the DMA map, initialized in a bus-dependent
fashion.
 1.21 30-Aug-1998  cgd don't define __BUS_SPACE_COMPAT_OLDDEFS by default. As stated in
bus_space(9), if drivers want it (they shouldn't; easy to convert) they
can define it right before including bus.h. There's been a release since
the interfaces were (slightly) changed, and no code in the source tree
uses the old interfaces as far as I can tell.
 1.20 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.19 09-Jun-1998  thorpej Don't enable BUS_SPACE_DEBUG automatically if DEBUG is defined.
 1.18 07-Jun-1998  thorpej Add debugging support to the bus_space macros. If BUS_SPACE_DEBUG (or DEBUG)
is defined, the bus_space macros will check to ensure that the bus address
and the target buffer (if applicable) are aligned properly for the size
of the type being used. If they are not, a message will be displayed on
the console.

While strict alignment is not strictly necessary on the x86, ensuring
proper alignment can aid performance, and help make drivers more portable
to architectures (like the Alpha and StrongARM) which _do_ require strict
alignment.
 1.17 03-Jun-1998  thorpej Add a `bounce threshold' to the i386 DMA tag.
 1.16 26-Apr-1998  thorpej Garbage-collect the DMA tag's "_cookie" member; it's not used for anything.
 1.15 04-Feb-1998  thorpej Add offset and length parameters to bus_dmamap_sync(), used for specifiying
partial syncs of a DMA mapping.
 1.14 04-Feb-1998  thorpej Change the last argument of bus_dmamap_sync() from bus_dmasync_op_t to int,
and allow more than one synchronization operation to be specified in
a single call. Dissallow mixing of PRE and POST operations.
 1.13 04-Feb-1998  thorpej Add dm_mapsize to bus_dmamap_t and rename BUS_DMAMEM_NOSYNC to
BUS_DMA_COHERENT.
 1.12 01-Oct-1997  fvdl Provide workaround (by Charles Hannum) for error in register allocation that
could occur in bus_space_write_multi*
 1.11 15-Aug-1997  cgd Sync with bus_space(9):
* make map and alloc take 'flags' rather than 'cacheable,' for
more flexibility.
* rename BUS_BARRIER_* to BUS_SPACE_BARRIER_*, for consistency.
* rename bus_space_copy_* to bus_space_copy_region_* and make their
defns match the updated spec.
Backward compatibility is provided by defining __BUS_SPACE_COMPAT_OLDDEFS,
which is currently defined by default.
 1.10 12-Aug-1997  perry fix spelling error, pr-3974 from Dave Huang
 1.9 10-Jul-1997  cgd branches: 1.9.2;
rename i386 bus_space_{map,unmap,subregion,alloc,free} implementation
functions (which only work on memory and i/o space) to i386_memio_*,
and make bus_space_* in bus.h be #defines which invoke them. This makes
life easier for people who need to define the all of the bus_space functions
so that they work on spaces other than memory and I/O space. Also, add
an _i386_memio_map function which is like i386_memio_map but doesn't do
the extent map checking or allocation. _i386_memio_map and i386_memio_*
are for use only by machine-dependent code.
 1.8 06-Jun-1997  thorpej Pull thorpej-bus-dma branch into mainline.
 1.7 02-Dec-1996  thorpej branches: 1.7.8;
Oops, bus_space_set_{multi,region}_N() is supposed to have an `offset'
argument. Add one to the `prototype' in the comment which preceeds
`not implemented' :-)
 1.6 10-Nov-1996  thorpej Two things pointed out by Chris Demetriou <cgd@cs.cmu.edu>:
- The boundary argument to bus_space_alloc() should be a bus_size_t, not
a bus_addr_t.
- The buffer arguments in the "multiple write" methods should have
const qualifiers.

And one from me:
- Make bus_space_barrier() eat up the arguments passed to it so that
the compiler doesn't needlessly whine.
 1.5 21-Oct-1996  thorpej New bus.h implementation/interface:
- No more distinction between i/o-mapped and memory-mapped
devices. It's all "bus space" now, and space tags
differentiate the space with finer grain than the
bus chipset tag.
- Add memory barrier methods.
- Implement space alloc/free methods.
- Implement region read/write methods (like memcpy to/from
bus space).
This interface provides a better abstraction for dealing with
machine-independent chipset drivers.
 1.4 23-Jun-1996  thorpej New implementation of bus_io_{,un}map() for the i386. Details:

- A fixed extent map (statically allocated descriptor storage) is
created in init386(), just before the call to consinit(). The
fixed descriptor storage has enough room for 8 region entires,
which is plenty for early initialization, but doesn't chew up
that much memory.

This extent map (ioport_ex) manages the i386 i/o port
space (0x0 - 0xffff).

- Just before the call to configure() in cpu_startup(), a
flag is set which notifies the bus_io functions that it is
safe to use malloc() to allocate descriptor storage, in the
event that more than 8 regions are needed.

- bus_io_map() attempts to allocate the specified region from
ioport_ex. If the allocation succeeds, the io handle is
filled in. If the allocation fails, it is implied that
something else is already using that io space, and an
error condition is returned.

- bus_io_unmap() frees a region previously allocated from
ioport_ex in bus_io_map(). If the free fails, a warning
is printed on the conole.

These changes implement "port accounting". This is required for
proper autoconfiguration on the i386 port, and makes dealing with,
among other things, PCMCIA io mappings _much_ easier.
 1.3 03-May-1996  christos Avoid unused variable warnings, by using the first argument to the bus
functions.
 1.2 05-Apr-1996  thorpej Add bus_io_{read,write}_multi_{1,2,4,8}() to the <machine/bus.h>
interface, and implement them (except for the 8-byte versions) on
the i386.
 1.1 08-Mar-1996  cgd bus memory and I/O space access functions/macros, to be used by
machine-independent code for more sane access to bus resources.
New functions will be added to this set, in the future, as appropriate,
but this is a good starting set. Defines:
bus_{io,mem}_{map,unmap}
bus_{io,mem}_{read,write}_{1,2,4,8}
functions, and several types to go with them.
 1.7.8.4 06-Jun-1997  thorpej Right, that's a bonk on the head! Zero-length arrays aren't legal
in C. Make the bus_dmamap_t variable-length array size 1, and compensate
for the size screw in _bus_dmamap_create(). Pointed out by Chris Demetriou.
 1.7.8.3 25-May-1997  thorpej Implement the missing methods in the i386 bus space implementation:
bus_space_set_multi, bus_space_set_region, bus_space_copy
 1.7.8.2 17-May-1997  thorpej Add two arguments to bus_dmamem_alloc():
- alignment - Each segment in the allocation will be aligned to this
power-of-two boundary.
- boundary - No segment in the allocation may cross this power-of-two
boundary. If no boundary is necessary, specify 0.
 1.7.8.1 13-May-1997  thorpej Define types, constants, and access methods required by the bus dma
API specification.
 1.9.2.2 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.23.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.24.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.24.2.2 12-Mar-2001  bouyer Sync with HEAD.
 1.24.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.28.6.2 06-Aug-2000  briggs Pull up revision 1.30 -- approved by thorpej --
Define bus_space_*_stream_N functions as their non-stream counterparts.
 1.28.6.1 30-Jun-2000  simonb Pull up mmap paddr_t/off_t changes from trunk.
 1.30.4.6 14-Nov-2001  nathanw Catch up to -current.
 1.30.4.5 26-Sep-2001  nathanw Catch up to -current.
Again.
 1.30.4.4 21-Sep-2001  nathanw Catch up to -current.
 1.30.4.3 24-Aug-2001  nathanw Catch up with -current.
 1.30.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.30.4.1 09-Apr-2001  nathanw Catch up with -current.
 1.30.2.8 29-Dec-2001  sommerfeld Yet another mergeup.

New work:
- Frank van der Linden's tlb shootdown fix.
Mainline functionality merged:
- IrDA
- Kernel RCSID's
- Transmeta CPU support
- ACPI
- XMM register access through procfs
 1.30.2.7 24-Sep-2001  sommerfeld Synch again with current, largely to test updates to my merge tools
which drop an entry in MP-UPDATING so there's a deterministic way to
discover the time of the last branch synch..
 1.30.2.6 06-Sep-2001  sommerfeld here we go again
 1.30.2.5 20-Jul-2001  sommerfeld merge up with -current
 1.30.2.4 30-Apr-2001  sommerfeld Catch up on some files missed the last time 'round
 1.30.2.3 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.30.2.2 10-Mar-2001  he Pull up revision 1.31, approved by sommerfeld:
Add the BUS_DMA_STREAMING flag.
 1.30.2.1 31-Jul-2000  he file bus.h was added on branch sommerfeld_i386mp_1 on 2001-03-10 19:41:46 +0000
 1.34.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.34.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.34.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.34.2.1 03-Aug-2001  lukem update to -current
 1.36.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.37.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.41.122.1 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.1 01-Jul-2011  dyoung branches: 1.1.2;
Per discussion at
<http://mail-index.netbsd.org/tech-kern/2010/04/02/msg007941.html>,
divide each machine's bus.h into bus_defs.h (constants & data types)
and bus_funcs.h (macro implementations of bus_space(9) routines and MD
prototypes).

Note that some bus_space(9) routines' implementation will move to .c
files from inline subroutines or macros in .h files.

I've only made the split for machine architectures where there is PCI.
All of the non-PCI-having architectures will require a similar split.

These #include files are not referenced by any (committed) Makefiles or
header files, yet. Changes to Makefiles, to <sys/bus.h>, and to some
more machine-dependent files will dribble in before I throw the switch.
 1.1.2.2 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.1.2.1 01-Jul-2011  jym file bus_defs.h was added on branch jym-xensuspend on 2011-08-27 15:59:48 +0000
 1.1 01-Jul-2011  dyoung branches: 1.1.2;
Per discussion at
<http://mail-index.netbsd.org/tech-kern/2010/04/02/msg007941.html>,
divide each machine's bus.h into bus_defs.h (constants & data types)
and bus_funcs.h (macro implementations of bus_space(9) routines and MD
prototypes).

Note that some bus_space(9) routines' implementation will move to .c
files from inline subroutines or macros in .h files.

I've only made the split for machine architectures where there is PCI.
All of the non-PCI-having architectures will require a similar split.

These #include files are not referenced by any (committed) Makefiles or
header files, yet. Changes to Makefiles, to <sys/bus.h>, and to some
more machine-dependent files will dribble in before I throw the switch.
 1.1.2.2 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.1.2.1 01-Jul-2011  jym file bus_funcs.h was added on branch jym-xensuspend on 2011-08-27 15:59:48 +0000
 1.2 11-Dec-2005  christos merge ktrace-lwp.
 1.1 16-Apr-2005  yamt branches: 1.1.2; 1.1.4; 1.1.12;
add files which i forgot to add with arch/x86/x86/bus_dma.c rev.1.21.
 1.1.12.2 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.12.1 16-Apr-2005  skrll file bus_private.h was added on branch ktrace-lwp on 2005-11-10 13:56:53 +0000
 1.1.4.2 29-Apr-2005  kent sync with -current
 1.1.4.1 16-Apr-2005  kent file bus_private.h was added on branch kent-audio2 on 2005-04-29 11:28:13 +0000
 1.1.2.2 21-Apr-2005  tron Pull up revision 1.1 (requested by yamt in ticket #175):
add files which i forgot to add with arch/x86/x86/bus_dma.c rev.1.21.
 1.1.2.1 16-Apr-2005  tron file bus_private.h was added on branch netbsd-3 on 2005-04-21 18:43:01 +0000
 1.17 10-Aug-2020  rin Clean up _LKM --> _MODULE leftovers.

Note that _KERNEL is always defined for modules.
 1.16 23-Jul-2020  skrll Trailing whitespace
 1.15 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.14 14-Nov-2007  ad branches: 1.14.14; 1.14.16; 1.14.18;
- Remove I486_CPU, I586_CPU, I686_CPU options. They buy us nothing and
clutter the code significantly.
- Remove pccons.
 1.13 17-Oct-2007  garbled branches: 1.13.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.12 26-Sep-2007  ad branches: 1.12.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.11 24-Jan-2007  hubertf branches: 1.11.6; 1.11.14; 1.11.22; 1.11.24; 1.11.26;
Remove duplicate #includes, patch contributed in private mail
by Slava Semushin <slava.semushin@gmail.com>.

To verify that no nasty side effects of duplicate includes (or their
removal) have an effect here, I've compiled an i386/ALL kernel with
and without the patch, and the only difference in the resulting .o
files was in shifted line numbers in some assert() calls.
The comparison of the .o files was based on the output of "objdump -D".

Thanks to martin@ for the input on testing.
 1.10 30-Jan-2006  dsl branches: 1.10.18;
Move all the stuff that detects bswapxx(constant) into the MI sys/bswap.h
Put the minimum to define the required inline assembler or C into the MD files.
NB: there may be some fallout from this!
 1.9 28-Dec-2005  perry branches: 1.9.2;
inline -> __inline
 1.8 26-Dec-2005  perry u_intN_t -> uintN_t
 1.7 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6 29-Nov-2001  lukem branches: 1.6.2; 1.6.34;
minor knf
 1.5 03-Nov-2001  lukem explicitly pull in sys/types.h
 1.4 02-Nov-2001  lukem replace __byte_swap_long_variable and __byte_swap_word_variable
#define ({ }) with static __inline { }
 1.3 30-May-2001  mrg branches: 1.3.4; 1.3.8;
use _KERNEL_OPT
 1.2 16-Mar-2000  mycroft branches: 1.2.8;
This code has nothing to do with UCB.
 1.1 15-Jan-1999  bouyer branches: 1.1.8;
Move the bswap functions from libutil to libc (this bups the
minor of libc and the major of libutil). For little-endian architectures
merge the bnswap() assembly versions with nto* and hton* using symbols
aliasing. Use symbol renaming for the bswap function in this case to avoid
namespace pollution.
Declare bswap* in machine/bswap.h, not machine/endian.h. For little-endian
machines, common code for inline macros go in machine/byte_swap.h
Sync libkern with libc.
Adjust #include in kernel sources for machine/bswap.h.
 1.1.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.8.3 08-Jan-2002  nathanw Catch up to -current.
 1.2.8.2 14-Nov-2001  nathanw Catch up to -current.
 1.2.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.3.8.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.3.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.34.4 15-Nov-2007  yamt sync with head.
 1.6.34.3 27-Oct-2007  yamt sync with head.
 1.6.34.2 26-Feb-2007  yamt sync with head.
 1.6.34.1 21-Jun-2006  yamt sync with head.
 1.6.2.2 29-Nov-2001  lukem minor knf
 1.6.2.1 29-Nov-2001  lukem file byte_swap.h was added on branch sommerfeld_i386mp_1 on 2001-11-29 02:46:56 +0000
 1.9.2.1 01-Feb-2006  yamt sync with head.
 1.10.18.1 01-Feb-2007  ad Sync with head.
 1.11.26.1 06-Oct-2007  yamt sync with head.
 1.11.24.2 09-Jan-2008  matt sync with HEAD
 1.11.24.1 06-Nov-2007  matt sync with HEAD
 1.11.22.2 21-Nov-2007  joerg Sync with HEAD.
 1.11.22.1 02-Oct-2007  joerg Sync with HEAD.
 1.11.14.1 03-Oct-2007  garbled Sync with HEAD
 1.11.6.2 03-Dec-2007  ad Sync with HEAD.
 1.11.6.1 09-Oct-2007  ad Sync with head.
 1.12.2.1 18-Nov-2007  bouyer Sync with HEAD
 1.13.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.14.18.1 16-May-2008  yamt sync with head.
 1.14.16.1 18-May-2008  yamt sync with head.
 1.14.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.9 20-Jan-2012  joerg Change CMSG_SPACE and CMSG_LEN to provide Integer Constant Expressions
again. This was changed in sys/socket.h r1.51 to work around fallout
from the IPv6 aux data migration. It broke the historic ABI on some
platforms. This commit restores compatibility for netbsd32 code on such
platforms and provides a template for future changes to the CMSG_*
alignment. Revert PCC/Clang workarounds in postfix and tmux.
 1.8 16-Jun-2011  joerg branches: 1.8.2; 1.8.6;
Add an optional MD calling convention flag for use in libsa when space
optimisation is critical. Use this on i386 to switch to register passing
calling convention for the file system entry points and most assembler
call backs that have to preserve at least 3 registers.
 1.7 26-Oct-2008  mrg branches: 1.7.8; 1.7.26;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.6 20-Mar-1999  thorpej branches: 1.6.146; 1.6.150; 1.6.156;
Garbage-collect.
 1.5 11-Jan-1999  christos Add ELF crap.
 1.4 04-Nov-1997  thorpej Bug fixes and cleanup from Chris Demetriou <cgd@pa.dec.com>:
- fix _C_LABEL so that it actually works.
- make __RENAME use _C_LABEL.
- fix __RENAME so that it expects an unquoted argument.
- fix __indr_reference and __warn_references so that they
supply their own final semicolon.
- define __warn_references to nothing if not GNU C (required
by the way it's used).

The __warn_references semicolon change has to be made
so that __warn_references can be defined into nothing.
(A ; all by itself isn't a great idea.) The __indr_reference
change was made for consistency.
 1.3 22-Oct-1997  thorpej Implement __RENAME() in <machine/cdefs.h>
 1.2 23-Mar-1995  jtc branches: 1.2.18;
Changed name of __weak_reference() to __indr_reference(). They really
are indirect references, and I want to add a real __weak_reference()
macro to <machine/cdefs.h> soon.
 1.1 19-Jan-1995  jtc This file, which will be included by <sys/cdefs.h>, will contain macros
such as __warn_references() and __weak_reference() which are actually
machine dependant. This will make it easier for ports that are being
bootstraped with ELF and ECOFF based toolchains.

This change also introduces a new macro, _C_LABEL(x). _C_LABEL expands
its argument, an identifier, to a character string of the identifier
name as it is represented in an object file.

For most ports, _C_LABEL(x) will expand to "_x", for ELF based ports
_C_LABEL(x) will expand to "x".
 1.2.18.2 04-Nov-1997  thorpej Pull up from trunk: bug fixes and cleaups.
 1.2.18.1 22-Oct-1997  thorpej Pull up from trunk: Implement __RENAME() in <machine/cdefs.h>
 1.6.156.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.6.150.1 04-May-2009  yamt sync with head.
 1.6.146.1 17-Jan-2009  mjf Sync with HEAD.
 1.7.26.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.7.8.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.8.6.1 18-Feb-2012  mrg merge to -current.
 1.8.2.1 17-Apr-2012  yamt sync with head
 1.2 07-Jun-2006  kardel branches: 1.2.4; 1.2.10;
convert to timecounters (from branch simonb-timecounters)
 1.1 04-Feb-2006  simonb branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12;
Prototypes for i386-related clock functions.
 1.1.12.1 19-Jun-2006  chap Sync with head.
 1.1.6.1 26-Jun-2006  yamt sync with head.
 1.1.4.2 18-Feb-2006  yamt sync with head.
 1.1.4.1 04-Feb-2006  yamt file clock.h was added on branch yamt-uio_vmspace on 2006-02-18 15:38:37 +0000
 1.1.2.3 27-May-2006  kardel move declaration into TSC specific file
 1.1.2.2 05-Feb-2006  simonb Pull up from HEAD - file mistakenly added to HEAD instead of timecounters
branch.
 1.1.2.1 04-Feb-2006  simonb file clock.h was added on branch simonb-timecounters on 2006-02-05 02:34:02 +0000
 1.2.10.2 09-Sep-2006  rpaulo sync with head
 1.2.10.1 07-Jun-2006  rpaulo file clock.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:40:14 +0000
 1.2.4.2 21-Jun-2006  yamt sync with head.
 1.2.4.1 07-Jun-2006  yamt file clock.h was added on branch yamt-lazymbuf on 2006-06-21 14:52:30 +0000
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 04-Jun-2000  mycroft branches: 1.1.4; 1.1.6; 1.1.8; 1.1.134; 1.1.136; 1.1.138;
Move a bunch of the COFF definitions into exec_coff.h, so they can be used by
other code. XXX Not tested on SH3 yet.
 1.1.138.1 16-May-2008  yamt sync with head.
 1.1.136.1 18-May-2008  yamt sync with head.
 1.1.134.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.8.1 04-Jun-2000  bouyer file coff_machdep.h was added on branch thorpej_scsipi on 2000-11-20 20:09:26 +0000
 1.1.6.2 04-Jun-2000  mycroft Move a bunch of the COFF definitions into exec_coff.h, so they can be used by
other code. XXX Not tested on SH3 yet.
 1.1.6.1 04-Jun-2000  mycroft file coff_machdep.h was added on branch sommerfeld_i386mp_1 on 2000-06-04 16:24:00 +0000
 1.1.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.1.4.1 04-Jun-2000  minoura file coff_machdep.h was added on branch minoura-xpg4dl on 2000-06-22 17:00:31 +0000
 1.11 06-Sep-2002  gehenna Merge the gehenna-devsw branch into the trunk.

This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
by using this grammer.

- Added the new naming convention.
The name of the device switch must be <prefix>_[bc]devsw for auto-generation
of device switch tables.

- The backward compatibility of loading block/character device
switch by LKM framework is broken. This is necessary to convert
from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
the LKM framework will refer it to assign device major number dynamically.
 1.10 18-Apr-2002  wiz branches: 1.10.2; 1.10.4;
Remove opms(4) and its device, /dev/pms0, from the i386 port, because
it has been obsoleted by pms(4).

Reviewed by fvdl and christos.
 1.9 28-Feb-2002  simonb Use "#define<tab>".
 1.8 27-Feb-2002  christos - define other DEV_ constants that the local port uses.
- delete cdev_decl(mm) since <sys/conf.h> does it.
 1.6 21-Mar-2001  lukem branches: 1.6.4;
now that duplicated stuff has been moved to sys/conf.h, remove unnecessary
defs for: lpt, joy, pc
 1.5 05-Sep-1998  christos branches: 1.5.12; 1.5.26;
Assign copyright to TNF.
 1.4 15-Apr-1998  drochner remove unneeded stuff
 1.3 07-Sep-1996  mycroft Implement poll(2).
 1.2 05-May-1996  christos Add the joystick
 1.1 03-May-1996  christos Fwd declarations for MD drivers.
 1.5.26.5 17-Sep-2002  nathanw Catch up to -current.
 1.5.26.4 20-Jun-2002  nathanw Catch up to -current.
 1.5.26.3 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.5.26.2 28-Feb-2002  nathanw Catch up to -current.
 1.5.26.1 09-Apr-2001  nathanw Catch up with -current.
 1.5.12.1 27-Mar-2001  bouyer Sync with HEAD.
 1.6.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.6.4.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.6.4.1 16-Mar-2002  jdolecek Catch up with -current.
 1.10.4.1 19-May-2002  gehenna Remove port-dependent conf.h.
 1.10.2.2 18-Apr-2002  wiz Remove opms(4) and its device, /dev/pms0, from the i386 port, because
it has been obsoleted by pms(4).

Reviewed by fvdl and christos.
 1.10.2.1 18-Apr-2002  wiz file conf.h was added on branch sommerfeld_i386mp_1 on 2002-04-18 12:54:16 +0000
 1.185 04-Sep-2023  mrg x86: avoid annoying GCC 12 bounds check in curcpu() and curlwp().

these functions read %gs and return an pointer at an offset from this
value (the current cpu, or lwp pointers), and GCC is complaining that
they're accessing a array cpu_info[0] (ie, zero length, no storage.)

several attempts to workaround it have failed, and because of the
asm volatile nature of this, it seems very unlikely a compiler would
take this and do something wrong with it.
 1.184 09-Apr-2023  riastradh i386: Make curlwp and curcpu() flushable.

The only effect of the `volatile' qualifier on an asm block with
outputs is to force the instructions to appear in the generated code,
even if the outputs end up being unused. Since these instructions
have no (architectural) side effects -- provided %fs is set
correctly, which must be the case here -- there's no need for the
volatile qualifier, so nix it.
 1.183 02-Nov-2021  ryo In order to prevent _mcount() from being recursively called when built with COPTS=-O0,
sprinkle `__always_inline' to make _mcount() be generated as a single function.
 1.182 21-Nov-2019  ad mi_userret(): take care of calling preempt(), set spc_curpriority directly,
and remove MD code that does the same.
 1.181 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.180 18-Nov-2018  cherry On Xen, copy just the bits we need from the trapframe for hardclock(9)
and statclock(9).

Current, the macros that use the trapframe are:
CLKF_USERMODE()
CLKF_PC()
CLKF_INTR()

Of these, CLKF_INTR() already ignores the frame and uses the ci_idepth
variable to do its job.

Convert the two remaining ones to do this, but only for XEN.
 1.179 17-Sep-2017  maxv branches: 1.179.2; 1.179.4;
Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.178 30-Dec-2011  cherry branches: 1.178.6;
Move the per-cpu l3 page allocation code to a separate MD function. Avoids code duplication for xen PAE
 1.177 26-Jul-2011  yamt branches: 1.177.2; 1.177.6;
whitespace
 1.176 29-Dec-2008  pooka branches: 1.176.2; 1.176.12;
_LKM -> _MODULE
 1.175 22-May-2008  ad branches: 1.175.6;
Mark x86_curlwp() with __attribute__ ((const)), so gcc can CSE it and know
that it does not clobber global data.
 1.174 11-May-2008  ad Wrap stuff in #ifdef _KERNEL
 1.173 11-May-2008  ad Share cpu.h between the x86 ports.
 1.172 11-May-2008  ad Simplify x86 identcpu code, and share between i386/amd64.
 1.171 10-May-2008  ad Improve x86 tsc handling:

- Ditch the cross-CPU calibration stuff. It didn't work properly, and it's
near impossible to synchronize the CPUs in a running system, because bus
traffic will interfere with any calibration attempt, messing up the
timings.

- Only enable the TSC on CPUs where we are sure it does not drift. If we are
On a known good CPU, give the TSC high timecounter quality, making it the
default.

- When booting CPUs, detect TSC skew and account for it. Most Intel MP
systems have synchronized counters, but that need not be true if the
system has a complicated bus structure. As far as I know, AMD systems
do not have synchronized TSCs and so we need to handle skew.

- While an AP is waiting to be set running, try and make the TSC drift by
entering a reduced power state. If we detect drift, ensure that the TSC
does not get a high timecounter quality. This should not happen and is
only for safety.

- Make cpu_counter() stuff LKM safe.
 1.170 09-May-2008  joerg Make cpu_idle a macro calling a function pointer on x86.
Select the Xen idle routine for Xen, mwait if supported by the CPU and
it is not AMD and halt otherwise. As reported by Christoph Egger,
AMD Barcelona keeps the CPU in C0 state with MWAIT, contrary to HLT,
which uses C1 and therefore much less power.
 1.169 30-Apr-2008  ad branches: 1.169.2;
Avoid unneeded AST faults.
 1.168 28-Apr-2008  ad Add support for kernel preeemption to the i386 and amd64 ports. Notes:

- I have seen one isolated panic in the x86 pmap, but otherwise i386
seems stable with preemption enabled.

- amd64 is missing the FPU handling changes and it's not yet safe to
enable it there.

- The usual level for kern.sched.kpreempt_pri will be 128 once enabled
by default. For testing, setting it to 0 helps to shake out bugs.
 1.167 24-Apr-2008  ad branches: 1.167.2;
- Give ci_want_resched a single cache line, and align. This is for monitor/
mwait. At least one errata sheet from Intel notes that a single line
should be used.
- Align cc_microtime.
 1.166 21-Apr-2008  cegger Access Xen's vcpu info structure per-CPU.
Tested on i386 and amd64 (both dom0 and domU) by me.
Xen2 tested (both dom0 and domU) by bouyer.
OK bouyer
 1.165 27-Feb-2008  xtraeme branches: 1.165.2;
Add back the CPU_TMLR_* definitions for binary sysctl compatibility
with NetBSD pre-2.0, and use them in the longrun driver again.

Requested by cube@.
 1.164 27-Feb-2008  xtraeme Remove CTL_MACHDEP_NAMES, it's not used anywhere.

Ok by martin@.
 1.163 27-Feb-2008  xtraeme - Fixup the machdep.tm_longrun_* sysctl nodes creation.
- The CTL_TMLR_ static definitions for CTL_MACHDEP are not needed anymore.
 1.162 26-Feb-2008  xtraeme Split off the Transmeta Crusoe Longrun code into its own file, that
way identcpu.c and machdep.c are not cluttered with foreign code.

The driver is built by default as before, but the sysctl subtree will
only be created if longrun is detected and not always as the old code
did. This matches what the FreeBSD code does.

Ok by christos@.
 1.161 10-Feb-2008  ad branches: 1.161.2; 1.161.6;
Align cc_microtime and struct cpu_info to 64b.
 1.160 16-Jan-2008  ad Remove options MATH_EMULATE.
 1.159 15-Jan-2008  joerg Introduce optional cpu_offline_md to execute MD actions at the end of
cpu_offline. Use this on amd64/i386 to force a FPU save. As this was
triggered by npxsave_cpu/fpusave_cpu not working for a different CPU,
remove the cpu_info argument and adjust npxsave_*/fpusave_* to use bool
for the save.

OK ad@
 1.158 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.157 05-Jan-2008  yamt move IOMAP_INVALOFF from cpu.h to tss.h
 1.156 05-Jan-2008  yamt g/c ci_idle_pcb_paddr
 1.155 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.154 01-Jan-2008  yamt try to detect processor resource sharing topologies. ie. package/core/smt IDs.
 1.153 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.152 18-Dec-2007  joerg Add new IPI for saving CPU state explicitly, share high-level part of
ACPI wakeup code and teach it how to start the APs again. As a side
effect the CPU_START interface allows choosing between different
bootstrap codes more easily now.
 1.151 03-Dec-2007  joerg branches: 1.151.4;
Add a CPU local timer based on the LAPIC. This is consistently faster
than TSC, but doesn't suffer from SpeedStep as TSC does.

The default quality is higher than HPET for UP, but -100 for
MULTIPROCESSOR as it needs CPU local state which doesn't exist yet.
 1.150 29-Oct-2007  ad branches: 1.150.2; 1.150.4;
Mark cpu_info::ci_tlbstate volatile to ensure that the compiler doesn't
reorder accesses to it. It's updated from the TLB IPI handlers and we don't
block those, so the order in which things are read/updated is important.
 1.149 26-Oct-2007  joerg Match delay/DELAY on x86 with delay(9). It takes an unsigned int as
argument. Use this and replace the inline assembly (mul + div using the
64bit intermediate result) with normal 32bit multiplication and
division. The compiler can turn the division into a multiplication and
shift, making it even cheaper then the original assembly. For extreme
long delays, just use 64bit arithmetic.
 1.148 18-Oct-2007  yamt merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.147 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.146 26-Sep-2007  ad branches: 1.146.2;
x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.145 25-Sep-2007  ad ci_astpending is no more.
 1.144 29-Aug-2007  ad branches: 1.144.2;
Merge most x86 changes from the vmlocking branch, except the threaded soft
interrupt stuff. This is mostly comprised of changes to the pmap modules to
work on multiprocessor systems without kernel_lock, and changes to speed up
tlb shootdowns.
 1.143 09-Jul-2007  ad branches: 1.143.4; 1.143.8; 1.143.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.142 03-Jun-2007  xtraeme Make the Enhanced Speedstep driver available for i386 and amd64.
To use it on EM64T CPUs supporting the EST CPUID feature. Note that
some CPUs still don't work with this driver, like Xeon or Pentium 4.

Move the p[34]_get_bus_clock functions into its own file,
intel_busclock.c and remove this code from i386/identcpu.c.

Tested on i386 by myself and amd64 by Tonerre.
 1.141 17-May-2007  yamt merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.140 16-Apr-2007  ad branches: 1.140.2;
Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.139 21-Mar-2007  xtraeme - Remove ci_msr_rvalue, it's not useful anymore as yamt@ pointed out.
- Remove completely debug from msr_ipifuncs, now it's known to work.
 1.138 20-Mar-2007  xtraeme MSR read and write IPI handlers for x86. A MSR will be read or written
in all CPUs available in the system. This adds another member
to struct cpu_info, ci_msr_rvalue; it will contain the value of the MSR
in a previous operation.

Tested with clockmod in UP and SMP by me, tested with est in SMP
by Daniel Carosone and Michael Van Elst.

Ok'ed by Andrew Doran and Matthew R. Green.
 1.137 18-Mar-2007  xtraeme There's no need to run est_init or k8_powernow_init on each CPU.
Just run it once (in the first cpu probed) with the RUN_ONCE(9)
framework.

Change the argument of est_init and k8_powernow_init to void, we don't
need cpu_info * anymore.

Suggested by tls@ and mrg@.
 1.136 12-Mar-2007  ad branches: 1.136.2; 1.136.4;
Include sys/simplelock.h, not sys/lock.h.
 1.135 05-Mar-2007  drochner branches: 1.135.2;
clean up how cpus and ioapics are attached at the mainbus:
Seperate "cpubus" and "ioapicbus" -- while they share a common "address
space" (the apic id), the kernel doesn't use this fact. There are different
data passed to cpus and apics, which caused some ugly polymorphism. This
also saves the special "submatch" functions needed to distingush cpus
and ioapics for autoconf. (And it makes that "apid" locators wired
in the kernel configuration are honored now; this allows one to dumb down
an mp box to singleprocessor by userconfig.)
Print "apid" locators in the buses "print" function "as everyone does",
so the per-port cpu drivers don't need to do it.
Being here, constify "struct cpu_functions" and g/c the unused MP_PICMODE
flag.
 1.134 04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.133 17-Feb-2007  daniel branches: 1.133.2;
Add an opencrypto provider for the AES xcrypt instructions found on VIA
C5P and later cores (also known as 'ACE', which is part of the VIA PadLock
security engine). Ported from OpenBSD.

Reviewed on tech-crypto and port-i386, no objections to commiting this.
 1.132 16-Feb-2007  ad Remove spllowersoftclock() and CLKF_BASEPRI(), and always dispatch callouts
via a soft interrupt. In the near future, softclock will be run from process
context.
 1.131 09-Feb-2007  ad Merge newlock2 to head.
 1.130 08-Dec-2006  yamt - pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.129 03-Sep-2006  xtraeme branches: 1.129.2; 1.129.4; 1.129.6;
Conditionalize *_get_bus_clock() functions inside of
#ifdef ENHANCED_SPEEDSTEP to fix build when ENHANCED_SPEEDSTEP is not
defined.

Reported by Geoff Wing.
 1.128 03-Sep-2006  xtraeme Update the enhanced speedstep driver and sync the code with OpenBSD:

est.c:

* Use a quintuplet (vendor, MHz_hi, mV_hi, MHz_lo, mV_lo } to match
CPUs more correctly than parsing the brand string.
* Add support for a bunch of models.
* Create a fake table on the fly if the CPU is unknown (there's no
table for it) with the current/highest/lowest frequency.

specialreg.h:

* Add some MSRs needed to get the bus clock value.

identcpu.c:

* Add functions specific to Pentium III, Pentium M and Pentium 4 to
get the bus clock value.

Note that the new fake table code from Simon Burge is not included on
this commit.

Ok'ed by simonb and dogcow.
 1.127 23-Aug-2006  xtraeme - Move k7_powernow_* prototypes from i386/include/cpu.h to
x86/include/powernow.h
- Protect k[78]_powernow_init() functions with #ifdef POWERNOW_K[78] to
make it build without these options.

This fixes the problem reported by hubertf.
 1.126 08-Aug-2006  xtraeme - Add k7_powernow_destroy() prototype into cpu.h.
- Call k7_powernow_destroy() unloading the module.
 1.125 06-Aug-2006  xtraeme branches: 1.125.2;
* Sync powernow_k7.c driver with OpenBSD, it seems to work much
better finding PST tables.
* Use functions defined in powernow_common.c to detect if the
CPU can run powernow.
* Update the LKM with current code.
 1.124 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.123 16-Feb-2006  perry branches: 1.123.2; 1.123.8;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.122 03-Feb-2006  xtraeme branches: 1.122.2;
Fix "hard reboot" problem reported by Rhialto weeks ago on current-users@.
The problem was that pnowk7_init() was called too early in the boot
process, at this point the required calls were not available.

Thanks to Rhialto for testing and cube/christos for comments.
 1.121 31-Dec-2005  xtraeme branches: 1.121.2;
AMD PowerNow K7 driver written by Martin Vegiard via PR port-i386/26239.

Enabled by default on GENERIC and GENERIC_LAPTOP.

Imported 1 year later... but it's here finally.
 1.120 26-Dec-2005  perry branches: 1.120.2;
u_intN_t -> uintN_t
 1.119 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.118 11-Aug-2005  cube Change all archs that did:

#define clockframe somethingelse

to:

struct clockframe {
struct somethingelse cf_se;
};

and change access macros accordingly.

That means that, at least for that very issue, things will not go
ka-boomy if you don't have the actual definition of struct clockframe
before including systm.h.
 1.117 21-Feb-2005  he branches: 1.117.4;
Probe and print the Intel Extended Feature Bits, as documented
in the CPUID instruction description in the "Intel Extended Memory 64
Technology Software Developer's Guide, Volume 1 of 2" available at
ftp://download.intel.com/technology/64bitextensions/30083402.pdf

This presently consists of the SYSCALL/SYSRET and the EM64T features.
CPUs with the EM64T feature available should be able to run amd64 code.

Reviewed by fvdl
 1.116 22-Sep-2004  yamt branches: 1.116.4; 1.116.6;
move some per-cpu data definitions to MI place so that they can be modified
without touching all ports. discussed on tech-kern@.
 1.115 16-May-2004  yamt curcpu: fix a typo. (cpuinfo -> cpu_info)
no functional difference.
 1.114 30-Apr-2004  lukem Integrate support for Enhanced SpeedStep Technology (est) that
Michael Eriksson posted to port-i386 on 20031102, with various
modifications by me to work in the new sysctl(9) framework.

The code is enabled with 'options ENHANCED_SPEEDSTEP', and if
the CPU supports EST the following sysctl(8) nodes appear
(with the values that a Dell Inspiron 8600 + WUXGA with a
1.4GHz Pentium M CPU supports):
machdep.est.cpu_brand = Intel(R) Pentium(R) M processor 1400MHz
machdep.est.frequency.target = 1400
machdep.est.frequency.current = 1400
machdep.est.frequency.available = 1400 1200 1000 800 600

If EST support isn't available, the "machdep.est" sysctl sub-MIB
is not created.

Once we have a more general "CPU frequency" control API we can
migrate this code to using that.

Thanks to Michael Erikkson for providing this code!
 1.113 20-Feb-2004  yamt defer pmap switching until it's really needed
to avoid frequent loading of cr3 register, which involves tlb flush.

with some fixes/improvements from Stephan Uphoff and Bang Jun-Young.
 1.112 04-Jan-2004  jdolecek Process and lwp exit path always executes lwp_exit2() now and cpu_exit()
is empty besides calling switch_exit(). So, rename switch_exit() to
cpu_exit() and modify the routine to call lwp_exit2() direct.
This saves couple cycles on the exit path.
 1.111 30-Dec-2003  pk Replace the traditional buffer memory management -- based on fixed per buffer
virtual memory reservation and a private pool of memory pages -- by a scheme
based on memory pools.

This allows better utilization of memory because buffers can now be allocated
with a granularity finer than the system's native page size (useful for
filesystems with e.g. 1k or 2k fragment sizes). It also avoids fragmentation
of virtual to physical memory mappings (due to the former fixed virtual
address reservation) resulting in better utilization of MMU resources on some
platforms. Finally, the scheme is more flexible by allowing run-time decisions
on the amount of memory to be used for buffers.

On the other hand, the effectiveness of the LRU queue for buffer recycling
may be somewhat reduced compared to the traditional method since, due to the
nature of the pool based memory allocation, the actual least recently used
buffer may release its memory to a pool different from the one needed by a
newly allocated buffer. However, this effect will kick in only if the
system is under memory pressure.
 1.110 30-Dec-2003  yamt g/c unused x86_ipisend.
 1.109 27-Oct-2003  junyoung Nuke __P().
 1.108 10-Oct-2003  simonb Take previous even further - leave only CTL_MACHDEP and related
definitions and structures outside the #ifdef _KERNEL block.
 1.107 10-Oct-2003  yamt revert the previous (thanks, lukem)
and wrap curcpu, cpu_info and friends with #ifdef _KERNEL completely.
 1.106 10-Oct-2003  lukem Userland needs <stddef.h> for offsetof(), not <lib/libkern/libkern.h> ...

(Arguably a chunk more of this file could be protected with _KERNEL.
That's a separate project.)
 1.105 09-Oct-2003  yamt avoid a magic number in curcpu().
 1.104 06-Sep-2003  christos SA_SIGINFO changes.
 1.103 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.102 26-Jun-2003  drochner branches: 1.102.2;
-make cpu_feature unsigned, just like ci_feature_flags
-clean up duplicate declaration of cpu_info_primary
 1.101 20-May-2003  kristerw Use __asm instead of asm, to make lint happy.
 1.100 25-Apr-2003  fvdl Share some common cache info cpuid code between i386 and x86_64.
 1.99 18-Mar-2003  fvdl Add some underscores in curcpu() to avoid a -Wshadow.
 1.98 01-Mar-2003  fvdl Move the CPU identification out of machdep.c into a seperate file.
 1.97 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.96 05-Feb-2003  nakayama Share i386/tsc_microtime.c with alpha and sparc64 as kern_microtime.c.
(approved by martin)
 1.95 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.94 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.93 16-Dec-2002  jdolecek use the __HAVE_CPU_MAXPROC hook to limit kern.maxproc to number
of available GDT slots
add code in init386() to force maxproc to be maximum cpu_maxproc()

this fixes port-i386/1635 by John Kohl
 1.92 06-Dec-2002  junyoung Don't pollute struct cpu_info with throwaway variables.
 1.91 06-Dec-2002  junyoung Display the extended feature flags with non-Intel processors rather than
the standard flags. See also PR#19163.

Before:

cpu0: AMD Athlon XP 1800+ (686-class), 1532.11 MHz
cpu0: features 383f9ff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR>
cpu0: features 383f9ff<PGE,MCA,CMOV,FGPAT,PSE36,MMX>
cpu0: features 383f9ff<FXSR,SSE>

After:

cpu0: AMD Athlon XP 1800+ (686-class), 1532.11 MHz
cpu0: features c3cbf9ff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR>
cpu0: features c3cbf9ff<PGE,MCA,CMOV,PAT,PSE36,MPC,MMXX,MMX>
cpu0: features c3cbf9ff<FXSR,SSE,3DNOW2,3DNOW>

While I'm here, amd_cpuid_cpu_cacheinfo() is an info function rather
than a probe function.
 1.90 28-Nov-2002  fvdl Add ci_apicid field.
 1.89 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.88 02-Nov-2002  perry /*CONTCOND*/ a while (0) macro
 1.87 06-Oct-2002  fvdl Remove ci_lapic_ints from struct cpu_info again, it isn't needed anymore.
 1.86 06-Oct-2002  fvdl Keep size of struct cpu_info independent of DIAGNOSTIC/LOCKDEBUG
(was done in rev. 1.81, got lost in the MP merge).
 1.85 06-Oct-2002  fvdl Add per-CPU local apic redir table (2 pointers).
 1.84 06-Oct-2002  fvdl cpu_swapin now exists, so remove the empty define.
 1.83 05-Oct-2002  fvdl Add mask for TLB IPI rendezvous, and stackpointers + TSS structures
for TSS gates per CPU.

XXX struct cpu_info is getting to be a bit large
 1.82 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.81 09-Jul-2002  jdolecek always include ci_s*_locks in struct cpu_info, so that the size doesn't depend
on DIAGNOSTIC/LOCKDEBUG settings
 1.80 12-May-2002  matt branches: 1.80.2; 1.80.4;
Eliminate commons.
 1.79 08-May-2002  mycroft Wire CLKF_BASEPRI() to 0 on this platform. (See tech-kern.)
 1.78 31-Jan-2002  christos Fix comments.
 1.77 27-Dec-2001  christos add a new function to the cpu struct's that can be called to print extra
cpu information after initialization.
 1.76 17-Nov-2001  christos Add transmeta crusoe cpu support from toshi.
 1.75 02-Aug-2001  thorpej - Rename cpu_use_fxsave to i386_use_fxsave.
- If we detect SSE/SSE2 support in the CPU, enable SSE exceptions
and set i386_has_{sse,sse2} as appropriate.
- Expose i386_use_fxsave and i386_has_{sse,sse2} through sysctl
as machdep.{osfsxr,sse,sse2}.
 1.74 02-Aug-2001  thorpej Add support for saving/restoring SSE/SSE2 state using FXSAVE/FXRSTOR.

Reviewed by Frank.
 1.73 01-Aug-2001  thorpej Add several more Intel cache info entries, and fetch the CFLUSH
line size if we have the CFLUSH insn.
 1.72 14-Jun-2001  thorpej branches: 1.72.2;
Don't need to prototype child_return() here, it's in <sys/proc.h>.
 1.71 30-May-2001  mrg use _KERNEL_OPT
 1.70 03-May-2001  thorpej Rearrange the cache info fetching code some more, and add support
for fetching cache info for AMD processors.
 1.69 02-May-2001  thorpej - Keep cache/tlb info in the cpu_info structure.
- Add "associativity" to the cache_info structure.
- Add a (*cpu_cacheinfo)() function pointer, like we have a
(*cpu_setup)() function pointer. Cache info in the `cpuid'
is vendor-specific.
 1.68 14-Feb-2001  nathanw branches: 1.68.2;
Remove prototype for long-defunct i386_user_cleanup().

Remove duplicate prototype for i386_{set,get}_ldt() from sys_machdep.c.

Change i386_iopl() and i386_{set,get}_{ldt,ioperm}() to take a second
argument of "void *" instead of "char *", for consistency with other syscalls.
 1.67 10-Dec-2000  mycroft Introduce PROC_PC(), which is used to get a process's user PC. If this is
defined, call addupc_intr() directly from statclock() in the system time case,
using the same P_OWEUPC path if the copyin/copyout fails.
Use this in i386 to remove profiling code from the normal userret() path.
 1.66 16-Nov-2000  jdolecek make i386_nocpuid_cpus[] and i386_cpuid_cpus[] const - this pushes
another ~1.4KB to text section
 1.65 25-Aug-2000  thorpej Make need_resched() take a "struct cpu_info *" argument. This
causes gives a primitive form of processor affinity. Its use in
roundrobin() still needs some work.
 1.64 04-Jun-2000  mycroft branches: 1.64.2;
Implement CLKF_INTR(), to count interrupt time separately.
 1.63 26-May-2000  thorpej branches: 1.63.2;
First sweep at scheduler state cleanup. Collect MI scheduler
state into global and per-CPU scheduler state:

- Global state: sched_qs (run queues), sched_whichqs (bitmap
of non-empty run queues), sched_slpque (sleep queues).
NOTE: These may collectively move into a struct schedstate
at some point in the future.

- Per-CPU state, struct schedstate_percpu: spc_runtime
(time process on this CPU started running), spc_flags
(replaces struct proc's p_schedflags), and
spc_curpriority (usrpri of processes on this CPU).

- Every platform must now supply a struct cpu_info and
a curcpu() macro. Simplify existing cpu_info declarations
where appropriate.

- All references to per-CPU scheduler state now made through
curcpu(). NOTE: this will likely be adjusted in the future
after further changes to struct proc are made.

Tested on i386 and Alpha. Changes are mostly mechanical, but apologies
in advance if it doesn't compile on a particular platform.
 1.62 21-Apr-2000  thorpej - Declare biosbasemem and biosextmem in <machine/cpu.h>, don't extern
them everywhere they're used.
- Avoid integer overflow when converting bios{base,ext}mem (in units of
kilobytes) to bytes.
 1.61 29-Mar-2000  simonb Remove redundant decl of consinit() - it's in <sys/systm.h>.
Remove duplicate definition of delay() - we only need one in this file.
 1.60 28-Mar-2000  thorpej Extern cpu_id and cpu_vendor[] here.
 1.59 26-Jan-2000  drochner branches: 1.59.2;
next step in getting machdep.c maintainable - put bus_space related
stuff into a separate file
 1.58 21-Dec-1999  drochner machdep.c is becoming an unmaintainable mess
put console initialisation into a separate file
 1.57 06-Nov-1999  enami branches: 1.57.2;
- Export initrtclock().
- Call it from apm_resume().

This fixes timer problem on some laptop after hybernation (PR#4808).
Reviewd by: fvdl@netbsd.org
 1.56 06-Oct-1999  fvdl branches: 1.56.2; 1.56.4;
Define CPU_FPU_PRESENT sysctl value.
 1.55 10-Aug-1999  thorpej branches: 1.55.2;
Define cpu_number() as discussed on tech-smp.
 1.54 20-Jul-1999  thorpej Implement cpu_wait(), and move the call to tss_free() from switch_exit()
to cpu_wait(); tss_free() may block, and thus requires a valid context.
 1.53 01-Apr-1999  thorpej branches: 1.53.2; 1.53.4;
Do proc0's TSS and LDT initialization at the end of configure() (i.e.
once the FPU has been attached).
 1.52 12-Mar-1999  fvdl Clean up the BIOS disk matching code a bit (better naming, one structure
and sysctl to export to userland). Also, only use total number of sectors
given in the extended parameters if the physical chs geometry is
marked invalid. Hopefully fixes a problem where BIOSs would not correctly
fill in this field.
 1.51 10-Mar-1999  fvdl Create a list of native disks too, and make it retrievable. It contains
all matching BIOS disks per entry, so that we have complete match info.
Enable the matching code.
 1.50 08-Mar-1999  fvdl Add some fields to the already defined, but unused, bootinfo structure
for BIOS geometry. Define CPU_BIOS_GEOM sysctl value in cpu.h.
 1.49 11-Nov-1998  thorpej Changes to support fork_kthread():
- cpu_set_kpc() now takes void *arg third argument, passed to the
entry point.
- cpu_fork() allows parent to be non-curproc iff parent is proc0.
When forking non-curproc, assume its state has already been saved.
- Adjust various pieces of machine-dependent code to account of all of this.
 1.48 07-Oct-1998  thorpej Erg, frame -> trapframe in last. (thanks to john kohl)
 1.47 07-Oct-1998  thorpej Oops, back out a buglet I didn't intend to commit in the last change.
 1.46 06-Oct-1998  thorpej Move the code that does the deferred (post-autoconfiguration) buffer
cache allocation to its own function, and call it at the end of configure().
 1.45 06-Oct-1998  thorpej configure() prototype is in <sys/device.h>
 1.44 22-Jan-1998  thorpej Generate dependencies on the USER_LDT option.
 1.43 21-Jan-1998  thorpej Generate dependencies on the MATH_EMULATE option.
 1.42 15-Jan-1998  thorpej Generate dependencies on the VM86 option.
 1.41 27-Nov-1997  bouyer Add a cpu_setup() function to "struct cpu_nocpuid_nameclass" and
"struct cpu_cpuid_family", so that we can have a cpu_setup function per
known cpu type. For now use it only for cyrix 6x86 to enable suspend-on-halt
and implement cyrix's workaround to the "coma bug".
 1.40 20-Sep-1997  drochner branches: 1.40.2;
Define "machdep.booted_kernel" for sysctl.
 1.39 04-Feb-1997  perry branches: 1.39.8;
Nuke some options GENERIC residue.
 1.38 03-Dec-1996  fvdl Added types/definitions for changed CPU recognition code.
 1.37 18-Nov-1996  fvdl Changes for NKPDE calculation from cgd.

- New variables: biosextmem, biosbasemem, nkpde
- Above can be set by using the options BIOSEXTMEM, BIOSBASEMEM,
and NKPDE respectively (EXTMEM_SIZE is now called BIOSEXTMEM).
When preset this way, they won't be filled in / calculated.
- Readable by sysctl using machdep.nkpde, machdep.biosbasemem
and machdep.biosextmem.
- nkpde is calculated as:

min(NKPDE_MAX, NKPDE_BASE + (biosextmem >> 10) * NKPDE_SCALE)

Where NKPDE_MAX is 31, NKPDE_BASE is 4, NKPDE_SCALE = 1.
 1.36 11-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.35 05-May-1996  christos Change the prototype of fillw from (int, caddr_t, size_t) to
(short, void *, size_t).
 1.34 03-May-1996  christos Add prototypes from other files.
 1.33 29-Mar-1996  mycroft Prototype delay().
 1.32 24-Dec-1995  mycroft Enable paging of the user area.
 1.31 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.30 10-Oct-1995  mycroft Add USERMODE() and KERNELMODE() macros, and use them.
 1.29 28-Jun-1995  cgd remove unused cpu_exec() definitions. moved "broken swap" markers, for
ports that still need it, to types.h.
 1.28 05-May-1995  cgd define BROKEN_SWAP and/or cpu_swapout as appropriate.
 1.27 22-Apr-1995  christos - added sunos_machdep.c for sun3, atari, amiga and mac68k.
- changed machdep.c and trap.c to use struct emul.
- remove ep_setup references.
- added struct emul to all emulations.
 1.26 21-Apr-1995  mycroft Alias delay() to DELAY() for mi code.
 1.25 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.24 27-Oct-1994  cgd new RCS ID format.
 1.23 14-Jun-1994  mycroft profile_tick() is no longer needed.
 1.22 27-May-1994  mycroft Add cpu_set_init_frame().
 1.21 23-May-1994  cgd add cpu_swapin
 1.20 19-May-1994  cgd make cpu_wait a macro, and define cpu_coredump
 1.19 07-May-1994  cgd cpu-dependent sysctl structs
 1.18 06-May-1994  mycroft Correct comment.
 1.17 05-May-1994  cgd lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.16 04-May-1994  cgd Rename a lot of process flags.
 1.15 07-Apr-1994  mycroft Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.14 03-Apr-1994  mycroft This is #included multiple times.
 1.13 08-Mar-1994  mycroft Add `com' softintr.
 1.12 17-Dec-1993  mycroft branches: 1.12.2;
From magnum branch:
Remove Jolitz's netisr kluge. Make sure cpl == 0 really means base priority.
Other minor cleanup.
 1.11 11-Sep-1993  jtc Remove NEED_* defines, as they are now satisfied by libkern.
 1.10 02-Sep-1993  cgd branches: 1.10.2;
get rid of bogus #define of resettodr(); now setting time actually works!
 1.9 16-Jun-1993  jtc Move my assembly versions of strlen and ffs into the kernel
 1.8 03-Jun-1993  cgd add prototype for a function to be called from execve to check a_mid type
 1.7 02-Jun-1993  cgd set things up so that the signal trampoline code is on the stack,
like it normally is in BSD systems. still has a bit of hair...
 1.6 21-May-1993  cgd add "cpu classes" in addition to cpu names, put cpu names in table, along
with mapping to classes. this is for upgraded cpu-id code coming "soon"
 1.5 21-May-1993  cgd move cpu types out of assym.s and into cputypes.h
and have that file included by cpu.h and by locore.s
 1.4 20-May-1993  cgd hack on the uname "machine name" stuff for hopefully the last time.
now it uses MACHINE, as defined in param.h
 1.3 20-May-1993  cgd clean up for new cpu stuff
 1.2 20-May-1993  cgd make uname stuff in init_main machine independent
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.10.2.9 01-Feb-1994  mycroft Revert clockframe and profiling stuff.
 1.10.2.8 11-Jan-1994  mycroft SIR_GENERIC --> SIR_AST, to match main branch.
 1.10.2.7 29-Oct-1993  mycroft Set sir bits correctly.
 1.10.2.6 18-Oct-1993  mycroft Add a more `normal' way of dealing with software interrupts.
 1.10.2.5 18-Oct-1993  mycroft Add need_proftick(), and some minor cleanup.
 1.10.2.4 14-Oct-1993  mycroft Remove aston().
 1.10.2.3 13-Oct-1993  mycroft Remove defunct profile_tick(). Put pending AST flag back in netisr.
 1.10.2.2 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.10.2.1 14-Sep-1993  mycroft New i386 code.
 1.12.2.2 17-Dec-1993  mycroft From magnum branch:
Remove Jolitz's netisr kluge. Make sure cpl == 0 really means base priority.
Other minor cleanup.
 1.12.2.1 17-Dec-1993  mycroft file cpu.h was added on branch magnum on 1993-12-17 00:10:50 +0000
 1.39.8.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.40.2.1 28-Nov-1997  mellon Pull rev 1.41 up from trunk (bouyer)
 1.53.4.1 02-Aug-1999  thorpej Update from trunk.
 1.53.2.1 27-Jun-2000  he Pull up revision 1.57 (via patch, requested by mjl):
Reinitialize clock after hibernation, something which seems to be
required on some laptops. Fixes PR#4808.
 1.55.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.56.4.1 15-Nov-1999  fvdl Sync with -current
 1.56.2.4 12-Mar-2001  bouyer Sync with HEAD.
 1.56.2.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.56.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.56.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.57.2.2 06-Nov-1999  enami - Export initrtclock().
- Call it from apm_resume().

This fixes timer problem on some laptop after hybernation (PR#4808).
Reviewd by: fvdl@netbsd.org
 1.57.2.1 06-Nov-1999  enami file cpu.h was added on branch comdex-fall-1999 on 1999-11-06 01:14:01 +0000
 1.59.2.32 18-May-2002  sommerfeld Catch up with -current. (commons elimination, changes to MI pci framework)
 1.59.2.31 27-Apr-2002  sommerfeld Add options TRAPLOG:

When enabled, each cpu gets a ring buffer; on every trap entry, we add
an entry to the trap log using the new locore "TLOG" macro. Somewhat
like a flight recorder, this may give some post-mortem clues as to
what was going on as we were spiralling in...

XXX currently depends on various intel MSR's to record the low order
32 bits of the cycle counter as well as last-branch from and to
addresses.
 1.59.2.30 24-Feb-2002  sommerfeld Resynch with mainline.
 1.59.2.29 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.59.2.28 29-Dec-2001  sommerfeld Yet another mergeup.

New work:
- Frank van der Linden's tlb shootdown fix.
Mainline functionality merged:
- IrDA
- Kernel RCSID's
- Transmeta CPU support
- ACPI
- XMM register access through procfs
 1.59.2.27 03-Sep-2001  sommerfeld Merge with -current once more.
 1.59.2.26 02-Jul-2001  fvdl Since cpuid_level value -1 is used to indicate "not available",
it should be signed.
 1.59.2.25 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.59.2.24 26-May-2001  sommerfeld Implement MP-synchronzed microtime(), based on Jason Thorpe's port of
Dave Mills's cycle-counter-based microtime.

XXX We need to figure out how to deal with processors where the cycle
counter speed varies. We don't have a whole lot of alternatives; we
could only use this on multiprocessors, which are less likely to
throttle the clock to save power.

The local apic timer runs at a fixed frequency, but it's
count-down-to-zero, not the count-up-forever type of timer which the
Mills code expects.

This also does not solve the problem of microtime on 486-based
multiprocessors..
 1.59.2.23 07-May-2001  sommerfeld Rework cache/tlb parsing, etc., One More Time.
Compact tables, rework associativity.
 1.59.2.22 07-May-2001  sommerfeld "Merge" in revised cache probing code (including amd cache size
probing). Separate feature probing from output formatting, and call
uvm_recolor() at an appropriate moment.
 1.59.2.21 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.59.2.20 10-Jan-2001  sommerfeld Significant rewrite of slave CPU attach and initialization, centering
on identifycpu() and spreading outward.

Separate feature probes (cpuid invocation), which runs on the cpu
being attached, from the display of this information, which runs on
the boot cpu; remove some of the probe code from locore as it doesn't
need to run that early.

We now spin up secondary cpu's during cpu_attach, have them do a cpu
feature probe, and then have them spin waiting for a "go" signal.

We no longer pay attention to the cpu signature and cpuid features
reported by the MP BIOS since those are known to be truncated for at
least some bioses.

We now do npx initialization (including FDIV bug detection) on all
cpus.

XXX Change some of the cyrix bug workarounds to fit the new
identifycpu() system; this is untested.
 1.59.2.19 08-Jan-2001  sommerfeld Mostly fix cpu identification:
- move globals which contain per-cpu state into cpu_info.
- fix cache size probing to work off of cpu_info rather than globals
- print out itlb/dtlb sizes
- add a few more cache identifiers from the latest version of AP-485

cpu timing, cache probing, and processor serial number lookup still
happens only on the main cpu; this needs to be restructured; mark what
code needs to move into per-cpu probe code.

While we're here, eradicate "cpu_info_store" in favor of "cpu_info_primary".
 1.59.2.18 07-Jan-2001  sommerfeld Correct merge botches.
Post-merge kernel now boots multiuser.
 1.59.2.17 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.59.2.16 04-Jan-2001  thorpej Make sure that there's at least one "cpu_info" slot, so that we don't
trash random memory in the non-MULTIPROCESSOR case.
 1.59.2.15 04-Jan-2001  thorpej Always statically allocated the primary CPU's cpu_info, and make the
cpu_info list available in the non-MULTIPROCESSOR case, as well.
 1.59.2.14 18-Nov-2000  sommerfeld Add some minimal support for iterating over cpus
 1.59.2.13 23-Sep-2000  sommerfeld Preliminary support for cloning MTRR values between CPU's at boot time.
XXX no API to *set* MTRR values yet.
 1.59.2.12 25-Aug-2000  sommerfeld Get this to at least build again in the !MULTIPROCESSOR case..
 1.59.2.11 25-Aug-2000  sommerfeld The need_resched() function now takes a (cpu_info *) parameter.
Get asts out of <machine/intr.h>
Untangle astpending and want_resched variables somewhat.
 1.59.2.10 18-Aug-2000  sommerfeld misc changes:
- CPUF_PAUSE (indicating CPU is paused in debugger).
- ci_flags is now a u_int32_t.
- npx interface changes.
 1.59.2.9 12-Aug-2000  sommerfeld Get ready for context switch changes:
- initialize idle pcbs earlier, before the first tsleep (instead of as
part of booting the secondary cpu's), since we'll actually use them
when idling in the near future.
- clean up cpu_hatch()
- fixup curproc's cpu pointer when switching to "real" cpu_info (XXX).
- turn on local apic clock in cpu_hatch()
- load the right gdt descriptor in cpu_hatch()
- return from cpu_hatch() instead of spinning there; current
mptramp code will spin; future code will jump to idle loop.
 1.59.2.8 26-Jun-2000  sommerfeld Start making npx.c MP-safe; Interface to npx now specifies the process
and/or cpu to act on. Implement an IPI for MP lazy FP save.
Tested and working when only one CPU is running; untested in the MP
case since we can't run user processes on multiple CPU's yet.

Along for the ride:
- Change i386_send_ipi to take a "struct cpu_info *" rather than a cpu number.
- Turn off the "give me the brain" test IPI's.
 1.59.2.7 25-Jun-2000  sommerfeld Add CPUF_PRIMARY, CPU_IS_PRIMARY()
 1.59.2.6 25-Jun-2000  sommerfeld Merge up to just-post-1.5 -current
 1.59.2.5 22-Apr-2000  sommerfeld Merge up to -current.
 1.59.2.4 17-Apr-2000  sommerfeld Catch up sommerfeld_i386mp_1 branch with -current.
 1.59.2.3 24-Feb-2000  sommerfeld Patch from Matt Debergalis to un-break bootblock build
 1.59.2.2 21-Feb-2000  sommerfeld MP: attempt to deal with the case where the BSP is at apic id 1 instead
of apic id 0.
 1.59.2.1 20-Feb-2000  sommerfeld MP: include cpu_info structure, which picks up what used to be in
several global variables.
XXX cpu_info is bigger than it should be..
 1.63.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.64.2.1 25-Apr-2001  he Pull up revision 1.66 (requested by jdolecek):
Add ``const'' to cpu tables.
Properly identify and distinguish newer Intel CPUs using Brand
ID information.
 1.68.2.18 07-Jan-2003  thorpej Sync with HEAD.
 1.68.2.17 03-Jan-2003  thorpej Merge switch_exit() and switch_lwp_exit().
 1.68.2.16 19-Dec-2002  thorpej Sync with HEAD.
 1.68.2.15 11-Dec-2002  thorpej Sync with HEAD.
 1.68.2.14 25-Nov-2002  nathanw Make ASTs per-proc rather than per-cpu; per-proc makes more sense when
a process that needs a trap can be running on multiple CPUs.
 1.68.2.13 11-Nov-2002  nathanw Catch up to -current
 1.68.2.12 18-Oct-2002  nathanw cpu_info->fp_curlwp is a struct lwp, not a struct proc.

npxsave_proc() -> npxsave_lwp().
 1.68.2.11 18-Oct-2002  nathanw Define curlwp, not curproc.
 1.68.2.10 18-Oct-2002  nathanw Catch up to -current.
 1.68.2.9 01-Aug-2002  nathanw Catch up to -current.
 1.68.2.8 20-Jun-2002  nathanw Catch up to -current.
 1.68.2.7 28-Feb-2002  nathanw Catch up to -current.
 1.68.2.6 23-Feb-2002  gmcgarry Protect cpu_proc_fork() with _KERNEL
 1.68.2.5 08-Jan-2002  nathanw Catch up to -current.
 1.68.2.4 08-Dec-2001  thorpej Add a cpu_proc_fork(), called from uvm_proc_fork(), which takes care
of machine-dependent handling a fork() time (this is different from
forking the actual context in an LWP world). #define it away on
platforms which do not need it.

Problem noted by Gregory McGarry.
 1.68.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.68.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.68.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.72.2.6 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.72.2.5 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.72.2.4 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.72.2.3 11-Feb-2002  jdolecek Sync w/ -current.
 1.72.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.72.2.1 03-Aug-2001  lukem update to -current
 1.80.4.1 07-Sep-2003  tron Apply patch (requested by drochner in ticket 1344):
Make output of CPU features look nicer on new Pentium IV CPUs.
 1.80.2.1 16-Jul-2002  gehenna catch up with -current.
 1.102.2.6 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.102.2.5 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.102.2.4 24-Sep-2004  skrll Sync with HEAD.
 1.102.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.102.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.102.2.1 03-Aug-2004  skrll Sync with HEAD
 1.116.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.116.4.1 29-Apr-2005  kent sync with -current
 1.117.4.11 17-Mar-2008  yamt sync with head.
 1.117.4.10 27-Feb-2008  yamt sync with head.
 1.117.4.9 11-Feb-2008  yamt sync with head.
 1.117.4.8 21-Jan-2008  yamt sync with head
 1.117.4.7 07-Dec-2007  yamt sync with head
 1.117.4.6 15-Nov-2007  yamt sync with head.
 1.117.4.5 27-Oct-2007  yamt sync with head.
 1.117.4.4 03-Sep-2007  yamt sync with head.
 1.117.4.3 26-Feb-2007  yamt sync with head.
 1.117.4.2 30-Dec-2006  yamt sync with head.
 1.117.4.1 21-Jun-2006  yamt sync with head.
 1.120.2.2 18-Feb-2006  yamt sync with head.
 1.120.2.1 15-Jan-2006  yamt sync with head.
 1.121.2.1 09-Sep-2006  rpaulo sync with head
 1.122.2.3 22-Apr-2006  simonb Sync with head.
 1.122.2.2 28-Feb-2006  kardel initrtclock() now gets the frequency as parameter
 1.122.2.1 04-Feb-2006  simonb Remove port-specific microtime() function support.
 1.123.8.1 19-Jun-2006  chap Sync with head.
 1.123.2.3 03-Sep-2006  yamt sync with head.
 1.123.2.2 11-Aug-2006  yamt sync with head
 1.123.2.1 26-Jun-2006  yamt sync with head.
 1.125.2.4 07-Sep-2006  tron Pull up following revision(s) (requested by xtraeme in ticket #114):
sys/arch/i386/include/cpu.h: revision 1.129
sys/arch/i386/i386/identcpu.c: revision 1.40
Conditionalize *_get_bus_clock() functions inside of
#ifdef ENHANCED_SPEEDSTEP to fix build when ENHANCED_SPEEDSTEP is not
defined.
Reported by Geoff Wing.
 1.125.2.3 06-Sep-2006  riz Pull up following revision(s) (requested by xtraeme in ticket #111):
sys/arch/x86/include/specialreg.h: revision 1.11
sys/arch/i386/i386/identcpu.c: revision 1.39
sys/arch/i386/include/cpu.h: revision 1.128
sys/arch/i386/i386/est.c: revision 1.26
Update the enhanced speedstep driver and sync the code with OpenBSD:
est.c:
* Use a quintuplet (vendor, MHz_hi, mV_hi, MHz_lo, mV_lo } to match
CPUs more correctly than parsing the brand string.
* Add support for a bunch of models.
* Create a fake table on the fly if the CPU is unknown (there's no
table for it) with the current/highest/lowest frequency.
specialreg.h:
* Add some MSRs needed to get the bus clock value.
identcpu.c:
* Add functions specific to Pentium III, Pentium M and Pentium 4 to
get the bus clock value.
Note that the new fake table code from Simon Burge is not included on
this commit.
Ok'ed by simonb and dogcow.
 1.125.2.2 27-Aug-2006  tron Pull up following revision(s) (requested by xtraeme in ticket #57):
sys/arch/i386/i386/identcpu.c: revision 1.37
sys/arch/x86/include/powernow.h: revision 1.4
sys/arch/i386/include/cpu.h: revision 1.127
- Move k7_powernow_* prototypes from i386/include/cpu.h to
x86/include/powernow.h
- Protect k[78]_powernow_init() functions with #ifdef POWERNOW_K[78] to
make it build without these options.
This fixes the problem reported by hubertf.
 1.125.2.1 11-Aug-2006  riz Pull up following revision(s) (requested by xtraeme in ticket #10):
sys/arch/i386/include/cpu.h: revision 1.126
sys/lkm/arch/i386/powernow/lkminit_powernow.c: revision 1.5
- Add k7_powernow_destroy() prototype into cpu.h.
- Call k7_powernow_destroy() unloading the module.
 1.129.6.2 12-Sep-2007  msaitoh Pull up following patches (requested by xtraeme in ticket #809)

share/man/man4/options.4 patch
sys/arch/i386/conf/files.i386 patch
sys/arch/i386/i386/est.c delete
sys/arch/i386/i386/identcpu.c patch
sys/arch/i386/include/cpu.h patch
sys/arch/x86/conf/files.x86 patch
sys/arch/x86/include/cpuvar.h patch
sys/arch/x86/x86/est.c new file
sys/arch/x86/x86/intel_busclock.c new file
sys/arch/amd64/amd64/identcpu.c patch
sys/arch/amd64/conf/GENERIC patch

Add support for the VIA C7-M and Eden processors in the Enhanced
Speedstep driver.
amd64: The Enhanced Speedstep driver is now able to work on EM64T
CPUs running in 64bit mode.
 1.129.6.1 20-Apr-2007  bouyer branches: 1.129.6.1.2;
Pull up following revision(s) (requested by mlelstv in ticket #575):
sys/arch/i386/i386/est.c sync with 1.37
sys/arch/i386/i386/ipifuncs.c sync with 1.16
sys/arch/x86/include/cpu_msr.h sync with 1.4
sys/arch/x86/include/intrdefs.h sync with 1.8
sys/arch/x86/include/powernow.h sync with 1.9
sys/arch/x86/x86/powernow_k8.c sync with 1.20
sys/arch/x86/x86/msr_ipifuncs.c sync with 1.8
sys/arch/amd64/amd64/ipifuncs.c sync with 1.9
sys/arch/i386/i386/identcpu.c patch
sys/arch/i386/i386/machdep.c patch
sys/arch/i386/include/cpu.h patch
sys/arch/x86/conf/files.x86 patch
sys/arch/x86/x86/x86_machdep.c patch
sys/arch/amd64/amd64/machdep.c patch
Add MSR write IPI handler for x86. Use it and the RUN_ONCE framework
to make est and powernow drivers work properly with SMP.
 1.129.6.1.2.1 23-Sep-2007  wrstuden Sync with somewhat-recent netbsd-4.
 1.129.4.1 10-Dec-2006  yamt sync with head.
 1.129.2.5 27-Jan-2007  ad If running on a PPro or later, at boot patch in versions of spllower() and
similar that use cmpxchg8b instead of cli/sti. Cuts the clock cycles for
splx() by a factor of ~6 on the P4, and ~3 on the PIII when bracketed by
serializing instructions (and hopefully more when not).
 1.129.2.4 12-Jan-2007  ad Sync with head.
 1.129.2.3 11-Jan-2007  ad Checkpoint work in progress.
 1.129.2.2 17-Nov-2006  ad Checkpoint work in progress.
 1.129.2.1 20-Oct-2006  ad - Make ASTs per-LWP.
- The signal stack and signal mask will be per-LWP shortly.

need_resched(), need_proftick(), signotify():

- Prefix with cpu_
- Make per-LWP.
- Send an IPI if the LWP is on another CPU.
 1.133.2.8 07-May-2007  yamt sync with head.
 1.133.2.7 24-Mar-2007  yamt sync with head.
 1.133.2.6 17-Mar-2007  rmind Backport lock.h split into the simplelock.h and other #include changes
from HEAD. This fixes the problems with circular includes.
 1.133.2.5 12-Mar-2007  rmind Sync with HEAD.
 1.133.2.4 03-Mar-2007  yamt curpcb: wrap the definition with parenthesises.
 1.133.2.3 23-Feb-2007  yamt - introduce sys/cpu.h which has cpu_idle and cpu_need_resched.
- use it where appropriate.
- while i'm here, remove several unnecessary #include.
 1.133.2.2 17-Feb-2007  yamt - separate context switching and thread scheduling.
- introduce idle lwp.
- change some related MD/MI interfaces and implement i386 version.
 1.133.2.1 17-Feb-2007  yamt file cpu.h was added on branch yamt-idlelwp on 2007-02-17 10:30:49 +0000
 1.135.2.14 03-Dec-2007  ad Sync with HEAD.
 1.135.2.13 23-Oct-2007  ad Sync with head.
 1.135.2.12 10-Oct-2007  ad Share cpu_intr_p() between amd64/i386.
 1.135.2.11 09-Oct-2007  ad Sync with head.
 1.135.2.10 21-Aug-2007  ad - Add ci_cpumask and use in preference to (1 << ci_cpuid). Some processors
are bad at shifting by non-constant amounts.
- pmap_tlb_shootdown() must be called with preemption disabled.
- Defer waiting for tlb shootdown to complete after kenter_pa()/kremove().
Spin in pmap_update() and in pmap_detactivate(), in case the LWP has been
preempted
- When preparing to send a multicast shootdown IPI, avoid scanning the list
of CPUs if the pmap's bitmask indicates that it's only active locally.
 1.135.2.9 29-Jul-2007  ad - When zeroing/copying pages, use SSE2 movtni to avoid polluting the cache.
- By default, align assembly routines on 32-byte starting boundaries.
- There are now 8 interrupt priority levels, half of which are softints.
Update intrdefs.h to match.
- Always clear/set spinlock words - removes lots of ifdefs.
- Remove the horrible ci_self150 hack that I introduced.
- Overhaul how TLB shootdown is performed. Inspired by a similar change in
OpenBSD but implemented quite differently. This should be a lot faster
but I have not benchmarked it yet.
 1.135.2.8 17-Jun-2007  ad - Increase the number of thread priorities from 128 to 256. How the space
is set up is to be revisited.
- Implement soft interrupts as kernel threads. A generic implementation
is provided, with hooks for fast-path MD code that can run the interrupt
threads over the top of other threads executing in the kernel.
- Split vnode::v_flag into three fields, depending on how the flag is
locked (by the interlock, by the vnode lock, by the file system).
- Miscellaneous locking fixes and improvements.
 1.135.2.7 09-Jun-2007  ad Sync with head.
 1.135.2.6 27-May-2007  ad Sync with head.
 1.135.2.5 29-Apr-2007  ad Replace another simplelock.
 1.135.2.4 28-Apr-2007  ad - Make the PV cache per-CPU and eliminate the global pvalloc_lock. Cuts
contention on the freelist locks by a factor of ~50 on a dual core box.
- Mirror a patch for amd64 posted by oster@, and make the TLB shootdown
freelist per-CPU. Increase the number of TLB shootdown jobs from 16
to 32 per CPU.
 1.135.2.3 10-Apr-2007  ad Sync with head.
 1.135.2.2 05-Apr-2007  ad Fix the pmap locking.
 1.135.2.1 13-Mar-2007  ad Sync with head.
 1.136.4.1 29-Mar-2007  reinoud Pullup to -current
 1.136.2.1 11-Jul-2007  mjf Sync with head.
 1.140.2.3 03-Oct-2007  garbled Sync with HEAD
 1.140.2.2 26-Jun-2007  garbled Sync with HEAD.
 1.140.2.1 22-May-2007  matt Update to HEAD.
 1.143.10.3 23-Mar-2008  matt sync with HEAD
 1.143.10.2 09-Jan-2008  matt sync with HEAD
 1.143.10.1 06-Nov-2007  matt sync with HEAD
 1.143.8.6 09-Dec-2007  jmcneill Sync with HEAD.
 1.143.8.5 29-Oct-2007  joerg Sync with HEAD.
 1.143.8.4 28-Oct-2007  joerg Sync with HEAD.
 1.143.8.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.143.8.2 02-Oct-2007  joerg Sync with HEAD.
 1.143.8.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.143.4.1 03-Sep-2007  skrll Sync with HEAD.
 1.144.2.3 07-Oct-2007  yamt g/c nkpde.
 1.144.2.2 06-Oct-2007  yamt sync with head.
 1.144.2.1 23-Sep-2007  yamt - sync with amd64.
- pmap_alloc_level: remove fast call special case.
- tweak some printf to work for both of LP64 and LP32.
- remove machdep.nkpde sysctl.
- remove automatic adjustment of nkpde for now. will revisit later.
 1.146.2.2 13-Nov-2007  bouyer Sync with HEAD
 1.146.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.150.4.4 26-Dec-2007  ad Sync with head.
 1.150.4.3 26-Dec-2007  ad Back out the dumppcb changes for the time being.
 1.150.4.2 12-Dec-2007  ad - Dump basic trap and register info before entering the debugger, in
case ddb screws the machine up further.
- Fill dumppcb asap so that gdb has less chance to get confused.
 1.150.4.1 08-Dec-2007  ad Sync with head.
 1.150.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.150.2.2 27-Dec-2007  mjf Sync with HEAD.
 1.150.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.151.4.4 19-Jan-2008  bouyer Sync with HEAD
 1.151.4.3 08-Jan-2008  bouyer Sync with HEAD
 1.151.4.2 06-Jan-2008  bouyer Merge needed changes to genassym.cf and locore.S for xeni386 back to
arch/i386. Switch xeni386 to use the arch/i386 cpu.h.
 1.151.4.1 02-Jan-2008  bouyer Sync with HEAD
 1.161.6.3 17-Jan-2009  mjf Sync with HEAD.
 1.161.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.161.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.161.2.1 24-Mar-2008  keiichi sync with head.
 1.165.2.2 04-Jun-2008  yamt sync with head
 1.165.2.1 18-May-2008  yamt sync with head.
 1.167.2.2 04-May-2009  yamt sync with head.
 1.167.2.1 16-May-2008  yamt sync with head.
 1.169.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.175.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.176.12.1 17-Aug-2011  cherry Pullup relevant changes from -current
 1.176.2.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.177.6.1 18-Feb-2012  mrg merge to -current.
 1.177.2.1 17-Apr-2012  yamt sync with head
 1.178.6.1 03-Dec-2017  jdolecek update from HEAD
 1.179.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.179.4.1 10-Jun-2019  christos Sync with HEAD
 1.179.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.9 10-May-2008  ad Merge cpu_counter.h.
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 14-Nov-2007  ad branches: 1.7.14; 1.7.16; 1.7.18;
- Remove I486_CPU, I586_CPU, I686_CPU options. They buy us nothing and
clutter the code significantly.
- Remove pccons.
 1.6 17-Oct-2007  garbled branches: 1.6.2;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.5 07-Jul-2007  tsutsui branches: 1.5.8; 1.5.10; 1.5.14;
Move x86 common cpu_counter functions into <x86/cpu_counter.h>.
 1.4 16-Feb-2006  perry branches: 1.4.24; 1.4.26; 1.4.32;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.3 24-Dec-2005  perry branches: 1.3.2; 1.3.4; 1.3.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 25-Jun-2005  fair branches: 1.2.2;
document more precisely the Cyrix TSC lossage: if you execute "hlt"
when in powersave mode, the TSC stops counting!
 1.1 05-Feb-2003  nakayama branches: 1.1.2; 1.1.16;
Share i386/tsc_microtime.c with alpha and sparc64 as kern_microtime.c.
(approved by martin)
 1.1.16.1 12-Jul-2005  tron Pull up revision 1.2 (requested by fair in ticket #554):
document more precisely the Cyrix TSC lossage: if you execute "hlt"
when in powersave mode, the TSC stops counting!
 1.1.2.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.2.2.2 15-Nov-2007  yamt sync with head.
 1.2.2.1 03-Sep-2007  yamt sync with head.
 1.3.6.1 22-Apr-2006  simonb Sync with head.
 1.3.4.1 09-Sep-2006  rpaulo sync with head
 1.3.2.1 18-Feb-2006  yamt sync with head.
 1.4.32.1 03-Oct-2007  garbled Sync with HEAD
 1.4.26.1 11-Jul-2007  mjf Sync with head.
 1.4.24.2 03-Dec-2007  ad Sync with HEAD.
 1.4.24.1 15-Jul-2007  ad Sync with head.
 1.5.14.1 18-Nov-2007  bouyer Sync with HEAD
 1.5.10.2 09-Jan-2008  matt sync with HEAD
 1.5.10.1 06-Nov-2007  matt sync with HEAD
 1.5.8.1 21-Nov-2007  joerg Sync with HEAD.
 1.6.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.7.18.1 16-May-2008  yamt sync with head.
 1.7.16.1 18-May-2008  yamt sync with head.
 1.7.14.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1 27-Feb-2016  tls branches: 1.1.2; 1.1.18;
Add cpu_rng, a framework for simple on-CPU random number generators.
 1.1.18.2 03-Dec-2017  jdolecek update from HEAD
 1.1.18.1 27-Feb-2016  jdolecek file cpu_rng.h was added on branch tls-maxphys on 2017-12-03 11:36:17 +0000
 1.1.2.2 19-Mar-2016  skrll Sync with HEAD
 1.1.2.1 27-Feb-2016  skrll file cpu_rng.h was added on branch nick-nhusb on 2016-03-19 11:30:00 +0000
 1.40 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.39 26-Sep-2007  ad x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.38 04-Mar-2007  christos branches: 1.38.2; 1.38.10; 1.38.18; 1.38.20; 1.38.22;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.37 09-Feb-2007  ad branches: 1.37.2;
Merge newlock2 to head.
 1.36 14-Jan-2007  ad .. but only if _KERNEL is defined.
 1.35 14-Jan-2007  ad On second thought, implement x86_pause() as a regular function. The small
delay from the call is useful for spinlock backoff.
 1.34 01-Jan-2007  ad Report on and where possible, try to work around some of the known errata
for Athlon 64 and Opteron processors. Tested briefly by cube@ and elad@.
 1.33 26-Aug-2006  ad branches: 1.33.2;
Add x86_sfence(), x86_mfence().
 1.32 19-Aug-2006  dsl Change the 'asm' pattern for lidt so that gcc4 knows it references memory
and doesn't optimise out the assignments to the descriptor memory area.
i386 kernels now build with -Os (and -O3) applied to machdep.c
 1.31 28-Dec-2005  perry branches: 1.31.4; 1.31.8; 1.31.18;
inline -> __inline
 1.30 26-Dec-2005  perry u_intN_t -> uintN_t
 1.29 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.28 14-Jan-2004  yamt branches: 1.28.14; 1.28.16;
issue memory read barrier for BUS_DMASYNC_POSTREAD operation.
PR/21665 from Stephan Uphoff.
 1.27 27-Oct-2003  junyoung Nuke __P().
 1.26 26-Jun-2003  drochner branches: 1.26.2;
make cpu_feature unsigned, just like ci_feature_flags
 1.25 08-May-2003  fvdl Move x86_pause() out of ifdef _KERNEL.
 1.24 08-May-2003  fvdl Add x86_pause() inline function, containing the "pause" instruction
for i386, and nothing for amd64. Sprinkle it in various spinloops,
as recommended by Intel.
 1.23 04-Mar-2003  fvdl Define read_psl and write_psl as aliases for read_eflags and write_eflags.
 1.22 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.21 03-Jul-2002  yamt add KSTACK_CHECK_DR0.
 1.20 31-Jul-2001  thorpej branches: 1.20.2; 1.20.14;
Set up function pointers for copyin/copyout in preparation for
adding optimized versions for various CPU classes/models.

Split the 386 version of copyout into a separate routine, and
add a 486 version that doesn't have the class/page-writeability
check.
 1.19 28-Mar-2000  thorpej branches: 1.19.8; 1.19.10;
The assembler understands rdmsr, wrmsr, rdtsc, and rdpmc, so there's
no need to use .byte.
 1.18 28-Mar-2000  thorpej Add functions to read the TSC and Performance Counters.
 1.17 24-Mar-2000  thorpej Add some MSR-related calls. From FreeBSD.
 1.16 15-Aug-1998  mycroft branches: 1.16.12;
Assign my copyrights to TNF.
 1.15 15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.14 26-Feb-1998  perry define kernel only inline static functions only #ifdef _KERNEL
 1.13 25-Feb-1998  perry add /* LINTLIBRARY */ to supress lots of "unused function" warnings
from lint.
 1.12 05-Feb-1998  drochner provide pushfl/popfl to C code
 1.11 09-Sep-1997  mycroft Remove some vestiges of BDB.
 1.10 05-Sep-1997  chuck add invlpg, and rcr4/lcr4
 1.9 05-Jul-1997  thorpej branches: 1.9.2;
Add a breakpoint() inline, used by DDB and KGDB.
 1.8 27-Oct-1994  cgd new RCS ID format.
 1.7 09-Oct-1994  mycroft #include cpufunc.h from pmap.h.
 1.6 09-Oct-1994  mycroft Eliminate register restrictions where possible.
 1.5 28-Jan-1994  jtc branches: 1.5.2; 1.5.4;
Fix spelling error in Copyright notice
 1.4 03-Jan-1994  mycroft Inline all the [lr]cr[023]() `functions' in cpufunc.h.
 1.3 20-Dec-1993  mycroft Remove some things which should not be here.
 1.2 02-Aug-1993  mycroft branches: 1.2.2;
Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1 06-Jun-1993  cgd incorporate Bruce Evans' interrupt changes, as hacked by Rod grimes,
for patchkit patch 158. it appears to work well.
 1.2.2.3 11-Oct-1993  mycroft Move {disable,enable}_intr() to psl.h, and inline all of {in,out}{,s}[bwl] in
pio.h.
 1.2.2.2 10-Oct-1993  mycroft Change an `unsigned int' to `u_int'.
 1.2.2.1 10-Oct-1993  mycroft Add inline versions of lidt(), lldt(), ltr(), tlbflush(), lcr0(), rcro(),
rcr2(), lcr3(), and rcr3().
 1.5.4.1 11-Oct-1994  mycroft Update from trunk.
 1.5.2.2 01-Feb-1994  mycroft Remove *_intr().
 1.5.2.1 28-Jan-1994  mycroft file cpufunc.h was added on branch magnum on 1994-02-01 18:39:24 +0000
 1.9.2.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.2.1 06-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.16.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19.10.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.19.10.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.19.10.1 03-Aug-2001  lukem update to -current
 1.19.8.3 18-Oct-2002  nathanw Catch up to -current.
 1.19.8.2 01-Aug-2002  nathanw Catch up to -current.
 1.19.8.1 24-Aug-2001  nathanw Catch up with -current.
 1.20.14.1 16-Jul-2002  gehenna catch up with -current.
 1.20.2.3 19-Aug-2002  sommerfeld merged with -current as of today.
rearranged gdt init to deal with KVM86 changes; however, KVM86 has no
chance of working yet; good thing it's not part of GENERIC
 1.20.2.2 22-Sep-2001  sommerfeld Move tlbflushg to cpufunc.h
 1.20.2.1 31-Jul-2001  sommerfeld file cpufunc.h was added on branch sommerfeld_i386mp_1 on 2001-09-22 23:07:34 +0000
 1.26.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.26.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.26.2.1 03-Aug-2004  skrll Sync with HEAD
 1.28.16.5 27-Oct-2007  yamt sync with head.
 1.28.16.4 03-Sep-2007  yamt sync with head.
 1.28.16.3 26-Feb-2007  yamt sync with head.
 1.28.16.2 30-Dec-2006  yamt sync with head.
 1.28.16.1 21-Jun-2006  yamt sync with head.
 1.28.14.1 28-Sep-2008  jdc Pull up revisions:
sys/arch/amd64/include/cpufunc.h patch
sys/arch/i386/include/cpufunc.h patch
sys/arch/x86/x86/bus_dma.c 1.45 via patch
requested by bouyer in ticket 1945.
 1.31.18.1 27-Aug-2006  riz Pull up following revision(s) (requested by dsl in ticket #67):
sys/arch/i386/include/cpufunc.h: revision 1.32
Change the 'asm' pattern for lidt so that gcc4 knows it references memory
and doesn't optimise out the assignments to the descriptor memory area.
i386 kernels now build with -Os (and -O3) applied to machdep.c
 1.31.8.1 03-Sep-2006  yamt sync with head.
 1.31.4.1 09-Sep-2006  rpaulo sync with head
 1.33.2.4 01-Feb-2007  ad Sync with head.
 1.33.2.3 27-Jan-2007  ad If running on a PPro or later, at boot patch in versions of spllower() and
similar that use cmpxchg8b instead of cli/sti. Cuts the clock cycles for
splx() by a factor of ~6 on the P4, and ~3 on the PIII when bracketed by
serializing instructions (and hopefully more when not).
 1.33.2.2 25-Jan-2007  ad Add x86_flush(): flush pipelines by doing a far return.
 1.33.2.1 12-Jan-2007  ad Sync with head.
 1.37.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.38.22.1 06-Oct-2007  yamt sync with head.
 1.38.20.1 06-Nov-2007  matt sync with HEAD
 1.38.18.1 02-Oct-2007  joerg Sync with HEAD.
 1.38.10.1 03-Oct-2007  garbled Sync with HEAD
 1.38.2.1 09-Oct-2007  ad Sync with head.
 1.15 01-Jan-2007  ad Report on and where possible, try to work around some of the known errata
for Athlon 64 and Opteron processors. Tested briefly by cube@ and elad@.
 1.14 16-Jul-2005  grant branches: 1.14.26;
fix typo in comment
 1.13 17-Nov-2001  christos branches: 1.13.2; 1.13.18; 1.13.34;
Add transmeta crusoe cpu support from toshi.
 1.12 29-Sep-2000  fvdl branches: 1.12.4; 1.12.6;
Bump CPU_MAXFAMILY to 7.
 1.11 15-Oct-1998  bad branches: 1.11.12;
Add CPUVENDOR_IDT and CPU_C6.
 1.10 18-Oct-1997  mikel branches: 1.10.2;
cosmetic cleanup (newlines, comments)
 1.9 17-Oct-1997  bouyer Add detection of cyrix/ibm 6x86 cpu: these CPU pass the 486 test, but
fail the cyrix486 one. Add a test which succeed for all cyrix CPUs (from
FreeBSD).
 1.8 03-Dec-1996  fvdl Added types/definitions for changed CPU recognition code.
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 24-May-1994  deraadt cyrix CPU_486DLC
 1.5 28-Jan-1994  jtc branches: 1.5.2;
Fix spelling error in Copyright notice
 1.4 19-Dec-1993  mycroft Forgot to decrement these.
 1.3 19-Dec-1993  mycroft Clean up trap handling and macroize interrupt entry and exit code. From
magnum branch.
 1.2 21-May-1993  cgd branches: 1.2.4;
add "cpu classes" in addition to cpu names, put cpu names in table, along
with mapping to classes. this is for upgraded cpu-id code coming "soon"
 1.1 21-May-1993  cgd move cpu types out of assym.s and into cputypes.h
and have that file included by cpu.h and by locore.s
 1.2.4.1 08-Nov-1993  mycroft Garbage collect some constants, and the entire 286 nonsense. (Like we even
get to start() on a 286? NOT!)
 1.5.2.2 28-Jan-1994  jtc Fix spelling error in Copyright notice
 1.5.2.1 28-Jan-1994  jtc file cputypes.h was added on branch magnum on 1994-01-28 23:44:12 +0000
 1.10.2.1 16-Oct-1998  cgd pull up rev 1.11 from trunk (bad)
 1.11.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.4.1 08-Jan-2002  nathanw Catch up to -current.
 1.13.34.2 26-Feb-2007  yamt sync with head.
 1.13.34.1 21-Jun-2006  yamt sync with head.
 1.13.18.1 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.13.2.2 17-Nov-2001  christos Add transmeta crusoe cpu support from toshi.
 1.13.2.1 17-Nov-2001  christos file cputypes.h was added on branch sommerfeld_i386mp_1 on 2001-11-17 08:21:44 +0000
 1.14.26.1 12-Jan-2007  ad Sync with head.
 1.5 01-Mar-2003  fvdl Redirect to x86/cpuvar.h
 1.4 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.3 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file cpuvar.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.6 10-Jan-2001  sommerfeld Significant rewrite of slave CPU attach and initialization, centering
on identifycpu() and spreading outward.

Separate feature probes (cpuid invocation), which runs on the cpu
being attached, from the display of this information, which runs on
the boot cpu; remove some of the probe code from locore as it doesn't
need to run that early.

We now spin up secondary cpu's during cpu_attach, have them do a cpu
feature probe, and then have them spin waiting for a "go" signal.

We no longer pay attention to the cpu signature and cpuid features
reported by the MP BIOS since those are known to be truncated for at
least some bioses.

We now do npx initialization (including FDIV bug detection) on all
cpus.

XXX Change some of the cyrix bug workarounds to fit the new
identifycpu() system; this is untested.
 1.1.2.5 23-Sep-2000  sommerfeld Preliminary support for cloning MTRR values between CPU's at boot time.
XXX no API to *set* MTRR values yet.
 1.1.2.4 18-Aug-2000  sommerfeld Add cleanup hook to return the NVRAM reset byte to its original value.
 1.1.2.3 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.2 21-Feb-2000  sommerfeld MP: attempt to deal with the case where the BSP is at apic id 1 instead
of apic id 0.
 1.1.2.1 20-Feb-2000  sommerfeld (some) per-CPU state.
 1.2.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file cpuvar.h was added on branch nathanw_sa on 2002-10-18 02:37:54 +0000
 1.6 26-Apr-2011  joerg Remove Darwin, MACH and Mach-O support.
 1.5 28-Apr-2008  martin branches: 1.5.14; 1.5.22; 1.5.28;
Remove clause 3 and 4 from TNF licenses
 1.4 25-Jun-2005  christos branches: 1.4.82; 1.4.84; 1.4.86;
move stack somewhere where it is mappable, and add defines for i386 commpage.
 1.3 04-Jul-2004  christos Add USRSTACK definitions
 1.2 05-Dec-2003  christos Add a dummy darwin_slock
 1.1 12-Dec-2002  christos branches: 1.1.6; 1.1.8;
This new file is wanted by compat_darwin.
 1.1.8.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.8.1 03-Aug-2004  skrll Sync with HEAD
 1.1.6.2 19-Dec-2002  thorpej Sync with HEAD.
 1.1.6.1 12-Dec-2002  thorpej file darwin_machdep.h was added on branch nathanw_sa on 2002-12-19 00:33:51 +0000
 1.4.86.1 16-May-2008  yamt sync with head.
 1.4.84.1 18-May-2008  yamt sync with head.
 1.4.82.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.5.22.1 31-May-2011  rmind sync with head
 1.5.14.1 02-May-2011  jym Sync with head.
 1.31 06-Nov-2017  christos Cleanup and clarify the ELFSIZE mess:

We now have 2 variables automatically set in elf_machdep.h:

ARCH_ELFSIZE: the size for userland binaries
KERN_ELFSIZE: the size for the kernel binaries

DB_ELFSIZE has been deleted and KERN_ELFSIZE should have always the
same values DB_ELFSIZE used to have.

In sys/exec_elf.h, if ELFSIZE is not set, it is set to KERN_ELFSIZE
for the kernel and ARCH_ELFSIZE for userland. These defaults should
eliminate the need for most manual ELFSIZE setting.
 1.30 26-May-2011  joerg branches: 1.30.14;
Introduce DDB_EXPR_FMT and replace the logic around DB_EXPR_T_IS_QUAD.
 1.29 11-Apr-2011  mrg obsolete DB_AOUT_SYMBOLS. however, we need to leave most of the code
in db_sym.[ch] as it is used by the elf version of crash(8).

i will be cleaning up the db_sym.c code in a follow up commit to avoid
having dead code compiled.
 1.28 10-Apr-2011  christos Merge db_trace for x86. From: Vladimir Kirillov proger at wilab dot org dot ua
 1.27 07-Mar-2009  ad branches: 1.27.4; 1.27.6;
Make ddb compile and work in userspace. Mostly this is comprised of three
types of changes:

- Add a few new methods to replace stuff like p_find(), CPU_INFO_FOREACH.

- Use db_read_bytes() instead of accessing kernel structures directly,
and similar changes.

- Add ifdef _KERNEL where the above hasn't been done, and an XXX comment.
 1.26 21-Feb-2007  thorpej branches: 1.26.46; 1.26.54; 1.26.60;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.25 01-Apr-2006  cherry branches: 1.25.14;
closes: PR kern/32359

modifies machine/db_machdep.h: BKPT_SET(inst) to BKPT_SET(inst, addr) for all archs ie; passess the
breakpoint address as well.

Patch from cherry@mahiti.org
 1.24 27-Oct-2003  junyoung branches: 1.24.16; 1.24.30; 1.24.32; 1.24.34; 1.24.36; 1.24.38;
Nuke __P().
 1.23 11-Aug-2003  atatat Make sure to wrap include opt_foo.h in _KERNEL_OPT.
 1.22 23-Jun-2003  martin branches: 1.22.2;
Make sure to include opt_foo.h if a defflag option FOO is used.
 1.21 29-Apr-2003  scw Add a BKPT_ADDR() macro which gives MD code a chance to munge a
breakpoint address before it's used. Currently a no-op on all but sh5.

This is useful on sh5, for example, to mask off the instruction
type encoding in the bottom two address bits, and makes it possible
to do "db> break $rXX" instead of manually munging the address.
 1.20 30-Mar-2003  kristerw Remove unneeded cast that prevents PC_REGS from being used as lvalue.
 1.19 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.18 12-May-2002  matt Eliminate commons.
 1.17 17-Jun-2001  sommerfeld branches: 1.17.2;
Add %fs/%gs to trap frame and save/restore them on
trap/interrupt/syscall entry from userspace.

Remove special-case "by hand" validation of fs/gs register values as
well as special handling of them in various signal handling paths.

Now, like %ds and %es, they are validated by the hardware on return to
userland.

This paves the way for the use of %fs for per-cpu data on
multiprocessor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.

Discussed in advance with Frank van der Linden.
 1.16 07-Jun-2001  lukem work around lint issue (inspired by similar work in sparc port)
 1.15 29-Jun-2000  mrg branches: 1.15.2; 1.15.4;
remove include of <vm/vm.h>. <vm/vm.h> -> <uvm/uvm_extern.h>
 1.14 04-Dec-1998  thorpej branches: 1.14.10; 1.14.22;
Support both a.out and Elf32 symbols in DDB.
 1.13 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.12 26-Jun-1997  thorpej #define DB_AOUT_SYMBOLS
 1.11 06-Feb-1997  gwr FIXUP_PC_AFTER_BREAK now takes an arg of type db_regs_t *
 1.10 03-Feb-1997  mycroft db_expr_t became a long.
 1.9 03-May-1996  christos Comment out unused routines; add prototype for kdb_trap
 1.8 27-Oct-1994  cgd new RCS ID format.
 1.7 09-Oct-1994  mycroft Fix typo.
 1.6 09-Oct-1994  mycroft Eliminate i386_saved_state.
 1.5 03-Apr-1994  mycroft branches: 1.5.2;
Clean up #includes.
 1.4 03-Apr-1994  mycroft Clean up #includes.
 1.3 19-Dec-1993  mycroft branches: 1.3.2;
Cleanup from magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.4 14-Nov-1993  mycroft EFL_TF --> PSL_T
 1.2.4.3 13-Nov-1993  mycroft In watchpoint test, check type == T_TRCTRAP, just to be safe.
 1.2.4.2 13-Nov-1993  mycroft Test for watchpoint trap by inspecting the saved image of %dr6.
 1.2.4.1 16-Oct-1993  mycroft VM_MIN_KERNEL_ADDRESS --> VM_MAX_ADDRESS
 1.3.2.2 19-Dec-1993  mycroft Cleanup from magnum branch.
 1.3.2.1 19-Dec-1993  mycroft file db_machdep.h was added on branch magnum on 1993-12-19 03:41:52 +0000
 1.5.2.1 11-Oct-1994  mycroft Update from trunk.
 1.14.22.1 17-Jun-2001  he Pull up revision 1.17 (requested by sommerfeld):
Add %fs/%gs to trap frame and save/restore them on trap/interupt/
syscall entry from userspace.

Remove special-case ``by hand'' validation of %fs/%gs register
values s well as special handling of them in various signal
handling paths. Now, like %ds and %es, they are validated by
the hardware on return to userland.

This paves the way for the use of %fs for per-cpu data on multi-
processor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.
 1.14.10.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.4.3 18-Oct-2002  nathanw Catch up to -current.
 1.15.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.15.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.15.2.5 18-May-2002  sommerfeld Catch up with -current. (commons elimination, changes to MI pci framework)
 1.15.2.4 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.15.2.3 21-Aug-2000  sommerfeld Add prototype for cpu_debug_dump
 1.15.2.2 18-Aug-2000  sommerfeld Preliminary multi-CPU support. Stop other cpu's on entry to DDB,
resume on exit. Add "mach cpu" command to display the list of CPU's,
and "mach cpu N" to view the registers of cpu N.
 1.15.2.1 29-Jun-2000  sommerfeld file db_machdep.h was added on branch sommerfeld_i386mp_1 on 2000-08-18 13:28:27 +0000
 1.17.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.17.2.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.22.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.22.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.22.2.1 03-Aug-2004  skrll Sync with HEAD
 1.24.38.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.24.36.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.24.34.1 11-Apr-2006  yamt sync with head
 1.24.32.1 22-Apr-2006  simonb Sync with head.
 1.24.30.1 09-Sep-2006  rpaulo sync with head
 1.24.16.2 26-Feb-2007  yamt sync with head.
 1.24.16.1 21-Jun-2006  yamt sync with head.
 1.25.14.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.26.60.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.26.60.3 02-May-2011  jym Sync with head.
 1.26.60.2 01-Nov-2009  jym Sync with HEAD.
 1.26.60.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.26.54.1 28-Apr-2009  skrll Sync with HEAD.
 1.26.46.1 04-May-2009  yamt sync with head.
 1.27.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.27.4.2 31-May-2011  rmind sync with head
 1.27.4.1 21-Apr-2011  rmind sync with head
 1.30.14.1 03-Dec-2017  jdolecek update from HEAD
 1.16 30-Aug-2011  bouyer Add getlabelusesmbr(), as proposed in
http://mail-index.netbsd.org/tech-userlevel/2011/08/25/msg005404.html
This is used by disk tools such as disklabel(8) to dynamically decide is
the undelyling platform uses a disklabel-in-mbr-partition or not
(instead of using a compile-time list of ports).
getlabelusesmbr() reads the sysctl kern.labelusesmbr, takes its value from the
machdep #define LABELUSESMBR.
For evbmips, make LABELUSESMBR 1 if the platform uses pmon
as bootloader, and 0 (the previous value) otherwise.
 1.15 23-Nov-2009  pooka If cpu_disklabel includes struct dkbad, define __HAVE_DISKLABEL_DKBAD.
This allows use of subr_disk_mbr on all archs. Default to it for
the rump disk component. No functional change for regular kernels.
(The other option would've been to include dkbad in disklabels
everywhere, but arguably this approach has less possible side-effects,
especially given that wedges and related magic will take over the
world any second now).
 1.14 26-Oct-2008  mrg branches: 1.14.8;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.13 12-Jun-2005  dyoung branches: 1.13.82; 1.13.86; 1.13.92;
Make disklabel(8) and fdisk(8) into "host tools " last step: build
and install ${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-disklabel,
${TOOLDIR}/bin/${MACHINE_GNU_PLATFORM}-fdisk by "reaching over" to
the sources in ${NETBSDSRCDIR}/sbin/{disklabel fdisk}/.

To avoid clashes with a build-host's header files, especially on
*BSD, the host-tools versions of fdisk and disklabel search for
#includes such as disklabel.h, disklabel_acorn.h, disklabel_gpt.h,
and bootinfo.h in a new #includes namespace, nbinclude/. That is,
they #include <nbinclude/sys/disklabel.h>, <nbinclude/machine/disklabel.h>,
<nbinclude/sparc64/disklabel.h>, instead of <sys/disklabel.h> and
such. I have also updated the system headers to #include from
nbinclude/-space when HAVE_NBTOOL_CONFIG_H is #defined.
 1.12 08-Oct-2003  lukem Overhaul MBR handling (part 1):

<sys/bootblock.h>:
* Added definitions for the Master Boot Record (MBR) used by
a variety of systems (primarily i386), including the format
of the BIOS Parameter Block (BPB).
This information was cribbed from a variety of sources
including <sys/disklabel_mbr.h> which this is a superset of.

As part of this, some data structure elements and #defines
were renamed to be more "namespace friendly" and consistent
with other bootblocks and MBR documentation.
Update all uses of the old names to the new names.

<sys/disklabel_mbr.h>:
* Deprecated in favor of <sys/bootblock.h> (the latter is more
"host tool" friendly).

amd64 & i386:
* Renamed /usr/mdec/bootxx_dosfs to /usr/mdec/bootxx_msdos, to
be consistent with the naming convention of the msdosfs tools.

* Removed /usr/mdec/bootxx_ufs, as it's equivalent to bootxx_ffsv1
and it's confusing to have two functionally equivalent bootblocks,
especially given that "ufs" has multiple meanings (it could be
a synonym for "ffs", or the group of ffs/lfs/ext2fs file systems).

* Rework pbr.S (the first sector of bootxx_*):
+ Ensure that BPB (bytes 11..89) and the partition table
(bytes 446..509) do not contain code.
+ Add support for booting from FAT partitions if BOOT_FROM_FAT
is defined. (Only set for bootxx_msdos).
+ Remove "dummy" partition 3; if people want to installboot(8)
these to the start of the disk they can use fdisk(8) to
create a real MBR partition table...
+ Compile with TERSE_ERROR so it fits because of the above.
Whilst this is less user friendly, I feel it's important
to have a valid partition table and BPB in the MBR/PBR.

* Renamed /usr/mdec/biosboot to /usr/mdec/boot, to be consistent
with other platforms.

* Enable SUPPORT_DOSFS in /usr/mdec/boot (stage2), so that
we can boot off FAT partitions.

* Crank version of /usr/mdec/boot to 3.1, and fix some of the other
entries in the version file.

installboot(8) (i386):
* Read the existing MBR of the filesystem and retain the BIOS
Parameter Block (BPB) in bytes 11..89 and the MBR partition
table in bytes 446..509. (Previously installboot(8) would
trash those two sections of the MBR.)

mbrlabel(8):
* Use sys/lib/libkern/xlat_mbr_fstype.c instead of homegrown code
to map the MBR partition type to the NetBSD disklabel type.


Test built "make release" for i386, and new bootblocks verified to work
(even off FAT!).
 1.11 07-Jul-2003  dsl Remove 'dosparts' it hasn't been used for a while (if ever).
 1.10 10-May-2003  thorpej branches: 1.10.2;
Remove redundant bounds_check_with_label() prototype.
 1.9 02-Jan-2001  tron branches: 1.9.2;
Use highest bit of minor as an extra bit for the partition number to
bump the maximum partition number on NetBSD-i386 to 16. (Approved by fvdl)
 1.8 27-Jan-1999  thorpej branches: 1.8.8; 1.8.20;
Use the MI <sys/disklabel_mbr.h>, not our own machine-dependent
definitions.
 1.7 07-Jul-1998  thorpej Use fixed-size types.
 1.6 22-Feb-1998  drochner -correct misleading name and comment for MBR partition type 14
-add FAT32 and EXT2FS
 1.5 19-Feb-1998  drochner -define new own partition ID for NetBSD (0xa9)
-protect structure definitions from inclusion in assembler files
 1.4 01-Oct-1996  christos branches: 1.4.14;
Fix PR/2782: Remove definition of dos_partitions[].
 1.3 09-Mar-1996  ghudson To enable people to mount DOS partitions on disks with no NetBSD
partition, add the MBR partitions to the default (faked-up)
disklabel used by NetBSD if it can't find a real one. If the
type of the MBR partition is one of the common DOS ones, mark the
partition as having an MSDOS filesystem.
 1.2 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.1 14-Oct-1994  cgd move arch dependence to archs. clean up a bit. deal with weird MAXPARTITONS.
 1.4.14.3 23-Nov-1998  cgd pull up rev 1.5 from trunk (jonathan)
 1.4.14.2 23-Nov-1998  cgd fix a spacing bogon in 1.4.14.1. (space in patch requested by fvdl,
tab on branch, making subsequent pullup harder.)
 1.4.14.1 09-Oct-1998  cgd pull up support for DOS FAT32 and Linux ext2fs partitions in
the default disklabel, via patch. (fvdl)
 1.8.20.1 01-May-2001  he Pull up revision 1.9 (requested by fvdl):
Increase the number of BSD disklabel partitions on i386 to 16.
 1.8.8.1 05-Jan-2001  bouyer Sync with HEAD
 1.9.2.2 02-Jan-2001  tron Use highest bit of minor as an extra bit for the partition number to
bump the maximum partition number on NetBSD-i386 to 16. (Approved by fvdl)
 1.9.2.1 02-Jan-2001  tron file disklabel.h was added on branch sommerfeld_i386mp_1 on 2001-01-02 23:06:55 +0000
 1.10.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.13.92.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.13.86.2 11-Mar-2010  yamt sync with head
 1.13.86.1 04-May-2009  yamt sync with head.
 1.13.82.1 17-Jan-2009  mjf Sync with HEAD.
 1.14.8.1 24-Oct-2010  jym Sync with HEAD
 1.4 17-Jun-1993  mycroft Clean up deleted files.
 1.3 17-Jun-1993  mycroft Make ioctl definitions ANSI-compliant.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.1 24-Sep-2022  riastradh x86: Support EFI runtime services.

This creates a special pmap, efi_runtime_pmap, which avoids setting
PTE_U but allows mappings to lie in what would normally be user VM --
this way we don't fall afoul of SMAP/SMEP when executing EFI runtime
services from CPL 0. SVS does not apply to the EFI runtime pmap.

The mechanism is intended to work with either physical addressing or
virtual addressing; currently the bootloader does physical addressing
but in principle it could be modified to do virtual addressing
instead, if it allocated virtual pages, assigned them in the memory
map, and issued RT->SetVirtualAddressMap.

Not sure pmap_activate_sync and pmap_deactivate_sync are correct,
need more review from an x86 wizard.

If this causes fallout, it can be disabled temporarily without
reverting anything by just making efi_runtime_init return immediately
without doing anything, or by removing options EFI_RUNTIME.

amd64-only for now pending type fixes and testing on i386.
 1.3 19-Dec-1993  mycroft Clean up deleted files.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.14 27-Apr-2015  knakahara fix i386 build for MSI/MSI-X support code.
 1.13 29-Mar-2014  christos branches: 1.13.6;
make pci_intr_string and eisa_intr_string take a buffer and a length
instead of relying in local static storage.
 1.12 17-Nov-2009  dyoung branches: 1.12.12; 1.12.22; 1.12.26;
Delete unused functions eisa_mem_alloc() and eisa_mem_free().
 1.11 27-Jun-2008  cegger branches: 1.11.10;
struct device * -> device_t
 1.10 26-Feb-2003  fvdl branches: 1.10.104; 1.10.108; 1.10.110; 1.10.112;
Redirect some includes to x86/foo.h
 1.9 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.8 11-Aug-2000  thorpej branches: 1.8.2; 1.8.4;
Add functions to read EISA configuration data for MEM, IRQ, DMA, and IO.

XXX Just error stubs on the i386 right now -- someone needs to write
XXX EISA BIOS code for i386.
 1.7 04-Jun-2000  cgd branches: 1.7.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).
 1.6 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.5 19-Mar-1999  cgd branches: 1.5.8; 1.5.16; 1.5.18;
Moved from ../eisa/eisa_machdep.h,v
 1.4 06-Jun-1997  thorpej Pull thorpej-bus-dma branch into mainline.
 1.3 21-Oct-1996  thorpej branches: 1.3.8;
Implement eisa_mem_{alloc,free}(), a method for allocating/freeing
EISA bus physical address space.

This i386 implementation allocates system physical address space
after the end of RAM.
 1.2 09-Apr-1996  cgd make the EISA code look a bit more like the PCI code, in the way
the bus is configured, interrupts are handled, etc. define
eisa_chipset_tag_t and eisa_intr_handle_t types, and the following
functions:
eisa_attach_hook()
eisa_maxslots()
eisa_intr_map()
eisa_intr_string()
eisa_intr_establish()
eisa_intr_disestablish()
to do the right things for the i386.
 1.1 04-Mar-1996  cgd Attach isa, eisa, and pci to mainbus now, rather than root. The i386
now has a single device tree (rather than a forest). Also, attach
EISA only if it's present, and attach in order: PCI, EISA, ISA (most
specific to least specific).
 1.3.8.1 18-May-1997  thorpej Add an external declaration for the eisa dma tag.
 1.5.18.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.5.16.3 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.5.16.2 25-Jun-2000  sommerfeld Merge up to just-post-1.5 -current
 1.5.16.1 29-Feb-2000  sommerfeld mpbiosreg.h
 1.5.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.7.2.1 11-Aug-2000  thorpej Pullup from trunk:
Add EISA configuration readining infrastructure.
 1.8.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.8.2.1 18-Oct-2002  nathanw Catch up to -current.
 1.10.112.1 27-Jun-2008  simonb Sync with head.
 1.10.110.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.108.2 11-Mar-2010  yamt sync with head
 1.10.108.1 04-May-2009  yamt sync with head.
 1.10.104.1 29-Jun-2008  mjf Sync with HEAD.
 1.11.10.1 24-Oct-2010  jym Sync with HEAD
 1.12.26.1 18-May-2014  rmind sync with head
 1.12.22.2 03-Dec-2017  jdolecek update from HEAD
 1.12.22.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.12.12.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.6.1 06-Jun-2015  skrll Sync with HEAD
 1.14 11-Feb-2025  jkoshy Add an alternate spelling for an i386 relocation type.
 1.13 06-Nov-2017  christos branches: 1.13.40;
Cleanup and clarify the ELFSIZE mess:

We now have 2 variables automatically set in elf_machdep.h:

ARCH_ELFSIZE: the size for userland binaries
KERN_ELFSIZE: the size for the kernel binaries

DB_ELFSIZE has been deleted and KERN_ELFSIZE should have always the
same values DB_ELFSIZE used to have.

In sys/exec_elf.h, if ELFSIZE is not set, it is set to KERN_ELFSIZE
for the kernel and ARCH_ELFSIZE for userland. These defaults should
eliminate the need for most manual ELFSIZE setting.
 1.12 02-Feb-2016  christos one more.
 1.11 02-Feb-2016  christos more relocations.
 1.10 30-May-2009  skrll branches: 1.10.22; 1.10.40;
Add TLS relocation definitions.
 1.9 09-Dec-2001  thorpej branches: 1.9.2; 1.9.124; 1.9.138;
Add support for dumping ELF-cormat core files.
 1.8 02-Apr-2000  minoura branches: 1.8.8; 1.8.10;
Move dl* function definitions to libc on ELF.
Based on the patch supplied by Takuya Shiozaki <tshiozak@astec.co.jp>.
See http://mail-index.netbsd.org/tech-userlevel/2000/02/23/0000.html.
 1.7 25-Oct-1999  kleink Update to match new SVR4-style definition names in <sys/exec_elf.h>.
 1.6 25-Feb-1999  christos branches: 1.6.8; 1.6.10; 1.6.12;
Don't need to stick the interpreter at 0 anymore, it relocates itself.
 1.5 07-Feb-1999  christos s/JUMP/JMP/ like every other arch.
 1.4 11-Jan-1999  christos We cannot relocate our interpreter (yet).
 1.3 12-Jul-1998  thorpej Add i386 relocations.
 1.2 11-Oct-1997  christos Add ENDIANNESS constant
 1.1 26-Sep-1996  cgd branches: 1.1.10;
add and use a machine-dependent header, which currently defines some
macros to use to remove #ifdefs from the machine ID case check.
Eventually, these headers will contain other information, e.g.
machine-dependent relocation information, etc.
 1.1.10.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.6.12.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.6.10.1 15-Nov-1999  fvdl Sync with -current
 1.6.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.10.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.8.1 08-Jan-2002  nathanw Catch up to -current.
 1.9.138.2 01-Nov-2009  jym Sync with HEAD.
 1.9.138.1 31-May-2009  jym Sync with HEAD.
 1.9.124.1 20-Jun-2009  yamt sync with head
 1.9.2.2 09-Dec-2001  thorpej Add support for dumping ELF-cormat core files.
 1.9.2.1 09-Dec-2001  thorpej file elf_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-12-09 23:05:58 +0000
 1.10.40.1 19-Mar-2016  skrll Sync with HEAD
 1.10.22.1 03-Dec-2017  jdolecek update from HEAD
 1.13.40.1 02-Aug-2025  perseant Sync with HEAD
 1.29 17-Mar-2000  mycroft branches: 1.29.2;
In the `MY THAT'S GROSS' department...
Eliminate the recursive include of machine/endian.h from sys/endian.h.
 1.28 16-Mar-2000  mycroft Foolish consistency. Mainly, always use underscores and sys/endian.h.
 1.27 21-Aug-1999  simonb branches: 1.27.2;
Include <sys/endian.h> after defining whether where are little- or
big-endian. i386, pc532 and vax still include <machine/byte_swap.h>
and define macros for the {n,h}to{h,n}*() functions. mips also
defines some endian-independent assembly-code aliases for unaligned
memory accesses.
 1.26 24-Jan-1999  mycroft Mark [hn]to[nh][ls]() with __const__, so they are subject to CSE.
 1.25 15-Jan-1999  bouyer Move the bswap functions from libutil to libc (this bups the
minor of libc and the major of libutil). For little-endian architectures
merge the bnswap() assembly versions with nto* and hton* using symbols
aliasing. Use symbol renaming for the bswap function in this case to avoid
namespace pollution.
Declare bswap* in machine/bswap.h, not machine/endian.h. For little-endian
machines, common code for inline macros go in machine/byte_swap.h
Sync libkern with libc.
Adjust #include in kernel sources for machine/bswap.h.
 1.24 16-Dec-1998  kleink Support for compound statements enclosed in parenthes to appear as
expressions is a GNU C extension; mark as such them with __extension__ to
suppress portability warnings. Addresses kern/3562 and misc/6185, as suggested
by Dave Sainty <dave@dtsp.co.nz>.
 1.23 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.22 15-Jan-1998  thorpej Generate dependencies on the CPU type options (I386_CPU, I486_CPU, ...)
 1.21 09-Oct-1997  bouyer Add byte-swapping functions (bswap16, bswap32, bswap64) to libkern.
Only assembly version for i386 bswap16 and bswap32 for now (bswap64 uses
bswap32). Contribution of assembly versions of these are welcome.
Add byte-swapping of ext2fs metadata for big-endian systems.
Tested on i386 and sparc.
 1.20 17-Jul-1997  thorpej branches: 1.20.2;
Give the __GNUC__ versions of ntohl() and friends the proper (in_addr_t
or in_port_t) signature.
 1.19 11-Oct-1996  christos add in_addr_t and in_port_t and use them.
 1.18 08-May-1996  jtc Revert last change.
Changing types from unsigned {long,short} to u_int{32,16}_t causes problems
in a lot of userlevel code because those types aren't defined when machine/
endian.h is included. And IMO including sys/types.h in machine/endian.h
is clearly wrong.

XPG4.2 defines new types in_addr_t and in_port_t for the {h,n}to{n,h}{l,s}
functions. But we don't have time to figure out the implementation issues
given the current release schedule.
 1.17 03-May-1996  christos use u_int32_t instead of unsigned long
and u_int16_t instead of short in the {h,n}to{n,h}{l,s} inline routines
and macros.
 1.16 01-Jun-1995  mycroft Allow [nh]to[hn][ls]() to do constant folding.
 1.15 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.14 27-Oct-1994  cgd new RCS ID format.
 1.13 09-Oct-1994  mycroft Make multiple-inclusion protection consistent.
 1.12 10-Sep-1994  jtc asm -> __asm (PR #463).
 1.11 15-Jul-1994  mycroft Since we're no longer using xchg instructions, there's no reason to prefer
a q reg over and other. Also, fix some types in the case of _POSIX_SOURCE.
 1.10 16-Mar-1994  jtc branches: 1.10.2;
Inline assembly [hn]to[nh][sl] functions used xchgb %h1,%b1 instead of the
faster (on the i486 & i586) rorw $8, %w1. The inline assembly for GCC 1.X
already used rorw. Using rorw is one byte longer, but we wouldn't be
inlining at all if we weren't optimizing for speed.
 1.9 12-Feb-1994  cgd fix from Thomas Eberhardt <thomas@mathematik.uni-Bremen.de>:
byte swap macros used a variable "X" internally, which would get
screwed up if user programs #defined "X". change uses of X to __x.
 1.8 20-Dec-1993  mycroft branches: 1.8.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.7 17-Sep-1993  cgd get rid of the #ifndef KERNEL around the include of sys/cdefs.h,
a la 4.4, because it seriously breaks things otherwise, given
inclusion of endian.h in types.h
 1.6 16-Sep-1993  mycroft Add an #ifndef _POSIX_SOURCE...
 1.5 16-Sep-1993  mycroft Add _QUAD_HIGHWORD and _QUAD_LOWWORD for Torek's quad stuff.
 1.4 16-Aug-1993  jtc branches: 1.4.2;
Declare ntohl, ntohs, htonl, and htons functions.
Use GCC's inline assembly iff we are using GCC.
Use bswap instruction if using gcc and defined(KERNEL) &&
((defined(I486_CPU) || defined(I586_CPU)) && !defined(I386_CPU))
 1.3 22-May-1993  cgd add rcsids to everything and clean up headers
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.8.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.8.2.1 20-Dec-1993  mycroft file endian.h was added on branch magnum on 1993-12-20 05:25:12 +0000
 1.10.2.3 11-Oct-1994  mycroft Update from trunk.
 1.10.2.2 12-Sep-1994  cgd from trunk
 1.10.2.1 15-Jul-1994  cgd from trunk
 1.20.2.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.27.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.29.2.2 17-Mar-2000  mycroft In the `MY THAT'S GROSS' department...
Eliminate the recursive include of machine/endian.h from sys/endian.h.
 1.29.2.1 17-Mar-2000  mycroft file endian.h was added on branch sommerfeld_i386mp_1 on 2000-03-17 00:09:21 +0000
 1.3 30-Jan-2006  dsl Move the definitions of ntohl() and friends into sys/endian.h where they
are defined in terms of bswap32() and bswap16().
This makes the definition be in the same place for all systems regardless
of creed^Wendianness.
 1.2 10-Jun-2004  kleink branches: 1.2.12; 1.2.22;
Reflect <sys/endian.h> rev. 1.4: make htonl() et al. arguments and
results uint{16,32}_t. Noted by Ian Zagorskih.
 1.1 17-Mar-2000  mycroft branches: 1.1.2; 1.1.8; 1.1.32; 1.1.34;
In the `MY THAT'S GROSS' department...
Eliminate the recursive include of machine/endian.h from sys/endian.h.
 1.1.34.1 14-Jun-2004  tron Pull up revision 1.2 (requested by kleink in ticket #467):
Reflect <sys/endian.h> rev. 1.4: make htonl() et al. arguments and
results uint{16,32}_t. Noted by Ian Zagorskih.
 1.1.32.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.32.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.32.1 03-Aug-2004  skrll Sync with HEAD
 1.1.8.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.8.1 17-Mar-2000  bouyer file endian_machdep.h was added on branch thorpej_scsipi on 2000-11-20 20:09:26 +0000
 1.1.2.2 17-Mar-2000  mycroft In the `MY THAT'S GROSS' department...
Eliminate the recursive include of machine/endian.h from sys/endian.h.
 1.1.2.1 17-Mar-2000  mycroft file endian_machdep.h was added on branch sommerfeld_i386mp_1 on 2000-03-17 00:09:21 +0000
 1.2.22.1 01-Feb-2006  yamt sync with head.
 1.2.12.1 21-Jun-2006  yamt sync with head.
 1.7 08-Oct-1996  cgd moved to aout_machdep.h (via repository copy)
 1.6 27-Oct-1994  cgd new RCS ID format.
 1.5 28-Jan-1994  jtc branches: 1.5.2;
Fix spelling error in Copyright notice
 1.4 18-Oct-1993  pk Put definition of __LDPGSZ and `struct relocation_info' where they belong:
in <machine/exec.h>.
 1.3 18-Jun-1993  cgd branches: 1.3.4;
convert magic numbers to network byte order, and attendent changes
 1.2 03-Jun-1993  cgd add prototype for a function to be called from execve to check a_mid type
 1.1 02-Jun-1993  cgd machine-dependent exec stuff
 1.3.4.2 18-Oct-1993  mycroft Merge changes from trunk.
 1.3.4.1 15-Oct-1993  mycroft Define __LDPGSZ.
 1.5.2.2 28-Jan-1994  jtc Fix spelling error in Copyright notice
 1.5.2.1 28-Jan-1994  jtc file exec.h was added on branch magnum on 1994-01-28 23:44:16 +0000
 1.2 12-Feb-2014  dsl Add definitions of the default control words directly to this file
instead of pulling the kernel definition of the fpu (etc) into
userspace programs.
I've included machine/fenv.h into x86/cpu.c to ensure the duplicated
definitions stay in step.
The default control words are now the hardware defaults.
XXX: Anyone care to explain the differences between the i386 and amd64
versions of this file?
 1.1 31-Jul-2010  joerg branches: 1.1.2; 1.1.4; 1.1.6; 1.1.12; 1.1.16; 1.1.26; 1.1.30;
Add support for fenv.h interface for i386 and amd64.

Submitted by Stathis Kamperis as part of GSoC 2010 and ported from
FreeBSD.
 1.1.30.1 18-May-2014  rmind sync with head
 1.1.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.16.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.12.2 05-Mar-2011  rmind sync with head
 1.1.12.1 31-Jul-2010  rmind file fenv.h was added on branch rmind-uvmplock on 2011-03-05 20:50:41 +0000
 1.1.6.2 24-Oct-2010  jym Sync with HEAD
 1.1.6.1 31-Jul-2010  jym file fenv.h was added on branch jym-xensuspend on 2010-10-24 22:48:02 +0000
 1.1.4.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.1.4.1 31-Jul-2010  uebayasi file fenv.h was added on branch uebayasi-xip on 2010-08-17 06:44:37 +0000
 1.1.2.2 11-Aug-2010  yamt sync with head.
 1.1.2.1 31-Jul-2010  yamt file fenv.h was added on branch yamt-nfs-mp on 2010-08-11 22:52:12 +0000
 1.12 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.11 21-May-2001  perry branches: 1.11.2;
remove needless externs in front of function prototypes
 1.10 18-Feb-1998  mycroft branches: 1.10.28;
Include correct information for long doubles (i387 extended precision).
 1.9 03-Feb-1998  mycroft Prototype __flt_rounds() consistently.
 1.8 20-Jun-1995  jtc branches: 1.8.18;
Wrap with #ifndef _XXX_FLOAT_H_/#define _XXX_FLOAT_H_/ ... /#endif.
 1.7 20-Jun-1995  jtc #include <sys/cdefs.h>.
Wrap __flt_rounds() declaration with __BEGIN_DECLS/__END_DECLS.
 1.6 07-Apr-1995  jtc Changed FLT_ROUNDS from constant to a call to __flt_rounds(), so that the
current rounding mode is accurately reported.
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 09-Jul-1993  cgd update for better FP routines, from AT&T & elsewhere
 1.3 22-May-1993  cgd add rcsids to everything and clean up headers
 1.2 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.18.1 08-May-1998  mycroft Sync with trunk, per request of mycroft.
 1.10.28.1 21-Jun-2001  nathanw Catch up to -current.
 1.11.2.2 21-May-2001  perry remove needless externs in front of function prototypes
 1.11.2.1 21-May-2001  perry file float.h was added on branch sommerfeld_i386mp_1 on 2001-05-21 04:47:36 +0000
 1.41 26-Dec-2021  andvar fix various typos, mainly in comments.
 1.40 14-Feb-2019  cherry Welcome XENPVHVM mode.

It is UP only, has xbd(4) and xennet(4) as PV drivers.

The console is com0 at isa and the native portion is very
rudimentary AT architecture, so is probably suboptimal to
run without PV support.
 1.39 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.38 19-Nov-2018  kre Hide differences between i386 and amd64 interrupt frames so XEN does
not need to know there is one. Hopefully unbreak i386 build.
 1.37 12-Aug-2017  maxv branches: 1.37.2; 1.37.4;
Remove the vm86 fields from the trap frame. It seems to me that we could
now remove the '-16' when initializing pcb_esp0.
 1.36 14-Jun-2017  chs add an lwp_trapframe() interface to return an LWP's user trapframe.
needed by dtrace.
 1.35 19-Feb-2012  rmind branches: 1.35.2; 1.35.16;
Remove COMPAT_SA / KERN_SA. Welcome to 6.99.3!
Approved by core@.
 1.34 02-Jun-2011  dsl branches: 1.34.2; 1.34.6;
Replace the trapframe fields for segment registers with two uint16_t
fields - one of which is an explicit pad.
 1.33 14-Nov-2008  ad branches: 1.33.4; 1.33.8; 1.33.10; 1.33.14;
Wrap sigframe_sigcontext in _KERNEL
 1.32 14-Nov-2008  ad Remove some compat ifdefs that aren't really needed.
 1.31 15-Oct-2008  wrstuden branches: 1.31.2;
Merge wrstuden-revivesa into HEAD.
 1.30 28-Apr-2008  martin branches: 1.30.2; 1.30.6;
Remove clause 3 and 4 from TNF licenses
 1.29 17-Oct-2007  garbled branches: 1.29.16; 1.29.18; 1.29.20;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.28 17-May-2007  yamt branches: 1.28.10;
merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.27 09-Feb-2007  ad branches: 1.27.2; 1.27.6; 1.27.8; 1.27.14;
Merge newlock2 to head.
 1.26 26-Dec-2005  perry branches: 1.26.20;
u_intN_t -> uintN_t
 1.25 25-Sep-2003  christos branches: 1.25.16;
constify sendsig/trapsignal
 1.24 10-Sep-2003  christos expose sendsig_sigcontext for compat_16
 1.23 10-Sep-2003  christos #ifdef struct sigframe_sigcontext and struct sigcontext, so that only code
that really needs them, get them.
XXX1: We need to fix the vm86 api.
XXX2: We need to fix the ibcs2 signal delivery mechanism.
 1.22 06-Sep-2003  christos SA_SIGINFO changes.
 1.21 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.20 17-Jan-2003  thorpej branches: 1.20.2;
Merge the nathanw_sa branch.
 1.19 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.18 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.17 23-Jun-2002  thorpej During native signal delivery (and iBCS2, since it uses the native
sigcode), arrange to have the signal handler invoked directly, using
the trampoline only for the return path, saving a call insn. Play
some other stack trickery in the trampoline to turn 2 pushl's into
one movl.
 1.16 17-Jun-2001  sommerfeld branches: 1.16.2; 1.16.14;
Add %fs/%gs to trap frame and save/restore them on
trap/interrupt/syscall entry from userspace.

Remove special-case "by hand" validation of fs/gs register values as
well as special handling of them in various signal handling paths.

Now, like %ds and %es, they are validated by the hardware on return to
userland.

This paves the way for the use of %fs for per-cpu data on
multiprocessor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.

Discussed in advance with Frank van der Linden.
 1.15 08-Feb-2001  christos branches: 1.15.2;
appease lint: use u_int32_t and name the bit fields.
 1.14 11-Dec-2000  tron Protect against multiple inclusion.
 1.13 15-Aug-1998  mycroft branches: 1.13.12; 1.13.20; 1.13.24;
Assign my copyrights to TNF.
 1.12 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.11 01-May-1995  mycroft Add VM86 segment registers to trapframe.
 1.10 27-Oct-1994  cgd new RCS ID format.
 1.9 09-Oct-1994  mycroft Eliminate tf_isp.
 1.8 07-Apr-1994  mycroft branches: 1.8.2;
Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.7 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.6 21-Sep-1993  brezak Include sys/signal.h instead of machine/signal.h
 1.5 19-Sep-1993  brezak Define signal frame here.
 1.4 16-Sep-1993  brezak Changes to use a trap frame for syscalls.
 1.3 27-Jun-1993  andrew branches: 1.3.4;
Clobbered '/*' within comment, to keep gcc -Wall happy.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.4.4 11-Jan-1994  mycroft Put the trapframe back in the old order; the reason for changing it is now
gone.
 1.3.4.3 13-Oct-1993  mycroft Remove if_vec from intrframe, as it no longer exists.
 1.3.4.2 09-Oct-1993  mycroft Rearrange trap and interrupt frames so segment registers are pushed before
pushal.
 1.3.4.1 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.8.2.1 11-Oct-1994  mycroft Update from trunk.
 1.13.24.2 30-Jul-2001  he Pull up revision 1.14 (requested by he):
Protect against multiple inclusion.
 1.13.24.1 17-Jun-2001  he Pull up revision 1.16 (requested by sommerfeld):
Add %fs/%gs to trap frame and save/restore them on trap/interupt/
syscall entry from userspace.

Remove special-case ``by hand'' validation of %fs/%gs register
values s well as special handling of them in various signal
handling paths. Now, like %ds and %es, they are validated by
the hardware on return to userland.

This paves the way for the use of %fs for per-cpu data on multi-
processor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.
 1.13.20.5 25-Jun-2002  sommerfeld Resynch with -current.
 1.13.20.4 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.13.20.3 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.13.20.2 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.13.20.1 24-Aug-2000  sommerfeld Since cpu_switch() is now always entered and left at IPL_HIGH, don't
bother saving CPL as part of the switch. Adjust "struct switchframe"
in frame.h and cpu_fork() in vm_machdep.c to compensate.
 1.13.12.2 11-Feb-2001  bouyer Sync with HEAD.
 1.13.12.1 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.15.2.9 11-Dec-2002  thorpej Sync with HEAD.
 1.15.2.8 18-Oct-2002  nathanw Catch up to -current.
 1.15.2.7 01-Aug-2002  nathanw Catch up to -current.
 1.15.2.6 19-Jul-2002  nathanw Invoke upcalls directly, instead of going through a trampoline.
(Since upcalls shouldn't return at all, even the return part of the
trampoline is unnecessary).
 1.15.2.5 02-Jul-2002  nathanw Whitespace.
 1.15.2.4 17-Nov-2001  nathanw Adapt to new upcall signature and possible argument copying.
 1.15.2.3 24-Aug-2001  nathanw A few files and lwp/proc conversions I missed in the last big update.
GENERIC runs again.
 1.15.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.15.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.16.14.1 16-Jul-2002  gehenna catch up with -current.
 1.16.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.16.2.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.20.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.20.2.1 03-Aug-2004  skrll Sync with HEAD
 1.25.16.3 03-Sep-2007  yamt sync with head.
 1.25.16.2 26-Feb-2007  yamt sync with head.
 1.25.16.1 21-Jun-2006  yamt sync with head.
 1.26.20.2 30-Jan-2007  ad Remove support for SA. Ok core@.
 1.26.20.1 17-Nov-2006  ad Checkpoint work in progress.
 1.27.14.1 22-May-2007  matt Update to HEAD.
 1.27.8.1 11-Jul-2007  mjf Sync with head.
 1.27.6.1 27-May-2007  ad Sync with head.
 1.27.2.1 17-Feb-2007  yamt - separate context switching and thread scheduling.
- introduce idle lwp.
- change some related MD/MI interfaces and implement i386 version.
 1.28.10.1 06-Nov-2007  matt sync with HEAD
 1.29.20.2 04-May-2009  yamt sync with head.
 1.29.20.1 16-May-2008  yamt sync with head.
 1.29.18.1 18-May-2008  yamt sync with head.
 1.29.16.2 17-Jan-2009  mjf Sync with HEAD.
 1.29.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.30.6.2 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.30.6.1 19-Oct-2008  haad Sync with HEAD.
 1.30.2.3 22-Jun-2008  wrstuden Re-add cpu_upcall() and page fault code. i386 kernels now compile.
They don't boot, but that seems to be a consequence of current from the
day this branch was started.
 1.30.2.2 14-May-2008  wrstuden Per discussion with ad, remove most of the #include <sys/sa.h> lines
as they were including sa.h just for the type(s) needed for syscallargs.h.

Instead, create a new file, sys/satypes.h, which contains just the
types needed for syscallargs.h. Yes, there's only one now, but that
may change and it's probably more likely to change if it'd be difficult
to handle. :-)

Per discussion with matt at n dot o, add an include of satypes.h to
sigtypes.h. Upcall handlers are kinda signal handlers, and signalling
is the header file that's already included for syscallargs.h that
closest matches SA.

This shaves about 3000 lines off of the diff of the branch relative
to the base. That also represents about 18% of the total before this
checkin.

I think this reduction is very good thing.
 1.30.2.1 10-May-2008  wrstuden Initial checkin of re-adding SA. Everything except kern_sa.c
compiles in GENERIC for i386. This is still a work-in-progress, but
this checkin covers most of the mechanical work (changing signalling
to be able to accomidate SA's process-wide signalling and re-adding
includes of sys/sa.h and savar.h). Subsequent changes will be much
more interesting.

Also, kern_sa.c has received partial cleanup. There's still more
to do, though.
 1.31.2.1 19-Jan-2009  skrll Sync with HEAD.
 1.33.14.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.33.10.1 06-Jun-2011  jruoho Sync with HEAD.
 1.33.8.1 12-Jun-2011  rmind sync with head
 1.33.4.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.34.6.1 24-Feb-2012  mrg sync to -current.
 1.34.2.1 17-Apr-2012  yamt sync with head
 1.35.16.1 28-Aug-2017  skrll Sync with HEAD
 1.35.2.1 03-Dec-2017  jdolecek update from HEAD
 1.37.4.1 10-Jun-2019  christos Sync with HEAD
 1.37.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.35 30-Jul-2022  riastradh x86: Eliminate mfence hotpatch for membar_sync.

The more-compatible LOCK ADD $0,-N(%rsp) turns out to be cheaper
than MFENCE anyway. Let's save some space and maintenance and rip
out the hotpatching for it.
 1.34 09-Apr-2022  riastradh x86: Every load is a load-acquire, so membar_consumer is a noop.

lfence is only needed for MD logic, such as operations on I/O memory
rather than normal cacheable memory, or special instructions like
RDTSC -- never for MI synchronization between threads/CPUs. No need
for hot-patching to do lfence here.

(The x86_lfence function might reasonably be patched on i386 to do
lfence for MD logic, but it isn't now and this doesn't change that.)
 1.33 01-May-2020  maxv Switch the rest of i386 to the x86_hotpatch mechanism.
 1.32 01-May-2020  maxv Use the hotpatch framework when patching _atomic_cas_64.
 1.31 26-Apr-2020  maxv Use the hotpatch framework for LFENCE/MFENCE.
 1.30 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.29 12-Oct-2019  maxv branches: 1.29.6;
Rewrite the FPU code on x86. This greatly simplifies the logic and removes
the dependency on IPL_HIGH. NVMM is updated accordingly. Posted on
port-amd64 a week ago.

Bump the kernel version to 9.99.16.
 1.28 14-Feb-2019  cherry Welcome XENPVHVM mode.

It is UP only, has xbd(4) and xennet(4) as PV drivers.

The console is com0 at isa and the native portion is very
rudimentary AT architecture, so is probably suboptimal to
run without PV support.
 1.27 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.26 17-Jun-2018  maxv branches: 1.26.2;
i586 and below don't have this 3-byte nop, so use three 1-byte nops,
reported by Nathanial Sloss
 1.25 27-Jan-2018  maxv branches: 1.25.2;
Declare INTR_RECURSE_HWFRAME, same as amd64.
 1.24 27-Jan-2018  maxv Add SMAP support for i386.
 1.23 27-Jan-2018  maxv Remove DO_DEFERRED_SWITCH and DO_DEFERRED_SWITCH_RETRY, unused.
 1.22 27-Jan-2018  maxv Use .pushsection (like amd64), and align INTRENTRY.
 1.21 07-Jan-2018  maxv Switch x86_retpatch[] -> HOTPATCH().
 1.20 07-Jan-2018  maxv Switch x86_lockpatch[] -> HOTPATCH().
 1.19 07-Jan-2018  maxv Implement a real hotpatch feature.

Define a HOTPATCH() macro, that puts a label and additional information
in the new .rodata.hotpatch kernel section. In patch.c, scan the section
and patch what needs to be. Now it is possible to hotpatch the content of
a macro.

SMAP is switched to use this new system; this saves a call+ret in each
kernel entry/exit point.

Many other operating systems do the same.
 1.18 17-Sep-2017  maxv Declare INTRFASTEXIT as a function, like amd64; will be expanded soon.
 1.17 17-Sep-2017  maxv Remove TRAPLOG from i386. Nowadays there are better instrumentation tools,
in both software and hardware.
 1.16 14-Jun-2017  maxv style
 1.15 26-Jul-2011  yamt branches: 1.15.12; 1.15.30; 1.15.46;
comment
 1.14 07-Jul-2008  gmcgarry branches: 1.14.2; 1.14.10;
Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.13 21-Apr-2008  cegger branches: 1.13.2; 1.13.4; 1.13.6;
Access Xen's vcpu info structure per-CPU.
Tested on i386 and amd64 (both dom0 and domU) by me.
Xen2 tested (both dom0 and domU) by bouyer.
OK bouyer
 1.12 29-Feb-2008  yamt branches: 1.12.2;
don't bother to check curlwp==NULL.
 1.11 11-Jan-2008  bouyer branches: 1.11.2; 1.11.6;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.10 29-Nov-2007  yamt branches: 1.10.6;
instead of setting pcb_onfault on every calls of copyin and friends,
make the fault handler investigate program counter of faulting code.
inspired from linux.
 1.9 14-Nov-2007  ad Clear the direction flag on entry to the kernel.
 1.8 18-Oct-2007  yamt branches: 1.8.2;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.7 09-Feb-2007  ad branches: 1.7.6; 1.7.22; 1.7.24; 1.7.26; 1.7.28;
Merge newlock2 to head.
 1.6 08-Dec-2006  yamt - pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.5 12-May-2004  yamt branches: 1.5.12; 1.5.40; 1.5.42;
add a comment to note that INTRFASTEXIT and trap() should be in sync.
 1.4 20-Feb-2004  yamt defer pmap switching until it's really needed
to avoid frequent loading of cr3 register, which involves tlb flush.

with some fixes/improvements from Stephan Uphoff and Bang Jun-Young.
 1.3 04-Oct-2003  junyoung Rearrange instructions for better use of pipeline. This shaves off 0.5%
of time on interrupt/trap entry on my Athlon 1800.
 1.2 17-Jan-2003  thorpej branches: 1.2.2;
Merge the nathanw_sa branch.
 1.1 22-Nov-2002  fvdl branches: 1.1.2;
Asm macros for interrupt/trap entry/exit, used in multiple .S files.
 1.1.2.2 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 22-Nov-2002  thorpej file frameasm.h was added on branch nathanw_sa on 2002-12-11 06:01:00 +0000
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.5.42.1 10-Dec-2006  yamt sync with head.
 1.5.40.2 12-Jan-2007  ad Sync with head.
 1.5.40.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.5.12.7 17-Mar-2008  yamt sync with head.
 1.5.12.6 21-Jan-2008  yamt sync with head
 1.5.12.5 07-Dec-2007  yamt sync with head
 1.5.12.4 15-Nov-2007  yamt sync with head.
 1.5.12.3 27-Oct-2007  yamt sync with head.
 1.5.12.2 26-Feb-2007  yamt sync with head.
 1.5.12.1 30-Dec-2006  yamt sync with head.
 1.7.28.2 18-Nov-2007  bouyer Sync with HEAD
 1.7.28.1 25-Oct-2007  bouyer Sync with HEAD.
 1.7.26.1 29-Sep-2007  yamt DO_DEFERRED_SWITCH, CHECK_DEFERRED_SWITCH: remove an unused argument.
 1.7.24.3 23-Mar-2008  matt sync with HEAD
 1.7.24.2 09-Jan-2008  matt sync with HEAD
 1.7.24.1 06-Nov-2007  matt sync with HEAD
 1.7.22.3 03-Dec-2007  joerg Sync with HEAD.
 1.7.22.2 14-Nov-2007  joerg Sync with HEAD.
 1.7.22.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.7.6.4 03-Dec-2007  ad Sync with HEAD.
 1.7.6.3 03-Dec-2007  ad Sync with HEAD.
 1.7.6.2 30-Oct-2007  ad CHECK_ASTPENDING: no need to check for curlwp == NULL.
 1.7.6.1 23-Oct-2007  ad Sync with head.
 1.8.2.3 18-Feb-2008  mjf Sync with HEAD.
 1.8.2.2 08-Dec-2007  mjf Sync with HEAD.
 1.8.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.10.6.1 09-Jan-2008  bouyer Move Xen bits to i386/include/frameasm.h and add CLI/STI macros for
i386. Make native i386 kernels build again.
 1.11.6.3 28-Sep-2008  mjf Sync with HEAD.
 1.11.6.2 02-Jun-2008  mjf Sync with HEAD.
 1.11.6.1 03-Apr-2008  mjf Sync with HEAD.
 1.11.2.1 24-Mar-2008  keiichi sync with head.
 1.12.2.1 18-May-2008  yamt sync with head.
 1.13.6.1 18-Jul-2008  simonb Sync with head.
 1.13.4.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.2.1 04-May-2009  yamt sync with head.
 1.14.10.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.14.2.2 07-Jul-2008  gmcgarry Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.14.2.1 07-Jul-2008  gmcgarry file frameasm.h was added on branch haad-dm on 2008-07-07 13:01:17 +0000
 1.15.46.1 01-Aug-2017  snj Pull up following revision(s) (requested by maxv in ticket #164):
distrib/sets/lists/base/md.amd64: revision 1.269
distrib/sets/lists/debug/md.amd64: revision 1.97
sys/arch/amd64/conf/GENERIC: revision 1.460
sys/arch/amd64/conf/files.amd64: revision 1.89
sys/arch/i386/conf/GENERIC: revision 1.1157
sys/arch/i386/conf/files.i386: revision 1.379
sys/arch/i386/i386/i386_trap.S: revision 1.7-1.8
sys/arch/i386/include/frameasm.h: revision 1.16
sys/arch/x86/include/sysarch.h: revision 1.12
sys/arch/x86/x86/pmc.c: revision 1.8-1.10
sys/arch/x86/x86/sys_machdep.c: revision 1.36
sys/arch/xen/conf/files.compat: revision 1.26
sys/secmodel/suser/secmodel_suser.c: revision 1.43
sys/sys/kauth.h: revision 1.74
usr.bin/pmc/Makefile: revision 1.5
usr.bin/pmc/pmc.1: revision 1.12-1.13
usr.bin/pmc/pmc.c: revision 1.24-1.25
style
--
style
--
Disable interrupts for T_NMI (inline calltrap). Note that there's still a
way to evade the NMI mode here, if a segment register faults in
INTRFASTEXIT; but we don't care. I didn't test this change, but it seems
fine enough.
--
Make the PMC syscalls privileged.
--
Check argc, and add a message.
--
include opt_pmc.h
--
Build the pmc tool on amd64.
--
Properly handle overflows, and take them into account in userland.
--
Update.
--
Enable PMCs by default.
--
Sort sections. Fix macro usage.
 1.15.30.1 28-Aug-2017  skrll Sync with HEAD
 1.15.12.1 03-Dec-2017  jdolecek update from HEAD
 1.25.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.26.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.26.2.1 10-Jun-2019  christos Sync with HEAD
 1.29.6.1 11-Apr-2020  bouyer Include ci_isources[] for XenPV too.
Adjust spllower() to XenPV needs, and switch XenPV to the native spllower().
Remove xen_spllower().
 1.15 08-Aug-2017  maxv Move freebsd_machdep.h into sys/compat/freebsd, and don't install it. Now,
the compat_freebsd files are all contained in sys/compat/freebsd.
 1.14 29-Jul-2017  maxv Remove unused.
 1.13 12-Feb-2014  dsl branches: 1.13.6;
Change i386 to use x86/fpu.c instead of i386/isa/npx.c
This changes the trap10 and trap13 code to call directly into fpu.c,
removing all the code for T_ARITHTRAP, T_XMM and T_FPUNDA from i386/trap.c
Not all of the code thate appeared to handle fpu traps was ever called!
Most of the changes just replace the include of machine/npx.h with x86/fpu.h
(or remove it entirely).
 1.12 19-Jan-2014  dsl Rip out the code that might once have supported the freebsd ptrace
system calls.
Removes some very dodgy conversions of FP register layouts.
Most of it has been disabled since 2007 when I removed the stackgap.
 1.11 09-Dec-2013  dsl Include machine/npx.h here.
The only file that needs 'struct freebsd_save87' includes it already.
 1.10 08-Dec-2013  dsl Rename the fields of 'struct envxmm' (itself badly named) so that they
are different from those used for the x87 fpu.
Use a union to describe the 64bit 'address' field so that it correctly
spilt for 32bit binaries.
The freebsd emulation defined its own 'struct freebsd_env87' that the
code just assumed matched the netbsd one.
Since this is a hardware structure, just use the netbsd one.
This shouldn't change the binaries except that 'en_fos' used to be
incorrectly a 32bit field.
 1.9 14-Sep-2005  he branches: 1.9.118; 1.9.128; 1.9.134;
Need <compat/sys/sigtypes.h> here for sigset13_t.
 1.8 27-Oct-2003  junyoung branches: 1.8.16;
Nuke __P().
 1.7 06-Sep-2003  christos SA_SIGINFO changes.
 1.6 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.5 04-Jul-2002  thorpej branches: 1.5.2; 1.5.8;
Add kernel support for having userland provide the signal trampoline:

* struct sigacts gets a new sigact_sigdesc structure, which has the
sigaction and the trampoline/version. Version 0 means "legacy kernel
provided trampoline". Other versions are coordinated with machine-
dependent code in libc.
* sigaction1() grows two more arguments -- the trampoline pointer and
the trampoline version.
* A new __sigaction_sigtramp() system call is provided to register a
trampoline along with a signal handler.
* The handler is no longer passed to sensig() functions. Instead,
sendsig() looks up the handler by peeking in the sigacts for the
process getting the signal (since it has to look in there for the
trampoline anyway).
* Native sendsig() functions now select the appropriate trampoline and
its arguments based on the trampoline version in the sigacts.

Changes to libc to use the new facility will be checked in later. Kernel
version not bumped; we will ride the 1.6C bump made recently.
 1.4 27-Oct-2001  jdolecek branches: 1.4.10;
Update freebsd_sigcontext to what FreeBSD currently uses, and save/restore
%fs/%gs as appropriate.

XXX Note that the new sigcontext uses the new sigset_t instead of old
int sc_mask. The new FreeBSD sigcontext doesn't contain any backward
compatibility sc_mask, so basically old FreeBSD application making
use of sigcontext are hosed. This can't be fixed in NetBSD compat code.
 1.3 18-Dec-2000  thorpej branches: 1.3.4; 1.3.6; 1.3.10;
Prototype freebsd_syscall_intern() in freebsd_machdep.h so that
freebsd_exec.c has access to it.
 1.2 11-Sep-1998  mycroft branches: 1.2.12;
Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.1 10-Oct-1995  mycroft FreeBSD binary compatibility module, from Noriyuki Soda.
 1.2.12.1 05-Jan-2001  bouyer Sync with HEAD
 1.3.10.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.3.6.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.3.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.4.2 01-Aug-2002  nathanw Catch up to -current.
 1.3.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.4.10.1 16-Jul-2002  gehenna catch up with -current.
 1.5.8.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.5.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.5.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.5.8.1 03-Aug-2004  skrll Sync with HEAD
 1.5.2.2 04-Jul-2002  thorpej Add kernel support for having userland provide the signal trampoline:

* struct sigacts gets a new sigact_sigdesc structure, which has the
sigaction and the trampoline/version. Version 0 means "legacy kernel
provided trampoline". Other versions are coordinated with machine-
dependent code in libc.
* sigaction1() grows two more arguments -- the trampoline pointer and
the trampoline version.
* A new __sigaction_sigtramp() system call is provided to register a
trampoline along with a signal handler.
* The handler is no longer passed to sensig() functions. Instead,
sendsig() looks up the handler by peeking in the sigacts for the
process getting the signal (since it has to look in there for the
trampoline anyway).
* Native sendsig() functions now select the appropriate trampoline and
its arguments based on the trampoline version in the sigacts.

Changes to libc to use the new facility will be checked in later. Kernel
version not bumped; we will ride the 1.6C bump made recently.
 1.5.2.1 04-Jul-2002  thorpej file freebsd_machdep.h was added on branch sommerfeld_i386mp_1 on 2002-07-04 23:32:06 +0000
 1.8.16.1 21-Jun-2006  yamt sync with head.
 1.9.134.1 18-May-2014  rmind sync with head
 1.9.128.2 03-Dec-2017  jdolecek update from HEAD
 1.9.128.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9.118.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.13.6.1 28-Aug-2017  skrll Sync with HEAD
 1.20 30-Apr-2021  christos Merge the x86 gdt function and constant definitions
 1.19 30-Apr-2021  christos Bump MAX_USERLDT_SIZE to the max size (wastes some memory). wine needs more
than PAGE_SIZE and fails spuriously.
XXX: Note the duplicate definition hacks. Should really create <x86/gdt.h>,
put the just the constants there and unify them.
This would also avoid the hack in: src/tests/lib/libi386/t_user_ldt.c#46
 1.18 25-Apr-2020  bouyer branches: 1.18.6;
Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.17 24-Apr-2020  maxv Give the ldt a fixed size of one page (512 slots), and drop the variable-
sized mechanism that was too complex.

This fixes a race between USER_LDT and SVS: during context switches, the
way SVS installs the new ldt relies on the ldt pointer AND the ldt size,
but both cannot be accessed atomically at the same time.
 1.16 02-Jul-2017  maxv branches: 1.16.16;
Define MINGDTSIZ/MAXGDTSIZ in bytes, not in number of slots; same as
amd64.
 1.15 08-Feb-2017  maxv Remove gdt_reload_cpu. GDTR takes a VA as base, and in our x86
implementation this VA is per-cpu and does not change; there is therefore
no need to remotely reload GDTR.
 1.14 20-Aug-2016  maxv branches: 1.14.2;
Localify.
 1.13 28-Apr-2008  martin branches: 1.13.44; 1.13.64; 1.13.68;
Remove clause 3 and 4 from TNF licenses
 1.12 04-Jan-2008  yamt branches: 1.12.6; 1.12.8; 1.12.10;
i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.11 16-Apr-2007  ad branches: 1.11.12; 1.11.18; 1.11.24;
Fix crappy locking around LDT updates. i386 part of PR kern/36046.
 1.10 27-Oct-2003  junyoung branches: 1.10.16; 1.10.54; 1.10.58; 1.10.60;
Nuke __P().
 1.9 01-Oct-2002  fvdl branches: 1.9.6;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.8 16-Aug-2000  thorpej branches: 1.8.2; 1.8.4;
Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.7 12-May-1999  thorpej branches: 1.7.2; 1.7.10; 1.7.14;
Move the user-set LDT out of the PCB and into the pmap. Applications
which set the LDT and share VM space (e.g. new versions of WINE) expect
the LDT to be logically coupled to the address space. Use the new pmap_fork()
interface to copy non-shared user-set LDTs when the address space is forked.
 1.6 13-Nov-1997  mycroft branches: 1.6.10;
Some general cleanup:
* Call gdt_init() earlier on.
* Don't bother to check for TSS and LDT descriptors in verr_gdt().
* Nuke the sti special case for trace and breakpoint traps.
* Move some variable declarations into more appropriate locations.
 1.5 09-Oct-1997  jtc branches: 1.5.2;
Fix tipo inherited from old version of TNF copyright template.
 1.4 25-Aug-1996  jtk branches: 1.4.10;
add Advanced Power Management driver
Includes bootstrap support from FreeBSD (Tatsumi HOSOKAWA and <ukai>)
 1.3 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.2 18-Feb-1996  mycroft Add the obligatory copyright notice.
 1.1 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.4.10.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.5.2.1 13-Nov-1997  mellon Pull rev 1.6 up from trunk (mycroft)
 1.6.10.1 21-Jun-1999  thorpej Sync w/ -current.
 1.7.14.1 16-Aug-2000  thorpej Update from trunk:
Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.7.10.6 19-Aug-2002  sommerfeld merged with -current as of today.
rearranged gdt init to deal with KVM86 changes; however, KVM86 has no
chance of working yet; good thing it's not part of GENERIC
 1.7.10.5 24-Feb-2002  sommerfeld Initialize gdt on boot cpu earlier in boot instead of in gdt_init().
Put apm back in GENERIC and APM_NO_IDLE in GENERIC.MP.
Subsystems which install gdt entries during autoconf no longer explode.
(Do *not* expect full apm functionality on multiprocessors).
 1.7.10.4 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.7.10.3 07-Jan-2001  sommerfeld Correct merge botches.
Post-merge kernel now boots multiuser.
 1.7.10.2 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.7.10.1 12-Aug-2000  sommerfeld Split creation/allocation of the memory containing the GDT from
loading of the GDT descriptor into the processor; the former happens
once, the latter, once per CPU.
 1.7.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.8.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.8.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.8.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.9.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.9.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.9.6.1 03-Aug-2004  skrll Sync with HEAD
 1.10.60.1 11-Jul-2007  mjf Sync with head.
 1.10.58.1 27-May-2007  ad Sync with head.
 1.10.54.1 07-May-2007  yamt sync with head.
 1.10.16.2 21-Jan-2008  yamt sync with head
 1.10.16.1 03-Sep-2007  yamt sync with head.
 1.11.24.1 08-Jan-2008  bouyer Sync with HEAD
 1.11.18.1 18-Feb-2008  mjf Sync with HEAD.
 1.11.12.1 09-Jan-2008  matt sync with HEAD
 1.12.10.1 16-May-2008  yamt sync with head.
 1.12.8.1 18-May-2008  yamt sync with head.
 1.12.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.13.68.1 20-Mar-2017  pgoyette Sync with HEAD
 1.13.64.2 28-Aug-2017  skrll Sync with HEAD
 1.13.64.1 05-Oct-2016  skrll Sync with HEAD
 1.13.44.1 03-Dec-2017  jdolecek update from HEAD
 1.14.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.16.16.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.18.6.1 13-May-2021  thorpej Sync with HEAD.
 1.11 13-Nov-2017  nakayama Don't write a 1 to the read only RIRR bit in the IOAPIC redirection
register to fix "tlp0: filter setup and transmit timeout" observed
on Hyper-V VMs with the Legacy Network Adapter.

From OpenBSD via PR kern/49323:

https://marc.info/?l=openbsd-cvs&m=146718035432599&w=2

| Modified files:
| sys/arch/amd64/amd64: ioapic.c
| sys/arch/amd64/include: i82093reg.h
|
| Log message:
| Don't write a 1 to the RIRR bit in the IOAPIC redirection register. This bit
| is R/O, and although it should not matter what value is written there,
| Hyper-V's emulated IOAPIC interprets a write of 1 in some unexpected way and
| subsequently blocks interrupt delivery. This primarily manifests itself as
| de(4) timeouts when using Hyper-V VMs with the "Legacy Network Adapter"
| interface.

Tested both amd64 and i386 on Client Hyper-V on Windows 10.
 1.10 23-May-2017  nonaka branches: 1.10.2;
x86: Add preliminary x2APIC support.

x2APIC is used only when x2APIC is enabled in BIOS/UEFI.
LAPIC ID is not supported above 256.
 1.9 25-Nov-2016  maxv Move the virtual address of the LAPIC page out of the data segment on amd64
and i386. The old design was error-prone, and it didn't allow us to map the
data segment with large pages.

Now, the VA is allocated dynamically in the pmap bootstrap code, and entered
manually later. We go from using &local_apic to using *local_apic_va, and we
therefore need one more level of indirection in the asm code.

Discussed on tech-kern.
 1.8 03-Jul-2008  drochner branches: 1.8.40; 1.8.58; 1.8.60; 1.8.62; 1.8.64; 1.8.68;
Remove "struct device" from "struct pic", where it was only real
for ioapics and faked up for others. Add it to "struct ioapic_softc"
for now, until device/softc get split.
This required all typecasts between "struct pic" and "struct ioapic_softc"
to be replaced, I hope I got them all.
functionally tested on i386, compile-tested on xen, untested on amd64
 1.7 08-Dec-2006  yamt branches: 1.7.44; 1.7.48; 1.7.50; 1.7.52;
- pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.6 11-May-2003  fvdl branches: 1.6.18; 1.6.48; 1.6.50;
The i82093 spec is unclear about it, but my assumption that the selected
ioapic register would stick across a read+write appears to be invalid
for some ioapics. So, select it again for the mask write.
 1.5 04-May-2003  fvdl Block level-triggered interrupts at the ioapic if they are deferred.
Avoids interrupt storms seen on some systems. Many thanks to
Stoned Elipot for testing.
 1.4 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.3 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file i82093reg.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld MP: Registers and state definitions for I/O APIC, which routes
interrupts from I/O devices onto the APIC bus.
 1.2.2.3 11-Dec-2002  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file i82093reg.h was added on branch nathanw_sa on 2002-10-18 02:37:55 +0000
 1.6.50.1 10-Dec-2006  yamt sync with head.
 1.6.48.1 12-Jan-2007  ad Sync with head.
 1.6.18.1 30-Dec-2006  yamt sync with head.
 1.7.52.1 03-Jul-2008  simonb Sync with head.
 1.7.50.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.7.48.1 04-May-2009  yamt sync with head.
 1.7.44.1 28-Sep-2008  mjf Sync with HEAD.
 1.8.68.1 03-Jan-2018  snj Pull up following revision(s) (requested by nakayama in ticket #1527):
sys/arch/amd64/include/i82093reg.h: revision 1.9
sys/arch/i386/include/i82093reg.h: revision 1.11
sys/arch/x86/x86/ioapic.c: revision 1.54
Don't write a 1 to the read only RIRR bit in the IOAPIC redirection
register to fix "tlp0: filter setup and transmit timeout" observed
on Hyper-V VMs with the Legacy Network Adapter.
From OpenBSD via PR kern/49323:
https://marc.info/?l=openbsd-cvs&m=146718035432599&w=2
 1.8.64.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.8.62.1 03-Jan-2018  snj Pull up following revision(s) (requested by nakayama in ticket #1527):
sys/arch/amd64/include/i82093reg.h: revision 1.9
sys/arch/i386/include/i82093reg.h: revision 1.11
sys/arch/x86/x86/ioapic.c: revision 1.54
Don't write a 1 to the read only RIRR bit in the IOAPIC redirection
register to fix "tlp0: filter setup and transmit timeout" observed
on Hyper-V VMs with the Legacy Network Adapter.
From OpenBSD via PR kern/49323:
https://marc.info/?l=openbsd-cvs&m=146718035432599&w=2
 1.8.60.2 28-Aug-2017  skrll Sync with HEAD
 1.8.60.1 05-Dec-2016  skrll Sync with HEAD
 1.8.58.1 03-Jan-2018  snj Pull up following revision(s) (requested by nakayama in ticket #1527):
sys/arch/amd64/include/i82093reg.h: revision 1.9
sys/arch/i386/include/i82093reg.h: revision 1.11
sys/arch/x86/x86/ioapic.c: revision 1.54
Don't write a 1 to the read only RIRR bit in the IOAPIC redirection
register to fix "tlp0: filter setup and transmit timeout" observed
on Hyper-V VMs with the Legacy Network Adapter.
From OpenBSD via PR kern/49323:
https://marc.info/?l=openbsd-cvs&m=146718035432599&w=2
 1.8.40.1 03-Dec-2017  jdolecek update from HEAD
 1.10.2.1 21-Nov-2017  martin Pull up following revision(s) (requested by nakayama in ticket #359):
sys/arch/amd64/include/i82093reg.h: revision 1.9
sys/arch/x86/x86/ioapic.c: revision 1.54
sys/arch/i386/include/i82093reg.h: revision 1.11
Don't write a 1 to the read only RIRR bit in the IOAPIC redirection
register to fix "tlp0: filter setup and transmit timeout" observed
on Hyper-V VMs with the Legacy Network Adapter.
From OpenBSD via PR kern/49323:
https://marc.info/?l=openbsd-cvs&m=146718035432599&w=2
Modified files:
sys/arch/amd64/amd64: ioapic.c
sys/arch/amd64/include: i82093reg.h
Log message:
Don't write a 1 to the RIRR bit in the IOAPIC redirection register. This bit
is R/O, and although it should not matter what value is written there,
Hyper-V's emulated IOAPIC interprets a write of 1 in some unexpected way and
subsequently blocks interrupt delivery. This primarily manifests itself as
de(4) timeouts when using Hyper-V VMs with the "Legacy Network Adapter"
interface.
Tested both amd64 and i386 on Client Hyper-V on Windows 10.
 1.7 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.6 13-Jan-2003  fvdl Declare nioapics as well.
 1.5 12-Jan-2003  fvdl Export the ioapic softc linked list, for the benefit of the mpbios code.
 1.4 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.3 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file i82093var.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.5 19-Nov-2000  sommerfeld Notice if multiple handlers with different IPL's share a single interrupt pin.
For now, warn if this is the case; in the future, we'll handle this correctly.
 1.1.2.4 21-Sep-2000  sommerfeld Deal more sanely with ioapic softc lookup in an attempt to deal with
systems which use weird id's for the ioapics.
- Use a linked list rather a fixed-size array indexed by ioapic id.
On all MP systems I've found so far, we only have one, and we only need to
look for them by id when establishing/disestablishing interrupt handlers; this
is not a performance-critical path..
- similarly, use ioapic_find() in mpbios.c rather than reaching into
ioapic.c's data.
While we're here, support single-apic systems which have interrupts
wired to "all ioapics".
 1.1.2.3 27-Feb-2000  sommerfeld multiple-include protection.
flush bogons.
add kludge to let ioapic know who the boot cpu is.
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld MP: Registers and state definitions for I/O APIC, which routes
interrupts from I/O devices onto the APIC bus.
 1.2.2.5 15-Jan-2003  thorpej Sync with HEAD.
 1.2.2.4 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.3 11-Dec-2002  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file i82093var.h was added on branch nathanw_sa on 2002-10-18 02:37:55 +0000
 1.3 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file i82489reg.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.1 20-Feb-2000  sommerfeld MP: registers and variable definitions for the Local APIC, which sits
between the APIC bus and the processor, and does a bunch of useful
things in an MP system:
- accepts APIC bus interrupt requests and passes the interrupt vector
to the processor
- manages the processor's interrupt priority.
- initiates priority-based software interrupts directed at this or
other processors

it also includes a local countdown timer and a few other functions.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file i82489reg.h was added on branch nathanw_sa on 2002-10-18 02:37:55 +0000
 1.5 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.4 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.3 01-Nov-2002  fvdl Make splsched == splclock, and splserial > splsched. Unfortunately,
we have to retain the 'pick unlocked interrupt handler' hack for
the MP case for now.
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file i82489var.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.5 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.1.2.4 30-Apr-2001  sommerfeld Do softints purely in software.

Using the local apic for softints is slow; exactly why isn't clear,
but ripping out the code and using pure-software softints speeds up
ping -f packet rates by more than 5%.
 1.1.2.3 12-Aug-2000  sommerfeld Move lapic_initclocks() prototype to header file.
 1.1.2.2 21-Feb-2000  sommerfeld MP: attempt to deal with the case where the BSP is at apic id 1 instead
of apic id 0.
 1.1.2.1 20-Feb-2000  sommerfeld MP: registers and variable definitions for the Local APIC, which sits
between the APIC bus and the processor, and does a bunch of useful
things in an MP system:
- accepts APIC bus interrupt requests and passes the interrupt vector
to the processor
- manages the processor's interrupt priority.
- initiates priority-based software interrupts directed at this or
other processors

it also includes a local countdown timer and a few other functions.
 1.2.2.4 11-Dec-2002  thorpej Sync with HEAD.
 1.2.2.3 11-Nov-2002  nathanw Catch up to -current
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file i82489var.h was added on branch nathanw_sa on 2002-10-18 02:37:56 +0000
 1.2 02-Mar-2003  fvdl Redirect to x86/
 1.1 22-Nov-2002  fvdl branches: 1.1.2;
New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.1.2.2 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 22-Nov-2002  thorpej file i8259.h was added on branch nathanw_sa on 2002-12-11 06:01:00 +0000
 1.18 09-Aug-2017  maxv Remove ibcs2_machdep.h on i386, and don't install it.
 1.17 10-Dec-2009  matt branches: 1.17.22; 1.17.40;
Change u_long to vaddr_t/vsize_t in exec code where appropriate (mostly
involves setregs and vmcmds). Should result in no code differences.
 1.16 28-Apr-2008  martin branches: 1.16.14;
Remove clause 3 and 4 from TNF licenses
 1.15 20-Dec-2007  dsl branches: 1.15.6; 1.15.8; 1.15.10;
Convert all the system call entry points from:
int foo(struct lwp *l, void *v, register_t *retval)
to:
int foo(struct lwp *l, const struct foo_args *uap, register_t *retval)
Fixup compat code to not write into 'uap' and (in some cases) to actually
pass a correctly formatted 'uap' structure with the right name to the
next routine.
A few 'compat' routines that just call standard ones have been deleted.
All the 'compat' code compiles (along with the kernels required to test
build it).
98% done by automated scripts.
 1.14 27-Oct-2003  junyoung branches: 1.14.16; 1.14.78; 1.14.88; 1.14.92;
Nuke __P().
 1.13 06-Sep-2003  christos SA_SIGINFO changes.
 1.12 17-Jan-2003  thorpej branches: 1.12.2;
Merge the nathanw_sa branch.
 1.11 04-Jul-2002  thorpej branches: 1.11.2;
Add kernel support for having userland provide the signal trampoline:

* struct sigacts gets a new sigact_sigdesc structure, which has the
sigaction and the trampoline/version. Version 0 means "legacy kernel
provided trampoline". Other versions are coordinated with machine-
dependent code in libc.
* sigaction1() grows two more arguments -- the trampoline pointer and
the trampoline version.
* A new __sigaction_sigtramp() system call is provided to register a
trampoline along with a signal handler.
* The handler is no longer passed to sensig() functions. Instead,
sendsig() looks up the handler by peeking in the sigacts for the
process getting the signal (since it has to look in there for the
trampoline anyway).
* Native sendsig() functions now select the appropriate trampoline and
its arguments based on the trampoline version in the sigacts.

Changes to libc to use the new facility will be checked in later. Kernel
version not bumped; we will ride the 1.6C bump made recently.
 1.10 11-Dec-2000  mycroft branches: 1.10.4; 1.10.6; 1.10.18;
Introduce 2 new flags in types.h:
* __HAVE_SYSCALL_INTERN. If this is defined, e_syscall is replaced by
e_syscall_intern, which is called at key places in the kernel. This can be
used to set a MD syscall handler pointer. This obsoletes and replaces the
*_HAS_SEPARATED_SYSCALL flags.
* __HAVE_MINIMAL_EMUL. If this is defined, certain (deprecated) elements in
struct emul are omitted.
 1.9 09-Dec-2000  jdolecek prototype ibcs2_syscall() in compat/ibcs2/ibcs2_exec.c
 1.8 02-Dec-2000  jdolecek add prototype for ibcs2_syscall()
 1.7 02-Dec-2000  jdolecek if IBCS2_MACHDEP_HAS_SEPARATED_SYSCALL is defined, put ibcs2_syscall to
emul_ibcs2
define IBCS2_MACHDEP_HAS_SEPARATED_SYSCALL in i386 ibcs2_machdep.h
 1.6 21-Jun-2000  matt Move COFF_LDPGSZ to ibcs2_machdep.h. Fix nmagic loader to deal with
subpage mappings.
 1.5 10-Jan-2000  matt branches: 1.5.6;
Add some i386 defines.
 1.4 11-Sep-1998  mycroft branches: 1.4.12;
Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.3 05-Mar-1998  scottb Added prototype for ibcs2_sendsig.
 1.2 09-Oct-1997  jtc branches: 1.2.2;
Fix tipo inherited from old version of TNF copyright template.
 1.1 11-Sep-1997  mycroft branches: 1.1.2;
Add an ibcs2_setregs().
 1.1.2.3 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.2 16-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 11-Sep-1997  thorpej file ibcs2_machdep.h was added on branch marc-pcmcia on 1997-09-16 03:48:40 +0000
 1.2.2.1 05-May-1998  mycroft Pull up 1.3, per request of scottb.
 1.4.12.3 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.4.12.2 08-Dec-2000  bouyer Sync with HEAD.
 1.4.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.6.1 22-Jun-2000  matt Move COFF_LDPGSZ to machine dependent includes.
 1.10.18.1 16-Jul-2002  gehenna catch up with -current.
 1.10.6.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.10.4.2 01-Aug-2002  nathanw Catch up to -current.
 1.10.4.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.11.2.2 04-Jul-2002  thorpej Add kernel support for having userland provide the signal trampoline:

* struct sigacts gets a new sigact_sigdesc structure, which has the
sigaction and the trampoline/version. Version 0 means "legacy kernel
provided trampoline". Other versions are coordinated with machine-
dependent code in libc.
* sigaction1() grows two more arguments -- the trampoline pointer and
the trampoline version.
* A new __sigaction_sigtramp() system call is provided to register a
trampoline along with a signal handler.
* The handler is no longer passed to sensig() functions. Instead,
sendsig() looks up the handler by peeking in the sigacts for the
process getting the signal (since it has to look in there for the
trampoline anyway).
* Native sendsig() functions now select the appropriate trampoline and
its arguments based on the trampoline version in the sigacts.

Changes to libc to use the new facility will be checked in later. Kernel
version not bumped; we will ride the 1.6C bump made recently.
 1.11.2.1 04-Jul-2002  thorpej file ibcs2_machdep.h was added on branch sommerfeld_i386mp_1 on 2002-07-04 23:32:06 +0000
 1.12.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.92.1 02-Jan-2008  bouyer Sync with HEAD
 1.14.88.1 26-Dec-2007  ad Sync with head.
 1.14.78.1 09-Jan-2008  matt sync with HEAD
 1.14.16.1 21-Jan-2008  yamt sync with head
 1.15.10.2 11-Mar-2010  yamt sync with head
 1.15.10.1 16-May-2008  yamt sync with head.
 1.15.8.1 18-May-2008  yamt sync with head.
 1.15.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.14.1 24-Oct-2010  jym Sync with HEAD
 1.17.40.1 28-Aug-2017  skrll Sync with HEAD
 1.17.22.1 03-Dec-2017  jdolecek update from HEAD
 1.2 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.1 10-Mar-1999  mycroft Add an ieee.h.
 1.3 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.2 05-Jan-1998  perry RCSID Police.
 1.1 09-Apr-1995  mycroft Move fp_except and fp_rnd definitions to machine/include.
 1.4 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.3 29-May-2010  tnozaki branches: 1.3.18; 1.3.32;
fix wrong integer promotion rule(removed U suffix from UINT{8,16}_C).
see ISO/IEC 9899:1999 7.18.4.3.
 1.2 28-Apr-2008  martin branches: 1.2.14; 1.2.20; 1.2.22;
Remove clause 3 and 4 from TNF licenses
 1.1 14-Apr-2001  kleink branches: 1.1.2; 1.1.4; 1.1.6; 1.1.8; 1.1.132; 1.1.134; 1.1.136;
Add definitions of C99 integer constant macros.
 1.1.136.2 11-Aug-2010  yamt sync with head.
 1.1.136.1 16-May-2008  yamt sync with head.
 1.1.134.1 18-May-2008  yamt sync with head.
 1.1.132.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.8.2 21-Jun-2001  nathanw Catch up to -current.
 1.1.8.1 14-Apr-2001  nathanw file int_const.h was added on branch nathanw_sa on 2001-06-21 19:25:48 +0000
 1.1.6.2 14-Apr-2001  kleink Add definitions of C99 integer constant macros.
 1.1.6.1 14-Apr-2001  kleink file int_const.h was added on branch sommerfeld_i386mp_1 on 2001-04-14 22:38:39 +0000
 1.1.4.1 21-Apr-2001  thorpej Add files to sommerfeld_i386mp_1 branch that have recently
appeared on the trunk.
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 14-Apr-2001  bouyer file int_const.h was added on branch thorpej_scsipi on 2001-04-21 17:53:52 +0000
 1.2.22.1 30-May-2010  rmind sync with head
 1.2.20.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.2.14.1 24-Oct-2010  jym Sync with HEAD
 1.3.32.1 10-Aug-2014  tls Rebase.
 1.3.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9 28-Jul-2014  joerg GCC sets up u?int_fast8_t to be int, so be consistent with it.
 1.8 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.7 28-Apr-2008  martin branches: 1.7.44; 1.7.60;
Remove clause 3 and 4 from TNF licenses
 1.6 22-May-2004  kleink branches: 1.6.96; 1.6.98; 1.6.100;
Bring back {u,}int_fast8_t back to 8 bits, as I had misunderstood Charles.
 1.5 21-May-2004  kleink Change {u,}int_fast{8,16}_t to 32-bit types, as the previous minimum-
width implementation was a rather poor choice. Per discussion with
Charles Hannum.

Note: While this is technically an ABI change I believe it is a
change that we can afford at this time (and to be pulled up to
2.0). The types are not widely used yet, and a survey of pkgsrc
has not shown uses that would be adversely affected by it.
 1.4 30-May-2003  kleink branches: 1.4.2; 1.4.4;
{u,}intptr_t are ints again.
 1.3 19-Sep-2001  simonb branches: 1.3.2;
{,u}intptr_t are longs; adjust printf/scanf formats.
 1.2 26-Apr-2001  kleink branches: 1.2.4; 1.2.6; 1.2.8;
Add definitions for C99 fastest minimum-width integer types.
 1.1 15-Apr-2001  kleink branches: 1.1.2; 1.1.4;
Add definitions of C99 integer format conversion macros.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.1.4.1 21-Apr-2001  thorpej Add files to sommerfeld_i386mp_1 branch that have recently
appeared on the trunk.
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 15-Apr-2001  bouyer file int_fmtio.h was added on branch thorpej_scsipi on 2001-04-21 17:53:52 +0000
 1.2.8.1 01-Oct-2001  fvdl Catch up with -current.
 1.2.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.2.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.2.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.4.1 26-Apr-2001  nathanw file int_fmtio.h was added on branch nathanw_sa on 2001-06-21 19:25:48 +0000
 1.3.2.2 19-Sep-2001  simonb {,u}intptr_t are longs; adjust printf/scanf formats.
 1.3.2.1 19-Sep-2001  simonb file int_fmtio.h was added on branch sommerfeld_i386mp_1 on 2001-09-19 05:23:44 +0000
 1.4.4.2 22-May-2004  he Pull up revision 1.6 (requested by kleink in ticket #376):
Change {u,}int_fast16_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.

Reverses previous commit for 8-bit types.
 1.4.4.1 22-May-2004  he Pull up revision 1.5 (requested by kleink in ticket #376):
Change {u,}int_fast{8,16}_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.
 1.4.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.100.1 16-May-2008  yamt sync with head.
 1.6.98.1 18-May-2008  yamt sync with head.
 1.6.96.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.60.1 10-Aug-2014  tls Rebase.
 1.7.44.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.9 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.8 28-Apr-2008  martin branches: 1.8.44; 1.8.60;
Remove clause 3 and 4 from TNF licenses
 1.7 17-Oct-2007  garbled branches: 1.7.16; 1.7.18; 1.7.20;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.6 31-Aug-2007  drochner Fix definitions of UCHAR_MAX/USHRT_MAX and related
types. C99 requires that these definitions promote to (signed/unsigned)
integer the same way as the types the definition is for. And since
unsigned char/short fit into an "int" on all our archs and thus promote
to signed int, the definitions must not be unsigned.
Fixes PR lib/31306 by Neil Booth.
 1.5 22-May-2004  kleink branches: 1.5.12; 1.5.52; 1.5.60; 1.5.66; 1.5.70; 1.5.72;
Bring back {u,}int_fast8_t back to 8 bits, as I had misunderstood Charles.
 1.4 21-May-2004  kleink Change {u,}int_fast{8,16}_t to 32-bit types, as the previous minimum-
width implementation was a rather poor choice. Per discussion with
Charles Hannum.

Note: While this is technically an ABI change I believe it is a
change that we can afford at this time (and to be pulled up to
2.0). The types are not widely used yet, and a survey of pkgsrc
has not shown uses that would be adversely affected by it.
 1.3 08-May-2004  kleink Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 1.2 26-Apr-2001  kleink branches: 1.2.2; 1.2.4; 1.2.26; 1.2.28;
Add definitions for C99 fastest minimum-width integer types.
 1.1 15-Apr-2001  kleink branches: 1.1.2; 1.1.4;
Add definitions of C99 specified-width integer type limits.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.1.4.1 21-Apr-2001  thorpej Add files to sommerfeld_i386mp_1 branch that have recently
appeared on the trunk.
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 15-Apr-2001  bouyer file int_limits.h was added on branch thorpej_scsipi on 2001-04-21 17:53:52 +0000
 1.2.28.2 22-May-2004  he Pull up revision 1.5 (requested by kleink in ticket #376):
Change {u,}int_fast16_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.

Reverses preivous commit with respect to 8-bit types.
 1.2.28.1 22-May-2004  he Pull up revision 1.4 (requested by kleink in ticket #376):
Change {u,}int_fast{8,16}_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.
 1.2.26.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.26.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.26.1 03-Aug-2004  skrll Sync with HEAD
 1.2.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.4.1 26-Apr-2001  nathanw file int_limits.h was added on branch nathanw_sa on 2001-06-21 19:25:49 +0000
 1.2.2.2 26-Apr-2001  kleink Add definitions for C99 fastest minimum-width integer types.
 1.2.2.1 26-Apr-2001  kleink file int_limits.h was added on branch sommerfeld_i386mp_1 on 2001-04-26 16:25:22 +0000
 1.5.72.1 06-Nov-2007  matt sync with HEAD
 1.5.70.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.5.66.1 03-Sep-2007  skrll Sync with HEAD.
 1.5.60.1 03-Oct-2007  garbled Sync with HEAD
 1.5.52.1 09-Oct-2007  ad Sync with head.
 1.5.12.1 03-Sep-2007  yamt sync with head.
 1.7.20.1 16-May-2008  yamt sync with head.
 1.7.18.1 18-May-2008  yamt sync with head.
 1.7.16.1 02-Jun-2008  mjf Sync with HEAD.
 1.8.60.1 10-Aug-2014  tls Rebase.
 1.8.44.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.8 28-Jul-2014  joerg GCC sets up u?int_fast8_t to be int, so be consistent with it.
 1.7 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.6 28-Apr-2008  martin branches: 1.6.44; 1.6.60;
Remove clause 3 and 4 from TNF licenses
 1.5 24-Dec-2005  perry branches: 1.5.74; 1.5.76; 1.5.78;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 22-May-2004  kleink branches: 1.4.12;
Bring back {u,}int_fast8_t back to 8 bits, as I had misunderstood Charles.
 1.3 21-May-2004  kleink Change {u,}int_fast{8,16}_t to 32-bit types, as the previous minimum-
width implementation was a rather poor choice. Per discussion with
Charles Hannum.

Note: While this is technically an ABI change I believe it is a
change that we can afford at this time (and to be pulled up to
2.0). The types are not widely used yet, and a survey of pkgsrc
has not shown uses that would be adversely affected by it.
 1.2 26-Apr-2001  kleink branches: 1.2.2; 1.2.4; 1.2.26; 1.2.28;
Add definitions for C99 fastest minimum-width integer types.
 1.1 14-Apr-2001  kleink branches: 1.1.2; 1.1.4;
Add definitions of C99 minimum-width and greatest-width integer types.
XXX Fastest minimum-width integer types haven't been decided upon yet.
 1.1.4.1 21-Apr-2001  thorpej Add files to sommerfeld_i386mp_1 branch that have recently
appeared on the trunk.
 1.1.2.2 21-Apr-2001  bouyer Sync with HEAD
 1.1.2.1 14-Apr-2001  bouyer file int_mwgwtypes.h was added on branch thorpej_scsipi on 2001-04-21 17:53:52 +0000
 1.2.28.2 22-May-2004  he Pull up revision 1.4 (requested by kleink in ticket #376):
Change {u,}int_fast16_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.

Reverses preivous commit with respect to 8-bit types.
 1.2.28.1 22-May-2004  he Pull up revision 1.3 (requested by kleink in ticket #376):
Change {u,}int_fast{8,16}_t to 32-bit types, as the previous
minimum-width implementation was a rather poor choice.

Note: While this is technically an ABI change I believe it
is a change that we can afford at this time (and to be
pulled up to 2.0). The types are not widely used yet, and
a survey of pkgsrc has not shown uses that would be adversely
affected by it.
 1.2.26.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.26.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.26.1 03-Aug-2004  skrll Sync with HEAD
 1.2.4.2 21-Jun-2001  nathanw Catch up to -current.
 1.2.4.1 26-Apr-2001  nathanw file int_mwgwtypes.h was added on branch nathanw_sa on 2001-06-21 19:25:50 +0000
 1.2.2.2 26-Apr-2001  kleink Add definitions for C99 fastest minimum-width integer types.
 1.2.2.1 26-Apr-2001  kleink file int_mwgwtypes.h was added on branch sommerfeld_i386mp_1 on 2001-04-26 16:25:22 +0000
 1.4.12.1 21-Jun-2006  yamt sync with head.
 1.5.78.1 16-May-2008  yamt sync with head.
 1.5.76.1 18-May-2008  yamt sync with head.
 1.5.74.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.60.1 10-Aug-2014  tls Rebase.
 1.6.44.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.11 25-Jul-2014  joerg Add generic versions of machine/int_*.h for compilers providing
appropiate macros for all necessary types.
 1.10 24-Dec-2005  perry branches: 1.10.122; 1.10.138;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.9 25-May-2005  kleink branches: 1.9.2;
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.8 07-Aug-2003  agc branches: 1.8.6; 1.8.14;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.7 29-May-2003  christos branches: 1.7.2;
Back to unsigned int and int for {u,}intptr_t, otherwise java has no chance...
 1.6 28-Apr-2001  kleink branches: 1.6.2;
* Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.5 12-Apr-2001  kleink Replace the 'unsigned __COMPILER_INT64__' construct with a new name,
__COMPILER_UINT64__, to be supplied - if such a case is made, it shouldn't
be assumed that the unsigned type-specifier may be applied to it.
 1.4 03-Jan-2001  takemura branches: 1.4.4;
replace 'long long' with int64_t to compile stand alone program with
compiler other than GCC.
 1.3 16-Jul-2000  christos branches: 1.3.4;
change intptr_t and uintptr_t to long and unsigned long respectively. This
is a noop on 32 bit machines, but it makes lint quiet and it is more correct.
 1.2 27-Jun-2000  kleink Resolve some formatting nits; add __intptr_t and __uintptr_t.
 1.1 26-Jun-2000  kleink Add <machine/int_types.h>, which provides namespace-pure definitions
of exact-width integer types.
 1.3.4.4 21-Apr-2001  bouyer Sync with HEAD
 1.3.4.3 05-Jan-2001  bouyer Sync with HEAD
 1.3.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.4.1 16-Jul-2000  bouyer file int_types.h was added on branch thorpej_scsipi on 2000-11-20 20:09:27 +0000
 1.4.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.6.2.2 28-Apr-2001  kleink * Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.6.2.1 28-Apr-2001  kleink file int_types.h was added on branch sommerfeld_i386mp_1 on 2001-04-28 15:41:32 +0000
 1.7.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.7.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.2.1 03-Aug-2004  skrll Sync with HEAD
 1.8.14.1 28-May-2005  tron Pull up revision 1.9 (requested by klein in ticket #346):
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.8.6.1 29-May-2005  riz Pull up revision 1.9 (requested by kleink in ticket #1555):
Include <sys/cdefs.h> for __signed; related to lib/30072.
 1.9.2.1 21-Jun-2006  yamt sync with head.
 1.10.138.1 10-Aug-2014  tls Rebase.
 1.10.122.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.37 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.36 16-Dec-2002  fvdl Remove leftover declarations used for debugging purposes only.
 1.35 11-Dec-2002  fvdl Since a CPU may spin waiting for another CPU to handle an IPI, an
IPI must be the very first thing to be handled in splx(), if it
had been blocked before. Change things around a bit to guarantee
this.
 1.34 01-Dec-2002  fvdl For softints, there's no intrframe on the stack, so don't try to use it.
Use a seperate lock function (in taking the same lock) instead.
 1.33 27-Nov-2002  fvdl Specify the interrupt frame as the argument to i386_int(un)lock.
 1.32 23-Nov-2002  fvdl Remove "ioapic.h" include, and always include the intr_find_mpmapping
prototype; it's not worth the extra bytes to avoid including this.
 1.31 22-Nov-2002  fvdl Removed unused function. From kristerw.
 1.30 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.29 01-Nov-2002  fvdl Make splsched == splclock, and splserial > splsched. Unfortunately,
we have to retain the 'pick unlocked interrupt handler' hack for
the MP case for now.
 1.28 05-Oct-2002  fvdl Adapt i386_send_ipi prototype. Make spllock < splipi (IPI paths
changed to use __cpu_simple_lock because of LOCKDEBUG conflict).
 1.27 01-Oct-2002  matt ANSI'fy the inline functions.
 1.26 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.25 12-May-2002  matt Eliminate commons.
 1.24 18-Dec-2001  yamt branches: 1.24.4;
use #define<TAB> style.
pointed by enami.
 1.23 18-Dec-2001  fvdl Prevent gcc from reordering things such that instructions may fall out
of a range which is protected by spl/splx. Originally proposed by
YAMAMOTO Takashi (yamt@netbsd.org) on tech-kern. This change mirrors
the one done by Bill Sommerfeld on the i386 mp branch.
 1.22 16-Jul-2001  thorpej In i386_softintr_lock(), use splserial() rather than splhigh(),
because of splhigh() braindamage on the i386 port.

Fixes port-i386/13038 and port-i386/12985.
 1.21 21-May-2001  perry branches: 1.21.2;
remove needless externs in front of function prototypes
 1.20 30-Apr-2001  lukem remove some lint, including ansifying some inlines
 1.19 14-Apr-2001  thorpej Generic soft interrupt implementation for NetBSD/i386. This could
probably be tuned somewhat, but this is a stop-gap measure to hold
us until Bill Sommerfeld's new interrupt code comes in from the
MP branch.
 1.18 13-Apr-2001  thorpej Remove the use of splimp() from the NetBSD kernel. splnet()
and only splnet() is allowed for the protection of data structures
used by network devices.
 1.17 14-Jan-2001  thorpej branches: 1.17.2;
Make sure everybody has an splvm() and equate it with splimp() (splimp()
is the historical name for this interrupt level, and the historical name
is going to go away in the near future).
 1.16 22-Aug-2000  thorpej Add spllock(). See spl(9) for details.
 1.15 21-Aug-2000  thorpej Make sure we provide splsched() as described in spl(9).
 1.14 08-Jun-2000  cgd make spl-lowering functions return void.
 1.13 04-Jun-2000  mycroft Implement CLKF_INTR(), to count interrupt time separately.
 1.12 05-Aug-1999  thorpej branches: 1.12.2; 1.12.10; 1.12.12;
Change the semantics of splsoftclock() to be like other spl*() functions,
that is priority is rasied. Add a new spllowersoftclock() to provide the
atomic drop-to-softclock semantics that the old splsoftclock() provided,
and update calls accordingly.

This fixes a problem with using the "rnd" pseudo-device from within
interrupt context to extract random data (e.g. from within the softnet
interrupt) where doing so would incorrectly unblock interrupts (causing
all sorts of lossage).

XXX 4 platforms do not have priority-raising capability: newsmips, sparc,
XXX sparc64, and VAX. This platforms still have this bug until their
XXX spl*() functions are fixed.
 1.11 26-Jan-1999  christos Fix this properly, using gcc assembly syntax (thanks ws!)
 1.10 26-Jan-1999  christos ifdef __ELF__ the softintr inline since we cannot use _C_LABEL to produce
a name. XXX: Is there a better way?
 1.9 15-Aug-1998  mycroft Assign my copyrights to TNF.
 1.8 18-Jul-1998  is Switching dev/ic/lpt.c to use spllpt() instead of spltty(). It doesn't use
tty structures, and on some machines (namely the DraCo internal lpt, and some
multi-i/o boards for Amigas and DraCos), tying spltty to the pretty high printer
interupt level would hurt serial performance.

On all affected ports but Amiga, spllpt() has been defined in machine/intr.h
to be spltty(), thus preserving old behaviour. Portmasters are encouraged to
change is, if they feel something else is better (e.g., one of its own were
possible).
 1.7 21-Mar-1997  mycroft Add IPL_AUDIO.
 1.6 28-Feb-1997  mycroft Import interrupt priority changes from com patches:
* Make it a strict hierarchy. (It was close anyway).
* Add `serial' and rename `softtty' to `softserial'.
* Make soft interrupts a bit less special-case.
 1.5 13-May-1996  mycroft branches: 1.5.8;
Make imask[] larger, to match other changes.
 1.4 13-May-1996  mycroft Add multiple-inclusion protection.
 1.3 13-May-1996  mycroft Move spl*() and soft interrupt definitions into intr.h. For now, include it
from psl.h. XXX Will change after release.
 1.2 12-May-1996  mycroft Implement IPL_HIGH.
 1.1 12-May-1996  mycroft Move IPL_* and IST_* constants into intr.h.
 1.5.8.1 12-Mar-1997  is Merge in Changes from The Trunk.
 1.12.12.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.10.21 25-Jun-2002  fvdl Add a spinlock around softintr queue management. Use a lock prefix to
protect manipulation of the 'ipending' variable. Fixes 'softclock
stops being called' AKA 'processes entering nanosleep do not return'
problem.
 1.12.10.20 18-May-2002  sommerfeld Catch up with -current. (commons elimination, changes to MI pci framework)
 1.12.10.19 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.12.10.18 29-Dec-2001  sommerfeld Yet another mergeup.

New work:
- Frank van der Linden's tlb shootdown fix.
Mainline functionality merged:
- IrDA
- Kernel RCSID's
- Transmeta CPU support
- ACPI
- XMM register access through procfs
 1.12.10.17 18-Dec-2001  sommerfeld Recent versions of gcc may reorder instructions around inline
functions, breaking the semantics of splraise() and spllower(); to
counteract this, insert a "barrier" (empty asm) as a sequence point.

Reportedly fixes a stability problems on AMD dual-processor systems.

the code-gen barrier primitive will likely move to <sys/cdefs.h> once
we figure out what to call it; in the mean time define it locally.
 1.12.10.16 19-Jul-2001  sommerfeld catch up with -current
 1.12.10.15 26-May-2001  sommerfeld Implement MP-synchronzed microtime(), based on Jason Thorpe's port of
Dave Mills's cycle-counter-based microtime.

XXX We need to figure out how to deal with processors where the cycle
counter speed varies. We don't have a whole lot of alternatives; we
could only use this on multiprocessors, which are less likely to
throttle the clock to save power.

The local apic timer runs at a fixed frequency, but it's
count-down-to-zero, not the count-up-forever type of timer which the
Mills code expects.

This also does not solve the problem of microtime on 486-based
multiprocessors..
 1.12.10.14 23-May-2001  sommerfeld Merge branch with tonight's current.
boots multiuser.
 1.12.10.13 30-Apr-2001  sommerfeld Do softints purely in software.

Using the local apic for softints is slow; exactly why isn't clear,
but ripping out the code and using pure-software softints speeds up
ping -f packet rates by more than 5%.
 1.12.10.12 30-Apr-2001  sommerfeld Catch up on some files missed the last time 'round
 1.12.10.11 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.12.10.10 14-Jan-2001  thorpej Add splvm().
 1.12.10.9 31-Dec-2000  thorpej Fill in the guts of i386_broadcast_ipi() and implement
i386_multicast_ipi().

Reviewed by Bill Sommerfeld.
 1.12.10.8 23-Sep-2000  sommerfeld Preliminary support for cloning MTRR values between CPU's at boot time.
XXX no API to *set* MTRR values yet.
 1.12.10.7 25-Aug-2000  sommerfeld Get this to at least build again in the !MULTIPROCESSOR case..
 1.12.10.6 25-Aug-2000  sommerfeld The need_resched() function now takes a (cpu_info *) parameter.
Get asts out of <machine/intr.h>
Untangle astpending and want_resched variables somewhat.
 1.12.10.5 18-Aug-2000  sommerfeld Add splipi(), IPL_IPI, and rearrange IPI's a bit.
Also, add SPL_ASSERT_ATMOST
 1.12.10.4 12-Aug-2000  sommerfeld Add spllock() (temporary) and splsched()
 1.12.10.3 26-Jun-2000  sommerfeld Start making npx.c MP-safe; Interface to npx now specifies the process
and/or cpu to act on. Implement an IPI for MP lazy FP save.
Tested and working when only one CPU is running; untested in the MP
case since we can't run user processes on multiple CPU's yet.

Along for the ride:
- Change i386_send_ipi to take a "struct cpu_info *" rather than a cpu number.
- Turn off the "give me the brain" test IPI's.
 1.12.10.2 25-Jun-2000  sommerfeld Merge up to just-post-1.5 -current
 1.12.10.1 20-Feb-2000  sommerfeld MP: MP-safe and APIC-friendly spl*/splx() implementation.

Keep spl state as a level, rather than interrupt mask, since on
multiple APIC systems there may be more interrupt lines than can fit
in a single 32-bit word.

Interrupt levels are now compatible with the APIC priority scheme
(high order 4 bits of the IDT vector number).
 1.12.2.3 21-Apr-2001  bouyer Sync with HEAD
 1.12.2.2 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.12.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.17.2.9 19-Dec-2002  thorpej Sync with HEAD.
 1.17.2.8 11-Dec-2002  thorpej Sync with HEAD.
 1.17.2.7 11-Dec-2002  thorpej Sync with HEAD.
 1.17.2.6 11-Nov-2002  nathanw Catch up to -current
 1.17.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.17.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.17.2.3 08-Jan-2002  nathanw Catch up to -current.
 1.17.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.17.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.21.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.21.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.21.2.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.21.2.1 03-Aug-2001  lukem update to -current
 1.24.4.2 17-Mar-2002  thorpej IPL_IMP -> IPL_VM
 1.24.4.1 17-Mar-2002  thorpej Add splraiseipl() for use by kern_mutex.c
 1.6 30-Apr-2020  bouyer Don't #include xen/intrdefs.h is !XEN.
Should fix third-party module builds (e.g. virtualbox)
 1.5 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.4 10-Aug-2011  cherry branches: 1.4.64;
Include Xen specific definitions.
 1.3 26-Feb-2003  fvdl branches: 1.3.122; 1.3.140;
Redirect some includes to x86/foo.h
 1.2 11-Dec-2002  fvdl Since a CPU may spin waiting for another CPU to handle an IPI, an
IPI must be the very first thing to be handled in splx(), if it
had been blocked before. Change things around a bit to guarantee
this.
 1.1 22-Nov-2002  fvdl branches: 1.1.2;
Interrupt defines that needed to be in a seperate file to avoid cyclic
includes.
 1.1.2.3 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.2 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 22-Nov-2002  thorpej file intrdefs.h was added on branch nathanw_sa on 2002-12-11 06:01:01 +0000
 1.3.140.1 31-Jul-2011  cherry grow MP support for i386. boots to single user
 1.3.122.1 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.4.64.1 16-Apr-2020  bouyer Avoid overflow of ci_ipi_events[] in the PVHVM case (it's size is
XEN_NIPIS but we use x86 IPIs): size XEN_NIPIS only for PV, and
CTASSERT that XEN_NIPIS <= X86_NIPI if we ever use Xen IPIs for
PVHVM.
 1.2 16-Mar-2018  maxv Remove ipkdb from i386. Also remove unused references in amd64.

I already talked about doing that six months ago on port-i386@. Back then
it was as general cleanup, but now, with SVS etc, we do actually have
good reasons for simplifying the entry points.

Ok kamil@. (christos@ was in the conversation too)
 1.1 22-Mar-2000  ws branches: 1.1.2; 1.1.8; 1.1.44;
Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.1.44.1 22-Mar-2018  pgoyette Synch with HEAD, resolve conflicts
 1.1.8.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.8.1 22-Mar-2000  bouyer file ipkdb.h was added on branch thorpej_scsipi on 2000-11-20 20:09:27 +0000
 1.1.2.2 22-Mar-2000  ws Make IPKDB working again.
Add support for i386 debugging and pci-based ne2000 boards.
 1.1.2.1 22-Mar-2000  ws file ipkdb.h was added on branch sommerfeld_i386mp_1 on 2000-03-22 20:58:29 +0000
 1.22 27-Feb-2003  fvdl Adapt for move to x86/include.
 1.21 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.20 22-Nov-2002  fvdl New interrupt code. The basic idea behind it is to hide the differences
in interrupt controllers in struct pic, and try to keep as much
common code as possible. At the lowest (asm) level, this is done
with CPP macros.

The main structure is now struct intrsource, describing an established
interrupt line, of any kind (soft/hard local apic/legacy apic/IO apic).
For quick masking, there may be a maximum of 32 sources per CPU.
Sources can be assigned to any CPU in the MP case, though currently they
all go to the boot CPU.
 1.19 18-Jun-2002  tshiozak branches: 1.19.2;
add MD support for ACPI sleep/wakeup.
 1.18 15-Nov-2000  thorpej branches: 1.18.4; 1.18.6; 1.18.18;
Garbage-collect some more stuff.
 1.17 15-Nov-2000  enami Make isa_machdep.c compile again.
 1.16 04-Jun-2000  cgd Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).
 1.15 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.14 07-Feb-2000  thorpej branches: 1.14.4;
Add a new function call to the ISA DMA API: isa_dmamaxsize(), which returns
the maximum transfer size for the specified DMA channel. Make all clients
of ISA DMA use this call to determine their maximum transfer size.
 1.13 19-Mar-1999  cgd branches: 1.13.8;
Moved from arch/i386/isa/isa_machdep.h,v
 1.12 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.11 09-Jun-1998  thorpej Add isa_dma{freeze,thaw}(), used to temporarily stop and then restart
all ISA DMA. Needed by e.g. the SmartCard reader for Sharks.
 1.10 09-Jun-1998  thorpej Change the ISA DMA API to take an isa_chipset_tag_t rather than
a struct device * corresponding to the ISA bus device. The ISA DMA
controller driver functions have been renamed and now take a struct
isa_dma_state *, and are called indirectly by machine-dependent code
which provides the DMA state.

These changes allow e.g. `ofisa' (the OpenFirmware configuration
mechanism for the ISA bus, used by e.g. Sharks) to use the MI ISA
DMA controller code.
 1.9 03-Jun-1998  thorpej Implement bounce buffers for mbufs.
 1.8 14-Oct-1997  thorpej Pull down from marc-pcmcia branch:

Implement new ISA interface functions:
* isa_intr_alloc() - allocate an ISA IRQ
* isa_mem_alloc() - allocate ISA memory space
* isa_mem_free() - free ISA memory space
 1.7 06-Jun-1997  thorpej branches: 1.7.4;
Pull thorpej-bus-dma branch into mainline.
 1.6 03-May-1996  christos branches: 1.6.10;
- Add missing prototypes.
- Fix gcc warnings
 1.5 11-Apr-1996  cgd prototype MD functions for use by MI ISA code (isa_attach_hook(),
isa_intr_{,dis}establish()) here. Make this file safely includable by
<dev/isa/isavar.h> and by all of the places in the i386 that are currently
including it, which means multiple inclusion protection and a few
otherwise-extraneous 'forward' structure declarations. isa_intr_establish()
and isa_intr_disestablish() now take as their first argument a
machine-dependent cookie of type isa_chipset_tag_t, which is also defined
here.
 1.4 04-May-1995  cgd use the machine-independent definitions for the mc146818.
wrap the various uses of the chip (including the uses of the NVRAM on it)
around the new defintions, structures, and functions specified in the header.
 1.3 21-Apr-1995  mycroft Clean up hole conversion functions a little.
 1.2 21-Apr-1995  mycroft Remove relocation of Crtat from locore.
 1.1 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.6.10.2 18-May-1997  thorpej Add an external declaration for the isa dma tag.
 1.6.10.1 13-May-1997  thorpej Implement ISA-specific bus dma methods, and provide the bus dma tag
to children via isa_attach_hook(). These bus dma methods are mostly
wrappers around the generic i386 bus dma methods, but include support
for DMA bounce buffers where required.
 1.7.4.3 29-Aug-1997  thorpej Make isa_mem_alloc() and isa_mem_free() functions, not macros, so that
IOM_* constants don't have to be in scope in order to call these.

Also, fix a fencepost in isa_mem_alloc().
 1.7.4.2 11-Aug-1997  thorpej Make isa_intr_alloc() return non-zero on IRQ allocation failure, rather
than panicing.
 1.7.4.1 30-Jul-1997  marc added pcmcia infrastructure and a few devices
 1.13.8.2 22-Nov-2000  bouyer Sync with HEAD.
 1.13.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.4.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.18.18.1 16-Jul-2002  gehenna catch up with -current.
 1.18.6.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.18.4.2 11-Dec-2002  thorpej Sync with HEAD.
 1.18.4.1 20-Jun-2002  nathanw Catch up to -current.
 1.19.2.2 18-Jun-2002  tshiozak add MD support for ACPI sleep/wakeup.
 1.19.2.1 18-Jun-2002  tshiozak file isa_machdep.h was added on branch sommerfeld_i386mp_1 on 2002-06-18 07:56:15 +0000
 1.6 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5 01-Jun-2000  cgd branches: 1.5.4; 1.5.130; 1.5.132; 1.5.134;
kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.4 19-Mar-1999  cgd branches: 1.4.8; 1.4.18;
Moved from arch/i386/isa/isapnp_machdep.h,v
 1.3 05-Sep-1998  christos Assign copyright to TNF.
 1.2 04-Oct-1997  thorpej Copyright assigned to The NetBSD Foundation.
 1.1 16-Jan-1997  christos branches: 1.1.2; 1.1.10;
i386 plug and play glue
 1.1.10.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.1.2.1 18-Jan-1997  thorpej Update from trunk.
 1.4.18.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.5.134.1 16-May-2008  yamt sync with head.
 1.5.132.1 18-May-2008  yamt sync with head.
 1.5.130.1 02-Jun-2008  mjf Sync with HEAD.
 1.5.4.2 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.5.4.1 01-Jun-2000  cgd file isapnp_machdep.h was added on branch sommerfeld_i386mp_1 on 2000-06-01 00:04:52 +0000
 1.2 02-Jul-2004  drochner just include <sys/joystick.h>
 1.1 27-Mar-1996  perry branches: 1.1.66;
add joystick driver from Matthieu Herrb (pr #2267)
 1.1.66.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.66.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.66.1 03-Aug-2004  skrll Sync with HEAD
 1.7 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.6 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.5 05-Oct-2010  jym branches: 1.5.70;
Import PAE support for kvm(3):
- add kvm_i386pae.c (used for PAE memory translations), and update Makefile
for libkvm build.
- in pdppaddr: pass a flag to indicate PAE mode. Use a bit ignored
by the MMU. Mask address with PG_FRAME to avoid side effects.

Tested with vmstat(1)/netstat(1) to debug core files of PAE and !PAE
kernels. Older kernel dumps will default to native i386 (!PAE) mode.

XXX Currently, savecore(8) will fail to dump a PAE kernel in a !PAE
environment (and reciprocally). So you need to sync and reboot
with a kernel of the same mode as the one that crashed. Once the dump
is successful, this does not matter anymore.
 1.4 12-Jan-2008  ad branches: 1.4.10; 1.4.24; 1.4.30; 1.4.32;
- Split crashdump code out into its own file.
- Remove NO_SPARSE_DUMP.
- Minor KNF, sprinkle static.
 1.3 26-Dec-2005  perry branches: 1.3.50; 1.3.56; 1.3.64;
u_intN_t -> uintN_t
 1.2 26-Aug-2004  junyoung branches: 1.2.12;
As suggested on tech-kern@ days ago:
* Get rid of PTmap, PTD, PTDpde, APTmap, APTD, and APTDpde from locore.S.
* Rename PTDpaddr to PDPpaddr, ptdpaddr in struct cpu_kcore_hdr to pdppaddr for consistency.
 1.1 18-Feb-1998  thorpej branches: 1.1.50;
Switch the i386 port to the new kernel crash dump format.
 1.1.50.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.50.2 18-Sep-2004  skrll Sync with HEAD.
 1.1.50.1 03-Sep-2004  skrll Sync with HEAD
 1.2.12.2 21-Jan-2008  yamt sync with head
 1.2.12.1 21-Jun-2006  yamt sync with head.
 1.3.64.1 19-Jan-2008  bouyer Sync with HEAD
 1.3.56.1 18-Feb-2008  mjf Sync with HEAD.
 1.3.50.1 23-Mar-2008  matt sync with HEAD
 1.4.32.1 05-Mar-2011  rmind sync with head
 1.4.30.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.4.24.1 24-Oct-2010  jym Sync with HEAD
 1.4.10.1 09-Oct-2010  yamt sync with head
 1.5.70.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.7 03-Oct-2012  dsl Remove all references to KVM86.
It was only ever used by APMBIOS - and then only if an option was selected.
Probably didn't work well at all!
 1.6 26-Oct-2008  mrg branches: 1.6.28; 1.6.38;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.5 26-Dec-2005  perry branches: 1.5.74; 1.5.78; 1.5.84;
u_intN_t -> uintN_t
 1.4 02-Oct-2002  drochner branches: 1.4.22;
add kvm86_incall again which got lost in the SMP merge
 1.3 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.2 10-Jul-2002  drochner branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8;
add a function to read from the BIOS vm86
(most of it is already mapped to KVM, but it appears easier to me
to do it this way instead of a lot of range checks)
 1.1 07-Jul-2002  drochner This is a (still experimental) framework to run BIOS code in a virtual
8086 machine. Ifff it works, it is much easier and more elegant than
going to real real mode:
-simpler code
-no need for "identity" memory mappings
-easy passing of buffers for bulk data to functions
-some more control
There is no interrupt support ATM, and it lacks a function to access
random virtual memory of the VM. MP issues to consider.
 1.2.8.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.8.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.2.8.1 10-Jul-2002  jdolecek file kvm86.h was added on branch kqueue on 2002-09-06 08:36:27 +0000
 1.2.6.2 19-Aug-2002  sommerfeld merged with -current as of today.
rearranged gdt init to deal with KVM86 changes; however, KVM86 has no
chance of working yet; good thing it's not part of GENERIC
 1.2.6.1 10-Jul-2002  sommerfeld file kvm86.h was added on branch sommerfeld_i386mp_1 on 2002-08-19 01:22:36 +0000
 1.2.4.2 01-Aug-2002  nathanw Catch up to -current.
 1.2.4.1 10-Jul-2002  nathanw file kvm86.h was added on branch nathanw_sa on 2002-08-01 02:42:10 +0000
 1.2.2.2 16-Jul-2002  gehenna catch up with -current.
 1.2.2.1 10-Jul-2002  gehenna file kvm86.h was added on branch gehenna-devsw on 2002-07-16 08:29:51 +0000
 1.4.22.1 21-Jun-2006  yamt sync with head.
 1.5.84.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.5.78.1 04-May-2009  yamt sync with head.
 1.5.74.1 17-Jan-2009  mjf Sync with HEAD.
 1.6.38.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6.28.1 30-Oct-2012  yamt sync with head
 1.26 21-Jan-2019  dholland Fix wrong scoping of {U,}LLONG_MAX. More cases, not just amd64.
PR 53298 from Roberto E. Vargas Caballero.
 1.25 21-Apr-2014  matt branches: 1.25.26; 1.25.28;
Since all our compilers support __DBL_* and __FLT_*, use them to define
{DBL,FLT}_{DIG,MIN,MAX}
 1.24 11-Apr-2013  christos branches: 1.24.4; 1.24.8;
add missing SSIZE_MIN
 1.23 28-Mar-2012  christos branches: 1.23.2;
- Normalize inclusion protection (remove)
- Move CHAR_{MIN,MAX} to a common file.
- Fix broken comments
 1.22 07-Jun-2010  tnozaki branches: 1.22.8; 1.22.12;
1. MB_LEN_MAX switch MD to MI.
2. unfortunately hppa's MB_LEN_MAX is defined incorrectly 6 instead of 32
so we have to add more setlocale(3) __RENAME func, __setlocale50.
3. move setlocale1.c and setlocale32.c to lib/libc/compat/locale/*
prepareing for next libc major crunk.
4. bump libc minor version.
 1.21 26-Oct-2008  mrg branches: 1.21.8; 1.21.14; 1.21.16;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.20 17-Oct-2007  garbled branches: 1.20.16; 1.20.20; 1.20.26;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.19 31-Aug-2007  drochner Fix definitions of UCHAR_MAX/USHRT_MAX and related
types. C99 requires that these definitions promote to (signed/unsigned)
integer the same way as the types the definition is for. And since
unsigned char/short fit into an "int" on all our archs and thus promote
to signed int, the definitions must not be unsigned.
Fixes PR lib/31306 by Neil Booth.
 1.18 23-Sep-2006  elad branches: 1.18.8; 1.18.16; 1.18.22; 1.18.26; 1.18.28;
PR/30760: David A. Holland: obsolete comment in i386/limits.h
Patch applied, thanks!
 1.17 07-Aug-2003  agc branches: 1.17.16; 1.17.46; 1.17.48;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.16 28-Apr-2003  bjh21 branches: 1.16.2;
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.

This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
 1.15 08-Aug-2000  tshiozak branches: 1.15.2;
Preparation for the future introduction of multibyte locale.
- MB_LEN_MAX is increased to 32.
- To ensure binary compatibility for old executables
under multibyte locale, versioned setlocale is added.
- __mb_len_cur definision is added in setlocale.c
and enable it in stdlib.h .
It is also important for multibyte locale stuffs,
but I just forgot.
 1.14 07-Mar-2000  kleink branches: 1.14.4; 1.14.6;
Define ISO C99 (unsigned) long long (min, max) symbols.
 1.13 06-Aug-1998  kleink branches: 1.13.12;
_POSIX_SOURCE -> _POSIX_C_SOURCE
 1.12 09-Jan-1998  perry multiple include protect machine/limits.h, fixes pr 4473 (from Mika Nystrom)
 1.11 21-Dec-1995  mycroft Minor cleanup.
 1.10 20-Dec-1995  mycroft Use the U suffix to insure unsigned values are treated as such.
 1.9 27-Oct-1994  cgd new RCS ID format.
 1.8 05-Oct-1994  jtc Add constants required by XPG3
 1.7 09-May-1994  cgd branches: 1.7.2;
new defn's
 1.6 20-Dec-1993  mycroft branches: 1.6.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.5 24-Sep-1993  jtc Do not provide quad constants if compiling in a strict ansi or a strict
posix environment.
 1.4 16-Sep-1993  mycroft Add constants for quad support.
 1.3 18-Aug-1993  jtc branches: 1.3.2;
Removed CLK_TCK, it's value is not machine dependant.
It's supposed to be defined in <time.h>, not <limits.h> anyway.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.2.2 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.3.2.1 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.6.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.6.2.1 20-Dec-1993  mycroft file limits.h was added on branch magnum on 1993-12-20 05:25:20 +0000
 1.7.2.1 11-Oct-1994  mycroft Update from trunk.
 1.13.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.6.1 09-Aug-2000  tshiozak pull up the following changes (approved by thorpej):
> cvs rdiff -r1.9 -r1.10 basesrc/include/locale.h
> cvs rdiff -r1.45 -r1.46 basesrc/include/stdlib.h
> cvs rdiff -r1.16 -r1.17 basesrc/lib/libc/locale/Makefile.inc
> cvs rdiff -r1.17 -r1.18 basesrc/lib/libc/locale/setlocale.c
> cvs rdiff -r0 -r1.2 basesrc/lib/libc/locale/setlocale_sb.c
> cvs rdiff -r1.6 -r1.7 syssrc/sys/arch/alpha/include/limits.h
> cvs rdiff -r1.1 -r1.2 syssrc/sys/arch/arm26/include/limits.h
> cvs rdiff -r1.7 -r1.8 syssrc/sys/arch/arm32/include/limits.h
> cvs rdiff -r1.14 -r1.15 syssrc/sys/arch/i386/include/limits.h
> cvs rdiff -r1.12 -r1.13 syssrc/sys/arch/m68k/include/limits.h
> cvs rdiff -r1.13 -r1.14 syssrc/sys/arch/mips/include/limits.h
> cvs rdiff -r1.10 -r1.11 syssrc/sys/arch/pc532/include/limits.h
> cvs rdiff -r1.6 -r1.7 syssrc/sys/arch/powerpc/include/limits.h
> cvs rdiff -r1.2 -r1.3 syssrc/sys/arch/sh3/include/limits.h
> cvs rdiff -r1.11 -r1.12 syssrc/sys/arch/sparc/include/limits.h
> cvs rdiff -r1.7 -r1.8 syssrc/sys/arch/sparc64/include/limits.h
> cvs rdiff -r1.9 -r1.10 syssrc/sys/arch/vax/include/limits.h
>
> Outline:
>
> Preparation for the future introduction of multibyte locale.
> - MB_LEN_MAX is increased to 32.
> - To ensure binary compatibility for old executables
> under multibyte locale, versioned setlocale is added.
> - __mb_len_cur definision is added in setlocale.c
> and enable it in stdlib.h .
> It is also important for multibyte locale stuffs,
> but I just forgot.
 1.14.4.1 28-May-2000  minoura Citrus Project XPG4DL, an implementation of I18N (locale) framework,
is imported.
 1.15.2.2 08-Aug-2000  tshiozak Preparation for the future introduction of multibyte locale.
- MB_LEN_MAX is increased to 32.
- To ensure binary compatibility for old executables
under multibyte locale, versioned setlocale is added.
- __mb_len_cur definision is added in setlocale.c
and enable it in stdlib.h .
It is also important for multibyte locale stuffs,
but I just forgot.
 1.15.2.1 08-Aug-2000  tshiozak file limits.h was added on branch sommerfeld_i386mp_1 on 2000-08-08 22:31:14 +0000
 1.16.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.2.1 03-Aug-2004  skrll Sync with HEAD
 1.17.48.1 22-Oct-2006  yamt sync with head
 1.17.46.1 18-Nov-2006  ad Sync with head.
 1.17.16.2 03-Sep-2007  yamt sync with head.
 1.17.16.1 30-Dec-2006  yamt sync with head.
 1.18.28.1 06-Nov-2007  matt sync with HEAD
 1.18.26.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.18.22.1 03-Sep-2007  skrll Sync with HEAD.
 1.18.16.1 03-Oct-2007  garbled Sync with HEAD
 1.18.8.1 09-Oct-2007  ad Sync with head.
 1.20.26.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.20.20.2 11-Aug-2010  yamt sync with head.
 1.20.20.1 04-May-2009  yamt sync with head.
 1.20.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.21.16.1 03-Jul-2010  rmind sync with head
 1.21.14.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.21.8.1 24-Oct-2010  jym Sync with HEAD
 1.22.12.1 05-Apr-2012  mrg sync to latest -current.
 1.22.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.22.8.1 17-Apr-2012  yamt sync with head
 1.23.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.23.2.1 23-Jun-2013  tls resync from head
 1.24.8.1 10-Aug-2014  tls Rebase.
 1.24.4.1 18-May-2014  rmind sync with head
 1.25.28.1 10-Jun-2019  christos Sync with HEAD
 1.25.26.1 26-Jan-2019  pgoyette Sync with HEAD
 1.8 01-Oct-1998  erh Moved to compat/linux/i386/linux_machdep.h.
 1.7 11-Sep-1998  mycroft Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.6 11-Jun-1998  drochner Since wscons can support VT_xxx ioctl()s, enable them if NWSDISPLAY > 0.
Implement KDGKBTYPE and KDGKBENT, this will make X servers happy.
 1.5 03-May-1996  christos Add missing prototypes.
 1.4 27-Aug-1995  fvdl A couple of definitions added for previous changes.
 1.3 07-May-1995  mycroft Improve Linux signal emulation, and emulate the modify_ldt() call.
 1.2 22-Apr-1995  christos - added sunos_machdep.c for sun3, atari, amiga and mac68k.
- changed machdep.c and trap.c to use struct emul.
- remove ep_setup references.
- added struct emul to all emulations.
 1.1 07-Apr-1995  fvdl Arch dependant defs for Linux. Just signal stackframe definition for now.
 1.9 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.8 01-Oct-2007  ad Now that the bootblocks are the same, share loadfile_machdep.h between
amd64 and i386.
 1.7 27-Sep-2007  ad - Make i386 bootblocks boot amd64 kernels, and change to say "NetBSD/x86..."
- Don't bother booting a.out kernels any more.
 1.6 25-Jan-2006  christos branches: 1.6.28; 1.6.36; 1.6.46; 1.6.48; 1.6.50;
free -> dealloc
unsigned -> size_t for alloc/dealloc
 1.5 27-Oct-2003  junyoung branches: 1.5.16; 1.5.28;
Nuke __P().
 1.4 31-Oct-2001  thorpej branches: 1.4.2; 1.4.18;
Split elf32 vs. elf64 handling in loadfile(), including support for
each separately and explicitly. BOOT_ELF is now BOOT_ELF32 and
BOOT_ELF64, and ELFSIZE should no longer be defined in loadfile_machdep.h.
 1.3 30-Nov-1999  drochner branches: 1.3.8; 1.3.10; 1.3.14;
Allow loading of kernels larger than (16-1)M.
XXX This is a stopgap fix which can be pulled up to 1.4.x. It only replaces
the arbitrary 16M boundary by an arbitrary 128M boundary. A clean solution
would need changes to the mi loadfile.c parts.
 1.2 28-Apr-1999  christos branches: 1.2.2; 1.2.4; 1.2.10;
Fix tyop
 1.1 28-Apr-1999  christos MD defines for the MI loadfile
 1.2.10.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.4.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.2.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.3.14.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.3.10.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.8.1 14-Nov-2001  nathanw Catch up to -current.
 1.4.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.18.1 03-Aug-2004  skrll Sync with HEAD
 1.4.2.2 31-Oct-2001  thorpej Split elf32 vs. elf64 handling in loadfile(), including support for
each separately and explicitly. BOOT_ELF is now BOOT_ELF32 and
BOOT_ELF64, and ELFSIZE should no longer be defined in loadfile_machdep.h.
 1.4.2.1 31-Oct-2001  thorpej file loadfile_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-10-31 17:20:47 +0000
 1.5.28.1 01-Feb-2006  yamt sync with head.
 1.5.16.2 27-Oct-2007  yamt sync with head.
 1.5.16.1 21-Jun-2006  yamt sync with head.
 1.6.50.1 06-Oct-2007  yamt sync with head.
 1.6.48.1 06-Nov-2007  matt sync with HEAD
 1.6.46.1 02-Oct-2007  joerg Sync with HEAD.
 1.6.36.1 03-Oct-2007  garbled Sync with HEAD
 1.6.28.1 09-Oct-2007  ad Sync with head.
 1.9 27-Feb-2003  fvdl Adapt for move to x86/include.
 1.8 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.7 30-Jan-2003  thorpej Test _KERNEL_OPT before including opt_*.h files.
 1.6 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.5 30-Apr-2001  lukem branches: 1.5.2; 1.5.10;
remove some lint, including ansifying some inlines
 1.4 02-May-2000  thorpej branches: 1.4.6; 1.4.8;
Let each platform typedef the new __cpu_simple_lock_t, which should
be the most efficient type used for the atomic operations in the
simplelock structure, and should also be __volatile.
 1.3 29-Apr-2000  thorpej Implement __cpu_simple_{,un}lock{,try}(), modeled after the Alpha
implementation.
 1.2 29-Apr-2000  thorpej Require that each each MACHINE/MACHINE_ARCH supply a lock.h. This file
contains the values __SIMPLELOCK_LOCKED and __SIMPLELOCK_UNLOCKED, which
replace the old SIMPLELOCK_LOCKED and SIMPLELOCK_UNLOCKED. These files
are also required to supply inline functions __cpu_simple_lock(),
__cpu_simple_lock_try(), and __cpu_simple_unlock() if locking is to be
supported on that platform (i.e. if MULTIPROCESSOR is defined in the
_KERNEL case). Change these functions to take an int * (&alp->lock_data)
rather than the struct simplelock * itself.

These changes make it possible for userland to use the locking primitives
by including <machine/lock.h>.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2;
file lock.h was initially added on branch sommerfeld_i386mp_1.
 1.1.2.7 05-May-2002  sommerfeld Make C++-safe
 1.1.2.6 29-Dec-2001  sommerfeld Add barriers, just in case
 1.1.2.5 30-Apr-2001  sommerfeld Catch up on some files missed the last time 'round
 1.1.2.4 07-Jan-2001  sommerfeld For the sake of my sanity, make this match the code in lock_machdep.c
a bit more closely.
 1.1.2.3 31-Aug-2000  sommerfeld Protect include of opt_lockdebug.h
 1.1.2.2 03-May-2000  sommerfeld Only do cpu_simple locks out-of-line if LOCKDEBUG is defined
 1.1.2.1 20-Feb-2000  sommerfeld Declarations of of cpu_simple_*lock* functions.
(currently not inlined, for debuggability)
 1.4.8.2 18-Oct-2002  nathanw Catch up to -current.
 1.4.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.6.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.6.1 02-May-2000  bouyer file lock.h was added on branch thorpej_scsipi on 2000-11-20 20:09:29 +0000
 1.5.10.3 20-Mar-2002  thorpej * Add a memory clobber to the atomic operations in the lock-acquire
path, so that the compiler will treat them as a memory access barrier.
* Spin with a normal memory load until the lock is released and then
retry the compare-and-swap in __cpu_simple_lock().
 1.5.10.2 20-Mar-2002  thorpej Use the new P4 "pause" insn in the body of the __cpu_simple_lock()
loop.
 1.5.10.1 19-Mar-2002  thorpej Change __cpu_simple_lock_t to a single byte.
 1.5.2.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2 04-Nov-2024  christos Undo previous lwp.h change.
 1.1 03-Nov-2024  christos Split __lwp_getprivate_fast and __lwp_*tcb from mcontext.h into a separate
lwp.h file.
 1.1 30-Nov-2024  christos branches: 1.1.4;
Create a new header lwp_private.h to contain _lwp_getprivate_fast,
_lwp_gettcb_fast, _lwp_settcb and remove them from mcontext.h, so that:
1. we don't need special hacks to hide them
2. we can include <lwp.h> where needed to get the necessary prototypes
without redefining them locally.
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 30-Nov-2024  perseant file lwp_private.h was added on branch perseant-exfatfs on 2025-08-02 05:55:44 +0000
 1.3 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.2 25-Jun-2005  christos branches: 1.2.82; 1.2.84; 1.2.86;
the siginfo trap codes are mi.
 1.1 04-Dec-2003  christos branches: 1.1.4;
add stub file so that the kernel compiles.
 1.1.4.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.4.2 03-Aug-2004  skrll Sync with HEAD
 1.1.4.1 04-Dec-2003  skrll file mach_machdep.h was added on branch ktrace-lwp on 2004-08-03 10:36:04 +0000
 1.2.86.1 16-May-2008  yamt sync with head.
 1.2.84.1 18-May-2008  yamt sync with head.
 1.2.82.1 02-Jun-2008  mjf Sync with HEAD.
 1.5 26-Apr-2011  joerg Remove Darwin, MACH and Mach-O support.
 1.4 28-Apr-2008  martin branches: 1.4.14; 1.4.22; 1.4.28;
Remove clause 3 and 4 from TNF licenses
 1.3 29-Oct-2002  manu branches: 1.3.108; 1.3.110; 1.3.112;
Introduce an array of supported CPU types by a given arch for Mach-O
 1.2 14-Jul-2001  christos branches: 1.2.2; 1.2.4; 1.2.6;
add MACHO_MACHDEP_CASES
 1.1 14-Jul-2001  christos new i386 files for macho and mach.
 1.2.6.3 11-Nov-2002  nathanw Catch up to -current
 1.2.6.2 24-Aug-2001  nathanw Catch up with -current.
 1.2.6.1 14-Jul-2001  nathanw file macho_machdep.h was added on branch nathanw_sa on 2001-08-24 00:08:34 +0000
 1.2.4.2 03-Aug-2001  lukem update to -current
 1.2.4.1 14-Jul-2001  lukem file macho_machdep.h was added on branch kqueue on 2001-08-03 04:11:45 +0000
 1.2.2.2 14-Jul-2001  christos add MACHO_MACHDEP_CASES
 1.2.2.1 14-Jul-2001  christos file macho_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-07-14 03:05:52 +0000
 1.3.112.1 16-May-2008  yamt sync with head.
 1.3.110.1 18-May-2008  yamt sync with head.
 1.3.108.1 02-Jun-2008  mjf Sync with HEAD.
 1.4.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.4.22.1 31-May-2011  rmind sync with head
 1.4.14.1 02-May-2011  jym Sync with head.
 1.5 22-Oct-2003  kleink Use a common <machine/math.h> for amd64 and i386.
 1.4 19-Feb-2002  simonb branches: 1.4.2; 1.4.18;
Clean up some rampant code duplication wrt ieee number handling:
- Add alignment-safe double and float unions.
- Use the above for the __infinity and __nan constants on all
architectures that use the standard ieee754 representation of
those constants.
- Add a single copy of various ieee754 math functions (frexp, isinf,
isnan, ldexp and modf) that had numerous duplicates among the
arch-specific directories.
- Use the above functions on all architectures where the generic C
versions where used. Architectures that had local assembly
routines are untouched (for those functions only).
 1.3 05-Feb-2000  kleink branches: 1.3.8; 1.3.10; 1.3.12;
Improve namespace test macros a bit.
 1.2 04-Jan-2000  kleink const -> __const and include <sys/cdefs.h> earlier; fixes PR lib/9052
by Takahiro Kambe.
 1.1 23-Dec-1999  kleink C99: Define a NAN macro in <math.h> which evaulates to a constant expression of
a single-precision quiet NaN; only to be defined on platforms that do support
this value.
 1.3.12.1 16-Mar-2002  jdolecek Catch up with -current.
 1.3.10.1 28-Feb-2002  nathanw Catch up to -current.
 1.3.8.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.8.1 05-Feb-2000  bouyer file math.h was added on branch thorpej_scsipi on 2000-11-20 20:09:29 +0000
 1.4.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.4.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.4.18.1 03-Aug-2004  skrll Sync with HEAD
 1.4.2.2 19-Feb-2002  simonb Clean up some rampant code duplication wrt ieee number handling:
- Add alignment-safe double and float unions.
- Use the above for the __infinity and __nan constants on all
architectures that use the standard ieee754 representation of
those constants.
- Add a single copy of various ieee754 math functions (frexp, isinf,
isnan, ldexp and modf) that had numerous duplicates among the
arch-specific directories.
- Use the above functions on all architectures where the generic C
versions where used. Architectures that had local assembly
routines are untouched (for those functions only).
 1.4.2.1 19-Feb-2002  simonb file math.h was added on branch sommerfeld_i386mp_1 on 2002-02-19 13:08:15 +0000
 1.15 01-Jul-2011  dyoung #include <sys/bus.h> instead of <machine/bus.h>.
 1.14 03-Apr-2011  dyoung Clean up excessive #ifdef'age of NMI trap handling for amd64/i386/xen.
Handle NMI in all Xen kernels.
 1.13 04-May-2009  cegger branches: 1.13.4; 1.13.6;
struct device * -> device_t
No functional changes intended.
 1.12 11-Apr-2007  garbled branches: 1.12.38; 1.12.52;
add the define of MCA_MAX_SLOTS here
 1.11 04-Mar-2007  christos branches: 1.11.2; 1.11.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.10 26-Dec-2005  perry branches: 1.10.26;
u_intN_t -> uintN_t
 1.9 26-Feb-2003  fvdl branches: 1.9.18;
Redirect some includes to x86/foo.h
 1.8 02-Dec-2001  jdolecek branches: 1.8.2;
Add couple hooks, needed primarily for NCR 53C90 MCA card driver:
* add flag to explicitly specify if the DMA should be done as 16bit or 8bit
* add flag to specify the DMA should happen via I/O port
* add new function mca_dma_set_ioport(), to set I/O port to be used for the
DMA operation

Also clarify copyright (welcome to 2001 :), and couple other minor nits
 1.7 23-Nov-2001  jdolecek add mca_dmamap_create() prototype for MI code
 1.6 02-May-2001  jdolecek branches: 1.6.4;
The system configuration block structure doesn't need to be public
 1.5 22-Apr-2001  jdolecek Introduce machdep mca_disk_[un]busy(), which turn on/off disk LED.
Call as appropriate from the ESDI disk driver
 1.4 09-Jul-2000  jdolecek branches: 1.4.4; 1.4.6;
move struct sys_config from mca_machdep.c to mca_machdep.h
fix copyright (overlooked in original commit)
use bitmask_snprintf() instead of printf("...%b") (though that part is commented
out anyway ATM)
 1.3 04-Jun-2000  cgd Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).
 1.2 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.1 11-May-2000  jdolecek branches: 1.1.2;
Add i386-specific part of MicroChannel Architecture bus support, as
found in some older IBM PS/2 machines.

This code is based upon work by Scott D. Telford, with some minor bits
in arch/i386/mca/mca_machdep.c taken from FreeBSD.

XXX this is still very experimental and development version; use at your
XXX own risk
 1.1.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.4.6.2 08-Jan-2002  nathanw Catch up to -current.
 1.4.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.4.4.3 23-Apr-2001  bouyer Sync with HEAD.
 1.4.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.4.1 09-Jul-2000  bouyer file mca_machdep.h was added on branch thorpej_scsipi on 2000-11-20 20:09:29 +0000
 1.6.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.8.2.2 02-Dec-2001  jdolecek Add couple hooks, needed primarily for NCR 53C90 MCA card driver:
* add flag to explicitly specify if the DMA should be done as 16bit or 8bit
* add flag to specify the DMA should happen via I/O port
* add new function mca_dma_set_ioport(), to set I/O port to be used for the
DMA operation

Also clarify copyright (welcome to 2001 :), and couple other minor nits
 1.8.2.1 02-Dec-2001  jdolecek file mca_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-12-02 17:02:34 +0000
 1.9.18.2 03-Sep-2007  yamt sync with head.
 1.9.18.1 21-Jun-2006  yamt sync with head.
 1.10.26.2 15-Apr-2007  yamt sync with head.
 1.10.26.1 12-Mar-2007  rmind Sync with HEAD.
 1.11.4.1 11-Jul-2007  mjf Sync with head.
 1.11.2.1 27-May-2007  ad Sync with head.
 1.12.52.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.12.52.3 02-May-2011  jym Sync with head.
 1.12.52.2 01-Nov-2009  jym Sync with HEAD.
 1.12.52.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.12.38.1 16-May-2009  yamt sync with head
 1.13.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.13.4.1 21-Apr-2011  rmind sync with head
 1.19 30-Nov-2024  christos Create a new header lwp_private.h to contain _lwp_getprivate_fast,
_lwp_gettcb_fast, _lwp_settcb and remove them from mcontext.h, so that:
1. we don't need special hacks to hide them
2. we can include <lwp.h> where needed to get the necessary prototypes
without redefining them locally.
 1.18 04-Nov-2024  christos Undo previous lwp.h change.
 1.17 03-Nov-2024  christos Split __lwp_getprivate_fast and __lwp_*tcb from mcontext.h into a separate
lwp.h file.
 1.16 18-May-2024  thorpej branches: 1.16.2;
Clean up the <sys/ucontext.h> <-> <machine/mcontext.h> interface up
a little:
- Define _UC_MD_BIT* constants for the available machine-dependent bits,
and use those constants to define the machine-dependent bits as well
as the machine-independent bits that have machine-dependent values.
- Explicitly generate an error if _UC_TLSBASE, _UC_SETSTACK, or
_UC_CLRSTACK are not defined by <machine/mcontext.h>.
 1.15 27-Dec-2019  kamil Harmonize the namespace of fast TLS base pointer getter functions

Protect __lwp_getprivate_fast() with _RTLD_SOURCE, _LIBC_SOURCE and
__LIBPTHREAD_SOURCE__.

Include in this namespace <sys/tcl.h> and use __BEGIN_DECLS/__END_DECLS
for the sake of consistency.
 1.14 15-Feb-2018  kamil branches: 1.14.4;
Introduce _UC_MACHINE_FP() as a macro

_UC_MACHINE_FP() is a helper macro to extract from mcontext a frame pointer.

Don't rely on this interface as a compiler might strip frame pointer or
optimize it making this interface unreliable.


For hppa assume a small frame context, for larger frames FP might be located
in a different register (4 instead of 3).

For ia64 there is no strict frame pointer, and registers might rotate.
Reuse 79 following:

./gcc/config/ia64/ia64.h:#define HARD_FRAME_POINTER_REGNUM LOC_REG (79)

Once ia64 will mature, this should be revisited.

A macro can encapsulate a real function for extracting Frame Pointer on
more complex CPUs / ABIs.


For the remaining CPUs, reuse standard register as defined in appropriate ABI.

The direct users of this macro are LLVM and GCC with Sanitizers.

Proposed on tech-userlevel@.

Sponsored by <The NetBSD Foundation>
 1.13 12-Aug-2017  maxv Remove vm86.

Pass 4.
 1.12 15-Feb-2014  dsl branches: 1.12.6; 1.12.22;
Load and save the fpu registers (for copies to/from userspace) using
helper functions in arch/x86/x86/fpu.c
They (hopefully) ensure that we write to the entire buffer and don't load
values that might cause faults in kernel.
Also zero out the 'pad' field of the i386 mcontext fp area that I think
once contained the registers of any Weitek fpu.
Dunno why it wasn't pasrt of the union.
Some of these copies could be removed if the code directly copied the save
area to/from userspace addresses.
 1.11 04-Feb-2014  dsl Remove the fields from 'struct save87' and 'struct fxsave' that were used
to save the control word and tag word on fp faults.
Nothing I could find looked at them before I removed the code that wrote them.
It might appear that these fields got exported to userspace (via mcontext),
but that code carefully avoided those fields.
I've also deleted some very historic fields from the union inside __fpregset_t
this doesn't affect its size.
The __fpregset_t fields are now the same size as the ones in the pcb.
Which is good because they get cast to each other in a few places.
 1.10 25-Feb-2011  joerg branches: 1.10.4; 1.10.14; 1.10.18;
Be nicer to software that insists on -ansi and use __inline.
 1.9 24-Feb-2011  joerg Allow storing and receiving the LWP private pointer via ucontext_t
on all platforms except VAX and IA64. Add fast access via register for
AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace
the stack based pthread_self(). Implement skeleton support for Alpha,
HPPA, PowerPC, SPARC and SPARC64, but leave it disabled.

Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in
machine/types.h and a corresponding __lwp_getprivate_fast in
machine/mcontext.h.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.8 23-Feb-2011  joerg Fix ucontext32_t on AMD64. Add optional compile time assertions for
ucontext_t and ucontext32_t to ensure that they don't change.
Provide the constants for AMD64, ARM, i386, and M68K.
 1.7 28-Apr-2008  martin branches: 1.7.14; 1.7.22; 1.7.28; 1.7.30;
Remove clause 3 and 4 from TNF licenses
 1.6 08-Oct-2003  thorpej branches: 1.6.102; 1.6.104; 1.6.106;
Add some accessor macros for the ucontext:
* _UC_MACHINE_PC() - access the program counter
* _UC_MACHINE_INTRV() - access the integer return value register
* _UC_MACHINE_SET_PC() - set the program counter (this requires
special handling on some platforms).
 1.5 06-Sep-2003  christos SA_SIGINFO changes.
 1.4 25-Aug-2003  tron Protect inclusion of "opt_vm86.h" with "#ifdef _KERNEL_OPT" as appropriate.
 1.3 25-Aug-2003  drochner fix _UC_MACHINE_SP() for the vm86 case: we have to add the SS offset
 1.2 17-Jan-2003  thorpej branches: 1.2.2;
Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file mcontext.h was initially added on branch nathanw_sa.
 1.1.2.5 19-Dec-2002  thorpej Expose _UC_UCONTEXT_ALIGN.
 1.1.2.4 06-Sep-2002  nathanw Define an alignment constraint, _UC_UCONTEXT_ALIGN; put it and
_UC_MACHINE_SP() inside #ifdef _KERNEL.
 1.1.2.3 14-Aug-2002  nathanw Add space for the fxsave/XMM save area to mcontext_t; since the fxsave
format includes the x87 register state (although in a different bit
pattern), make it overlap the x87 save area, and add a flag to
indicate that this format is in use.

This makes mcontext_t 264 bytes larger, for a total of 720 bytes.
 1.1.2.2 28-Dec-2001  nathanw Add a macro, _UC_MACHINE_SP(), to fetch the user stack pointer from
a ucontext_t.
 1.1.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.2.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.2.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.2.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.106.1 16-May-2008  yamt sync with head.
 1.6.104.1 18-May-2008  yamt sync with head.
 1.6.102.1 02-Jun-2008  mjf Sync with HEAD.
 1.7.30.1 05-Mar-2011  bouyer Sync with HEAD
 1.7.28.1 06-Jun-2011  jruoho Sync with HEAD.
 1.7.22.1 05-Mar-2011  rmind sync with head
 1.7.14.1 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.10.18.1 18-May-2014  rmind sync with head
 1.10.14.2 03-Dec-2017  jdolecek update from HEAD
 1.10.14.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.10.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.12.22.3 21-Mar-2018  martin Pull up the following, requested by kamil in ticket #552:

external/gpl3/gcc{.old}/dist/libsanitizer/asan/asan_linux.cc 1.4
sys/arch/aarch64/include/mcontext.h 1.2
sys/arch/alpha/include/mcontext.h 1.9
sys/arch/amd64/include/mcontext.h 1.19
sys/arch/arm/include/mcontext.h 1.19
sys/arch/hppa/include/mcontext.h 1.9
sys/arch/i386/include/mcontext.h 1.14
sys/arch/ia64/include/mcontext.h 1.6
sys/arch/m68k/include/mcontext.h 1.10
sys/arch/mips/include/mcontext.h 1.22
sys/arch/or1k/include/mcontext.h 1.2
sys/arch/powerpc/include/mcontext.h 1.18
sys/arch/riscv/include/mcontext.h 1.5
sys/arch/sh3/include/mcontext.h 1.11
sys/arch/sparc/include/mcontext.h 1.14-1.17
sys/arch/sparc64/include/mcontext.h 1.10
sys/arch/vax/include/mcontext.h 1.9
tests/lib/libc/sys/Makefile 1.50
tests/lib/libc/sys/t_ucontext.c 1.2-1.5
sys/arch/hppa/include/mcontext.h 1.10
sys/arch/ia64/include/mcontext.h 1.7

- Introduce _UC_MACHINE_FP(). _UC_MACHINE_FP() is a helper
macro to extract from mcontext a frame pointer.
- Add new tests in lib/libc/sys/t_ucontext:
* ucontext_sp (testing _UC_MACHINE_SP)
* ucontext_fp (testing _UC_MACHINE_FP)
* ucontext_pc (testing _UC_MACHINE_PC)
* ucontext_intrv (testing _UC_MACHINE_INTRV)

Add a dummy implementation of _UC_MACHINE_INTRV() for ia64.

Implement _UC_MACHINE_INTRV() for hppa.

Make the t_ucontext.c test more portable.

We now have _UC_MACHINE_FP.
 1.12.22.2 26-Feb-2018  snj revert ticket 552, which broke the build
 1.12.22.1 25-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #552):
sys/arch/aarch64/include/mcontext.h: 1.2
sys/arch/alpha/include/mcontext.h: 1.9
sys/arch/amd64/include/mcontext.h: 1.19
sys/arch/arm/include/mcontext.h: 1.19
sys/arch/hppa/include/mcontext.h: 1.9
sys/arch/i386/include/mcontext.h: 1.14
sys/arch/ia64/include/mcontext.h: 1.6
sys/arch/m68k/include/mcontext.h: 1.10
sys/arch/mips/include/mcontext.h: 1.22
sys/arch/or1k/include/mcontext.h: 1.2
sys/arch/powerpc/include/mcontext.h: 1.18
sys/arch/riscv/include/mcontext.h: 1.5
sys/arch/sh3/include/mcontext.h: 1.11
sys/arch/sparc/include/mcontext.h: 1.14-1.17
sys/arch/sparc64/include/mcontext.h: 1.10
sys/arch/vax/include/mcontext.h: 1.9
tests/lib/libc/sys/Makefile: 1.50
tests/lib/libc/sys/t_ucontext.c: 1.2
Introduce _UC_MACHINE_FP() as a macro
_UC_MACHINE_FP() is a helper macro to extract from mcontext a frame pointer.
Don't rely on this interface as a compiler might strip frame pointer or
optimize it making this interface unreliable.
For hppa assume a small frame context, for larger frames FP might be located
in a different register (4 instead of 3).
For ia64 there is no strict frame pointer, and registers might rotate.
Reuse 79 following:
./gcc/config/ia64/ia64.h:#define HARD_FRAME_POINTER_REGNUM LOC_REG (79)
Once ia64 will mature, this should be revisited.
A macro can encapsulate a real function for extracting Frame Pointer on
more complex CPUs / ABIs.
For the remaining CPUs, reuse standard register as defined in appropriate ABI.
The direct users of this macro are LLVM and GCC with Sanitizers.
Proposed on tech-userlevel@.
Sponsored by <The NetBSD Foundation>
--
Improve _UC_MACHINE_FP() for SPARC/SPARC64
Introduce a static inline function _uc_machine_fp() that contains improved
caluclation of a frame pointer.
Algorithm:
uptr *stk_ptr;
# if defined (__arch64__)
stk_ptr = (uptr *) (*sp + 2047);
# else
stk_ptr = (uptr *) *sp;
# endif
*bp = stk_ptr[15];
Noted by <mrg>
--
Make _UC_MACHINE_FP() compile again and fix it so that it does not add
the offset twice.
--
fix _UC_MACHINE32_FP() -- use 32 bit pointer value so that [15] is
the right offset. do this by using __greg32_t, which is only in
the sparc64 version, and these are only useful there, so move them.
--
Add new tests in lib/libc/sys/t_ucontext
New tests:
- ucontext_sp
- ucontext_fp
- ucontext_pc
- ucontext_intrv
They test respectively:
- _UC_MACHINE_SP
- _UC_MACHINE_FP
- _UC_MACHINE_PC
- _UC_MACHINE_INTRV
These tests attempt to access and print the values from ucontext, without
interpreting the values.
This is a follow up of the _UC_MACHINE_FP() introduction.
These tests use PRIxREGISTER, and require to be built with -D_KERNTYPES.
Sponsored by <The NetBSD Foundation>
 1.12.6.1 28-Aug-2017  skrll Sync with HEAD
 1.14.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16.2.1 02-Aug-2025  perseant Sync with HEAD
 1.5 15-May-2003  wiz Don't install machine/mouse.h on i386 and prep; there are no users for
the old busmouse interface any longer, we use wsmouse now.
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 20-Dec-1993  mycroft branches: 1.3.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2 02-Aug-1993  mycroft branches: 1.2.2;
Add RCS identifiers, remove some completely useless RCS logs and patchkit
headers, and a few other insignificant changes.
 1.1 13-Jun-1993  andrew Microsoft/Logitech busmouse ioctls.
 1.2.2.1 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.3.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.3.2.1 20-Dec-1993  mycroft file mouse.h was added on branch magnum on 1993-12-20 05:25:25 +0000
 1.3 11-May-2003  fvdl Redirect to x86/
 1.2 10-Jan-2003  fvdl Pass acpi_softc down to mpacpi functions.
 1.1 07-Jan-2003  fvdl branches: 1.1.2;
Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.1.2.3 15-Jan-2003  thorpej Sync with HEAD.
 1.1.2.2 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.1 07-Jan-2003  thorpej file mpacpi.h was added on branch nathanw_sa on 2003-01-07 21:11:47 +0000
 1.4 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.3 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file mpbiosreg.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.4 23-Sep-2000  sommerfeld Eliminate magic number -- use MPS_ALL_APICS instead of 0xff
 1.1.2.3 29-Feb-2000  sommerfeld Multiple include protection.
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld "register" definitions for the Intel MP BIOS (spec rev 1.4).

These data structures are defined by the BIOS and are read by our MP
BIOS driver to figure out the configuration of a multiprocessor PC.
 1.2.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.2.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.2.2.1 01-Oct-2002  nathanw file mpbiosreg.h was added on branch nathanw_sa on 2002-10-18 02:37:56 +0000
 1.6 04-Mar-2003  fvdl Enable the define for EISA MPBIOS support.
 1.5 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.4 07-Jan-2003  fvdl Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.3 06-Oct-2002  fvdl branches: 1.3.2;
Add cpu_id field to mp_intr_map structure. Declare mp_nintr.
 1.2 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 20-Feb-2000  sommerfeld branches: 1.1.2; 1.1.4;
file mpbiosvar.h was initially added on branch sommerfeld_i386mp_1.
 1.1.4.1 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.2.5 25-Jun-2002  sommerfeld Resynch with -current.
 1.1.2.4 21-Aug-2000  sommerfeld Give systems reporting EISA interrupts in the mpbios tables a prayer
of working.
 1.1.2.3 29-Feb-2000  sommerfeld mpbiosreg.h
 1.1.2.2 21-Feb-2000  sommerfeld RCS ID patrol
 1.1.2.1 20-Feb-2000  sommerfeld MP BIOS support, including some of the interrupt-routing data
structures built after parsing the MP BIOS information.
 1.3.2.3 07-Jan-2003  thorpej Sync with HEAD.
 1.3.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.1 06-Oct-2002  nathanw file mpbiosvar.h was added on branch nathanw_sa on 2002-10-18 02:37:56 +0000
 1.2 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.1 07-Jan-2003  fvdl branches: 1.1.2;
Add various external declarations to accomodate ACPI MP probing as an
alternate method to MPBIOS probing. Move some stuff common to the two
methods into mpconfig.h
 1.1.2.2 07-Jan-2003  thorpej Sync with HEAD.
 1.1.2.1 07-Jan-2003  thorpej file mpconfig.h was added on branch nathanw_sa on 2003-01-07 21:11:49 +0000
 1.3 16-Jan-1994  mycroft Clean up deleted files.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.7 19-Feb-2003  fvdl Revert previous. This file is also used on x86_64, you see.
 1.6 09-Feb-2003  jdolecek make k6_mtrr_funcs, i686_mtrr_funcs and mtrr_funcs const
remove extern definition for i686_mtrr_funcs from include/mtrr.h, it's
not used outside mtrr_i686.c
 1.5 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.4 19-Sep-2001  thorpej branches: 1.4.2;
Add code to frob the MTRR-like registers on the AMD K6-2
and AMD K6-III.
 1.3 19-Sep-2001  thorpej Define UWCCR bits for the AMD K6 (these are its MTRR-like registers).
 1.2 10-Sep-2001  fvdl MTRR include file, based on the one by Bill Sommerfeld from the i386 mp
branch.
 1.1 23-Sep-2000  sommerfeld branches: 1.1.2; 1.1.4; 1.1.6;
file mtrr.h was initially added on branch sommerfeld_i386mp_1.
 1.1.6.1 01-Oct-2001  fvdl Catch up with -current.
 1.1.4.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.1.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.1.4.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.1.2.2 22-Sep-2001  sommerfeld Merge branch with current, post ubcperf, MTRR, etc., etc.,
with the recent fifo_putpages fix to the trunk, GENERIC.MPDEBUG config
boots multiuser on my BP6.
 1.1.2.1 23-Sep-2000  sommerfeld Preliminary support for cloning MTRR values between CPU's at boot time.
XXX no API to *set* MTRR values yet.
 1.4.2.2 21-Sep-2001  nathanw Catch up to -current.
 1.4.2.1 19-Sep-2001  nathanw file mtrr.h was added on branch nathanw_sa on 2001-09-21 22:35:09 +0000
 1.11 18-Oct-2019  manu Multiboot2 kernel support for i386

That implementation works either with BIOS or UEFI bootstrap

This requires the following kernel changes:

Add UEFI boot services and I/O method protoypes
src/sys/arch/x86/include/efi.h 1.8 - 1.9

Fix EFI system table mapping in virtual space
src/sys/arch/x86/x86/efi.c 1.19 - 1.20

Make sure no bioscall is issued when booting off UEFI system
src/sys/arch/i386/i386/machdep.c 1.821 - 1.822
src/sys/arch/i386/pci/piixpcib.c 1.22 - 1.23

And the following bootstrap changes:

Add kernel symbols for multiboot1
src/sys/arch/i386/stand/lib/exec_multiboot1.c 1.2 - 1.3
src/sys/arch/i386/stand/lib/libi386.h 1.45 - 1.47

Fix kernel symbols for multiboot2
src/sys/arch/i386/stand/lib/exec_multiboot2.c 1.2 - 1.3
 1.10 13-Nov-2018  mlelstv Framebuffer definitions for multiboot protocol.
 1.9 13-Apr-2018  khorben branches: 1.9.2;
Correct discrepancy with the Multiboot specification

The VBE mode was missing, and the types of the subsequent VBE members
were also wrong. Nothing in NetBSD's base seems to be using this, and
therefore nothing is expected to break as a result of this fix, or any
binary to change for that matter.
The latest specification (as of today) can be found at:
https://www.gnu.org/software/grub/manual/multiboot/multiboot.html

This was already reported in misc/52366, and addresses part of it.

Patch sent to port-i386@. Build-tested on NetBSD/amd64.
 1.8 22-Feb-2009  ahoka branches: 1.8.62;
Add a missing opt_multiboot.h into sys/arch/i386/i386/machdep.c.
Also do the missed rename of multiboot_ksyms_init to
multiboot_ksyms_addsyms_elf to compile with MULTIBOOT set.

This caused a minor and a more serious bug in the past:
- dmesg did not contain the information about the loader
- /dev/ksyms did not work when the kernel was booted with a
multiboot bootloader (grub for example)

Ok by jmcneill, joerg.
 1.7 11-Oct-2008  joerg branches: 1.7.2; 1.7.8;
Add "multiboot" command to boot multiboot compliant kernels like Xen.
Patch provided by Robert Swindell with fixes for the command line
parsing and addition of passing module options from me. The kernel now
always gets the full string for modules like for the command line,
everything before the first space/tab is the path name of the module.
 1.6 28-Apr-2008  martin branches: 1.6.6;
Remove clause 3 and 4 from TNF licenses
 1.5 21-Feb-2007  thorpej branches: 1.5.42; 1.5.44; 1.5.46;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.4 25-Oct-2006  jmmv branches: 1.4.4;
Remove the usage of Multiboot's "a.out kludge" to tell the boot loader to
reserve some more space for the BSS section than the binary says. This
trick was used to leave room after the kernel's image to copy the symbol
table following the format required by ksyms_init. (It was also used to
workaround a bug in the physical address fields of the binary, but this has
been long fixed.) Yes, the MULTIBOOT_SYMTAB_SPACE option goes away; yay!

Instead, copy the required data after the kernel in a way that avoids having
to reserve space and use the new ksyms_init_explicit function to avoid the
need to construct a minimal ELF image.

Fixes ksyms when using an "unpatched" GRUB (one that does not contain the
fix to honour the "a.out kludge" for ELF images, even when present) -- i.e.
ddb and lkms. As a side effect, the new code is much clearer to read and
digest.

Closes PR port-i386/32865.
 1.3 04-Feb-2006  jmmv branches: 1.3.2; 1.3.14; 1.3.18; 1.3.20; 1.3.22;
Revert yesterday's change that attempted to fix the detection of the
boot device when using a Multiboot boot loader. It couldn't work because
these boot loaders do not pass a checksum of the disk so matchbiosdisk()
cannot really find any matches. I should have gone to sleep before
commiting...

Found by xtraeme@.
 1.2 03-Feb-2006  jmmv branches: 1.2.2;
When booting an i386 kernel with Multiboot, properly detect the boot device
by looking it up in the x86_alldisks table (instead of trying to match it
to 'wd*' manually).

In order to do this, move the cpu_rootconf function from x86 common code
to amd64 and i386 specific one. This way, i386 can do an extra step (call
the appropriate Multiboot code) in the appropriate place (after
x86_matchbiosdisks and before findroot()).
 1.1 03-Feb-2006  jmmv Implement support for 'The Multiboot Specification' so that i386 kernels
can be booted directly from Multiboot-compliant boot loaders (e.g. GRUB).
See the added multiboot(8) manual page for more information.

No objections in tech-kern@; only positive comments.
 1.2.2.1 22-Apr-2006  simonb Sync with head.
 1.3.22.1 10-Dec-2006  yamt sync with head.
 1.3.20.2 09-Sep-2006  rpaulo sync with head
 1.3.20.1 04-Feb-2006  rpaulo file multiboot.h was added on branch rpaulo-netinet-merge-pcb on 2006-09-09 02:40:14 +0000
 1.3.18.1 18-Nov-2006  ad Sync with head.
 1.3.14.4 26-Feb-2007  yamt sync with head.
 1.3.14.3 30-Dec-2006  yamt sync with head.
 1.3.14.2 21-Jun-2006  yamt sync with head.
 1.3.14.1 04-Feb-2006  yamt file multiboot.h was added on branch yamt-lazymbuf on 2006-06-21 14:52:30 +0000
 1.3.2.2 18-Feb-2006  yamt sync with head.
 1.3.2.1 04-Feb-2006  yamt file multiboot.h was added on branch yamt-uio_vmspace on 2006-02-18 15:38:37 +0000
 1.4.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.5.46.2 04-May-2009  yamt sync with head.
 1.5.46.1 16-May-2008  yamt sync with head.
 1.5.44.1 18-May-2008  yamt sync with head.
 1.5.42.2 17-Jan-2009  mjf Sync with HEAD.
 1.5.42.1 02-Jun-2008  mjf Sync with HEAD.
 1.6.6.1 19-Oct-2008  haad Sync with HEAD.
 1.7.8.2 01-Nov-2009  jym Sync with HEAD.
 1.7.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.7.2.1 03-Mar-2009  skrll Sync with HEAD.
 1.8.62.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.8.62.1 16-Apr-2018  pgoyette Sync with HEAD, resolve some conflicts
 1.9.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9.2.1 10-Jun-2019  christos Sync with HEAD
 1.1 13-Sep-2019  manu branches: 1.1.2; 1.1.4; 1.1.12;
Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.
This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h
 1.1.12.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.1.12.1 13-Sep-2019  martin file multiboot2.h was added on branch phil-wifi on 2020-04-13 08:03:52 +0000
 1.1.4.2 18-Sep-2019  martin Pull up following revision(s) [adapted, via patch]
(requested by manu in ticket #1382):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
distrib/sets/lists/comp/md.amd64: revision 1.273
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
distrib/sets/lists/comp/md.i386: revision 1.191
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32
sys/external/bsd/gnu-efi/dist/inc/efiapi.h (apply patch)

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)

Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot

Add new multiboot2.h header.
 1.1.4.1 13-Sep-2019  martin file multiboot2.h was added on branch netbsd-8 on 2019-09-18 17:30:05 +0000
 1.1.2.2 17-Sep-2019  martin Pull up following revision(s) (requested by manu in ticket #203):

sys/arch/i386/include/multiboot2.h: revision 1.1
sys/arch/i386/stand/lib/exec.c: revision 1.74
sys/arch/i386/stand/efiboot/efiboot.c: revision 1.11
sys/arch/i386/stand/efiboot/bootia32/multiboot32.S: revision 1.1
sys/arch/i386/stand/lib/biosdisk.c: revision 1.52
sys/arch/i386/stand/efiboot/bootx64/efibootx64.c: revision 1.5
sys/arch/i386/stand/efiboot/eficons.c: revision 1.7
sys/arch/i386/stand/efiboot/bootia32/efibootia32.c: revision 1.5
sys/arch/i386/stand/lib/libi386.h: revision 1.45
sys/arch/i386/stand/lib/bootinfo_memmap.c: revision 1.6
sys/arch/i386/stand/lib/pread.c: revision 1.8
sys/arch/i386/stand/efiboot/efiboot.h: revision 1.10
sys/arch/i386/stand/efiboot/bootia32/Makefile: revision 1.3
sys/arch/i386/stand/lib/Makefile: revision 1.47
sys/arch/i386/stand/efiboot/bootx64/Makefile: revision 1.2
sys/arch/i386/stand/lib/multiboot.S: revision 1.3
sys/arch/i386/stand/efiboot/bootx64/multiboot64.S: revision 1.1
sys/arch/i386/stand/efiboot/efimemory.c: revision 1.9
sys/arch/i386/stand/efiboot/boot.c: revision 1.16
sys/arch/i386/include/Makefile: revision 1.50
sys/arch/i386/stand/efiboot/Makefile.efiboot: revision 1.16
share/man/man8/man8.x86/boot.8: revision 1.20
sys/arch/i386/stand/boot/Makefile.boot: revision 1.73
sys/arch/i386/stand/pxeboot/Makefile: revision 1.26
sys/arch/i386/stand/lib/exec_multiboot1.c: revision 1.1
sys/arch/i386/stand/netboot/Makefile.netboot: revision 1.11
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.1
sys/arch/i386/stand/lib/biosdisk.h: revision 1.12
sys/arch/i386/stand/lib/exec_multiboot2.c: revision 1.2
sys/arch/i386/stand/dosboot/Makefile: revision 1.32

Add multiboot 2 support to x86 bootloaders

multiboot 2 is required to boot Xen on an EFI system.

This also require a kernel patch for properly discovering
the ACPI RSDP, which is available after 20190912, in
src/sys/arch/x86/acpi/acpi_machdep.c 1.26-1.28

There are a few missing bit in this multiboot 2 implementation
(which are unused by Xen):
- Header tags Address, Freambuffer, and Relocatable are ignored
- Tags APM and Network are not provided
- Tags ACPI old and ACP new are only provided for ACPI boot
- Tag boot device does not provides the subpart (BSD disklabel partition)
Notes:
- multiboot2 is disabled in dosboot, otherwise the binary
gets too big and build fails.
- in src/sys/arch/i386/stand/efiboot, consinit() is renamed
as efi_consinit() to avoid prototype conflicts in src/sys/sys/systm.h

Remove debug define.

It remained there unseen because it was misspelled!

Remove obsoeolete BUGS note that UEFI bootloader does not support multiboot
 1.1.2.1 13-Sep-2019  martin file multiboot2.h was added on branch netbsd-9 on 2019-09-17 19:31:59 +0000
 1.2 09-Feb-2007  ad branches: 1.2.4;
Merge newlock2 to head.
 1.1 10-Sep-2006  ad branches: 1.1.2;
file mutex.h was initially added on branch newlock2.
 1.1.2.4 29-Dec-2006  ad Checkpoint work in progress.
 1.1.2.3 24-Oct-2006  ad Compile fixes
 1.1.2.2 20-Oct-2006  ad - Don't need locked bus cycles on release from C code.
- Save an integer ID in the lock structures for LOCKDEBUG code.
 1.1.2.1 10-Sep-2006  ad Add updated locking primatives.
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file mutex.h was added on branch yamt-lazymbuf on 2007-02-26 09:07:02 +0000
 1.1 17-Mar-2002  thorpej branches: 1.1.2;
file mutex_impl.h was initially added on branch newlock.
 1.1.2.5 22-Mar-2002  thorpej Wrap the stuff that manipulates the guts of a mutex in __MUTEX_PRIVATE.
 1.1.2.4 22-Mar-2002  thorpej Add debug info structures if MUTEX_DEBUG or RWLOCK_DEBUG is
defined.

XXX Revisit, so that the structure doesn't change when debugging
is turned on; do it out-of-band?
 1.1.2.3 19-Mar-2002  thorpej Shuffle around the mutex structure and change some types, so that
now the mutex structure is 1/2 the size it was before (8 bytes vs 16).
 1.1.2.2 18-Mar-2002  thorpej Remove an untrue comment.
 1.1.2.1 17-Mar-2002  thorpej Add first-cut mutex and rwlock implementation bits for the x86.
XXX Does not actually handle i386 CPUs yet, only i486 and later.
 1.36 12-Feb-2014  dsl Change i386 to use x86/fpu.c instead of i386/isa/npx.c
This changes the trap10 and trap13 code to call directly into fpu.c,
removing all the code for T_ARITHTRAP, T_XMM and T_FPUNDA from i386/trap.c
Not all of the code thate appeared to handle fpu traps was ever called!
Most of the changes just replace the include of machine/npx.h with x86/fpu.h
(or remove it entirely).
 1.35 07-Feb-2014  dsl Convert the amd64 build to use x86/cpu_extended_state.h so that the fpu
definitions match those of i386.
Mostly just structure and field renames, in addition:
1) process_xmm_to_s87() and process_s87_to_xmm() moved into
x86/convert_xmm_s87.c so they can be used by amd64's netbsd32 code.
2) The linux signal code simplified to use a structure copy for ths fxsave
data - it matches the hardware definition and won't change.
 1.34 07-Feb-2014  dsl Move all the hardware register layout for the x86 cpus into a header
that can also be used by amd64.
Add in skeleton definitions for XSAVE and AVX.
Update some comments to match reality.
 1.33 04-Feb-2014  dsl Remove the fields from 'struct save87' and 'struct fxsave' that were used
to save the control word and tag word on fp faults.
Nothing I could find looked at them before I removed the code that wrote them.
It might appear that these fields got exported to userspace (via mcontext),
but that code carefully avoided those fields.
I've also deleted some very historic fields from the union inside __fpregset_t
this doesn't affect its size.
The __fpregset_t fields are now the same size as the ones in the pcb.
Which is good because they get cast to each other in a few places.
 1.32 26-Jan-2014  dsl Remove support for 'external' floating point units and the MS-DOS
compatible method of handling floating point exceptions.
Make kernel support for teh fpu non-optional (486SX should still work).
Only 386 cpus support external fpu, and i386 support was removed years ago.
This means that the npx code no longer uses port 0xf0 or interupt 13.
All the "npx at isa" lines go from the configs, arch/i386/isa/npx.c
is now mandatory for all i386 kernels.
I've renamed npxinit() to fpuinit() and npxinit_cpu() to fpuinit_cpu()
to match the very similar amd64 functions.
The fpu of the boot cpu is now initialised by a direct call from
cpu_configure(), this enables FP emulation for a 486SX.
(for amd64 the cr0 values are set in locore.S and similar).
This fixes a long-standing bug in linux_setregs() - which did not
save the fpu regsiters if they were active.
I've test booted a single cpu i386 kernel (using anita).
amd64 builds - none of teh changes should affect it.
The i386 XEN kernels build, but I'm not sure where they set cr0, and
it might have got lost!
 1.31 25-Jan-2014  dsl Change the way the x87 fp register is defined so that the copies between
fsave and fxsave layouts can be done by structure assignments.
 1.30 25-Jan-2014  christos help lint.
 1.29 19-Jan-2014  dsl Add a couple of __CTASSERT() for the sizes of the fp save structures.
 1.28 19-Jan-2014  dsl Flatten the floating point register structures bu moving the
'environment' registers into the main strcuture.
There are x87 instructions that only affect the environment, but that
is no real excuse for all the sub-structures.
Rename fields so that there are far fewer collisions between the two
sets of field names.
 1.27 08-Dec-2013  dsl Rename the fields of 'struct envxmm' (itself badly named) so that they
are different from those used for the x87 fpu.
Use a union to describe the 64bit 'address' field so that it correctly
spilt for 32bit binaries.
The freebsd emulation defined its own 'struct freebsd_env87' that the
code just assumed matched the netbsd one.
Since this is a hardware structure, just use the netbsd one.
This shouldn't change the binaries except that 'en_fos' used to be
incorrectly a 32bit field.
 1.26 11-Nov-2013  joerg NetBSD 6.99.26: Switch i386 and amd64 to the x87 default control word
as initial value for new processes. This means that long double
computations get the expected 63bit mantissa. Binaries tagged as
compiled for 6.99.25 and older get the old value.

Add a simple test case to ensure that double and long double computation
are working correctly.
 1.25 31-Jul-2010  joerg branches: 1.25.8; 1.25.18; 1.25.22;
Add support for fenv.h interface for i386 and amd64.

Submitted by Stathis Kamperis as part of GSoC 2010 and ported from
FreeBSD.
 1.24 25-Jul-2010  christos map npx control/status codes into siginfo codes.
 1.23 25-Sep-2009  mlelstv branches: 1.23.2; 1.23.4;
The FPU Tag word is a 16bit register, in FPU (387) mode it
defines 2-bit tags for each FPU data register, in MMX mode it
defines 1-bit tags for each data register. The single bit
tags are stored in the lower 8 bits and thus in the first byte
of the save frame.

See amd64/include/fpu.h and the IA-32 Software Developer's manual Vol 2A.
 1.22 02-May-2006  drochner branches: 1.22.12; 1.22.66; 1.22.76; 1.22.80; 1.22.84;
-explicitely align "struct savexmm" so that we don't get surprised
if we play with the PCB
-remove historical "struct emcsts"; there is no support in context
switching code for ages (if there has ever been)
 1.21 10-Oct-2005  christos branches: 1.21.10; 1.21.12; 1.21.14; 1.21.16; 1.21.18;
Add defines for the control and status bits of the 80387.
 1.20 07-Aug-2003  agc branches: 1.20.2; 1.20.6; 1.20.14; 1.20.16;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.19 01-Oct-2002  fvdl branches: 1.19.6;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.18 03-Aug-2001  thorpej Upon further reading of the manual, don't save the MXCSR-at-last-exception.
Its status bits are sticky, and unaffacted by FNINIT.
 1.17 03-Aug-2001  thorpej In setregs(), initialize the process's MXCSR to the reset-default
value as documented in the IA-32 Instruction Set Reference (in the
description of the LDMXCSR insn).
 1.16 03-Aug-2001  thorpej Remember the MXCSR at last-exception the way we do the FPU SW/TW.
 1.15 02-Aug-2001  thorpej Add support for saving/restoring SSE/SSE2 state using FXSAVE/FXRSTOR.

Reviewed by Frank.
 1.14 26-Jan-1999  christos branches: 1.14.16; 1.14.22; 1.14.24;
add prototypes for the assembly functions that moved to locore.s
 1.13 24-Jan-1998  mycroft Add some comments about what the control words do.
 1.12 24-Jan-1998  mycroft Store the initial NPX control word appropriate for the emulation in the saved
FPU state, and use it when initializing the FPU on demand.
 1.11 27-Oct-1994  cgd branches: 1.11.20;
new RCS ID format.
 1.10 22-Sep-1994  jtc Updated bde's comments wrt. i387 control word settings so that they
describe NetBSD, rather than 386BSD 0.1.
Removed 386BSD and BDE control word constants, since we don't need and
will never use them. However, The iBCS control word constant is kept,
since we might want to use it in the iBCS binary compatibility code.
 1.9 25-Jan-1994  jtc branches: 1.9.2; 1.9.4;
FPU control word of 0x137f doesn't work well in "real" world applications
so I've changed it to 0x127f. 64 bit precision causes errors in paranoia
and our math library, changing to 53 bit precision solves these problems.

I've been told that long double support in Gcc 2.5 requires 64 bit mode,
so a comprehensive FP strategy (compiler, library, FPU, emulator) will
have to be addressed in the future.
 1.8 17-Jan-1994  jtc My previous checkin didn't really change the FPU Exception Mask -- it was
trapped inside an #ifdef -- this commit changes it as I had originally
intended.
 1.7 08-Jan-1994  jtc Change default NetBSD NPX control word to 0x137f.
This masks all FP exceptions (like every other UNIX system), and makes
it possible for gcc 2.5's long double support to work.
 1.6 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.5 07-Dec-1993  deraadt __386BSD__ -> __NetBSD__
 1.4 29-Jul-1993  jtc branches: 1.4.2;
Change "#endif FOO" to "#endif /* FOO */", to keep gcc -Wall, lint, etc.
from complaining about a trivial issue.
 1.3 22-May-1993  cgd add rcsids to everything and clean up headers
 1.2 09-May-1993  deraadt npx patches from Bruce Evans. patchkit 10002
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.1 10-Dec-1993  cgd 386bsd -> NetBSD
 1.9.4.1 06-Oct-1994  mycroft Update from trunk.
 1.9.2.2 25-Jan-1994  jtc FPU control word of 0x137f doesn't work well in "real" world applications
so I've changed it to 0x127f. 64 bit precision causes errors in paranoia
and our math library, changing to 53 bit precision solves these problems.

I've been told that long double support in Gcc 2.5 requires 64 bit mode,
so a comprehensive FP strategy (compiler, library, FPU, emulator) will
have to be addressed in the future.
 1.9.2.1 25-Jan-1994  jtc file npx.h was added on branch magnum on 1994-01-25 19:58:31 +0000
 1.11.20.1 29-Jan-1998  mellon Pull up 1.12 and 1.13 (mycroft)
 1.14.24.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.14.24.1 03-Aug-2001  lukem update to -current
 1.14.22.2 18-Oct-2002  nathanw Catch up to -current.
 1.14.22.1 24-Aug-2001  nathanw Catch up with -current.
 1.14.16.2 03-Sep-2001  sommerfeld Merge with -current once more.
 1.14.16.1 10-Jan-2001  sommerfeld Significant rewrite of slave CPU attach and initialization, centering
on identifycpu() and spreading outward.

Separate feature probes (cpuid invocation), which runs on the cpu
being attached, from the display of this information, which runs on
the boot cpu; remove some of the probe code from locore as it doesn't
need to run that early.

We now spin up secondary cpu's during cpu_attach, have them do a cpu
feature probe, and then have them spin waiting for a "go" signal.

We no longer pay attention to the cpu signature and cpuid features
reported by the MP BIOS since those are known to be truncated for at
least some bioses.

We now do npx initialization (including FDIV bug detection) on all
cpus.

XXX Change some of the cyrix bug workarounds to fit the new
identifycpu() system; this is untested.
 1.19.6.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.19.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.19.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.19.6.1 03-Aug-2004  skrll Sync with HEAD
 1.20.16.1 21-Jun-2006  yamt sync with head.
 1.20.14.1 11-Oct-2005  tron Pull up following revision(s) (requested by christos in ticket #880):
sys/arch/i386/include/npx.h: revision 1.21
Add defines for the control and status bits of the 80387.
 1.20.6.1 11-Oct-2005  riz Pull up following revision(s) (requested by christos in ticket #5923):
sys/arch/i386/include/npx.h: revision 1.21
Add defines for the control and status bits of the 80387.
 1.20.2.1 11-Oct-2005  riz Pull up following revision(s) (requested by christos in ticket #5923):
sys/arch/i386/include/npx.h: revision 1.21
Add defines for the control and status bits of the 80387.
 1.21.18.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.21.16.1 11-May-2006  elad sync with head
 1.21.14.1 24-May-2006  yamt sync with head.
 1.21.12.1 01-Jun-2006  kardel Sync with head.
 1.21.10.1 09-Sep-2006  rpaulo sync with head
 1.22.84.1 21-Apr-2010  matt sync to netbsd-5
 1.22.80.2 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.22.80.1 01-Nov-2009  jym Sync with HEAD.
 1.22.76.1 03-Oct-2009  snj Pull up following revision(s) (requested by mlelstv in ticket #1050):
sys/arch/i386/include/npx.h: revision 1.23
The FPU Tag word is a 16bit register, in FPU (387) mode it
defines 2-bit tags for each FPU data register, in MMX mode it
defines 1-bit tags for each data register. The single bit
tags are stored in the lower 8 bits and thus in the first byte
of the save frame.
See amd64/include/fpu.h and the IA-32 Software Developer's manual Vol 2A.
 1.22.66.2 11-Aug-2010  yamt sync with head.
 1.22.66.1 11-Mar-2010  yamt sync with head
 1.22.12.1 18-Oct-2009  bouyer Pull up following revision(s) (requested by mlelstv in ticket #1362):
sys/arch/i386/include/npx.h: revision 1.23
The FPU Tag word is a 16bit register, in FPU (387) mode it
defines 2-bit tags for each FPU data register, in MMX mode it
defines 1-bit tags for each data register. The single bit
tags are stored in the lower 8 bits and thus in the first byte
of the save frame.
See amd64/include/fpu.h and the IA-32 Software Developer's manual Vol 2A.
 1.23.4.1 05-Mar-2011  rmind sync with head
 1.23.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.25.22.1 18-May-2014  rmind sync with head
 1.25.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.89 20-Apr-2025  riastradh t_signal_and_sp: Add i386 support.

i386 too is confused by misaligned sigaltstack or esp on interrupt.

PR kern/59327: user stack pointer is not aligned properly
 1.88 31-May-2021  simonb branches: 1.88.18;
Include "opt_param.h" (ifdef _KERNEL_OPT) everywhere that MSGBUFSIZE is
referenced since some sources include <machine/param.h>.
 1.87 05-Mar-2020  riastradh branches: 1.87.8;
Revert "Include opt_diagnostic.h for DIAGNOSTIC."

This did not do what I thought it did. opt_diagnostic.h is only for
the unused _DIAGNOSTIC, which seems like an abortive attempt to
incrementally convert DIAGNOSTIC to an opt_*.h option rather than a
command-line option.
 1.86 05-Mar-2020  riastradh Include opt_diagnostic.h for DIAGNOSTIC.

...at least, in header files, which may not have already included
libkern.h.
 1.85 20-Aug-2019  riastradh New macro ALIGNED_POINTER_LOAD.

To be used with ALIGNED_POINTER(p,t) instead of writing *(const t *)p
directly. This way, on machines without strict alignment, we can use
memcpy to pacify sanitizers, while getting the same compiled code in
the end with a single (say) MOV instruction.
 1.84 07-Jan-2019  jdolecek branches: 1.84.4;
move DEV_BSIZE, DEV_BSHIFT out of MD param.h, they are same on all ports

also move BLKDEV_IOSIZE, MAXPHYS, but allow override since some ports
have different value (powerpc uses NBPG for BLKDEV_IOSIZE, sun2/sun3
have lower MAXPHYS)
 1.83 19-Feb-2018  sborrill branches: 1.83.2; 1.83.4;
Double size of MSGBUFSIZE as existing value is not big enough to hold boot dmesg
on modern server-class hardware with lots of CPUs, etc.
 1.82 29-Jul-2017  maxv Remove unused.
 1.81 14-Jun-2017  maxv Define MAXPHYSMEM globally.
 1.80 20-Jan-2017  maya branches: 1.80.6;
increase max io mem on amd64. some devices need it.
 1.79 26-Aug-2016  mlelstv branches: 1.79.2;
The 64MB was intended.
 1.78 27-Oct-2015  mrg branches: 1.78.2;
make sure MSGBUFSIZE can't expand strangely by using parens.
 1.77 20-Apr-2012  rmind branches: 1.77.2; 1.77.14; 1.77.16;
- Convert x86 MD code, mainly pmap(9) e.g. TLB shootdown code, to use
kcpuset(9) and thus replace hardcoded CPU bitmasks. This removes the
limitation of maximum CPUs.

- Support up to 256 CPUs on amd64 architecture by default.

Bug fixes, improvements, completion of Xen part and testing on 64-core
AMD Opteron(tm) Processor 6282 SE (also, as Xen HVM domU with 128 CPUs)
by Manuel Bouyer.
 1.76 10-Feb-2012  para branches: 1.76.2;
proper sizing of kmem_arena on different ports

PR port-i386/45946: Kernel locks up in VMEM system
 1.75 04-Feb-2012  para improve sizing of kmem_arena now that more allocations are made from it
don't enforce limits if not required

ok: riz@
 1.74 24-Jan-2012  christos Use and define ALIGN() ALIGN_POINTER() and STACK_ALIGN() consistently,
and avoid definining them in 10 different places if not needed.
 1.73 20-Jan-2012  joerg Change CMSG_SPACE and CMSG_LEN to provide Integer Constant Expressions
again. This was changed in sys/socket.h r1.51 to work around fallout
from the IPv6 aux data migration. It broke the historic ABI on some
platforms. This commit restores compatibility for netbsd32 code on such
platforms and provides a template for future changes to the CMSG_*
alignment. Revert PCC/Clang workarounds in postfix and tmux.
 1.72 08-Feb-2010  joerg branches: 1.72.10; 1.72.14;
Remove separate mb_map. The nmbclusters is computed at boot time based
on the amount of physical memory and limited by NMBCLUSTERS if present.
Architectures without direct mapping also limit it based on the kmem_map
size, which is used as backing store. On i386 and ARM, the maximum KVA
used for mbuf clusters is limited to 64MB by default.

The old default limits and limits based on GATEWAY have been removed.
key_registered_sb_max is hard-wired to a value derived from 2048
clusters.
 1.71 10-Mar-2009  bouyer branches: 1.71.2;
More i386PAE fixes:
- x86_round_page, x86_trunc_page, x86_btop and x86_ptob macros are used with
physical addresses; cast to paddr_t instead of u_long. Issue pointed out
by jym@
- machine_to_phys_mapping[] is a long. This is fine as it holds page
frame numbers (and this fits in a 32bit int as physical addresses are
only 36bits), but cast to paddr_t before << PAGE_SHIFT
- xen_start_info.store_mfn is a long; cast it to paddr_t before << PAGE_SHIFT.
should fix issue pointed out by cegger@
 1.70 20-Dec-2008  ad branches: 1.70.2;
Revert part of previous.
 1.69 20-Dec-2008  ad opt_noredzone.h is gone.
 1.68 20-Dec-2008  ad - Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.67 18-Oct-2007  yamt branches: 1.67.16; 1.67.20; 1.67.28; 1.67.30;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.66 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.65 13-Oct-2007  joerg branches: 1.65.2;
Bump default size of the message buffer from 16 KB to 32 KB.
This is large enough that boot -v on most systems fits into the
message buffer, which makes it easier for debugging.
 1.64 03-Oct-2007  ad Back out the ALIGNBYTES change. There are structures used in userspace
that depend on the constant.
 1.63 26-Sep-2007  ad x86 changes for pcc and LKMs.

- Replace most inline assembly with proper functions. As a side effect
this reduces the size of amd64 GENERIC by about 120kB, and i386 by a
smaller amount. Nearly all of the inlines did something slow, or something
that does not need to be fast.
- Make curcpu() and curlwp functions proper, unless __GNUC__ && _KERNEL.
In that case make them inlines. Makes curlwp LKM and preemption safe.
- Make bus_space and bus_dma more LKM friendly.
- Share a few more files between the ports.
- Other minor changes.
 1.62 08-Dec-2006  yamt branches: 1.62.6; 1.62.14; 1.62.22; 1.62.24; 1.62.26;
- pass intrframe by-pointer, not by-value.
- make i386 and xen use per-cpu interrupt stack.

xen part is reviewed by Manuel Bouyer.
 1.61 28-Aug-2006  yamt branches: 1.61.2; 1.61.4;
- remove unused bdbtofsb.
- move the following macros from MD headers to sys/param.h.
ctod
dtoc
ctob
btoc
dbtob
btodb
 1.60 04-Jun-2006  perry Wrap the UPAGES definition with an #ifndef so that (in emergencies) it
can be put into a kernel config file.

Stack overflows should be fixed, not patched around, but this makes it
easier to test if one is causing a panic.
 1.59 22-May-2006  yamt i386 and xen: move struct user to the highest address in uarea
and reduce UPAGES from 4 to 3 in the case of !NOREDZONE.
 1.58 07-Nov-2005  yamt branches: 1.58.6; 1.58.8; 1.58.10; 1.58.14; 1.58.16;
some assym cleanup.
- move copyin and friends from locore.S to their own file, copy.S.
share it between i386 and xen.
- defparam KERNBASE and kill KERNBASE_LOCORE hack.
- add more symbols to assym.h and use it where appropriate.
 1.57 08-Aug-2003  christos branches: 1.57.16;
cleanup the mess with KERNBASE and KERNBASE_LOCORE.
 1.56 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.55 18-Jul-2003  tls Allow redefiniton of KERNBASE. Because the type of this constant is
different for locore.S and the rest of the kernel, if you redefine
it from the default value, you must also define KERNBASE_LOCORE -- this
is ugly, but so is having the same constant with two different types
depending where in the kernel it's used...
 1.54 26-Feb-2003  fvdl branches: 1.54.2;
Redirect some includes to x86/foo.h
 1.53 02-Nov-2002  perry 1) egg, meet face. face, meet egg.
2) re-UL KERNBASE, but this time, protect it with #ifndef _LOCORE so we
don't get a big kaboom in .S files.
 1.52 02-Nov-2002  kristerw Revert previous. The assembler bombs on UL integer suffix.
 1.51 02-Nov-2002  perry define KERNBASE with a UL -- eliminates 830 or so lines of lint.
 1.50 06-Oct-2002  fvdl If NOREDZONE is defined, keep UPAGES at 2 as before.
 1.49 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.48 26-Feb-2002  simonb branches: 1.48.10;
Purge CLSIZE, CLSIZELOG2 and MCLOFSET.
Be consistant in the way that MSIZE, MCLSHIFT, MCLBYTES and NMBCLUSTERS
are defined.
Remove old VM constants from cesfic port.
Bump MSIZE to 256 on mipsco (the only one that wasn't already 256).
 1.47 03-Aug-2001  groo Remove trailing "U" on KERNBASE introduced in last commit.
Breaks assembly of locore.
 1.46 03-Aug-2001  thorpej Define KERNTEXTOFF in terms of KERNBASE.
 1.45 30-May-2001  mrg branches: 1.45.2;
use _KERNEL_OPT
 1.44 02-Apr-2001  fvdl Override NFS read and write size to default to 32k for the i386 here
(can be overridden from a config file).
 1.43 19-Sep-2000  fvdl branches: 1.43.2;
Bring the default value of NMBCLUSTERS into the modern age.
 1.42 13-Aug-2000  christos cast to u_long before casting to u_int to appease lint.
 1.41 30-Jun-2000  itojun raise MSIZE from 128 to 256.
- for sizeof(void *) == 8 arch, this is mandatory. MHLEN is too small
already (less than 80) and there are chances for unwanted packet loss due
to m_pullup restriction.
- for other cases, the change should avoid allocating clusters in most cases
(even when you have IPv4 IPsec tunnel, or IPv6 with moderate amount of
extension header)

portmasters: if your arch chokes with the change (high memory usage or
whatever), please backout the change for your arch.
 1.40 11-Feb-2000  thorpej branches: 1.40.2; 1.40.6;
Update for the NKMEMPAGES changes.
 1.39 11-Feb-2000  thorpej Move KERNBASE to 0xc0000000, giving the kernel a more-or-less full 1G
of virtual address space, leaving userland with 3G, and update comments
to match the new reality.

We knew we were going to have to bite this bullet eventually, and there
are a couple of outstanding PRs related to this issue (9389 and 9313).
Complete solution to those PRs is going to involve some sort of run-time
decision on how large kmem_map should be, as well as changing some data
structure allocation strategies in UVM. However, this change will at
least allow the PR submitter to simply throw resources at the problem.
 1.38 04-Dec-1999  ragge CL* discarding.
 1.37 10-Mar-1999  sommerfe branches: 1.37.2; 1.37.8; 1.37.14;
Increase default MSGBUFSIZE due to more and chattier drivers in -current
 1.36 01-Jul-1998  mjacob allow a config file to redefine MAXPHYS
 1.35 29-Apr-1998  thorpej Pull in opt_gateway.h as appropriate.
 1.34 20-Jan-1998  drochner remove unused and misleading KERNSIZE definition
 1.33 20-Oct-1997  fvdl Change various constants that depend on the kernel VM base address. Lower
it to 0xf0000000 to give it more breathing space.
 1.32 19-Sep-1997  leo Implement the kernel part of pr-1891. This allows for a more flexible sized
msgbuf. Note that old 'dmesg' and 'syslogd' binaries will continue running,
though old 'dmesg' binaries will output a few bytes of junk at the start of
the buffer, and will miss a few bytes at the end of the buffer.
 1.31 26-Feb-1997  jonathan branches: 1.31.4;
Protect MCLSHIFT definition so users can customize MCLBYTES.
 1.30 24-Feb-1997  fvdl Define ALIGNED_POINTER
 1.29 04-Mar-1996  cgd branches: 1.29.8;
add _MACHINE and _MACHINE_ARCH, which are like MACHINE and MACHINE_ARCH,
execpt without quotes. meant to be __CONCAT()ted for easy #includes
of machine-dependent headers for MI code (e.g. for the MI ISA/EISA/PCI/TC
bus code).
 1.28 01-Mar-1996  cgd Clean up tabbing/spacing in defns of MACHINE, MACHINE_ARCH, and MID_MACHINE.
 1.27 01-Feb-1996  mycroft LOCORE -> _LOCORE
 1.26 26-Jun-1995  cgd clean up definitions of ctod(), dtoc(), ctob(), btoc(), btodb(), and
dbtob(). remove unused definitions of ctos(), stoc(), and dtob().
 1.25 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.24 18-Mar-1995  cgd don't be so quick to cast macro arguments to unsigned; if the
arguments are really off_t's (e.g. to btodb), then you can lose
information. This was the "> 4G file systems don't work" bug; physio
uses btodb, which was broken.
 1.23 27-Oct-1994  cgd new RCS ID format.
 1.22 14-Oct-1994  cgd move arch dependence to archs. clean up a bit. deal with weird MAXPARTITONS.
 1.21 09-Oct-1994  mycroft Make the conversion macros more consistent.
 1.20 24-Aug-1994  mycroft Add USPACE.
 1.19 15-Aug-1994  mycroft Eliminate struct pte and struct pde.
 1.18 08-Apr-1994  mycroft branches: 1.18.2;
Only #include other stuff #ifdef KERNEL.
 1.17 03-Apr-1994  mycroft Make sure we get psl.h.
 1.16 09-Mar-1994  mycroft Back out previous change for now.
 1.15 08-Mar-1994  mycroft Inline spl*() calls.
 1.14 22-Feb-1994  hpeyerl Move some machine dependant disklabel stuff in here.
 1.13 05-Jan-1994  mycroft branches: 1.13.2;
Move kernel to 0xf8000000.
 1.12 22-Dec-1993  cgd add NPTEPG back in. gdb wants it. Thanks to Rich Murphey for pointing it out.
 1.11 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.10 04-Dec-1993  cgd add MACHINE_ARCH as i386
 1.9 09-Oct-1993  cgd patch from rod grimes:
Fix definitions to be in terms of a minimum number of constants by
using the SHIFT value as the basis for the other values, for example
instead of:
#define NBPG 4096
#define PGSHIFT 12
use:
#define PGSHIFT 12
#define NBPG (1 << PGSHIFT)
 1.8 03-Aug-1993  mycroft branches: 1.8.2;
Add ALIGNBYTES for new fts().
 1.7 05-Jul-1993  deraadt No need for the DELAY() macro. in userland. It just polutes the namespace.
 1.6 18-Jun-1993  cgd convert magic numbers to network byte order, and attendent changes
 1.5 05-Jun-1993  cgd change MCLSHIFT to 11, so mbuf cluster size is bigger than MTU
of network interfaces, for performance. to use old size,
use "options MCLSHIFT=10" in your kernel config.
 1.4 22-May-1993  cgd add rcsids to everything and clean up headers
 1.3 22-Apr-1993  mycroft Make mbuf sizes tunable from config file (from 386BSD path 134).
 1.2 01-Apr-1993  cgd changed value of NKMEMCLUSTERS, to help avoid kmem_map too small problem
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.8.2.4 04-Dec-1993  cgd add MACHINE_ARCH
 1.8.2.3 26-Oct-1993  mycroft Reduce NKMEMCLUSTERS back to 6MB. We don't need 16.
 1.8.2.2 15-Oct-1993  mycroft Major cleanup of include files and constants.
 1.8.2.1 09-Oct-1993  mycroft Merge changes from trunk.
 1.13.2.2 05-Jan-1994  mycroft Move kernel to 0xf8000000.
 1.13.2.1 05-Jan-1994  mycroft file param.h was added on branch magnum on 1994-01-05 16:02:37 +0000
 1.18.2.2 11-Oct-1994  mycroft Update from trunk.
 1.18.2.1 15-Aug-1994  mycroft update from trunk
 1.29.8.1 12-Mar-1997  is Merge in Changes from The Trunk.
 1.31.4.1 22-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.37.14.2 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.37.14.1 21-Dec-1999  wrstuden Initial commit of recent changes to make DEV_BSIZE go away.

Runs on i386, needs work on other arch's. Main kernel routines should be
fine, but a number of the stand programs need help.

cd, fd, ccd, wd, and sd have been updated. sd has been tested with non-512
byte block devices. vnd, raidframe, and lfs need work.

Non 2**n block support is automatic for LKM's and conditional for kernels
on "options NON_PO2_BLOCKS".
 1.37.8.2 21-Apr-2001  bouyer Sync with HEAD
 1.37.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.37.2.1 19-Feb-2000  he Apply patch (requested by thorpej):
Move KERNBASE to 0xc0000000, giving the kernel a more-or-less
full 1GB of virtual address space, leaving userland with 3GB,
and update comments to match the new reality.
 1.40.6.3 25-Apr-2001  he Pull up revision 1.43 (requested by itojun):
Bump NMBCLUSTERS to 1024 or 2048 in GATEWAY case (was 256/512).
 1.40.6.2 06-Apr-2001  he Pull up revision 1.44 (requested by fvdl):
Adjust default NFS operation size back to 8KB on all systems
except on i386.
 1.40.6.1 23-Jul-2000  itojun pullup from main trunc (approved by releng-1-5)

raise MSIZE from 128 to 256.
- for sizeof(void *) == 8 arch, this is mandatory. MHLEN is too small
already (less than 80) and there are chances for unwanted packet loss due
to m_pullup restriction.
- for other cases, the change should avoid allocating clusters in most cases
(even when you have IPv4 IPsec tunnel, or IPv6 with moderate amount of
extension header)

portmasters: if your arch chokes with the change (high memory usage or
whatever), please backout the change for your arch.

1.1 -> 1.2 syssrc/sys/arch/amigappc/include/param.h
1.13 -> 1.14 syssrc/sys/arch/arc/include/param.h
1.1 -> 1.2 syssrc/sys/arch/arm26/include/param.h
1.17 -> 1.18 syssrc/sys/arch/arm32/include/param.h
1.6 -> 1.7 syssrc/sys/arch/bebox/include/param.h
1.4 -> 1.5 syssrc/sys/arch/cobalt/include/param.h
1.4 -> 1.5 syssrc/sys/arch/evbsh3/include/param.h
1.2 -> 1.3 syssrc/sys/arch/hpcmips/include/param.h
1.40 -> 1.41 syssrc/sys/arch/i386/include/param.h
1.7 -> 1.8 syssrc/sys/arch/m68k/include/param.h
1.9 -> 1.10 syssrc/sys/arch/macppc/include/param.h
1.4 -> 1.5 syssrc/sys/arch/mmeye/include/param.h
1.6 -> 1.7 syssrc/sys/arch/newsmips/include/param.h
1.7 -> 1.8 syssrc/sys/arch/ofppc/include/param.h
1.23 -> 1.24 syssrc/sys/arch/pc532/include/param.h
1.32 -> 1.33 syssrc/sys/arch/pmax/include/param.h
1.7 -> 1.8 syssrc/sys/arch/powerpc/include/param.h
1.1 -> 1.2 syssrc/sys/arch/prep/include/param.h
1.1 -> 1.2 syssrc/sys/arch/sgimips/include/param.h
1.3 -> 1.4 syssrc/sys/arch/sh3/include/param.h
1.44 -> 1.45 syssrc/sys/arch/sparc/include/param.h
1.21 -> 1.22 syssrc/sys/arch/sparc64/include/param.h
1.43 -> 1.44 syssrc/sys/arch/vax/include/param.h
 1.40.2.7 27-Apr-2002  sommerfeld Merge with current as of today
 1.40.2.6 03-Sep-2001  sommerfeld Merge with -current once more.
 1.40.2.5 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.40.2.4 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.40.2.3 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.40.2.2 07-Aug-2000  sommerfeld Merge sommerfeld_i386mp_1 branch forward to 20000806 sources
 1.40.2.1 20-Feb-2000  sommerfeld Bump MSGBUFSIZE since mp_verbose is pretty verbose.
 1.43.2.6 11-Nov-2002  nathanw Catch up to -current
 1.43.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.43.2.4 28-Feb-2002  nathanw Catch up to -current.
 1.43.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.43.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.43.2.1 09-Apr-2001  nathanw Catch up with -current.
 1.45.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.45.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.45.2.1 03-Aug-2001  lukem update to -current
 1.48.10.1 13-Aug-2003  grant Pull up revision 1.55 via patch (requested by tls in ticket #1387):

Allow redefiniton of KERNBASE. Because the type of this constant is
different for locore.S and the rest of the kernel, if you redefine
it from the default value, you must also define KERNBASE_LOCORE -- this
is ugly, but so is having the same constant with two different types
depending where in the kernel it's used...
 1.54.2.4 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.54.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.54.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.54.2.1 03-Aug-2004  skrll Sync with HEAD
 1.57.16.3 27-Oct-2007  yamt sync with head.
 1.57.16.2 30-Dec-2006  yamt sync with head.
 1.57.16.1 21-Jun-2006  yamt sync with head.
 1.58.16.1 19-Jun-2006  chap Sync with head.
 1.58.14.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.58.10.3 03-Sep-2006  yamt sync with head.
 1.58.10.2 26-Jun-2006  yamt sync with head.
 1.58.10.1 24-May-2006  yamt sync with head.
 1.58.8.2 07-Jun-2006  kardel Sync with head.
 1.58.8.1 01-Jun-2006  kardel Sync with head.
 1.58.6.1 09-Sep-2006  rpaulo sync with head
 1.61.4.1 10-Dec-2006  yamt sync with head.
 1.61.2.1 12-Jan-2007  ad Sync with head.
 1.62.26.3 14-Oct-2007  yamt sync with head.
 1.62.26.2 08-Oct-2007  yamt remove an #ifdef _LOCORE.
 1.62.26.1 23-Sep-2007  yamt - sync with amd64.
- pmap_alloc_level: remove fast call special case.
- tweak some printf to work for both of LP64 and LP32.
- remove machdep.nkpde sysctl.
- remove automatic adjustment of nkpde for now. will revisit later.
 1.62.24.1 06-Nov-2007  matt sync with HEAD
 1.62.22.3 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.62.22.2 04-Oct-2007  joerg Sync with HEAD.
 1.62.22.1 02-Oct-2007  joerg Sync with HEAD.
 1.62.14.2 16-Oct-2007  garbled Sync with HEAD
 1.62.14.1 03-Oct-2007  garbled Sync with HEAD
 1.62.6.1 23-Oct-2007  ad Sync with head.
 1.65.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.67.30.4 30-Sep-2009  snj Pull up following revision(s) (requested by bouyer in ticket #1040):
sys/arch/i386/include/param.h: revision 1.71
sys/arch/i386/i386/db_memrw.c: revision 1.25
sys/arch/xen/include/xenpmap.h: revision 1.22
sys/arch/xen/xen/xenevt.c: revision 1.31
More i386PAE fixes:
- x86_round_page, x86_trunc_page, x86_btop and x86_ptob macros are used with
physical addresses; cast to paddr_t instead of u_long. Issue pointed out
by jym@
- machine_to_phys_mapping[] is a long. This is fine as it holds page
frame numbers (and this fits in a 32bit int as physical addresses are
only 36bits), but cast to paddr_t before << PAGE_SHIFT
- xen_start_info.store_mfn is a long; cast it to paddr_t before << PAGE_SHIFT.
should fix issue pointed out by cegger@
 1.67.30.3 16-Feb-2009  snj branches: 1.67.30.3.4;
Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/i386/include/param.h: revision 1.70
Revert part of previous.
 1.67.30.2 16-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/i386/include/param.h: revision 1.69
opt_noredzone.h is gone.
 1.67.30.1 16-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/i386/conf/GENERIC_TINY: revision 1.116
sys/arch/i386/conf/INSTALL_TINY: revision 1.122
sys/arch/i386/conf/files.i386: revision 1.341
sys/arch/i386/i386/vm_machdep.c: revision 1.142
sys/arch/i386/include/param.h: revision 1.68
sys/arch/xen/conf/files.xen: revision 1.91
- Kill NOREDZONE.
- Make the redzone conditional on DIAGNOSTIC.
- Give amd64 an additional page for the uarea. 2 is not enough.
 1.67.30.3.4.1 21-Apr-2010  matt sync to netbsd-5
 1.67.28.2 28-Apr-2009  skrll Sync with HEAD.
 1.67.28.1 19-Jan-2009  skrll Sync with HEAD.
 1.67.20.2 11-Mar-2010  yamt sync with head
 1.67.20.1 04-May-2009  yamt sync with head.
 1.67.16.1 17-Jan-2009  mjf Sync with HEAD.
 1.70.2.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.70.2.2 01-Nov-2009  jym Sync with HEAD.
 1.70.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.71.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.72.14.2 29-Apr-2012  mrg sync to latest -current.
 1.72.14.1 18-Feb-2012  mrg merge to -current.
 1.72.10.2 23-May-2012  yamt sync with head.
 1.72.10.1 17-Apr-2012  yamt sync with head
 1.76.2.1 09-May-2012  riz Pull up following revision(s) (requested by rmind in ticket #202):
sys/arch/x86/include/cpuvar.h: revision 1.46
sys/arch/xen/include/xenpmap.h: revision 1.34
sys/arch/i386/include/param.h: revision 1.77
sys/arch/x86/x86/pmap_tlb.c: revision 1.5
sys/arch/x86/x86/pmap_tlb.c: revision 1.6
sys/arch/i386/i386/genassym.cf: revision 1.92
sys/arch/xen/x86/cpu.c: revision 1.91
sys/arch/x86/x86/pmap.c: revision 1.177
sys/arch/xen/x86/xen_pmap.c: revision 1.21
sys/arch/x86/acpi/acpi_wakeup.c: revision 1.31
sys/kern/subr_kcpuset.c: revision 1.5
sys/arch/amd64/include/param.h: revision 1.18
sys/sys/kcpuset.h: revision 1.5
sys/arch/x86/x86/mtrr_i686.c: revision 1.26
sys/arch/x86/x86/mtrr_i686.c: revision 1.27
sys/arch/xen/x86/x86_xpmap.c: revision 1.43
sys/arch/x86/x86/cpu.c: revision 1.98
sys/arch/amd64/amd64/mptramp.S: revision 1.14
sys/kern/sys_sched.c: revision 1.42
sys/arch/amd64/amd64/genassym.cf: revision 1.50
sys/arch/i386/i386/mptramp.S: revision 1.24
sys/arch/x86/include/pmap.h: revision 1.52
sys/arch/x86/include/cpu.h: revision 1.50
- Convert x86 MD code, mainly pmap(9) e.g. TLB shootdown code, to use
kcpuset(9) and thus replace hardcoded CPU bitmasks. This removes the
limitation of maximum CPUs.
- Support up to 256 CPUs on amd64 architecture by default.
Bug fixes, improvements, completion of Xen part and testing on 64-core
AMD Opteron(tm) Processor 6282 SE (also, as Xen HVM domU with 128 CPUs)
by Manuel Bouyer.
- pmap_tlb_shootdown: do not overwrite tp_cpumask with pm_cpus, but merge
like pm_kernel_cpus. Remove unecessary intersection with kcpuset_running.
Do not reset tp_userpmap if pmap_kernel().
- Remove pmap_tlb_mailbox_t wrapping, which is pointless after recent changes.
- pmap_tlb_invalidate, pmap_tlb_intr: constify for packet structure.
i686_mtrr_init_first: handle the case when there are no variable-size MTRR
registers available (i686_mtrr_vcnt == 0).
 1.77.16.4 28-Aug-2017  skrll Sync with HEAD
 1.77.16.3 05-Feb-2017  skrll Sync with HEAD
 1.77.16.2 05-Oct-2016  skrll Sync with HEAD
 1.77.16.1 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.77.14.1 26-Mar-2017  snj Pull up following revision(s) (requested by maya in ticket #1375):
sys/arch/amd64/include/param.h: revision 1.20
sys/arch/i386/include/param.h: revision 1.80
sys/arch/x86/x86/bus_space.c: revision 1.39
increase max io mem on amd64. some devices need it.
 1.77.2.1 03-Dec-2017  jdolecek update from HEAD
 1.78.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.79.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.80.6.1 11-Apr-2018  martin Pull up following revision(s) (requested by sborrill in ticket #736):

sys/arch/i386/include/param.h: revision 1.83
sys/arch/amd64/include/param.h: revision 1.24

Double size of MSGBUFSIZE as existing value is not big enough to hold
boot dmesg on modern server-class hardware with lots of CPUs, etc.
 1.83.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.83.4.1 10-Jun-2019  christos Sync with HEAD
 1.83.2.1 18-Jan-2019  pgoyette Synch with HEAD
 1.84.4.1 08-Dec-2019  martin Pull up following revision(s) (requested by riastradh in ticket #505):

common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.7
common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.8
sys/sys/param.h: revision 1.610
sys/arch/amd64/include/param.h: revision 1.31
sys/arch/i386/include/param.h: revision 1.85

New macro ALIGNED_POINTER_LOAD.

To be used with ALIGNED_POINTER(p,t) instead of writing *(const t *)p
directly. This way, on machines without strict alignment, we can use
memcpy to pacify sanitizers, while getting the same compiled code in
the end with a single (say) MOV instruction.

Fix byte order bug in murmurhash and pacify sanitizers.
add now required includes for memcpy prototypes analogue to other hash functions
(fix the build)
 1.87.8.1 17-Jun-2021  thorpej Sync w/ HEAD.
 1.88.18.1 02-Aug-2025  perseant Sync with HEAD
 1.61 24-Apr-2025  kre offsetof() needs <stddef.h> (<sys/stddef.h>)

Include <sys/stddef.h> when offsetof() is to be used.

First step in fixing x86 builds.
 1.60 24-Apr-2025  riastradh amd64: Allocate FPU save state outside pcb if it's too large.

We have seen x86_fpu_save_size values (CPUID[EAX=0x0d, ECX=0].ECX) as
large as 11008 bytes, notably with Intel AMX TILEDATA's 8192-byte
state.

We only do this for user threads, and only on machines where it's
necessary, to avoid incurring much overhead. There is still a tiny
bit of overhead when saving and restoring the FPU state by using a
pointer indirection instead of arithmetic indirection for access to
struct pcb::pcb_savefpu, but this is probably a drop in the bucket
compared to the memory traffic incurred by the FPU state save/restore
anyway.

For now, these paths are mostly disabled on i386. We could enable
them but it will require either rewriting cpu_uarea_alloc/free for
i386, or adopting a guard page like amd64 does, which might be costly
and so should be undertaken only with some thought and care. And
since Intel AMX instructions only work in 64-bit mode, it's not
likely to be useful on i386.

PR port-amd64/57661: Crash when booting on Xeon Silver 4416+ in
KVM/Qemu

These changes, as a side effect, may fix:

PR kern/57258: kthread_fpu_enter/exit problem

by making sure to allocate an FPU save space that is large enough to
guarantee fpu_kern_enter/leave work safely, instead of just using a
union savefpu object on the stack (which, at 576 bytes, may be too
small on some machines, particularly with AVX512 requiring ~2.5K).
(But we'll have to do some extra work with kthread_fpu_enter/exit_md
-- if we try doing them again on x86 -- to actually allocate the
separate pcb on these machines!)
 1.59 12-Oct-2019  maxv branches: 1.59.32;
Rewrite the FPU code on x86. This greatly simplifies the logic and removes
the dependency on IPL_HIGH. NVMM is updated accordingly. Posted on
port-amd64 a week ago.

Bump the kernel version to 9.99.16.
 1.58 26-Jul-2018  maxv Rework dbregs, to switch the registers during context switches, and not on
each user->kernel transition via userret. Reloads of DR6/DR7 are expensive
on both native and xen.
 1.57 31-Oct-2017  maxv branches: 1.57.2; 1.57.4;
Don't embed our own values in the reserved fields of the XSAVE area, it
really is a bad idea. Move them into the PCB.
 1.56 12-Aug-2017  maxv Remove the vm86 fields from the pcb.
 1.55 23-Feb-2017  kamil Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.54 21-Apr-2014  christos branches: 1.54.4; 1.54.8; 1.54.12;
disable assert for lint.
 1.53 20-Feb-2014  dsl branches: 1.53.2;
Move the amd64 and i386 pcb to the bottom of the uarea, and move the
kernel stack to the top.
Change the pcb layouts so that fpu save area is at the end and is
64byte aligned ready for xsave (saving the ymm registers).
Welcome to 6.99.32
 1.52 12-Feb-2014  dsl Change i386 to use x86/fpu.c instead of i386/isa/npx.c
This changes the trap10 and trap13 code to call directly into fpu.c,
removing all the code for T_ARITHTRAP, T_XMM and T_FPUNDA from i386/trap.c
Not all of the code thate appeared to handle fpu traps was ever called!
Most of the changes just replace the include of machine/npx.h with x86/fpu.h
(or remove it entirely).
 1.51 19-Jan-2014  dsl Remove the unused 'struct md_coredump'.
 1.50 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.49 23-Oct-2013  drochner Use the MI "pcu" framework for bookkeeping of npx/fpu states on x86.
This reduces the amount of MD code enormously, and makes it easier
to implement support for newer CPU features which require more fpu
state, or for fpu usage by the kernel.
For access to FPU state across CPUs, an xcall kthread is used now
rather than a dedicated IPI.
No user visible changes intended.
 1.48 23-Apr-2010  joerg branches: 1.48.8; 1.48.18; 1.48.22;
Use struct segment_descriptor for pcb_fsd and pcb_gsd instead of int[2].
 1.47 21-Mar-2009  ad branches: 1.47.2; 1.47.4;
PR port-i386/40143 Viewing an mpeg transport stream with mplayer causes crash

Fix numerous problems:

1. LDT updates are not atomic.

2. Number of processes running with private LDTs and/or I/O bitmaps
is not capped. System with high maxprocs can be paniced.

3. LDTR can be leaked over context switch.

4. GDT slot allocations can race, giving the same LDT slot to two procs.

5. Incomplete interrupt/trap frames can be stacked.

6. In some rare cases segment faults are not handled correctly.
 1.46 26-Oct-2008  mrg branches: 1.46.2; 1.46.4; 1.46.8;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.45 28-Apr-2008  martin branches: 1.45.6;
Remove clause 3 and 4 from TNF licenses
 1.44 05-Jan-2008  yamt branches: 1.44.6; 1.44.8; 1.44.10;
remove a stale comment.
 1.43 04-Jan-2008  yamt fix a bug in the previous. (per-cpu tss change)
keep iopl in pcb so that it won't lost.
 1.42 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.41 10-Nov-2007  ad branches: 1.41.6;
fsbase/gsbase:

- Fix a few bugs with it, in particular fork/exec handling.
- Store the descriptors in the PCB, not in the LWP.
 1.40 04-Mar-2007  christos branches: 1.40.2; 1.40.18; 1.40.20; 1.40.24; 1.40.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.39 02-Mar-2007  ad Define pcb_esp0.
 1.38 02-May-2006  drochner branches: 1.38.14;
-explicitely align "struct savexmm" so that we don't get surprised
if we play with the PCB
-remove historical "struct emcsts"; there is no support in context
switching code for ages (if there has ever been)
 1.37 20-Feb-2004  yamt branches: 1.37.16; 1.37.30; 1.37.32; 1.37.34; 1.37.36; 1.37.38;
defer pmap switching until it's really needed
to avoid frequent loading of cr3 register, which involves tlb flush.

with some fixes/improvements from Stephan Uphoff and Bang Jun-Young.
 1.36 09-Nov-2003  tsutsui Use #if defined(_KERNEL_OPT) to protect #include "opt_xxx.h"
from building LKM etc. Suggested by mrg.
 1.35 24-Aug-2003  chs add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

- pmap and trap-handler changes. these are all MD:
= alpha: we already track per-page execute permission with the (software)
PG_EXEC bit, so just have the trap handler pay attention to it.
= i386: use a new GDT segment for %cs for processes that have no
executable mappings above a certain threshold (currently the
bottom of the stack). track per-page execute permission with
the last unused PTE bit.
= powerpc/ibm4xx: just use the hardware exec bit.
= powerpc/oea: we already track per-page exec bits, but the hardware only
implements non-exec mappings at the segment level. so track the
number of executable mappings in each segment and turn on the no-exec
segment bit iff the count is 0. adjust the trap handler to deal.
= sparc (sun4m): fix our use of the hardware protection bits.
fix the trap handler to recognize text faults.
= sparc64: split the existing unified TSB into data and instruction TSBs,
and only load TTEs into the appropriate TSB(s) for the permissions.
fix the trap handler to check for execute permission.
= not yet implemented: amd64, hppa, sh5

- changes in all the emulations that put a signal trampoline on the stack.
instead, we now put the trampoline into a uvm_aobj and map that into
the process separately.

originally from openbsd, adapted for netbsd by me.
 1.34 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.33 08-Oct-2002  fvdl branches: 1.33.6;
Delete pcb_flags.
 1.32 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.31 12-May-2002  matt Eliminate commons.
 1.30 16-Feb-2002  christos save cr2 for the benefit of linux emulation, and normalize use of pcb
in trap(), i.e. always initialize *pcb and use it instead of doing it
sometimes.
 1.29 02-Aug-2001  thorpej Add support for saving/restoring SSE/SSE2 state using FXSAVE/FXRSTOR.

Reviewed by Frank.
 1.28 17-Jun-2001  sommerfeld branches: 1.28.2;
Add %fs/%gs to trap frame and save/restore them on
trap/interrupt/syscall entry from userspace.

Remove special-case "by hand" validation of fs/gs register values as
well as special handling of them in various signal handling paths.

Now, like %ds and %es, they are validated by the hardware on return to
userland.

This paves the way for the use of %fs for per-cpu data on
multiprocessor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.

Discussed in advance with Frank van der Linden.
 1.27 16-Aug-2000  thorpej branches: 1.27.2;
Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.26 12-Sep-1999  chs branches: 1.26.2; 1.26.10; 1.26.14;
eliminate the PMAP_NEW option by making it required for all ports.
ports which previously had no support for PMAP_NEW now implement
the pmap_k* interfaces as wrappers around the non-k versions.
 1.25 12-May-1999  thorpej Move the user-set LDT out of the PCB and into the pmap. Applications
which set the LDT and share VM space (e.g. new versions of WINE) expect
the LDT to be logically coupled to the address space. Use the new pmap_fork()
interface to copy non-shared user-set LDTs when the address space is forked.
 1.24 15-Aug-1998  mycroft branches: 1.24.8;
Assign my copyrights to TNF.
 1.23 10-Feb-1998  mrg - add defopt's for UVM, UVMHIST and PMAP_NEW.
- remove unnecessary UVMHIST_DECL's.
 1.22 06-Feb-1998  mrg add the i386 MD portions for UVM.
 1.21 08-Jan-1996  mycroft VM86 support, by John Kohl, touched up a bit by me.
 1.20 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.19 06-Aug-1995  mycroft Move the `used fpu' flag into mdproc, so it can be referenced when a process
is swapped out. Implement process_{read,write}_fpregs.
 1.18 03-May-1995  mycroft Add PCB_USEDFPU.
 1.17 01-May-1995  mycroft Remove historical garbage.
 1.16 01-May-1995  mycroft Add pcb_cr0.
 1.15 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.14 08-Nov-1994  mycroft pcb.h requires segments.h now.
 1.13 05-Nov-1994  mycroft Only use ssdtosd() when creating, expanding, or copying the LDT. Keep a copy
of the result in the PCB so it can be loaded quickly on context switches.
 1.12 27-Oct-1994  cgd new RCS ID format.
 1.11 21-May-1994  cgd struct md_coredump
 1.10 21-Dec-1993  mycroft branches: 1.10.2;
Remove two unused fields.
 1.9 14-Dec-1993  mycroft Fold in most of the magnum vm changes.
 1.8 19-Sep-1993  brezak Add per-process LDT slot.
 1.7 16-Sep-1993  brezak Changes to use a trap frame for syscalls.
 1.6 27-Jun-1993  andrew branches: 1.6.4;
Re-entrancy protection.
 1.5 02-Jun-1993  cgd get rid of last bit of signal-trampoline-in-pcb hackery
 1.4 02-Jun-1993  cgd set things up so that the signal trampoline code is on the stack,
like it normally is in BSD systems. still has a bit of hair...
 1.3 22-May-1993  cgd add rcsids to everything and clean up headers
 1.2 09-May-1993  deraadt npx patches from Bruce Evans. patchkit 10002
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.4.3 11-Nov-1993  mycroft pcb_cmap2 could not justify its existance.
 1.6.4.2 09-Oct-1993  mycroft Make pcb_iml an int.
 1.6.4.1 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.10.2.2 21-Dec-1993  mycroft Remove two unused fields.
 1.10.2.1 21-Dec-1993  mycroft file pcb.h was added on branch magnum on 1993-12-21 09:47:46 +0000
 1.24.8.1 21-Jun-1999  thorpej Sync w/ -current.
 1.26.14.2 17-Jun-2001  he Pull up revision 1.28 (requested by sommerfeld):
Add %fs/%gs to trap frame and save/restore them on trap/interupt/
syscall entry from userspace.

Remove special-case ``by hand'' validation of %fs/%gs register
values s well as special handling of them in various signal
handling paths. Now, like %ds and %es, they are validated by
the hardware on return to userland.

This paves the way for the use of %fs for per-cpu data on multi-
processor systems, and fixes an otherwise difficult-to-fix
interaction between threads/clone(2) and USER_LDT.
 1.26.14.1 16-Aug-2000  thorpej Update from trunk:
Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.26.10.7 24-Feb-2002  sommerfeld Resynch with mainline.
 1.26.10.6 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.26.10.5 03-Sep-2001  sommerfeld Merge with -current once more.
 1.26.10.4 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.26.10.3 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.26.10.2 26-Jun-2000  sommerfeld Start making npx.c MP-safe; Interface to npx now specifies the process
and/or cpu to act on. Implement an IPI for MP lazy FP save.
Tested and working when only one CPU is running; untested in the MP
case since we can't run user processes on multiple CPU's yet.

Along for the ride:
- Change i386_send_ipi to take a "struct cpu_info *" rather than a cpu number.
- Turn off the "give me the brain" test IPI's.
 1.26.10.1 20-Feb-2000  sommerfeld On MULTIPROCESSOR kernels, delete the "curpcb" global variable since
it's per-CPU (it lives in struct cpu_info, defined in cpu.h)
 1.26.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.27.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.27.2.4 20-Jun-2002  nathanw Catch up to -current.
 1.27.2.3 28-Feb-2002  nathanw Catch up to -current.
 1.27.2.2 24-Aug-2001  nathanw Catch up with -current.
 1.27.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.28.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.28.2.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.28.2.2 16-Mar-2002  jdolecek Catch up with -current.
 1.28.2.1 03-Aug-2001  lukem update to -current
 1.33.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.33.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.33.6.1 03-Aug-2004  skrll Sync with HEAD
 1.37.38.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.37.36.1 11-May-2006  elad sync with head
 1.37.34.1 24-May-2006  yamt sync with head.
 1.37.32.1 01-Jun-2006  kardel Sync with head.
 1.37.30.1 09-Sep-2006  rpaulo sync with head
 1.37.16.4 21-Jan-2008  yamt sync with head
 1.37.16.3 15-Nov-2007  yamt sync with head.
 1.37.16.2 03-Sep-2007  yamt sync with head.
 1.37.16.1 21-Jun-2006  yamt sync with head.
 1.38.14.1 12-Mar-2007  rmind Sync with HEAD.
 1.40.26.2 18-Feb-2008  mjf Sync with HEAD.
 1.40.26.1 19-Nov-2007  mjf Sync with HEAD.
 1.40.24.1 13-Nov-2007  bouyer Sync with HEAD
 1.40.20.1 09-Jan-2008  matt sync with HEAD
 1.40.18.1 11-Nov-2007  joerg Sync with HEAD.
 1.40.2.1 03-Dec-2007  ad Sync with HEAD.
 1.41.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.44.10.3 11-Aug-2010  yamt sync with head.
 1.44.10.2 04-May-2009  yamt sync with head.
 1.44.10.1 16-May-2008  yamt sync with head.
 1.44.8.1 18-May-2008  yamt sync with head.
 1.44.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.44.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.45.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.46.8.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.46.8.2 01-Nov-2009  jym Sync with HEAD.
 1.46.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.46.4.1 04-Apr-2009  snj Pull up following revision(s) (requested by ad in ticket #656):
sys/arch/amd64/amd64/gdt.c: revision 1.21 via patch
sys/arch/amd64/amd64/machdep.c: revision 1.129 via patch
sys/arch/i386/i386/gdt.c: revision 1.47 via patch
sys/arch/i386/i386/kvm86.c: revision 1.17 via patch
sys/arch/i386/i386/locore.S: revision 1.85 via patch
sys/arch/i386/i386/machdep.c: revision 1.666 via patch
sys/arch/i386/i386/vector.S: revision 1.45 via patch
sys/arch/i386/include/pcb.h: revision 1.47 via patch
sys/arch/x86/include/pmap.h: revision 1.22 via patch
sys/arch/x86/include/sysarch.h: revision 1.8 via patch
sys/arch/x86/x86/pmap.c: revision 1.80 via patch
sys/arch/x86/x86/sys_machdep.c: revision 1.17 via patch
sys/compat/linux/arch/i386/linux_machdep.c: revision 1.143 via patch
sys/kern/init_main.c: revision 1.384 via patch
PR port-i386/40143 Viewing an mpeg transport stream with mplayer causes crash
Fix numerous problems:
1. LDT updates are not atomic.
2. Number of processes running with private LDTs and/or I/O bitmaps
is not capped. System with high maxprocs can be paniced.
3. LDTR can be leaked over context switch.
4. GDT slot allocations can race, giving the same LDT slot to two procs.
5. Incomplete interrupt/trap frames can be stacked.
6. In some rare cases segment faults are not handled correctly.
 1.46.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.47.4.1 30-May-2010  rmind sync with head
 1.47.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.48.22.1 18-May-2014  rmind sync with head
 1.48.18.2 03-Dec-2017  jdolecek update from HEAD
 1.48.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.48.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.53.2.1 10-Aug-2014  tls Rebase.
 1.54.12.1 21-Apr-2017  bouyer Sync with HEAD
 1.54.8.1 20-Mar-2017  pgoyette Sync with HEAD
 1.54.4.1 28-Aug-2017  skrll Sync with HEAD
 1.57.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.57.4.1 10-Jun-2019  christos Sync with HEAD
 1.57.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.59.32.1 02-Aug-2025  perseant Sync with HEAD
 1.10 14-Nov-2007  ad Remove pccons.
 1.9 27-Oct-2003  junyoung branches: 1.9.16; 1.9.58; 1.9.76; 1.9.78; 1.9.82; 1.9.84;
Nuke __P().
 1.8 06-Feb-1999  drochner branches: 1.8.44;
sort the dependencies between terminal devices a bit and add consistency
checks to catch conflicting devices at compile time
 1.7 22-Mar-1998  drochner Export pcconskbd_cnattach() - it is used if pccons attaches to the MI
keyboard controller driver.
 1.6 23-Aug-1997  drochner Put all console initialization into 1 exported function (pccnattach()).
Delay setting of cn_tab->cn_dev until autoconfiguration attach
to get the minor number right.
Delete unused pccnprobe() and pccninit().
 1.5 14-Aug-1997  drochner -Export variables needed for system console initialization.
-Because *cnputc()'s second argument is an "int" in cons.h, correct
pccnputc() accordingly.
 1.4 02-Feb-1996  mycroft branches: 1.4.12;
Fix #includes.
 1.3 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 28-Sep-1993  andrew branches: 1.1.2;
Exports the pccons ioctls.
 1.1.2.2 28-Sep-1993  andrew Exports the pccons ioctls.
 1.1.2.1 28-Sep-1993  andrew file pccons.h was added on branch magnum on 1993-09-28 03:26:18 +0000
 1.4.12.2 01-Sep-1997  thorpej Update marc-pcmcia-branch from trunk (missed this the last time).
 1.4.12.1 23-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.8.44.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.8.44.2 18-Sep-2004  skrll Sync with HEAD.
 1.8.44.1 03-Aug-2004  skrll Sync with HEAD
 1.9.84.1 19-Nov-2007  mjf Sync with HEAD.
 1.9.82.1 18-Nov-2007  bouyer Sync with HEAD
 1.9.78.1 23-Mar-2008  matt sync with HEAD
 1.9.76.1 21-Nov-2007  joerg Sync with HEAD.
 1.9.58.1 03-Dec-2007  ad Sync with HEAD.
 1.9.16.1 15-Nov-2007  yamt sync with head.
 1.19 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.18 15-May-2002  thorpej branches: 1.18.4;
Let machine-dependent code specify how to enumerate the bus.
Currently, everyone uses pci_enumerate_bus_generic().
 1.17 08-Jun-2001  simonb branches: 1.17.4;
For ports that wire up pciide in compatibility mode, have
them define __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
in pci_machdep.h and pciide_map_compat_intr() only calls
pciide_machdep_compat_intr_establish() if that preprocessor
define exists.

Ports that don't need to do this no longer need to supply a
dummy function.
 1.16 28-Dec-2000  sommerfeld branches: 1.16.4;
Change pci_intr_map to get interrupt source information from a "struct
pci_attach_args *" instead of from four separate parameters which in
all cases were extracted from the same "struct pci_attach_args".

This both simplifies the driver api, and allows for alternate PCI
interrupt mapping schemes, such as one using the tables described in
the Intel Multiprocessor Spec which describe interrupt wirings for
devices behind pci-pci bridges based on the device's location rather
the bridge's location.

Tested on alpha and i386; welcome to 1.5Q
 1.15 18-Jul-2000  soda add "#define I386_PCI_INTERRUPT_LINE_NO_CONNECTION 0xff"
 1.14 04-Jun-2000  cgd branches: 1.14.2;
Implement the more flexiable `evcnt' interface as discussed (briefly) on
tech-kern and now documented in evcnt(9).
 1.13 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.12 19-Mar-1999  cgd branches: 1.12.8; 1.12.18;
Moved from arch/i386/pci/pci_machdep.h,v
 1.11 15-Aug-1998  mycroft Make copyright notices with my name consistent.
 1.10 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.9 04-May-1998  thorpej Add a function, pci_bus_flags(), that determines which flags (for memory
and i/o enabled) should be passed to the primary PCI bus's autconfiguration
node. Use this function to detect broken PCI-Host bridges, which have
problems with memory-mapped access. Add the SIS 85C496 to this list.
 1.8 26-Aug-1997  thorpej Notify drivers that we "prefer" I/O mapped space, per discussion with
Chris Demetriou and Matt Thomas, some two or three months ago. (This hint
is used by the latest "de" driver.)
 1.7 06-Jun-1997  thorpej branches: 1.7.4;
Pull thorpej-bus-dma branch into mainline.
 1.6 17-Dec-1996  thorpej branches: 1.6.8;
Implement pci_decompose_tag().
 1.5 27-Mar-1996  cgd modify these to provide a new, better-specified PCI interface
(soon to be documented on mailing lists; eventually in section 9 manual
pages), most importantly:
(1) support interrupt pin swizzling on non-i386 systems with
PCI-PCI bridges (per PPB spec; done, but meaningless, on i386).
(2) provide pci_{io,mem}_find(), to determine what I/O or memory
space is described by a given PCI configuration space
mapping register.
(3) provide pci_intr_map(), pci_intr_string(), and
pci_intr_{,dis}establish() to manipulate and print info about
PCI interrupts.
(4) deprecate the pci_map_* functions, and provide them only
as compatibility interfaces (in pci_compat.c) which will
eventually go away, implemented as wrappers around
the functions described above.
(5) make pci functions take as an argument a machine-dependent
cookie, to allow more flexibility in implementation.
 1.4 14-Mar-1996  cgd (1) remove the #ifdef i386 from pci.c, and provide a machine-dependent
hook (pci_md_attach_hook()) to do any machine-dependent attachment
gunk, e.g. on the i386 printing out the configuration mode (if bus 0)
(2) don't pass max device number for a given bus in, use
PCI_MAX_DEVICE_NUMBER, which can be defined on a per-machine basis.
(defaults to 32. on i386, it's 32 if pci conf mode == 1, 16 if 2.)
 1.3 17-Apr-1995  cgd clean up several ISA device interfaces: autoconfiguration, header
inclusion, and interrupt configuration. more work still needs to be done,
but it's getting better...
 1.2 27-Oct-1994  cgd new RCS ID format.
 1.1 09-Aug-1994  mycroft Add PCI autoconfiguration support.
 1.6.8.1 18-May-1997  thorpej Add an external declaration for the pci dma tag.
 1.7.4.1 27-Aug-1997  thorpej Update marc-pcmcia branch from trunk.
 1.12.18.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.12.8.2 05-Jan-2001  bouyer Sync with HEAD
 1.12.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.2.1 10-Aug-2000  soda Pull up to netbsd-1-5 branch
Approved by: thorpej

- define PCI_INTERRUPT_PIN_MAX and use it instead of magic number.
- define I386_PCI_INTERRUPT_LINE_NO_CONNECTION and use it instead of
magic number.

Revisions pulled up:
> cvs rdiff -r1.28 -r1.29 syssrc/sys/dev/pci/pcireg.h
> cvs rdiff -r1.14 -r1.15 syssrc/sys/arch/i386/include/pci_machdep.h
> cvs rdiff -r1.38 -r1.39 syssrc/sys/arch/i386/pci/pci_machdep.c
> cvs rdiff -r1.1 -r1.2 syssrc/sys/arch/i386/pci/opti82c558.c \
> syssrc/sys/arch/i386/pci/sis85c503.c \
> syssrc/sys/arch/i386/pci/via82c586.c
 1.16.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.16.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.17.4.1 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.18.4.2 15-May-2002  thorpej Let machine-dependent code specify how to enumerate the bus.
Currently, everyone uses pci_enumerate_bus_generic().
 1.18.4.1 15-May-2002  thorpej file pci_machdep.h was added on branch sommerfeld_i386mp_1 on 2002-05-15 19:23:55 +0000
 1.2 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.1 22-Nov-2002  fvdl branches: 1.1.2;
Define a generic PIC structure, used by the interrupt code.
 1.1.2.2 11-Dec-2002  thorpej Sync with HEAD.
 1.1.2.1 22-Nov-2002  thorpej file pic.h was added on branch nathanw_sa on 2002-12-11 06:01:01 +0000
 1.20 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.19 28-Dec-2001  thorpej branches: 1.19.2;
Fix some register constraints; specifically, the "port" operand,
if not an immediate, must be in a 16-bit register.
 1.18 13-Nov-2001  perry Make the type of ports in the in*()/out*() routines u_long instead of
int. Massively reduced kernel lint, causes no harm. Discussed
extensively with christos and thorpej.
 1.17 30-Apr-2001  lukem branches: 1.17.4;
remove some lint, including ansifying some inlines
 1.16 26-Apr-2001  thorpej Const poison.
 1.15 13-Mar-2000  kristerw branches: 1.15.8;
Make the inline asm conform to what gcc thinks they should look like (per
discussions in http://gcc.gnu.org/ml/gcc-patches/1998-11/msg00004.html)

Approved by fvdl.
 1.14 15-Aug-1998  mycroft branches: 1.14.12;
Assign my copyrights to TNF.
 1.13 08-Mar-1996  cgd make this idempotent. bus.h needs to include it, and other things which
may include something that includes bus.h may include it as well.
 1.12 20-Dec-1995  mycroft Use explicit integer sizes. Adjust constraints for GCC 2.7.2.
 1.11 22-Apr-1995  mycroft branches: 1.11.2;
Clean this up a bit:
* Abstract the conditional for immediate port numbers, and make it always
false if not optimizing.
* Add some whitespace to the string functions to make them more readable.
 1.10 20-Nov-1994  mycroft Use immediate constants for port numbers < 0x100.
 1.9 18-Nov-1994  mycroft Convert port, IRQ, and DRQ numbers to ints.
 1.8 27-Oct-1994  cgd new RCS ID format.
 1.7 28-Jan-1994  jtc branches: 1.7.2;
Fix spelling error in Copyright notice
 1.6 31-Dec-1993  mycroft Make sure we get the correct `rep' prefix per the Intel manual (though really
GAS should figure this out itself).
 1.5 30-Dec-1993  deraadt fix __asm() clobber list for some instructions. fix from
Lennart Augustsson <augustss@cs.chalmers.se>
 1.4 20-Dec-1993  mycroft New, more complete version.
 1.3 06-Jun-1993  cgd branches: 1.3.4;
incorporate Bruce Evans' interrupt changes, as hacked by Rod grimes,
for patchkit patch 158. it appears to work well.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.3.4.3 19-Dec-1993  mycroft Clear the direction flag before string insns.
 1.3.4.2 29-Oct-1993  mycroft Fix definitions of outs[bwl](), and note that none of the string functions
bashes dx.
 1.3.4.1 11-Oct-1993  mycroft Move {disable,enable}_intr() to psl.h, and inline all of {in,out}{,s}[bwl] in
pio.h.
 1.7.2.2 28-Jan-1994  jtc Fix spelling error in Copyright notice
 1.7.2.1 28-Jan-1994  jtc file pio.h was added on branch magnum on 1994-01-28 23:44:19 +0000
 1.11.2.1 01-Mar-1996  scottr Fix register constraints so that kernels can be compiled with gcc-2.7.2
 1.14.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.8.3 08-Jan-2002  nathanw Catch up to -current.
 1.15.8.2 14-Nov-2001  nathanw Catch up to -current.
 1.15.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.17.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.19.2.2 28-Dec-2001  thorpej Fix some register constraints; specifically, the "port" operand,
if not an immediate, must be in a 16-bit register.
 1.19.2.1 28-Dec-2001  thorpej file pio.h was added on branch sommerfeld_i386mp_1 on 2001-12-28 06:44:13 +0000
 1.129 20-Aug-2022  riastradh x86: Move definition of struct pmap to pmap_private.h.

This makes pmap_resident_count and pmap_wired_count out-of-line
functions instead of inline. No functional change intended
otherwise.
 1.128 20-Aug-2022  riastradh x86: Split most of pmap.h into pmap_private.h or vmparam.h.

This way pmap.h only contains the MD definition of the MI pmap(9)
API, which loads of things in the kernel rely on, so changing x86
pmap internals no longer requires recompiling the entire kernel every
time.

Callers needing these internals must now use machine/pmap_private.h.
Note: This is not x86/pmap_private.h because it contains three parts:

1. CPU-specific (different for i386/amd64) definitions used by...

2. common definitions, including Xenisms like xpmap_ptetomach,
further used by...

3. more CPU-specific inlines for pmap_pte_* operations

So {amd64,i386}/pmap_private.h defines 1, includes x86/pmap_private.h
for 2, and then defines 3. Maybe we should split that out into a new
pmap_pte.h to reduce this trouble.

No functional change intended, other than that some .c files must
include machine/pmap_private.h when previously uvm/uvm_pmap.h
polluted the namespace with pmap internals.

Note: This migrates part of i386/pmap.h into i386/vmparam.h --
specifically the parts that are needed for several constants defined
in vmparam.h:

VM_MAXUSER_ADDRESS
VM_MAX_ADDRESS
VM_MAX_KERNEL_ADDRESS
VM_MIN_KERNEL_ADDRESS

Since i386 needs PDP_SIZE in vmparam.h, I added it there on amd64
too, just to keep things parallel.
 1.127 20-Aug-2022  riastradh x86: Move struct vm_page_md to common x86/pmap.h.
 1.126 19-Jul-2020  maxv don't include opt_user_ldt.h when it is not needed
 1.125 15-May-2020  ad Revert previous after thinking about it. It was wrong, don't need to use
an atomic to clear a PTE or set initial version unless the circumstances
call for it.
 1.124 17-Mar-2020  ad Always set PTEs using atomics. There are too many assumptions to go wrong.
 1.123 09-Mar-2019  maxv New software PTE bits.
 1.122 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.121 19-Nov-2018  maxv Introduce pl_pi, will be used soon.
 1.120 19-Nov-2018  maxv Rename 'mask' -> 'frame', we will use the real 'mask' soon.
 1.119 25-Jul-2018  maxv Remove NPTECL, unused.
 1.118 19-Sep-2016  maya branches: 1.118.14; 1.118.16;
move function prototype to x86, so it is available to amd64 too
 1.117 21-Apr-2014  christos branches: 1.117.4; 1.117.8;
forward decl for struct pcb.
 1.116 18-Mar-2013  para branches: 1.116.6; 1.116.10;
i386 pmap.h got a forward declarition for vm_map from systm.h
insert a forward declaration
 1.115 19-Feb-2012  cherry branches: 1.115.2;
Removing remaining references to the alternate PTE space. Modify documentation appropriately
 1.114 19-Jan-2012  bouyer pmap_pte_set() is not supposed to be atomic, so only raise IPL, no need to
take pte_lock
 1.113 09-Jan-2012  cherry Make cross-cpu pte access MP safe.
XXX: review cases of use of pmap_set_pte() vs direct use of xpq_queue_pte_update()
 1.112 06-Nov-2011  cherry branches: 1.112.4;
[merging from cherry-xenmp] make pmap_kernel() shadow PMD per-cpu and MP aware.
 1.111 06-Nov-2011  cherry [merging from cherry-xenmp] Make the xen MMU op queue locking api private. Implement per-cpu queues.
 1.110 13-Aug-2011  cherry branches: 1.110.2;
Add locking around ops to the hypervisor MMU "queue".
 1.109 01-Feb-2011  chuck branches: 1.109.2;
udpate license clauses on my code to match the new-style BSD licenses.
based on diff that rmind@ sent me.

no functional change with this commit.
 1.108 14-Nov-2010  uebayasi branches: 1.108.2; 1.108.4;
Move struct vm_page_md definition from vmparam.h to pmap.h, because
it's used only by pmap. vmparam.h has definitions for wider
audience.

All GENERIC kernels build tested, except ia64.

powerpc/include/booke/vmparam.h has one too, but it has no pmap.h,
so it's left as is.
 1.107 24-Jul-2010  jym Welcome PAE inside i386 current.

This patch is inspired by work previously done by Jeremy Morse, ported by me
to -current, merged with the work previously done for port-xen, together with
additionals fixes and improvements.

PAE option is disabled by default in GENERIC (but will be enabled in ALL in
the next few days).

In quick, PAE switches the CPU to a mode where physical addresses become
36 bits (64 GiB). Virtual address space remains at 32 bits (4 GiB). To cope
with the increased size of the physical address, they are manipulated as
64 bits variables by kernel and MMU.

When supported by the CPU, it also allows the use of the NX/XD bit that
provides no-execution right enforcement on a per physical page basis.

Notes:

- reworked locore.S

- introduce cpu_load_pmap(), used to switch pmap for the curcpu. Due to the
different handling of pmap mappings with PAE vs !PAE, Xen vs native, details
are hidden within this function. This helps calling it from assembly,
as some features, like BIOS calls, switch to pmap_kernel before mapping
trampoline code in low memory.

- some changes in bioscall and kvm86_call, to reflect the above.

- the L3 is "pinned" per-CPU, and is only manipulated by a
reduced set of functions within pmap. To track the L3, I added two
elements to struct cpu_info, namely ci_l3_pdirpa (PA of the L3), and
ci_l3_pdir (the L3 VA). Rest of the code considers that it runs "just
like" a normal i386, except that the L2 is 4 pages long (PTP_LEVELS is
still 2).

- similar to the ci_pae_l3_pdir{,pa} variables, amd64's xen_current_user_pgd
becomes an element of cpu_info (slowly paving the way for MP world).

- bootinfo_source struct declaration is modified, to cope with paddr_t size
change with PAE (it is not correct to assume that bs_addr is a paddr_t when
compiled with PAE - it should remain 32 bits). bs_addrs is now a
void * array (in bootloader's code under i386/stand/, the bs_addrs
is a physaddr_t, which is an unsigned long).

- fixes in multiboot code (same reason as bootinfo): paddr_t size
change. I used Elf32_* types, use RELOC() where necessary, and move the
memcpy() functions out of the if/else if (I do not expect sym and str tables
to overlap with ELF).

- 64 bits atomic functions for pmap

- all pmap_pdirpa access are now done through the pmap_pdirpa macro. It
hides the L3/L2 stuff from PAE, as well as the pm_pdirpa change in
struct pmap (it now becomes a PDP_SIZE array, with or without PAE).

- manipulation of recursive mappings ( PDIR_SLOT_{,A}PTEs ) is done via
loops on PDP_SIZE.

See also http://mail-index.netbsd.org/port-i386/2010/07/17/msg002062.html

No objection raised on port-i386@ and port-xen@R for about a week.

XXX kvm(3) will be fixed in another patch to properly handle both PAE and !PAE
kernel dumps (VA => PA macros are slightly different, and need proper 64 bits
PA support in kvm_i386).

XXX Mixing PAE and !PAE modules may lead to unwanted/unexpected results. This
cannot be solved easily, and needs lots of thinking before being declared
safe (paddr_t/bus_addr_t size handling, PD/PT macros abstractions).
 1.106 15-Jul-2010  jym Purely cosmetic: move L2_SLOT_KERNBASE out of the PAE #ifdef/#endif block.
 1.105 01-Mar-2010  jym branches: 1.105.2;
Use PDP_SIZE for NTOPLEVEL_PDES (number of top level PDEs) instead of
#ifdef'ing PAE.
 1.104 09-Feb-2010  jym Fix typos in comments.
 1.103 26-Oct-2008  mrg branches: 1.103.8; 1.103.14;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.102 23-Jan-2008  bouyer branches: 1.102.6; 1.102.10; 1.102.16;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.101 20-Jan-2008  bouyer Make first argument of Xen's pmap_pte_cas() volatile, fix a warning
building pmap.c.
 1.100 13-Jan-2008  yamt add pmap_pte_cas.
 1.99 12-Jan-2008  bouyer Xen doesn't need NKPTP_MIN/NKPTP_MAX any more.
 1.98 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.97 28-Nov-2007  ad branches: 1.97.6;
Remove remaining CPUCLASS_386 tests.
 1.96 28-Nov-2007  ad Use the new atomic ops.
 1.95 22-Nov-2007  bouyer Pull up the bouyer-xenamd64 branch to HEAD. This brings in amd64 support
to NetBSD/Xen, both Dom0 and DomU.
 1.94 18-Oct-2007  yamt branches: 1.94.2;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.93 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.92 17-Oct-2007  ad Match amd64:

-#if defined(_KERNEL) || defined(_LKM)
+#if defined(_KERNEL)
 1.91 26-Sep-2007  ad branches: 1.91.2;
Only include machine/cpufunc.h if _KERNEL.
 1.90 29-Aug-2007  ad branches: 1.90.2;
Merge most x86 changes from the vmlocking branch, except the threaded soft
interrupt stuff. This is mostly comprised of changes to the pmap modules to
work on multiprocessor systems without kernel_lock, and changes to speed up
tlb shootdowns.
 1.89 21-Feb-2007  thorpej branches: 1.89.4; 1.89.12; 1.89.16; 1.89.20; 1.89.22;
Replace the Mach-derived boolean_t type with the C99 bool type. A
future commit will replace use of TRUE and FALSE with true and false.
 1.88 16-Nov-2006  christos branches: 1.88.4;
__unused removal on arguments; approved by core.
 1.87 12-Oct-2006  christos - sprinkle __unused on function decls.
- fix a couple of unused bugs
- no more -Wno-unused for i386
 1.86 16-Feb-2006  perry branches: 1.86.14; 1.86.16;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.85 26-Dec-2005  perry branches: 1.85.2; 1.85.4; 1.85.6;
u_intN_t -> uintN_t
 1.84 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.83 08-Aug-2005  junyoung - Fix typo in comment.
- Remove trailing spaces.
 1.82 26-Aug-2004  junyoung branches: 1.82.12;
As suggested on tech-kern@ days ago:
* Get rid of PTmap, PTD, PTDpde, APTmap, APTD, and APTDpde from locore.S.
* Rename PTDpaddr to PDPpaddr, ptdpaddr in struct cpu_kcore_hdr to pdppaddr for consistency.
 1.81 22-Aug-2004  junyoung Fix various typos in comments including ones that weren't noticed
for years.
 1.80 05-Aug-2004  mycroft Set NKPTP default to 0 (it's calculated in locore). Also reduce NKPTP_MIN to
2 -- though, with our current rounding of the data section, we will never take
advantage of that.
 1.79 20-Feb-2004  yamt defer pmap switching until it's really needed
to avoid frequent loading of cr3 register, which involves tlb flush.

with some fixes/improvements from Stephan Uphoff and Bang Jun-Young.
 1.78 27-Oct-2003  junyoung Nuke __P().
 1.77 23-Oct-2003  chs rename pv_next to pv_node. use SPLAY_RIGHT() instead of expanding it inline.
 1.76 23-Oct-2003  provos changed linked list in pmap_remove_pv to a splay tree; approved: fvdl@
 1.75 24-Aug-2003  chs add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

- pmap and trap-handler changes. these are all MD:
= alpha: we already track per-page execute permission with the (software)
PG_EXEC bit, so just have the trap handler pay attention to it.
= i386: use a new GDT segment for %cs for processes that have no
executable mappings above a certain threshold (currently the
bottom of the stack). track per-page execute permission with
the last unused PTE bit.
= powerpc/ibm4xx: just use the hardware exec bit.
= powerpc/oea: we already track per-page exec bits, but the hardware only
implements non-exec mappings at the segment level. so track the
number of executable mappings in each segment and turn on the no-exec
segment bit iff the count is 0. adjust the trap handler to deal.
= sparc (sun4m): fix our use of the hardware protection bits.
fix the trap handler to recognize text faults.
= sparc64: split the existing unified TSB into data and instruction TSBs,
and only load TTEs into the appropriate TSB(s) for the permissions.
fix the trap handler to check for execute permission.
= not yet implemented: amd64, hppa, sh5

- changes in all the emulations that put a signal trampoline on the stack.
instead, we now put the trampoline into a uvm_aobj and map that into
the process separately.

originally from openbsd, adapted for netbsd by me.
 1.74 22-Jul-2003  yamt move pv_head and page attributes into md part of vm_page structure
instead of having separate arrays for them.
(i.e. use __HAVE_VM_PAGE_MD instead of __HAVE_PMAP_PHYSSEG.)
 1.73 09-Apr-2003  thorpej branches: 1.73.2;
Add the ability for pool caches to cache the physical address of
objects. Clients of the pool_cache API must consistently use
the "paddr" variants or not, otherwise behavior is undefined.

Enable this on Alpha, ARM, MIPS, and x86. Other platforms must
define POOL_VTOPHYS() in the appropriate manner in order to enable
the feature.

Part 1 of a series of simple patches contributed by Wasabi Systems
to improve network performance.
 1.72 09-Apr-2003  thorpej Remove something accidentally included in last commit.
 1.71 02-Apr-2003  thorpej Use PAGE_SIZE rather than NBPG.
 1.70 03-Mar-2003  fvdl define pmap_cpu_has_pg_n and pmap_cpu_has_invlpg to make code sharing
easier.
 1.69 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.68 29-Jan-2003  drochner give some VM which was reserved for the UAREA but not used anymore back
to the user and adjust some comments (which were not accurate anyway
since NOREDZONE)
binary compatibility note: changing VM_MAXUSER_ADDRESS might influence
some sanity check in kvm_proc, where arguments on the stack are dealt
with, but it was a variable anyway and noone did care...
 1.67 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.66 02-Nov-2002  perry /*ARGSUSED*/ one function -- eliminates 414 lint complaints
 1.65 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.64 22-Sep-2002  chs it really helps to get the stub right before cutting + pasting it 27 times.
alas, I did not. doh.
 1.63 22-Sep-2002  chs add pmap_remove_all() hook (empty on most platforms so far).
 1.62 23-Dec-2001  thorpej Use ANSI declarations for static inline functions, and give them
the __unused__ attribute.
 1.61 07-Nov-2001  yamt correct comment.
 1.60 10-Sep-2001  chris branches: 1.60.2;
Update pmap_update to now take the updated pmap as an argument.
This will allow improvements to the pmaps so that they can more easily defer expensive operations, eg tlb/cache flush, til the last possible moment.

Currently this is a no-op on most platforms, so they should see no difference.

Reviewed by Jason.
 1.59 12-Aug-2001  chs branches: 1.59.2;
update some comments.
 1.58 30-May-2001  mrg branches: 1.58.2;
use _KERNEL_OPT
 1.57 26-May-2001  chs replace {simple_,}lock{_data,}_t with struct {simple,}lock {,*}.
 1.56 29-Apr-2001  thorpej The idle loop page zero'er no longer needs to do uncached access
now that we have page coloring.
 1.55 22-Apr-2001  thorpej Undo a misguided previous change to the pmap_update() API.
 1.54 22-Apr-2001  thorpej Give pmap_update() an argument (a pmap_t) so that it knows which
pmap it should be updating.
 1.53 04-Jan-2001  thorpej branches: 1.53.2;
Just garbage-collect the #if 0'd pmap_transfer() stuff.
 1.52 01-Jan-2001  thorpej Don't equate pmap_update() with tlbflush(), but instead call
tlbflush() when that's what we mean (currently everywhere, except
in the one place in MI code where it is called).

The whole pmap_update() thing needs to be reexamined, but this helps
to clarify things a little with the currently-defined semantics of
that function.
 1.51 06-Dec-2000  chs in kvtopte(), return the mapping of the pde in the recursive page-table
mapping space rather than the mapping in the kernel address space.
 1.50 28-Sep-2000  is We do wired page accounting. Tell UVM about it.
 1.49 21-Sep-2000  thorpej Make PMAP_PAGEIDLEZERO() return a boolean value. FALSE indidcates
that the page being zero'd was not completed and that page zeroing
should be aborted. This may be used by machine-dependent code doing
slow page access to reduce the latency of running a process that has
become runnable while in the middle of doing a slow page zero.
 1.48 07-Sep-2000  thorpej Add optional support for mapping the kernel with large (4MB) pages.
Right now, only does kernel text, and wastes a little memory, but
there is some noticeable performance improvement even with just text.
 1.47 06-Sep-2000  thorpej vtopte() and kvtopte() now check for kernel vs. non-kernel addresses,
respectively.
 1.46 06-Sep-2000  thorpej Remove some vto*() macros that won't stand a chance of working
with PSE or PAE, and reimplement vtphys() in terms of pmap_extract().
 1.45 15-Jun-2000  mycroft branches: 1.45.2;
Disable pmap_copy() for now.
 1.44 24-Apr-2000  thorpej branches: 1.44.2;
Glue in uvm_pageidlezero(). While here, improve some panic messages
in pmap.c, as requested by Jonathan Stone.
 1.43 11-Feb-2000  thorpej branches: 1.43.2;
Move KERNBASE to 0xc0000000, giving the kernel a more-or-less full 1G
of virtual address space, leaving userland with 3G, and update comments
to match the new reality.

We knew we were going to have to bite this bullet eventually, and there
are a couple of outstanding PRs related to this issue (9389 and 9313).
Complete solution to those PRs is going to involve some sort of run-time
decision on how large kmem_map should be, as well as changing some data
structure allocation strategies in UVM. However, this change will at
least allow the PR submitter to simply throw resources at the problem.
 1.42 28-Jul-1999  thorpej branches: 1.42.2;
Don't inline pmap_kenter_pa(). It doesn't buy us much to do so, and
it's nice to have it show up in stack traces.
 1.41 18-Jul-1999  chs KNF.
 1.40 17-Jun-1999  thorpej PMAP_NEW is no longer optional on the i386; the old pmap's page table
allocation strategy no longer works at all. Move pmap.new.* to pmap.*.

To read the revision history of PMAP_NEW up until this merge, use cvs
rlog of the old pmap.new.* files.
 1.39 12-May-1999  thorpej Move the user-set LDT out of the PCB and into the pmap. Applications
which set the LDT and share VM space (e.g. new versions of WINE) expect
the LDT to be logically coupled to the address space. Use the new pmap_fork()
interface to copy non-shared user-set LDTs when the address space is forked.
 1.38 15-Aug-1998  mycroft branches: 1.38.6; 1.38.8;
Assign my copyrights to TNF.
 1.37 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.36 18-Feb-1998  thorpej Fixup an inconsistency in the declaration of PTDpaddr, pointed out by
Chris Demetriou.
 1.35 18-Feb-1998  cgd Move pmap_map() function definition to MD headers, as appropriate. It's
an internal function, and the VM system shouldn't try to prototype it.
(Note that some ports _don't_ prototype it.)
 1.34 10-Feb-1998  mrg - add defopt's for UVM, UVMHIST and PMAP_NEW.
- remove unnecessary UVMHIST_DECL's.
 1.33 06-Feb-1998  mrg add the i386 MD portions for UVM.
 1.32 13-Jan-1998  mrg this is the i386 MD portion of the MACHINE_NEW_NONCONTIG code, as
written by chuck cranor. thanks to mycroft for helping me find the
one little line of code i accidentally deleted while merging it.

this is not enabled by default. `options MACHINE_NEW_NONCONTIG'
will use this code. eventually, this should go into <machine/vmparam.h>
insteaed of MACHINE_NONCONTIG.
 1.31 06-Jan-1998  thorpej Garbage-collect pm_pdchanged; it's not used by anything.
 1.30 03-Jan-1998  thorpej Now that all ports have pmap_activate(), and it has an identical interface,
prototype it in <vm/pmap.h>
 1.29 07-Dec-1997  fvdl Define constants for the start and end VA of user page tables.
 1.28 04-Nov-1997  thorpej Make pmap_{,de}activate() take a pointer to a proc.
 1.27 20-Oct-1997  fvdl branches: 1.27.2;
Change various constants that depend on the kernel VM base address. Lower
it to 0xf0000000 to give it more breathing space.
 1.26 12-Jun-1997  thorpej Nuke __VM_PMAP_HACK.
 1.25 16-May-1997  gwr Add #define __VM_PMAP_HACK as a temporary measure.
 1.24 18-Nov-1996  fvdl Changes for NKPDE calculation from cgd.

- New variables: biosextmem, biosbasemem, nkpde
- Above can be set by using the options BIOSEXTMEM, BIOSBASEMEM,
and NKPDE respectively (EXTMEM_SIZE is now called BIOSEXTMEM).
When preset this way, they won't be filled in / calculated.
- Readable by sysctl using machdep.nkpde, machdep.biosbasemem
and machdep.biosextmem.
- nkpde is calculated as:

min(NKPDE_MAX, NKPDE_BASE + (biosextmem >> 10) * NKPDE_SCALE)

Where NKPDE_MAX is 31, NKPDE_BASE is 4, NKPDE_SCALE = 1.
 1.23 03-May-1996  christos Add missing prototypes.
 1.22 12-Feb-1996  christos Move pmap_page_index declaration to <vm/pmap.h>
 1.21 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.20 26-Jun-1995  cgd IdlePTD has been gone for a while. PTDpaddr now exists.
 1.19 11-May-1995  jtc KERNEL -> _KERNEL
 1.18 10-Apr-1995  mycroft Bring back pmap_kernel(), for now always inlined as a pointer to
kernel_pmap_store.
 1.17 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.16 31-Oct-1994  andrew Increase NKPDE to cope with 64MB RAM.
 1.15 27-Oct-1994  cgd new RCS ID format.
 1.14 09-Oct-1994  mycroft #include cpufunc.h from pmap.h.
 1.13 09-Oct-1994  mycroft Define pmap_update() using tlbflush().
 1.12 09-Sep-1994  mycroft Make kernel_pmap a macro that points directly to kernel_pmap_store.
 1.11 07-Sep-1994  mycroft Various changes:
* Inline some functions.
* Eliminate redundant calls to pmap_page_index().
* Reduce the number of TLB flushes in accordance with the i386 SSWG.
* Inline pmap_remove() in pmap_remove_all(). (Most if it is unnecessary.)
* Allocate pv_entry's in pages, and keep a list of free entries in each page,
and a list of pages with free entries. (Trying to reduce malloc() overhead,
and improve locality of reference.)
* Remove a couple of macros that aren't really useful.
* Remove pmap_kernel() completely.
 1.10 15-Aug-1994  mycroft Eliminate struct pte and struct pde.
 1.9 02-Jun-1994  mycroft branches: 1.9.2;
Increase default NKPDE.
 1.8 23-May-1994  cgd cast to quiet warning
 1.7 05-Jan-1994  mycroft branches: 1.7.2;
Move kernel to 0xf8000000.
 1.6 14-Dec-1993  mycroft Fold in most of the magnum vm changes.
 1.5 30-Aug-1993  brezak branches: 1.5.2;
Add prototype for pmap_bootstrap().
 1.4 27-Aug-1993  brezak i386 Machine dependant changes to handle non-contiguous memory.
 1.3 29-Jul-1993  jtc Change "#endif FOO" to "#endif /* FOO */", to keep gcc -Wall, lint, etc.
from complaining about a trivial issue.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.4 13-Dec-1993  mycroft Stylistic changes.
 1.5.2.3 26-Oct-1993  mycroft Nuke I386_PAGE_SIZE and I386_PDR_SIZE. Make the kernel page directory 7
pages.
 1.5.2.2 15-Oct-1993  mycroft Major cleanup of include files and constants.
 1.5.2.1 10-Oct-1993  mycroft load_cr3 --> lcr3
 1.7.2.2 05-Jan-1994  mycroft Move kernel to 0xf8000000.
 1.7.2.1 05-Jan-1994  mycroft file pmap.h was added on branch magnum on 1994-01-05 16:02:39 +0000
 1.9.2.2 11-Oct-1994  mycroft Update from trunk.
 1.9.2.1 15-Aug-1994  mycroft update from trunk
 1.27.2.1 09-Dec-1997  thorpej Pull up rev 1.29 (fvdl)
 1.38.8.2 02-Aug-1999  thorpej Update from trunk.
 1.38.8.1 21-Jun-1999  thorpej Sync w/ -current.
 1.38.6.1 19-Feb-2000  he Apply patch (requested by thorpej):
Move KERNBASE to 0xc0000000, giving the kernel a more-or-less
full 1GB of virtual address space, leaving userland with 3GB,
and update comments to match the new reality.
 1.42.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.42.2.2 08-Dec-2000  bouyer Sync with HEAD.
 1.42.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.43.2.16 29-Dec-2001  sommerfeld Yet another mergeup.

New work:
- Frank van der Linden's tlb shootdown fix.
Mainline functionality merged:
- IrDA
- Kernel RCSID's
- Transmeta CPU support
- ACPI
- XMM register access through procfs
 1.43.2.15 22-Sep-2001  sommerfeld Merge branch with current, post ubcperf, MTRR, etc., etc.,
with the recent fifo_putpages fix to the trunk, GENERIC.MPDEBUG config
boots multiuser on my BP6.
 1.43.2.14 03-Sep-2001  sommerfeld Merge with -current once more.
 1.43.2.13 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.43.2.12 26-May-2001  sommerfeld Merge up with -current
 1.43.2.11 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.43.2.10 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.43.2.9 03-Jan-2001  thorpej Clean up the TLB invalidation logic. Remove the last vestiges of
the old "remove record" stuff, and just use the shootdown path, even
for uniprocessor kernels. Change the shootdown path to defer actually
peforming work (or sending the IPI to signal other processors to begin
work) until explicitly triggered by a call to pmap_tlb_shootnow().

Also remove all of the PTP and PV entry stealing code -- it's complicated,
not often called, and not really useful anymore now that UVM itself can
handle pmap_enter() failures.
 1.43.2.8 02-Jan-2001  thorpej Mirror a change made on the trunk:

Don't equate pmap_update() with tlbflush(), but instead call
tlbflush() when that's what we mean (currently everywhere, except
in the one place in MI code where it is called).

The whole pmap_update() thing needs to be reexamined, but this helps
to clarify things a little with the currently-defined semantics of
that function.
 1.43.2.7 31-Dec-2000  thorpej - Keep track of which CPUs are using a given pmap, and use this
information to flush the APTE space of other CPUs as necessary.
- Use atomic operations in the appropriate places to avoid race
conditions between the kernel and the CPU microcode which could
lose modified/referenced information.

Reviewed by Bill Sommerfeld.
 1.43.2.6 23-Sep-2000  sommerfeld Pending more complete pmap merge, deal with PMAP_PAGEIDLEZERO change
 1.43.2.5 06-Sep-2000  sommerfeld If MULTIPROCESSOR, allocate per-cpu VA space and special PTE for page
zero, page copy, and ptp mapping. Eliminate the locks which were used
to protect those special PTE/VA pairs since they're no longer
necessary.
 1.43.2.4 18-Aug-2000  sommerfeld Do tlb shootdown work at splipi().
Pass cpu_info to tlb shootdown ipi entrypoint.
 1.43.2.3 25-Jun-2000  sommerfeld Merge up to just-post-1.5 -current
 1.43.2.2 03-May-2000  sommerfeld Merge with -current
 1.43.2.1 20-Feb-2000  sommerfeld MP: preliminary TLB shootdown support.

Note that the pmap previously had its own idea of a deferred
invalidation queue; use the TLB shootdown queue mechanism for this as
well.
 1.44.2.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.45.2.1 28-Sep-2000  is Pullup from -current, requested by is, approved by thorpej:

sys/arch/arm32/include/pmap.h 1.18
sys/arch/atari/include/pmap.h 1.21
sys/arch/i386/include/pmap.h 1.50
sys/arch/pc532/include/pmap.h 1.29
sys/arch/sh3/include/pmap.h 1.6

These are architectures that do implemented wired page accounting;
advertize it to UVM, so that mlock() from non-root processes works.
 1.53.2.8 11-Nov-2002  nathanw Catch up to -current
 1.53.2.7 18-Oct-2002  nathanw Catch up to -current.
 1.53.2.6 08-Jan-2002  nathanw Catch up to -current.
 1.53.2.5 14-Nov-2001  nathanw Catch up to -current.
 1.53.2.4 21-Sep-2001  nathanw Catch up to -current.
 1.53.2.3 24-Aug-2001  nathanw Catch up with -current.
 1.53.2.2 21-Jun-2001  nathanw Catch up to -current.
 1.53.2.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.58.2.4 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.58.2.3 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.58.2.2 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.58.2.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.59.2.1 01-Oct-2001  fvdl Catch up with -current.
 1.60.2.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.73.2.7 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.73.2.6 21-Sep-2004  skrll Fix the sync with head I botched.
 1.73.2.5 18-Sep-2004  skrll Sync with HEAD.
 1.73.2.4 03-Sep-2004  skrll Sync with HEAD
 1.73.2.3 25-Aug-2004  skrll Sync with HEAD.
 1.73.2.2 12-Aug-2004  skrll Sync with HEAD.
 1.73.2.1 03-Aug-2004  skrll Sync with HEAD
 1.82.12.7 04-Feb-2008  yamt sync with head.
 1.82.12.6 21-Jan-2008  yamt sync with head
 1.82.12.5 07-Dec-2007  yamt sync with head
 1.82.12.4 27-Oct-2007  yamt sync with head.
 1.82.12.3 03-Sep-2007  yamt sync with head.
 1.82.12.2 26-Feb-2007  yamt sync with head.
 1.82.12.1 21-Jun-2006  yamt sync with head.
 1.85.6.1 22-Apr-2006  simonb Sync with head.
 1.85.4.1 09-Sep-2006  rpaulo sync with head
 1.85.2.1 18-Feb-2006  yamt sync with head.
 1.86.16.2 10-Dec-2006  yamt sync with head.
 1.86.16.1 22-Oct-2006  yamt sync with head
 1.86.14.1 18-Nov-2006  ad Sync with head.
 1.88.4.1 27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.89.22.3 23-Mar-2008  matt sync with HEAD
 1.89.22.2 09-Jan-2008  matt sync with HEAD
 1.89.22.1 06-Nov-2007  matt sync with HEAD
 1.89.20.6 03-Dec-2007  joerg Sync with HEAD.
 1.89.20.5 27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.89.20.4 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.89.20.3 02-Oct-2007  joerg Sync with HEAD.
 1.89.20.2 10-Sep-2007  joerg Introduce pmap_init_tmp_pgtbl to build a temporary copy of the kernel
side page mapping and an identity mapping low page for use in real mode.
Switch MP bootstrap and i386 ACPI wakeup code to use it.
 1.89.20.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.89.16.1 03-Sep-2007  skrll Sync with HEAD.
 1.89.12.2 17-Oct-2007  garbled Sync with HEAD
 1.89.12.1 03-Oct-2007  garbled Sync with HEAD
 1.89.4.8 03-Dec-2007  ad Sync with HEAD.
 1.89.4.7 23-Oct-2007  ad Sync with head.
 1.89.4.6 09-Oct-2007  ad Sync with head.
 1.89.4.5 23-Aug-2007  ad Add pmap_pte_set, pmap_pte_setbits, pmap_pte_clearbits where missing.
 1.89.4.4 21-Aug-2007  ad - Add ci_cpumask and use in preference to (1 << ci_cpuid). Some processors
are bad at shifting by non-constant amounts.
- pmap_tlb_shootdown() must be called with preemption disabled.
- Defer waiting for tlb shootdown to complete after kenter_pa()/kremove().
Spin in pmap_update() and in pmap_detactivate(), in case the LWP has been
preempted
- When preparing to send a multicast shootdown IPI, avoid scanning the list
of CPUs if the pmap's bitmask indicates that it's only active locally.
 1.89.4.3 18-Aug-2007  yamt - fix TLB problems in recursive PTE mappings, which causes various crashes.
as they are used by the kernel itself, they need to be synced regardless
of lazy tlb flushing mode.

- pmap_tlb_shootdown: fix the case of sva != -1 && eva == 0.

ok'ed by Andrew Doran.
 1.89.4.2 29-Jul-2007  ad - When zeroing/copying pages, use SSE2 movtni to avoid polluting the cache.
- By default, align assembly routines on 32-byte starting boundaries.
- There are now 8 interrupt priority levels, half of which are softints.
Update intrdefs.h to match.
- Always clear/set spinlock words - removes lots of ifdefs.
- Remove the horrible ci_self150 hack that I introduced.
- Overhaul how TLB shootdown is performed. Inspired by a similar change in
OpenBSD but implemented quite differently. This should be a lot faster
but I have not benchmarked it yet.
 1.89.4.1 28-Apr-2007  ad - Make the PV cache per-CPU and eliminate the global pvalloc_lock. Cuts
contention on the freelist locks by a factor of ~50 on a dual core box.
- Mirror a patch for amd64 posted by oster@, and make the TLB shootdown
freelist per-CPU. Increase the number of TLB shootdown jobs from 16
to 32 per CPU.
 1.90.2.13 18-Oct-2007  yamt sync with head.
 1.90.2.12 14-Oct-2007  yamt forward decl of trapframe.
 1.90.2.11 08-Oct-2007  yamt merge some parts of x86 pmap.h.
 1.90.2.10 07-Oct-2007  yamt tweak assertions to reduce diffs between i386 and amd64.
 1.90.2.9 07-Oct-2007  yamt remove unnecessary casts.
 1.90.2.8 07-Oct-2007  yamt sync comments and whitespaces.
 1.90.2.7 07-Oct-2007  yamt g/c nkpde.
 1.90.2.6 07-Oct-2007  yamt whitespace.
 1.90.2.5 07-Oct-2007  yamt remove unused definitions.
 1.90.2.4 06-Oct-2007  yamt sync with head.
 1.90.2.3 04-Oct-2007  yamt remove LARGEPAGES option. always use large pages if available.
 1.90.2.2 24-Sep-2007  yamt remove hardcoded numbers of PTPs used for kernel image and bootstrap tables.
 1.90.2.1 23-Sep-2007  yamt - sync with amd64.
- pmap_alloc_level: remove fast call special case.
- tweak some printf to work for both of LP64 and LP32.
- remove machdep.nkpde sysctl.
- remove automatic adjustment of nkpde for now. will revisit later.
 1.91.2.3 26-Oct-2007  bouyer Make amd64, i386 and xen kernels build and work again.
 1.91.2.2 25-Oct-2007  bouyer Finish sync with HEAD. Especially use the new x86 pmap for xenamd64.
For this:
- rename pmap_pte_set() to pmap_pte_testset()
- make pmap_pte_set() a function or macro for non-atomic PTE write
- define and use pmap_pa2pte()/pmap_pte2pa() to read/write PTE entries
- define pmap_pte_flush() which is a nop in x86 case, and flush the
MMUops queue in the Xen case
 1.91.2.1 25-Oct-2007  bouyer Sync with HEAD.
 1.94.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.94.2.1 08-Dec-2007  mjf Sync with HEAD.
 1.97.6.9 20-Jan-2008  bouyer Sync with HEAD: make first argument of pmap_pte_cas() volatile.
 1.97.6.8 19-Jan-2008  bouyer Make things build again after sync with HEAD
 1.97.6.7 19-Jan-2008  bouyer Sync with HEAD
 1.97.6.6 18-Jan-2008  bouyer Fix APDP handling. A XEN i386PAE kernel now boots multiuser
 1.97.6.5 17-Jan-2008  bouyer - Fix L2_SLOT_APTE value (not sure how I got this value but it was definitively
wrong)
- Use global variable for the PAE L3 page adresses, so that pmap.c can get it
from the bootstrap code
- Extent the size of our virtual PDP from 3 to 4 pages, so that pmap->pm_pdir[]
is contigous for the whole VA range. The last page is a shadow of
the kernel's real PDP (L3[3]).
- make pm_pdirpa an array of 4 paddr_t if using PAE. introduce a
pmap_pdirpa macro to get the physical address of a given PD entry.
- fix pmap_map_pte

The kernel now boots single-user. fsck will cause a kernel fault in
pmap_pdes_invalid() on exit.
 1.97.6.4 15-Jan-2008  bouyer Snapshot of work in progress: an Xen i386PAE kernel boots and start init
on a amd64 dom0, but panics when init forks.
This code needs a lot of cleanup, and the pmap handling is minimal to
allow init to start. It's a proof of concept of how PAE on Xen can work.

For PAE guest, the Xen MMU handling differs in some significant way
from the i386 or amd64 Xen.
The L3 page has only 4 entries, the last one mapping 0xc0000000->0xffffffff
(which happens to be our kenrel VM range, that's cool). The L2 page
pointed to by this last entry is handled specially by Xen because it
contains some Xen private mapping, including a recursive mapping. So this
page can only be pointed to by exactly one L3 entry, and nothing else
(it can't be part of a recursive mapping for example). In addition, it
would waste too much VA space to do recursive mapping at the L3 level.

We do pmap switching at the L# level, instead of doing it though %cr3.
%cr3 is static, as is L3[3] which contains only kenrel mappings.
pmap_load() does pmap switching though the first 3 entries for L3.

PTE mapping is done though 4 contigous L2 entries; the last one pointing
to a shadow of L3[3]. This way we can consider we have a 2-level VM system,
but with the L2 being 4 pages in size instead of one. The plx_i()
macros can be used with it to access the PTE without changes.

This can be reused as is for native PAE support (without the L3[3] shadow
which wouldn't be needed here)
 1.97.6.3 13-Jan-2008  bouyer Update system macros for PAE. Because the L3 page directory has only 4 entries,
and because of the way Xen handles it, it's better to have it has static as
possible. So we claim to have only 2 levels, with level 2 being a
"super" PD of 4 pages. pmap switches will be handled by changing the
L3 entries instead of %cr3. Only the first 3 entries will have to be changed,
the last one mapping KVA space only.
 1.97.6.2 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.97.6.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.102.16.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.102.10.3 11-Aug-2010  yamt sync with head.
 1.102.10.2 11-Mar-2010  yamt sync with head
 1.102.10.1 04-May-2009  yamt sync with head.
 1.102.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.103.14.3 16-Nov-2010  uebayasi Sync with HEAD.
 1.103.14.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.103.14.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.103.8.4 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.103.8.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.103.8.2 10-Jan-2011  jym Sync with HEAD
 1.103.8.1 24-Oct-2010  jym Sync with HEAD
 1.105.2.1 05-Mar-2011  rmind sync with head
 1.108.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.108.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.109.2.3 20-Sep-2011  cherry Remove the "xpq lock", since we have per-cpu mmu queues now. This may need further testing. Also add some preliminary locking around queue-ops in the network backend driver
 1.109.2.2 20-Aug-2011  cherry PAE MP support (preliminary), amd64 per-cpu L4 model redesigned, i386 pmap_pa_start/end fixup
 1.109.2.1 31-Jul-2011  cherry grow MP support for i386. boots to single user
 1.110.2.3 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.110.2.2 17-Apr-2012  yamt sync with head
 1.110.2.1 10-Nov-2011  yamt sync with head
 1.112.4.2 24-Feb-2012  mrg sync to -current.
 1.112.4.1 18-Feb-2012  mrg merge to -current.
 1.115.2.3 03-Dec-2017  jdolecek update from HEAD
 1.115.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.115.2.1 23-Jun-2013  tls resync from head
 1.116.10.1 10-Aug-2014  tls Rebase.
 1.116.6.1 18-May-2014  rmind sync with head
 1.117.8.1 04-Nov-2016  pgoyette Sync with HEAD
 1.117.4.1 05-Oct-2016  skrll Sync with HEAD
 1.118.16.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.118.16.1 10-Jun-2019  christos Sync with HEAD
 1.118.14.2 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.118.14.1 28-Jul-2018  pgoyette Sync with HEAD
 1.10 17-Jun-1999  thorpej PMAP_NEW is no longer optional on the i386; the old pmap's page table
allocation strategy no longer works at all. Move pmap.new.* to pmap.*.

To read the revision history of PMAP_NEW up until this merge, use cvs
rlog of the old pmap.new.* files.
 1.9 12-May-1999  thorpej Move the user-set LDT out of the PCB and into the pmap. Applications
which set the LDT and share VM space (e.g. new versions of WINE) expect
the LDT to be logically coupled to the address space. Use the new pmap_fork()
interface to copy non-shared user-set LDTs when the address space is forked.
 1.8 05-May-1999  chs update resident_count and wired_count properly in pmap_kenter_*()
and pmap_kremove().
 1.7 13-Aug-1998  thorpej branches: 1.7.6;
vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.6 05-May-1998  chuck correct some addresses in the comment that i missed when
KERNBASE changed a while back (from Matthias Drochner)
 1.5 02-Mar-1998  fvdl Don't make simple_lock decls dependent on NCPU > 1, be consistent with
the rest of the kernel.
 1.4 18-Feb-1998  thorpej Fixup an inconsistency in the declaration of PTDpaddr, pointed out by
Chris Demetriou.
 1.3 18-Feb-1998  cgd Move pmap_map() function definition to MD headers, as appropriate. It's
an internal function, and the VM system shouldn't try to prototype it.
(Note that some ports _don't_ prototype it.)
 1.2 06-Feb-1998  thorpej RCS ID police.
 1.1 06-Feb-1998  mrg oops, forgot to add these new files
 1.7.6.2 19-Feb-2000  he Apply patch (requested by thorpej):
Move KERNBASE to 0xc0000000, giving the kernel a more-or-less
full 1GB of virtual address space, leaving userland with 3GB,
and update comments to match the new reality.
 1.7.6.1 05-May-1999  perry branches: 1.7.6.1.2;
pullup 1.7->1.8 (chuq)
 1.7.6.1.2.1 21-Jun-1999  thorpej Sync w/ -current.
 1.4 21-Aug-2022  riastradh x86 Move VA_SIGN_POS/NEG to machine/pte.h.

It's used by pl[1-4]_pi, also defined in machine/pte.h, and used in
libkvm without pmap_private.h.
 1.3 20-Aug-2022  riastradh {amd64,i386}/pmap_private.h: Fix minor whitespace issues.
 1.2 20-Aug-2022  riastradh x86: Move definition of struct pmap to pmap_private.h.

This makes pmap_resident_count and pmap_wired_count out-of-line
functions instead of inline. No functional change intended
otherwise.
 1.1 20-Aug-2022  riastradh x86: Split most of pmap.h into pmap_private.h or vmparam.h.

This way pmap.h only contains the MD definition of the MI pmap(9)
API, which loads of things in the kernel rely on, so changing x86
pmap internals no longer requires recompiling the entire kernel every
time.

Callers needing these internals must now use machine/pmap_private.h.
Note: This is not x86/pmap_private.h because it contains three parts:

1. CPU-specific (different for i386/amd64) definitions used by...

2. common definitions, including Xenisms like xpmap_ptetomach,
further used by...

3. more CPU-specific inlines for pmap_pte_* operations

So {amd64,i386}/pmap_private.h defines 1, includes x86/pmap_private.h
for 2, and then defines 3. Maybe we should split that out into a new
pmap_pte.h to reduce this trouble.

No functional change intended, other than that some .c files must
include machine/pmap_private.h when previously uvm/uvm_pmap.h
polluted the namespace with pmap internals.

Note: This migrates part of i386/pmap.h into i386/vmparam.h --
specifically the parts that are needed for several constants defined
in vmparam.h:

VM_MAXUSER_ADDRESS
VM_MAX_ADDRESS
VM_MAX_KERNEL_ADDRESS
VM_MIN_KERNEL_ADDRESS

Since i386 needs PDP_SIZE in vmparam.h, I added it there on amd64
too, just to keep things parallel.
 1.12 12-Jul-2018  maxv Remove the kernel PMC code. Sent yesterday on tech-kern@.

This change:

* Removes "options PERFCTRS", the associated includes, and the associated
ifdefs. In doing so, it removes several XXXSMPs in the MI code, which is
good.

* Removes the PMC code of ARM XSCALE.

* Removes all the pmc.h files. They were all empty, except for ARM XSCALE.

* Reorders the x86 PMC code not to rely on the legacy pmc.h file. The
definitions are put in sysarch.h.

* Removes the kern/sys_pmc.c file, and along with it, the sys_pmc_control
and sys_pmc_get_info syscalls. They are marked as OBSOL in kern,
netbsd32 and rump.

* Removes the pmc_evid_t and pmc_ctr_t types.

* Removes all the associated man pages. The sets are marked as obsolete.
 1.11 10-Mar-2017  maxv branches: 1.11.12; 1.11.14;
unused
 1.10 18-Feb-2017  maxv There is currently an ugly mix between the PERFCTRS subsystem (MI), and
i386's own PMC interface (MD). Stop using PERFCTRS and use PMC instead.
While here remove some unused flags, which are wrong on the latest CPUs
anyway.
 1.9 17-Feb-2017  maxv Support PMCs on multi-processor systems. Still several things to fix, but
at least it works a little. Will be improved and moved into x86/ soon.
 1.8 16-Apr-2007  ad branches: 1.8.80; 1.8.100; 1.8.104; 1.8.108;
Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.7 17-Jan-2003  thorpej branches: 1.7.18; 1.7.56; 1.7.60; 1.7.62;
Merge the nathanw_sa branch.
 1.6 09-Aug-2002  thorpej branches: 1.6.2;
PMC_TYPE_I586 -> PMC_CLASS_I586
PMC_TYPE_I686 -> PMC_CLASS_I686
PMC_TYPE_K7 -> PMC_CLASS_K7

To reflect terminilogy used in pmc(3).
 1.5 08-Aug-2002  thorpej Add macros to encode the "unit number" in the event selector.
 1.4 08-Aug-2002  thorpej Define new-style PMC types for i586, i686, and K7 performance counters.
 1.3 07-Aug-2002  briggs Stubs for new pmc(9) interface.
 1.2 07-Aug-2002  briggs Forward declare structures that are used here.
 1.1 13-Sep-2000  thorpej branches: 1.1.2; 1.1.6; 1.1.8; 1.1.20;
Add support for using the 586- and 686-class performance
counters.
 1.1.20.1 31-Aug-2002  gehenna catch up with -current.
 1.1.8.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.1.6.2 13-Aug-2002  nathanw Catch up to -current.
 1.1.6.1 21-Jun-2002  gmcgarry LWPify
 1.1.2.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.1.2.1 13-Sep-2000  bouyer file pmc.h was added on branch thorpej_scsipi on 2000-11-20 20:09:30 +0000
 1.6.2.2 09-Aug-2002  thorpej PMC_TYPE_I586 -> PMC_CLASS_I586
PMC_TYPE_I686 -> PMC_CLASS_I686
PMC_TYPE_K7 -> PMC_CLASS_K7

To reflect terminilogy used in pmc(3).
 1.6.2.1 09-Aug-2002  thorpej file pmc.h was added on branch sommerfeld_i386mp_1 on 2002-08-09 05:28:09 +0000
 1.7.62.1 11-Jul-2007  mjf Sync with head.
 1.7.60.1 27-May-2007  ad Sync with head.
 1.7.56.1 07-May-2007  yamt sync with head.
 1.7.18.1 03-Sep-2007  yamt sync with head.
 1.8.108.1 21-Apr-2017  bouyer Sync with HEAD
 1.8.104.1 20-Mar-2017  pgoyette Sync with HEAD
 1.8.100.1 28-Aug-2017  skrll Sync with HEAD
 1.8.80.1 03-Dec-2017  jdolecek update from HEAD
 1.11.14.1 10-Jun-2019  christos Sync with HEAD
 1.11.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.48 13-Jun-2020  ad Print a rate limited warning if the TSC timecounter goes backwards from the
viewpoint of any single LWP.
 1.47 13-Jan-2020  ad Remove now unused mdlwp fields md_gc_pmap and md_gc_ptp.
 1.46 12-Oct-2019  maxv branches: 1.46.2;
Rewrite the FPU code on x86. This greatly simplifies the logic and removes
the dependency on IPL_HIGH. NVMM is updated accordingly. Posted on
port-amd64 a week ago.

Bump the kernel version to 9.99.16.
 1.45 25-Feb-2017  kamil branches: 1.45.14;
Garbage collect unneeded inclusion of <x86/dbregs.h> in <machine/proc.h>

This is left over after introduction of Debug Register accessors.
This interface replaced older watchpoint API.

Sponsored by <The NetBSD Foundation>
 1.44 23-Feb-2017  kamil Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.43 15-Dec-2016  kamil branches: 1.43.2;
Add support for hardware assisted watchpoints/breakpoints API in ptrace(2)

Add new ptrace(2) calls:
- PT_COUNT_WATCHPOINTS - count the number of available hardware watchpoints
- PT_READ_WATCHPOINT - read struct ptrace_watchpoint from the kernel state
- PT_WRITE_WATCHPOINT - write new struct ptrace_watchpoint state, this
includes enabling and disabling watchpoints

The ptrace_watchpoint structure contains MI and MD parts:

typedef struct ptrace_watchpoint {
int pw_index; /* HW Watchpoint ID (count from 0) */
lwpid_t pw_lwpid; /* LWP described */
struct mdpw pw_md; /* MD fields */
} ptrace_watchpoint_t;

For example amd64 defines MD as follows:
struct mdpw {
void *md_address;
int md_condition;
int md_length;
};

These calls are protected with the __HAVE_PTRACE_WATCHPOINTS guard.

Tested on amd64, initial support added for i386 and XEN.

Sponsored by <The NetBSD Foundation>
 1.42 20-Feb-2014  dsl branches: 1.42.6; 1.42.10;
Move the amd64 and i386 pcb to the bottom of the uarea, and move the
kernel stack to the top.
Change the pcb layouts so that fpu save area is at the end and is
64byte aligned ready for xsave (saving the ymm registers).
Welcome to 6.99.32
 1.41 15-Feb-2014  dsl Remove all references to MDL_USEDFPU and deferred fpu initialisation.
The cost of zeroing the save area on exec is minimal.
This stops the FP registers of a random process being used the first
time an lwp uses the fpu.
sendsig_siginfo() and get_mcontext() now unconditionally copy the FP
registers.
I'll remove the double-copy for signal handlers soon.
get_mcontext() might have been leaking kernel memory to userspace - and
may still do so if i386_use_fxsave is false (short copies).
 1.40 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.39 23-Oct-2013  drochner Use the MI "pcu" framework for bookkeeping of npx/fpu states on x86.
This reduces the amount of MD code enormously, and makes it easier
to implement support for newer CPU features which require more fpu
state, or for fpu usage by the kernel.
For access to FPU state across CPUs, an xcall kthread is used now
rather than a dedicated IPI.
No user visible changes intended.
 1.38 14-Jan-2011  rmind branches: 1.38.8; 1.38.18; 1.38.22;
Retire struct user, remove sys/user.h inclusions. Note sys/user.h header
as obsolete. Remove USER_TO_UAREA/UAREA_TO_USER macros.

Various #include fixes and review by matt@.
 1.37 20-Dec-2008  ad branches: 1.37.2; 1.37.6;
Remove stray opt_redzone.h
 1.36 05-Jun-2008  ad branches: 1.36.6; 1.36.8;
pmap_remove_all() for x86. Also, always defer freeing ptps to pmap_update().
There may be a better way to do this, but for now this is simple and avoids
potential bugs.

Proposed on tech-kern and discussed with chs@.
 1.35 04-Jan-2008  yamt branches: 1.35.6; 1.35.8; 1.35.10; 1.35.12;
i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.34 16-Nov-2007  skrll branches: 1.34.6;
s/proc/lwp/ in comment
 1.33 10-Nov-2007  ad fsbase/gsbase:

- Fix a few bugs with it, in particular fork/exec handling.
- Store the descriptors in the PCB, not in the LWP.
 1.32 10-Nov-2007  ad - When computing the TSC frequency, call i8254_delay() and not DELAY().
- Use atomics to adjust the pmap reference count, instead of taking locks.
- Implement I386_{SET,GET}_{FS,GS}BASE, allowing %fs and %gs to be used
as per-thread registers. This is compatible with FreeBSD.
- Run patches after we have attached CPUs, since we then know if the
system is uniprocessor or not. Eliminates a lot of #ifdef MULTIPROCESSOR
and makes running MP kernels on UP systems cheaper.
- Patch out many of the 'lock' prefixes to nops if uniprocessor.
- Do a wbinvd after patching to ensure that the trace/instruction cache
is up to date.
 1.31 04-Mar-2007  christos branches: 1.31.2; 1.31.18; 1.31.20; 1.31.24; 1.31.26;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.30 09-Feb-2007  ad branches: 1.30.2;
Merge newlock2 to head.
 1.29 23-Sep-2006  yamt fix a typo in 1.28. (ccaddr_t -> caddr_t)
 1.28 22-May-2006  yamt branches: 1.28.6; 1.28.8;
i386 and xen: move struct user to the highest address in uarea
and reduce UPAGES from 4 to 3 in the case of !NOREDZONE.
 1.27 24-Dec-2005  perry branches: 1.27.4; 1.27.6; 1.27.8; 1.27.12; 1.27.14;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.26 21-Feb-2004  junyoung branches: 1.26.16;
- Locate comment in right place.
- Fix wrt protection against multiple inclusion.
 1.25 28-Jan-2004  yamt rename i386 mdlwp flags from MDP_ to MDL_
to avoid confusion with mdproc flags which also have MDP_ prefixes.
 1.24 14-Jan-2004  yamt remove a duplicated definition of MDP_USEDFPU.
 1.23 27-Oct-2003  junyoung Nuke __P().
 1.22 20-Aug-2003  fvdl Pass pointers to frames from assembly, do not use the 'frame on stack
as argument passed by value' trick, as gcc 3.3.x makes (valid) assumptions
about the stack that will not be true. Costs 2 instructions per trap/syscall
on i386, 4 per interrupt for MP. One instruction per trap/syscall on amd64,
2 per interrupt for MP. I expect gcc 3.3.1 to make up for this by better
optimization (it'd better..)

While here, make amd64 compile again by using subr_mbr_disk.c
 1.21 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.20 23-Jun-2003  martin branches: 1.20.2;
Protect kernel opt_*.h include by #ifdef _KERNEL_OPT
 1.19 23-Jun-2003  martin Make sure to include opt_foo.h if a defflag option FOO is used.
 1.18 02-Apr-2003  thorpej Use PAGE_SIZE rather than NBPG.
 1.17 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.16 12-Oct-2002  yamt re-do my previous commit correctly
 1.15 11-Oct-2002  yamt override KSTACK_LOWEST_ADDR and KSTACK_SIZE for redzone.
 1.14 10-Sep-2001  fvdl branches: 1.14.2;
Add flag to indicate that a process set some mtrrs that need to be
cleaned up automatically on exit.
 1.13 11-Dec-2000  tron branches: 1.13.4; 1.13.6; 1.13.8;
Include "machine/frame.h" to avoid lint errors while building "libc".
 1.12 11-Dec-2000  mycroft Introduce 2 new flags in types.h:
* __HAVE_SYSCALL_INTERN. If this is defined, e_syscall is replaced by
e_syscall_intern, which is called at key places in the kernel. This can be
used to set a MD syscall handler pointer. This obsoletes and replaces the
*_HAS_SEPARATED_SYSCALL flags.
* __HAVE_MINIMAL_EMUL. If this is defined, certain (deprecated) elements in
struct emul are omitted.
 1.11 16-Aug-2000  thorpej Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.10 06-Aug-1995  mycroft branches: 1.10.32; 1.10.44;
Move the `used fpu' flag into mdproc, so it can be referenced when a process
is swapped out. Implement process_{read,write}_fpregs.
 1.9 01-May-1995  mycroft Make md_regs a pointer to a trapframe.
 1.8 01-May-1995  mycroft Rename ibcs2_sigflags to __spare, but leave the space for now.
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 15-Aug-1994  mycroft Add flags for iBCS2 compat.
 1.5 05-May-1994  cgd branches: 1.5.2;
lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.4 21-Dec-1993  mycroft branches: 1.4.2;
Remove two unused fields.
 1.3 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 14-Nov-1993  mycroft md_flags is not used.
 1.4.2.2 21-Dec-1993  mycroft Remove two unused fields.
 1.4.2.1 21-Dec-1993  mycroft file proc.h was added on branch magnum on 1993-12-21 09:47:58 +0000
 1.5.2.1 15-Aug-1994  mycroft update from trunk
 1.10.44.1 16-Aug-2000  thorpej Update from trunk:
Move the TSS selector out of the PCB and put it into mdproc. We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph). We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.
 1.10.32.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.10.32.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.13.8.1 01-Oct-2001  fvdl Catch up with -current.
 1.13.6.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.13.4.4 25-Nov-2002  nathanw Make ASTs per-proc rather than per-cpu; per-proc makes more sense when
a process that needs a trap can be running on multiple CPUs.
 1.13.4.3 18-Oct-2002  nathanw Catch up to -current.
 1.13.4.2 21-Sep-2001  nathanw Catch up to -current.
 1.13.4.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.14.2.2 10-Sep-2001  fvdl Add flag to indicate that a process set some mtrrs that need to be
cleaned up automatically on exit.
 1.14.2.1 10-Sep-2001  fvdl file proc.h was added on branch sommerfeld_i386mp_1 on 2001-09-10 10:11:22 +0000
 1.20.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.20.2.1 03-Aug-2004  skrll Sync with HEAD
 1.26.16.6 21-Jan-2008  yamt sync with head
 1.26.16.5 07-Dec-2007  yamt sync with head
 1.26.16.4 03-Sep-2007  yamt sync with head.
 1.26.16.3 26-Feb-2007  yamt sync with head.
 1.26.16.2 30-Dec-2006  yamt sync with head.
 1.26.16.1 21-Jun-2006  yamt sync with head.
 1.27.14.1 19-Jun-2006  chap Sync with head.
 1.27.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.27.8.1 24-May-2006  yamt sync with head.
 1.27.6.1 01-Jun-2006  kardel Sync with head.
 1.27.4.1 09-Sep-2006  rpaulo sync with head
 1.28.8.1 22-Oct-2006  yamt sync with head
 1.28.6.2 18-Nov-2006  ad Sync with head.
 1.28.6.1 20-Oct-2006  ad Make ASTs per-LWP.
 1.30.2.1 12-Mar-2007  rmind Sync with HEAD.
 1.31.26.2 18-Feb-2008  mjf Sync with HEAD.
 1.31.26.1 19-Nov-2007  mjf Sync with HEAD.
 1.31.24.1 18-Nov-2007  bouyer Sync with HEAD
 1.31.20.1 09-Jan-2008  matt sync with HEAD
 1.31.18.2 21-Nov-2007  joerg Sync with HEAD.
 1.31.18.1 11-Nov-2007  joerg Sync with HEAD.
 1.31.2.1 03-Dec-2007  ad Sync with HEAD.
 1.34.6.1 08-Jan-2008  bouyer Sync with HEAD
 1.35.12.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.35.10.1 04-May-2009  yamt sync with head.
 1.35.8.1 17-Jun-2008  yamt sync with head.
 1.35.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.35.6.1 29-Jun-2008  mjf Sync with HEAD.
 1.36.8.1 16-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #355):
sys/arch/i386/i386/vm_machdep.c: revision 1.143
sys/arch/i386/include/proc.h: revision 1.37
Remove stray opt_redzone.h
 1.36.6.1 19-Jan-2009  skrll Sync with HEAD.
 1.37.6.1 05-Mar-2011  rmind sync with head
 1.37.2.1 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.38.22.1 18-May-2014  rmind sync with head
 1.38.18.2 03-Dec-2017  jdolecek update from HEAD
 1.38.18.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.38.8.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.42.10.2 20-Mar-2017  pgoyette Sync with HEAD
 1.42.10.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.42.6.2 28-Aug-2017  skrll Sync with HEAD
 1.42.6.1 05-Feb-2017  skrll Sync with HEAD
 1.43.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.45.14.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.45.14.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.46.2.1 17-Jan-2020  ad Sync with head.
 1.38 02-Nov-2021  ryo In order to prevent _mcount() from being recursively called when built with COPTS=-O0,
sprinkle `__always_inline' to make _mcount() be generated as a single function.
 1.37 08-Jun-2017  christos use compiler builtins to compute addresses instead %ebp assembly arithmetic.
(from joerg)
 1.36 04-Jun-2017  christos - prevent optimization from omitting the frame pointer (and re-using it);
we use it in our inline assembly.
- convert to c a little assembly to make the code more understandable.
 1.35 31-May-2017  christos branches: 1.35.2;
prevent coredumps by skipping everything early if we are not counting.
 1.34 10-Jan-2016  ryo __mcount_lock is moved to MI from MD.
because it is needed for all MULTIPROCESSOR arch, but it is exists only in i386 and amd64.

ok christos@, on tech-kern@
 1.33 20-Dec-2007  ad branches: 1.33.54; 1.33.74;
- Make __cpu_simple_lock and similar real functions and patch at runtime.
- Remove old x86 atomic ops.
- Drop text alignment back to 16 on i386 (really, this time).
- Minor cleanup.
 1.32 17-Oct-2007  garbled branches: 1.32.4; 1.32.8;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.31 26-Sep-2007  ad Inline interrupt disable for _mcount, so the real function calls don't
screw with profiling.
 1.30 26-Sep-2007  ad Make build in userspace again.
 1.29 26-Sep-2007  xtraeme Fix profiling kernels:

read_psl -> x86_read_psl
write_psl -> x86_write_psl
disable_intr -> x86_disable_intr
 1.28 16-Apr-2007  christos branches: 1.28.2; 1.28.10; 1.28.12; 1.28.14;
As noted by uwe, we need to also save %edx because it can be used with
the regparm calling convention.
XXX: The c stub should be replaced with an assembly one.
 1.27 16-Apr-2007  christos save and restore %eax, %ecx, otherwise profiling does not work properly.
From Anon Ymous. Example program that fails:

int
main(int argc, char *argv[])
{
return argc;
}
 1.26 09-Feb-2007  ad branches: 1.26.2; 1.26.6; 1.26.8; 1.26.12;
Merge newlock2 to head.
 1.25 16-Feb-2006  perry branches: 1.25.14; 1.25.18;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.24 24-Dec-2005  perry branches: 1.24.2; 1.24.4; 1.24.6;
__asm__ -> __asm
__const__ -> const
__inline__ -> inline
__volatile__ -> volatile
 1.23 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.22 02-Oct-2005  chs put mcount.c in the normal object list, so that "make depend" works.
use a gcc attribute to prevent it from being instrumented.
 1.21 25-Feb-2005  chs branches: 1.21.4;
fix a typoe in previous.
 1.20 21-Feb-2005  chs allow profiling of MP kernels, add a spinlock around the body of mcount().
 1.19 24-May-2004  yamt branches: 1.19.4; 1.19.6;
instead of blindly set IF in MCOUNT_EXIT,
save eflags in MCOUNT_ENTER and restore it.
 1.18 27-Oct-2003  junyoung Nuke __P().
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.16 30-Nov-2001  enami branches: 1.16.2; 1.16.18;
Declare some asm statement with output as volatile. Without this,
gcc with -march=pentiumpro produce bad code.
 1.15 23-Aug-2001  chs use cli/sti instead of splhigh/splx for MCOUNT_ENTER/MCOUNT_EXIT.
this makes clearer how much time mcount() is really taking.
 1.14 22-Jan-2000  mycroft branches: 1.14.8; 1.14.10;
Delint.
 1.13 28-Sep-1999  enami branches: 1.13.2;
Add missing backslash.
 1.12 27-Sep-1999  kleink For ELF, rename the profiling entry from mcount to __mcount to avoid clashing
with the user's namespace, also within file scope; for binary compatibility,
define a weak alias for the previous name to cover our tracks.
 1.11 13-Nov-1998  christos cast _mcount args to u_long, to avoid lint warnings.
 1.10 05-Nov-1997  thorpej asm -> __asm__
 1.9 07-Dec-1996  fvdl branches: 1.9.14;
Remove _MCOUNT_DECL prototype once more.
 1.8 05-Dec-1996  fvdl Add _MCOUNT_DECL prototype.
 1.7 04-Dec-1996  fvdl Change asm.h to make it usable for kernel profiling as well.
Make mcount() a prototype in profile.h
 1.6 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 13-May-1994  mycroft Duh.
 1.3 13-May-1994  mycroft Need some more macros not in the 4.4-Lite version.
 1.2 13-May-1994  mycroft Do this better.
 1.1 13-May-1994  mycroft Needed for new profiling code.
 1.9.14.1 05-Nov-1997  thorpej Pull up from trunk: asm -> __asm__
 1.13.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.14.10.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.14.10.1 25-Aug-2001  thorpej Merge Aug 24 -current into the kqueue branch.
 1.14.8.2 08-Jan-2002  nathanw Catch up to -current.
 1.14.8.1 21-Sep-2001  nathanw Catch up to -current.
 1.16.18.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.16.18.4 04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.16.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.18.1 03-Aug-2004  skrll Sync with HEAD
 1.16.2.2 30-Nov-2001  enami Declare some asm statement with output as volatile. Without this,
gcc with -march=pentiumpro produce bad code.
 1.16.2.1 30-Nov-2001  enami file profile.h was added on branch sommerfeld_i386mp_1 on 2001-11-30 06:53:57 +0000
 1.19.6.1 19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.19.4.1 29-Apr-2005  kent sync with -current
 1.21.4.5 21-Jan-2008  yamt sync with head
 1.21.4.4 27-Oct-2007  yamt sync with head.
 1.21.4.3 03-Sep-2007  yamt sync with head.
 1.21.4.2 26-Feb-2007  yamt sync with head.
 1.21.4.1 21-Jun-2006  yamt sync with head.
 1.24.6.1 22-Apr-2006  simonb Sync with head.
 1.24.4.1 09-Sep-2006  rpaulo sync with head
 1.24.2.1 18-Feb-2006  yamt sync with head.
 1.25.18.1 20-Apr-2007  bouyer Pull up following revision(s) (requested by christos in ticket #579):
sys/arch/i386/include/profile.h: revisions 1.27 - 1.28
save and restore %eax, %ecx, otherwise profiling does not work properly.
 1.25.14.1 06-Feb-2007  ad mcount(): fix entry so LOCKDEBUG+GPROF can be used together. Previously
it would recurse until eventually the machine triple faulted.
 1.26.12.1 18-Apr-2007  thorpej Convert i386 and amd64 to the new atomic ops API.
 1.26.8.1 11-Jul-2007  mjf Sync with head.
 1.26.6.2 09-Oct-2007  ad Sync with head.
 1.26.6.1 27-May-2007  ad Sync with head.
 1.26.2.1 07-May-2007  yamt sync with head.
 1.28.14.1 06-Oct-2007  yamt sync with head.
 1.28.12.2 09-Jan-2008  matt sync with HEAD
 1.28.12.1 06-Nov-2007  matt sync with HEAD
 1.28.10.1 02-Oct-2007  joerg Sync with HEAD.
 1.28.2.1 03-Oct-2007  garbled Sync with HEAD
 1.32.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.32.4.1 26-Dec-2007  ad Sync with head.
 1.33.74.2 28-Aug-2017  skrll Sync with HEAD
 1.33.74.1 19-Mar-2016  skrll Sync with HEAD
 1.33.54.1 03-Dec-2017  jdolecek update from HEAD
 1.35.2.1 22-Mar-2018  martin Pull up following revision(s) (requested by christos in ticket #653):
sys/arch/i386/include/profile.h: revision 1.36
sys/arch/i386/include/profile.h: revision 1.37

- prevent optimization from omitting the frame pointer (and re-using it);
we use it in our inline assembly.
- convert to c a little assembly to make the code more understandable.

use compiler builtins to compute addresses instead %ebp assembly arithmetic.
(from joerg)
 1.35 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.34 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.33 30-May-2001  mrg branches: 1.33.2;
use _KERNEL_OPT
 1.32 15-Jan-1998  thorpej branches: 1.32.28;
Generate dependencies on the VM86 option.
 1.31 19-Mar-1997  mycroft Do not permit the user to set the nested task flag.
 1.30 13-May-1996  mycroft branches: 1.30.4;
Move spl*() and soft interrupt definitions into intr.h. For now, include it
from psl.h. XXX Will change after release.
 1.29 12-May-1996  mycroft Move IPL_* and IST_* constants into intr.h.
 1.28 03-May-1996  christos Add missing prototypes.
 1.27 01-Feb-1996  mycroft LOCORE -> _LOCORE
 1.26 07-Jan-1996  mycroft Hand-code softintr() to deal with GCC braindamage.
 1.25 07-Jan-1996  mycroft Deal with GCC's dead code elimination being suboptimal.
 1.24 07-Jan-1996  mycroft Modify splraise() to allow better optimization.
 1.23 07-Jan-1996  mycroft Make cpl, ipending, and astpending volatile.
 1.22 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.21 13-Aug-1995  mycroft Replace splnet() with splsoftnet(). Add splnet().
 1.20 04-Jul-1995  mycroft Make hardware interrupts always block all software interrupts.
 1.19 04-Jun-1995  mycroft Increase size of imask[]. Sigh.
 1.18 04-Jun-1995  mycroft Add a separate IPL_IMP, used by splimp().
 1.17 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.16 15-Jan-1995  mycroft Remove PSL_USERCLR, and add a PSL_USERSTATIC. Change the bit descriptions to
more closely match the 386 manual. (Probably the mnemonics should be changed,
too.)
 1.15 03-Jan-1995  mycroft Add interrupt sharing types.
 1.14 06-Nov-1994  mycroft As pointed out by Bruce, splsoftclock() needs to process pending interrupts
when lowering the priority. Do this by simply calling splx(). For the
benefit of NFS (for now), modify splx() to return a value so that
splsoftclock() does. This work is optimized out for every use of splx()
that ignores the value, so it only affects relevant code.
Also, clean up this file a little.
 1.13 27-Oct-1994  cgd new RCS ID format.
 1.12 19-Sep-1994  mycroft Prototype spllower().
 1.11 13-Aug-1994  mycroft Don't allow VM86 mode, for now.
 1.10 05-May-1994  mycroft branches: 1.10.2;
Mostly stylistic change.
 1.9 05-May-1994  cgd lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.8 07-Apr-1994  mycroft Implement dynamic IRQ configuration and IRQ sharing. Inline spl*() calls.
Reorganize and clean up the relevant code.
 1.7 09-Mar-1994  mycroft Back out previous change for now.
 1.6 08-Mar-1994  mycroft Inline spl*() calls.
 1.5 09-Jan-1994  mycroft Use PSL_MBO and PSL_MBZ in the more traditional way.
 1.4 22-Dec-1993  cgd add (possibly iffy) definitions of PSL_USERSET and PSL_USERCLR,
"standard" PSL masks.
 1.3 15-Dec-1993  mycroft Cleanup of startup and signal handling code from magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.9 01-Feb-1994  mycroft Sigh. There is code which includes this twice.
 1.2.4.8 11-Jan-1994  mycroft PSL_MB[OZ] changes from main branch.
 1.2.4.7 08-Nov-1993  mycroft Garbage collect some constants, and the entire 286 nonsense. (Like we even
get to start() on a 286? NOT!)
 1.2.4.6 11-Oct-1993  mycroft Move {disable,enable}_intr() to psl.h, and inline all of {in,out}{,s}[bwl] in
pio.h.
 1.2.4.5 09-Oct-1993  mycroft Add splast(), and correct definitions of splsoftclock() and splstatclock().
 1.2.4.4 06-Oct-1993  mycroft Don't define spl stuff is not in kernel or in locore.s.
 1.2.4.3 30-Sep-1993  mycroft Temporary kluge.
 1.2.4.2 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.2.4.1 14-Sep-1993  mycroft New i386 code.
 1.10.2.2 06-Oct-1994  mycroft Update from trunk.
 1.10.2.1 13-Aug-1994  mycroft update from trunk
 1.30.4.1 19-Mar-1997  mycroft Pull up trap handling changes.
 1.32.28.2 21-Jun-2001  nathanw Catch up to -current.
 1.32.28.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.33.2.2 30-May-2001  mrg use _KERNEL_OPT
 1.33.2.1 30-May-2001  mrg file psl.h was added on branch sommerfeld_i386mp_1 on 2001-05-30 12:28:46 +0000
 1.36 21-Aug-2022  riastradh x86 Move VA_SIGN_POS/NEG to machine/pte.h.

It's used by pl[1-4]_pi, also defined in machine/pte.h, and used in
libkvm without pmap_private.h.
 1.35 20-Aug-2022  riastradh x86: Forbid using x86/pte.h directly; use machine/pte.h.

machine/pte.h already used outside sys/arch, so let's make it the
primary thing and make sure to use x86/pte.h only as a subroutine.
 1.34 20-Aug-2022  riastradh amd64/pte.h, i386/pte.h: Need sys/stdint.h for uintN_t.
 1.33 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.32 25-Apr-2020  maxv Switch to the new PTE naming. The old naming is now unused, remove it.
 1.31 09-Mar-2019  maxv branches: 1.31.10;
Start replacing the x86 PTE bits.
 1.30 07-Mar-2019  maxv Introduce a new set of PTE bits, with a different naming convention.

PG_V -> PTE_P /* Present */
PG_RW -> PTE_W /* Write */
PG_u -> PTE_U /* User */
PG_WT -> PTE_PWT /* Write-Through */
PG_N -> PTE_PCD /* Cache-Disable */
PG_U -> PTE_A /* Accessed */
PG_M -> PTE_D /* Dirty */
PG_PAT -> PTE_PAT /* PAT on 4KB Pages */
PG_PS -> PTE_PS /* Large Page Size */
PG_G -> PTE_G /* Global Translation */
PG_AVAIL1 -> PTE_AVL1 /* Ignored by Hardware */
PG_AVAIL2 -> PTE_AVL2 /* Ignored by Hardware */
PG_AVAIL3 -> PTE_AVL3 /* Ignored by Hardware */
PG_LGPAT -> PTE_LGPAT /* PAT on Large Pages */
PG_NX -> PTE_NX /* No Execute */

Until now we were using "PG_BIT". The "BIT" part of the naming did not
follow the x86 naming convention in the spec, and was very confusing. We
don't want the "PG_" part of it either, because UVM has similar flags
(ie PG_BUSY).
 1.29 07-Mar-2019  maxv Drop PG_RO, PG_KR and PG_PROT, they are useless and create confusion.
 1.28 07-Mar-2019  maxv Style, and remove useless comments.
 1.27 01-Feb-2011  chuck branches: 1.27.56;
udpate license clauses on my code to match the new-style BSD licenses.
based on diff that rmind@ sent me.

no functional change with this commit.
 1.26 02-Oct-2010  jym branches: 1.26.2; 1.26.4;
Update the comment for PG_PS when used with PAE.
 1.25 14-Sep-2010  jym Add ULL suffix to PG_NX when it is defined.
 1.24 06-Jul-2010  cegger Turn PMAP_NOCACHE into MI flag.
Add MI flags PMAP_WRITE_COMBINE, PMAP_WRITE_BACK, PMAP_NOCACHE_OVR.
Update pmap(9) manpage.

hppa: Remove MD PMAP_NOCACHE flag as it exists as MI flag
mips: Rename MD PMAP_NOCACHE to PGC_NOCACHE.

x86: Implement new MI flags using Page-Attribute Tables.
x86: Implement BUS_SPACE_MAP_PREFETCHABLE.

Patch presented on tech-kern@:
http://mail-index.netbsd.org/tech-kern/2010/06/30/msg008458.html

No comments on this last version.
 1.23 04-May-2010  jym Enable the NX bit feature for Xen i386pae and amd64 kernels.

Tested with Xen 3.1 and Xen 3.3, dom0 and domU, by bouyer@ and jym@.

Ok bouyer@.
 1.22 06-Apr-2010  jld Fix typos in PAE comment.
 1.21 26-Feb-2010  jym branches: 1.21.2;
Fixes regarding paddr_t/pd_entry_t types in MD x86 code, exposed by PAE:

- NBPD_* macros are set to the types that better match their architecture
(UL for i386 and amd64, ULL for i386 PAE) - will revisit when paddr_t is
set to 64 bits for i386 non-PAE.

- type fixes in printf/printk messages (Use PRIxPADDR when printing paddr_t
values, instead of %lx - paddr_t/pd_entry_t being 64 bits with PAE)

- remove casts that are no more needed now that Xen2 support has been dropped

Some fixes are from jmorse@ patches for PAE.

Compile + tested for i386 GENERIC and XEN3 kernels. Only compile tested for
amd64.

Reviewed by bouyer@.

See also http://mail-index.netbsd.org/tech-kern/2010/02/22/msg007373.html
 1.20 17-Nov-2009  dyoung branches: 1.20.2;
Fix spelling in comments, s/extention/extension/.
 1.19 15-Apr-2009  cegger No Execute bit is available in PAE-paging mode.
However to use it, NXE bit in EFER register must be set.
 1.18 21-Dec-2008  ad branches: 1.18.2;
Fix a comment.
 1.17 23-Jan-2008  bouyer branches: 1.17.6; 1.17.10; 1.17.18;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.16 18-Oct-2007  yamt branches: 1.16.2; 1.16.8;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.15 26-Dec-2005  perry branches: 1.15.30; 1.15.48; 1.15.50; 1.15.52; 1.15.54;
u_intN_t -> uintN_t
 1.14 24-Aug-2003  chs branches: 1.14.16;
add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

- pmap and trap-handler changes. these are all MD:
= alpha: we already track per-page execute permission with the (software)
PG_EXEC bit, so just have the trap handler pay attention to it.
= i386: use a new GDT segment for %cs for processes that have no
executable mappings above a certain threshold (currently the
bottom of the stack). track per-page execute permission with
the last unused PTE bit.
= powerpc/ibm4xx: just use the hardware exec bit.
= powerpc/oea: we already track per-page exec bits, but the hardware only
implements non-exec mappings at the segment level. so track the
number of executable mappings in each segment and turn on the no-exec
segment bit iff the count is 0. adjust the trap handler to deal.
= sparc (sun4m): fix our use of the hardware protection bits.
fix the trap handler to recognize text faults.
= sparc64: split the existing unified TSB into data and instruction TSBs,
and only load TTEs into the appropriate TSB(s) for the permissions.
fix the trap handler to check for execute permission.
= not yet implemented: amd64, hppa, sh5

- changes in all the emulations that put a signal trampoline on the stack.
instead, we now put the trampoline into a uvm_aobj and map that into
the process separately.

originally from openbsd, adapted for netbsd by me.
 1.13 02-Apr-2003  thorpej branches: 1.13.2;
Use PAGE_SIZE rather than NBPG.
 1.12 05-Sep-2000  thorpej branches: 1.12.2;
Define PG_LGFRAME, which is the page frame mask for large (4MB) pages.
 1.11 06-Feb-1998  thorpej branches: 1.11.14;
Allow userland access to pd_entry_t and pt_entry_t, like the old pte.h
used to do. Also, RCS ID police.
 1.10 06-Feb-1998  mrg add the i386 MD portions for UVM.
 1.9 01-Feb-1996  mycroft LOCORE -> _LOCORE
 1.8 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 09-Oct-1994  mycroft Nuke dirty().
 1.5 15-Aug-1994  mycroft Eliminate struct pte and struct pde.
 1.4 14-Dec-1993  mycroft branches: 1.4.2; 1.4.4;
Fold in most of the magnum vm changes.
 1.3 27-Jun-1993  andrew branches: 1.3.4;
Re-entrancy protection.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.4.5 13-Dec-1993  mycroft Stylistic changes.
 1.3.4.4 09-Nov-1993  mycroft Rearrange bits to match hardware.
 1.3.4.3 09-Nov-1993  mycroft Change comment on PG_W to reflect that it is in fact used.
 1.3.4.2 08-Nov-1993  mycroft Garbage collect some constants, and the entire 286 nonsense. (Like we even
get to start() on a 286? NOT!)
 1.3.4.1 15-Oct-1993  mycroft Major cleanup of include files and constants.
 1.4.4.2 11-Oct-1994  mycroft Update from trunk.
 1.4.4.1 15-Aug-1994  mycroft update from trunk
 1.4.2.2 14-Dec-1993  mycroft Fold in most of the magnum vm changes.
 1.4.2.1 14-Dec-1993  mycroft file pte.h was added on branch magnum on 1993-12-14 05:31:41 +0000
 1.11.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.12.2.2 05-Sep-2000  thorpej Define PG_LGFRAME, which is the page frame mask for large (4MB) pages.
 1.12.2.1 05-Sep-2000  thorpej file pte.h was added on branch sommerfeld_i386mp_1 on 2000-09-05 21:52:17 +0000
 1.13.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.13.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.13.2.1 03-Aug-2004  skrll Sync with HEAD
 1.14.16.3 04-Feb-2008  yamt sync with head.
 1.14.16.2 27-Oct-2007  yamt sync with head.
 1.14.16.1 21-Jun-2006  yamt sync with head.
 1.15.54.1 25-Oct-2007  bouyer Sync with HEAD.
 1.15.52.1 23-Sep-2007  yamt - sync with amd64.
- pmap_alloc_level: remove fast call special case.
- tweak some printf to work for both of LP64 and LP32.
- remove machdep.nkpde sysctl.
- remove automatic adjustment of nkpde for now. will revisit later.
 1.15.50.2 23-Mar-2008  matt sync with HEAD
 1.15.50.1 06-Nov-2007  matt sync with HEAD
 1.15.48.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.15.30.1 23-Oct-2007  ad Sync with head.
 1.16.8.3 17-Jan-2008  bouyer - Fix L2_SLOT_APTE value (not sure how I got this value but it was definitively
wrong)
- Use global variable for the PAE L3 page adresses, so that pmap.c can get it
from the bootstrap code
- Extent the size of our virtual PDP from 3 to 4 pages, so that pmap->pm_pdir[]
is contigous for the whole VA range. The last page is a shadow of
the kernel's real PDP (L3[3]).
- make pm_pdirpa an array of 4 paddr_t if using PAE. introduce a
pmap_pdirpa macro to get the physical address of a given PD entry.
- fix pmap_map_pte

The kernel now boots single-user. fsck will cause a kernel fault in
pmap_pdes_invalid() on exit.
 1.16.8.2 13-Jan-2008  bouyer Update system macros for PAE. Because the L3 page directory has only 4 entries,
and because of the way Xen handles it, it's better to have it has static as
possible. So we claim to have only 2 levels, with level 2 being a
"super" PD of 4 pages. pmap switches will be handled by changing the
L3 entries instead of %cr3. Only the first 3 entries will have to be changed,
the last one mapping KVA space only.
 1.16.8.1 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.16.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.17.18.2 28-Apr-2009  skrll Sync with HEAD.
 1.17.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.17.10.4 09-Oct-2010  yamt sync with head
 1.17.10.3 11-Aug-2010  yamt sync with head.
 1.17.10.2 11-Mar-2010  yamt sync with head
 1.17.10.1 04-May-2009  yamt sync with head.
 1.17.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.18.2.4 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.18.2.3 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.18.2.2 01-Nov-2009  jym Sync with HEAD.
 1.18.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.2.3 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.20.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.20.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.21.2.2 05-Mar-2011  rmind sync with head
 1.21.2.1 30-May-2010  rmind sync with head
 1.26.4.1 08-Feb-2011  bouyer Sync with HEAD
 1.26.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.27.56.1 10-Jun-2019  christos Sync with HEAD
 1.31.10.1 25-Apr-2020  bouyer Sync with bouyer-xenpvh-base2 (HEAD)
 1.28 12-Aug-2025  gutteridge i386/include/ptrace.h: move __HAVE_PROCFS_MACHDEP under _KERNEL

For consistency and readability, guard with _KERNEL and move to be next
to the PROCFS_MACHDEP_NODE_TYPES definition, as is done already with
other ports like powerpc.

As discussed in PR port-i386/59402. NFCI.
 1.27 20-Nov-2023  simonb Note some large xstate stack objects what Somebody(tm) should look at
when they find some round tuits.
 1.26 30-May-2020  maxv Introduce PTRACE_REGS_ALIGN, and on x86, enforce a 16-byte alignment, due
to fpregs having fxsave which requires 16-byte alignment.

Reported-by: syzbot+f44d47e617ebf7fda081@syzkaller.appspotmail.com
 1.25 09-Jan-2020  kamil Add missing compat define of PT32_GETXSTATE

Fixes i386 build.

Reviewed by <mgorny>
 1.24 08-Jan-2020  mgorny Include XSTATE note in x86 core dumps

Introduce a simple COREDUMP_MACHDEP_LWP_NOTES logic to provide machdep
API for injecting per-LWP notes into coredumps, and use it to append
PT_GETXSTATE note.

Since the XSTATE block uses the same format on i386 and amd64, the code
does not have to conditionalize between 32-bit and 64-bit ELF format
on that. However, it does need to distinguish between 32-bit and 64-bit
PT_* values. In order to do that, it reuses PT32_* constant already
present for ptrace(), and adds a matching PT64_GETXSTATE to satisfy
the cpp logic.
 1.23 26-Jun-2019  mgorny branches: 1.23.4;
Implement PT_GETXSTATE and PT_SETXSTATE

Introduce two new ptrace() requests: PT_GETXSTATE and PT_SETXSTATE,
that provide access to the extended (and extensible) set of FPU
registers on amd64 and i386. At the moment, this covers AVX (YMM)
and AVX-512 (ZMM, opmask) registers. It can be easily extended
to cover further register types without breaking backwards
compatibility.

PT_GETXSTATE issues the XSAVE instruction with all kernel-supported
extended components enabled. The data is copied into 'struct xstate'
(which -- unlike the XSAVE area itself -- has stable format
and offsets).

PT_SETXSTATE issues the XRSTOR instruction to restore the register
values from user-provided 'struct xstate'. The function replaces only
the specific XSAVE components that are listed in 'xs_rfbm' field,
making it possible to issue partial updates.

Both syscalls take a 'struct iovec' pointer rather than a direct
argument. This requires the caller to explicitly specify the buffer
size. As a result, existing code will continue to work correctly
when the structure is extended (performing partial reads/updates).
 1.22 18-Jun-2019  kamil Introduce PTRACE_REG_FP() a helper macro to retrieve the frame pointer

The macro is dummy for ia64 (the FP register is unknown and can change
freely) and sparc/sparc64 (not stored in struct reg).
 1.21 17-Jun-2019  kamil Define PTRACE_ILLEGAL_ASM for i386
 1.20 22-May-2018  kamil branches: 1.20.2;
Define PTRACE_BREAKPOINT_ASM for i386 in the MD part of <sys/ptrace.h>

x86 uses int3 for software breakpoint on i386 and amd64.

Sponsored by <The NetBSD Foundation>
 1.19 08-Apr-2017  kamil branches: 1.19.12;
Define PT_SETSTEP and PT_CLEARSTEP for i386 (ptrace(2))

Sponsored by <The NetBSD Foundation>
 1.18 23-Feb-2017  kamil Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.17 16-Jan-2017  kamil Refactor ptrace_watchpoint structure to allow extensions

Add new field pw_type in the ptrace_watchpoint structure.

amd64 and i386 offer the current set of watchpoints as
PTRACE_PW_TYPE_DBREGS.

On other archs than x86, there are readily available different types of
hardware assisted watchpoints like for code-only or data-only registers on
ARM. Also in future there is an option to implement MMU-based watchpoints
and future per-port or per-cpu extensions.

Next step is to alter this interface on x86 to generate SIGTRAP with
si_code TRAP_HWWTRAP with additional information on occurred event:
- which watchpoint fired,
- additional watchpoint-type specific information, like on amd64 with
PTRACE_PW_TYPE_DBREGS.:
* only watchpoint fired
* watchpoint fired and single step occurred

Adjust ATF tests for the pw_type change.

Sponsored by <The NetBSD Foundation>
 1.16 15-Dec-2016  kamil branches: 1.16.2;
Add support for hardware assisted watchpoints/breakpoints API in ptrace(2)

Add new ptrace(2) calls:
- PT_COUNT_WATCHPOINTS - count the number of available hardware watchpoints
- PT_READ_WATCHPOINT - read struct ptrace_watchpoint from the kernel state
- PT_WRITE_WATCHPOINT - write new struct ptrace_watchpoint state, this
includes enabling and disabling watchpoints

The ptrace_watchpoint structure contains MI and MD parts:

typedef struct ptrace_watchpoint {
int pw_index; /* HW Watchpoint ID (count from 0) */
lwpid_t pw_lwpid; /* LWP described */
struct mdpw pw_md; /* MD fields */
} ptrace_watchpoint_t;

For example amd64 defines MD as follows:
struct mdpw {
void *md_address;
int md_condition;
int md_length;
};

These calls are protected with the __HAVE_PTRACE_WATCHPOINTS guard.

Tested on amd64, initial support added for i386 and XEN.

Sponsored by <The NetBSD Foundation>
 1.15 25-Sep-2015  christos branches: 1.15.2;
For processors that have memory breakpoints, add macros for them to help
libproc
 1.14 15-Sep-2015  christos Provide access to pc/sp/syscall-return registers like we have for mcontext
 1.13 05-Mar-2006  christos branches: 1.13.2; 1.13.116; 1.13.136;
provide strings for the machdep ptrace calls.
 1.12 11-Dec-2005  christos branches: 1.12.4; 1.12.6;
merge ktrace-lwp.
 1.11 29-Jun-2003  fvdl branches: 1.11.2; 1.11.18;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.10 28-Jun-2003  darrenr Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records. The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
 1.9 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 09-May-2002  thorpej branches: 1.8.4;
Mirror cleanup wrt. procfs-centric naming made to the MI ptrace code.
 1.7 05-Dec-2001  thorpej * Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.
 1.6 06-Aug-1995  mycroft branches: 1.6.46; 1.6.48;
Move the `used fpu' flag into mdproc, so it can be referenced when a process
is swapped out. Implement process_{read,write}_fpregs.
 1.5 27-Oct-1994  cgd new RCS ID format.
 1.4 28-Jan-1994  jtc branches: 1.4.2;
Fix spelling error in Copyright notice
 1.3 28-Jan-1994  cgd getting and setting FP regs aren't appropriate yet
 1.2 09-Jan-1994  cgd define PT_STEP, and clean up some
 1.1 08-Jan-1994  cgd code reorg
 1.4.2.2 28-Jan-1994  jtc Fix spelling error in Copyright notice
 1.4.2.1 28-Jan-1994  jtc file ptrace.h was added on branch magnum on 1994-01-28 23:44:22 +0000
 1.6.48.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.6.48.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.6.46.5 15-Oct-2002  nathanw Make _validfoo() routines go back to taking a proc.
 1.6.46.4 21-Jun-2002  gmcgarry LWPify
 1.6.46.3 20-Jun-2002  nathanw Catch up to -current.
 1.6.46.2 09-Jan-2002  nathanw Adapt xmm handling to LWPs.
 1.6.46.1 08-Jan-2002  nathanw Catch up to -current.
 1.8.4.2 09-May-2002  thorpej Mirror cleanup wrt. procfs-centric naming made to the MI ptrace code.
 1.8.4.1 09-May-2002  thorpej file ptrace.h was added on branch sommerfeld_i386mp_1 on 2002-05-09 16:28:13 +0000
 1.11.18.1 21-Jun-2006  yamt sync with head.
 1.11.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.11.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.11.2.1 02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.12.6.1 22-Apr-2006  simonb Sync with head.
 1.12.4.1 09-Sep-2006  rpaulo sync with head
 1.13.136.4 28-Aug-2017  skrll Sync with HEAD
 1.13.136.3 05-Feb-2017  skrll Sync with HEAD
 1.13.136.2 27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.13.136.1 22-Sep-2015  skrll Sync with HEAD
 1.13.116.1 03-Dec-2017  jdolecek update from HEAD
 1.13.2.2 05-Mar-2006  christos provide strings for the machdep ptrace calls.
 1.13.2.1 05-Mar-2006  christos file ptrace.h was added on branch yamt-pdpolicy on 2006-03-05 07:17:22 +0000
 1.15.2.3 26-Apr-2017  pgoyette Sync with HEAD
 1.15.2.2 20-Mar-2017  pgoyette Sync with HEAD
 1.15.2.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.16.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.19.12.1 25-Jun-2018  pgoyette Sync with HEAD
 1.20.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.20.2.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.23.4.1 17-Jan-2020  ad Sync with head.
 1.9 01-Mar-2010  jym Change rbus_min_start_hint() semantic for i386. "ram" is now psize_t
(instead of size_t) to avoid possible overflow when system may have more
than 4GB of memory (like PAE).

The behavior of rbus_min_start_hint() remains the same. While here, fix
printf's format strings (paddr_t => PRIxPADDR).

Use ctob() and cast physmem to psize_t to avoid losing bits above 4GB.

Comes from PAE patch from Jeremy Morse; adaptation by me.

Compile tested for GENERIC only. No regression expected.
 1.8 15-Dec-2009  snj branches: 1.8.2;
Move to 2-clause license. Approved by HAYAKAWA Koichi (copyright holder).
 1.7 12-Jan-2007  gdt branches: 1.7.48; 1.7.62;
Add a heuristic to set rbus_min_start based on total RAM. The new
behavior is to choose 0.5 GB for <= 192 MB, 1 GB normally, and 2 GB
for >= 1 GB. This should make the defaults work additionally old
Thinkpad 600Es, and also on notebooks with lots of RAM (e.g. T60 with
2GB).

ok christos@
 1.6 26-Feb-2003  fvdl branches: 1.6.18; 1.6.48; 1.6.54;
Redirect some includes to x86/foo.h
 1.5 25-Apr-2001  thorpej branches: 1.5.2;
Move _i386_memio_unmap() into bus_machdep.c; the ACPI code wants it.
 1.4 06-Jun-2000  haya branches: 1.4.6;
Remove unnecessary function arguments.
 1.3 01-Jun-2000  cgd kill __P in these files. (I had to look at them anyway with an eye for
adding some protos... and adding them with __P seems wrong, but mixing
__P and not __P in the same file seems wrong too, so...)
 1.2 15-Oct-1999  haya branches: 1.2.2; 1.2.8; 1.2.12;
add NetBSD ID tag.
 1.1 15-Oct-1999  haya This is the first check-in of CardBus driver. CardBus driver contains
CardBus bus stub, YENTA PCI-CardBus bridge (cbb), 3Com 3C575TX driver
(ex) and Intel fxp driver.

TODO:
o Conform to the KNF more strictly.
o Be unified with pcmcia code as much as possible.
o Add more drivers for CardBus card, such as APA-1480 or USB card.

The affected files are listed below.

sys/arch/i386/conf/files.i386
sys/arch/macppc/conf/files.macppc
sys/conf/files
sys/dev/ic/elinkxl.c
sys/dev/ic/elinkxlvar.h
sys/dev/ic/i82365.c
sys/dev/ic/i82365var.h
sys/dev/isa/i82365_isasubr.c
sys/dev/pci/files.pci
sys/dev/pcmcia/pcmcia.c
sys/dev/pcmcia/pcmciachip.h

The added files are listed below.

sys/arch/i386/conf/CARDBUS
sys/arch/i386/include/rbus_machdep.h
sys/arch/i386/i386/rbus_machdep.c
sys/arch/macppc/include/rbus_machdep.h
sys/arch/macppc/macppc/rbus_machdep.c
sys/dev/cardbus/if_ex_cardbus.c
sys/dev/cardbus/Makefile.cardbusdevs
sys/dev/cardbus/cardbus.c
sys/dev/cardbus/cardbus_map.c
sys/dev/cardbus/cardbusdevs
sys/dev/cardbus/cardbusdevs.h
sys/dev/cardbus/cardbusdevs_data.h
sys/dev/cardbus/cardbusvar.h
sys/dev/cardbus/cardslot.c
sys/dev/cardbus/cardslotvar.h
sys/dev/cardbus/devlist2h.awk
sys/dev/cardbus/files.cardbus
sys/dev/cardbus/if_fxp_cardbus.c
sys/dev/cardbus/pccardcis.h
sys/dev/cardbus/rbus.c
sys/dev/cardbus/rbus.h
sys/dev/pci/pccbb.c
sys/dev/pci/pccbbreg.h
sys/dev/pci/pccbbvar.h
 1.2.12.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.2.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.4.6.1 21-Jun-2001  nathanw Catch up to -current.
 1.5.2.2 25-Apr-2001  thorpej Move _i386_memio_unmap() into bus_machdep.c; the ACPI code wants it.
 1.5.2.1 25-Apr-2001  thorpej file rbus_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-04-25 03:31:24 +0000
 1.6.54.1 28-Mar-2007  jdc Pull up revision 1.7 (requested by gdt in ticket #521)

Add a heuristic to set rbus_min_start based on total RAM. The new
behavior is to choose 0.5 GB for <= 192 MB, 1 GB normally, and 2 GB
for >= 1 GB. This should make the defaults work additionally old
Thinkpad 600Es, and also on notebooks with lots of RAM (e.g. T60 with
2GB).

ok christos@
 1.6.48.1 01-Feb-2007  ad Sync with head.
 1.6.18.1 26-Feb-2007  yamt sync with head.
 1.7.62.1 24-Oct-2010  jym Sync with HEAD
 1.7.48.1 11-Mar-2010  yamt sync with head
 1.8.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.22 18-May-2019  christos lint gets the wrong size.
 1.21 10-May-2019  mgorny Fill 'struct fpreg' & 'struct xmmregs' in

The 'struct fpreg' data type used by PT_GETFPREGS, and 'struct xmmregs'
used by PT_GETXMMREGS are currently opaque. Define them to contain
correct data structs instead, the same way they are defined for amd64.
For 'struct fpreg' this means 'struct save87', and for 'struct xmmregs'
this means 'struct fxsave'. This makes it more transparent for
consumers how the data is formatted, and allows using it without need
for explicit casts.

Reviewed by <kamil>.
 1.20 23-Feb-2017  kamil branches: 1.20.14;
Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.19 16-Jan-2008  ad branches: 1.19.54; 1.19.74; 1.19.78; 1.19.82;
Remove options MATH_EMULATE.
 1.18 07-Aug-2003  agc branches: 1.18.16; 1.18.78; 1.18.84; 1.18.92;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.17 05-Dec-2001  thorpej branches: 1.17.2; 1.17.18;
* Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.
 1.16 17-Jul-2001  fvdl Redefine evil tXXX register offset defines into the trapframe structure
to use offsetof. These should be completely nuked.

Fixes math_emulate lossage.
 1.15 16-Oct-1997  mycroft branches: 1.15.28; 1.15.30; 1.15.32;
Update a comment dating from 4.3/VAX.
 1.14 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.13 06-Aug-1995  mycroft Move the `used fpu' flag into mdproc, so it can be referenced when a process
is swapped out. Implement process_{read,write}_fpregs.
 1.12 26-Jan-1995  mycroft Rearrange struct reg to match what the rest of the world expects.
 1.11 27-Oct-1994  cgd new RCS ID format.
 1.10 09-Oct-1994  mycroft Make reg, frame, and sigcontext more similar.
 1.9 09-Oct-1994  mycroft Eliminate tf_isp.
 1.8 22-Dec-1993  cgd branches: 1.8.2; 1.8.4;
should be 'struct reg' not 'struct regs' -- it's in reg.h, after all!
also, delete r_fs and r_gs; looking at the code and comments
describing/using this struct, they don't belong here
(though if support for them is ever put in here, they should be,
but for i486-en only... how do you do that 'reasonably,' though?
interface issues...)
 1.7 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.6 19-Sep-1993  brezak Add tISP offset
 1.5 16-Sep-1993  brezak Changes to use a trap frame for syscalls.
 1.4 05-Sep-1993  sef branches: 1.4.2;
Yet more of the ptrace() reorg; now ptrace_setregs() and ptrace_getregs()
are present, along with PT_GETREGS and PT_SETREGS ptrace commands.
 1.3 24-May-1993  cgd move sipcreg into i386/include/reg.h where it belongs, right next to ipcreg.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.4.2.3 14-Nov-1993  mycroft Eliminate tEDI, tESI, etc.
 1.4.2.2 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.4.2.1 24-Sep-1993  mycroft Changes from trunk.
cpu.h: Add dummy (for now) CLKF_INTR(). #include psl.h.
endian.h: Add multiple-inclusion protection. #define _QUAD_{LOW,HIGH}WORD.
#include sys/cdefs for __P(). Don't define byte order stuff if _POSIX_SOURCE.
Remove big endian shit.
limits.h: Add {,U}QUAD_{MIN,MAX}.
psl.h: Get PSL_MB[ZO] right. Make cpl volatile just in case. Add alias for
spl0(). splnone() and splx() return int for now.
 1.8.4.1 11-Oct-1994  mycroft Update from trunk.
 1.8.2.2 22-Dec-1993  cgd should be 'struct reg' not 'struct regs' -- it's in reg.h, after all!
also, delete r_fs and r_gs; looking at the code and comments
describing/using this struct, they don't belong here
(though if support for them is ever put in here, they should be,
but for i486-en only... how do you do that 'reasonably,' though?
interface issues...)
 1.8.2.1 22-Dec-1993  cgd file reg.h was added on branch magnum on 1993-12-22 12:57:25 +0000
 1.15.32.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.15.32.1 03-Aug-2001  lukem update to -current
 1.15.30.2 08-Jan-2002  nathanw Catch up to -current.
 1.15.30.1 24-Aug-2001  nathanw Catch up with -current.
 1.15.28.1 29-Jul-2001  he Pull up revision 1.16 (requested by fvdl):
Redefine register offsets using offsetof(). Fixes math emulation
lossage.
 1.17.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.17.18.1 03-Aug-2004  skrll Sync with HEAD
 1.17.2.2 05-Dec-2001  thorpej * Allow machine-dependent code to specify hooks for ptrace(2)
(__HAVE_PTRACE_MACHDEP) and procfs (__HAVE_PROCFS_MACHDEP).
These changes will allow platforms like x86 (XMM) and PowerPC
(AltiVec) to export extended register sets in a sane manner.

* Use __HAVE_PTRACE_MACHDEP to export x86 XMM registers (standard
FP + SSE/SSE2) using PT_{GET,SET}XMMREGS (in the machdep
ptrace request space).
* Use __HAVE_PROCFS_MACHDEP to export x86 XMM registers via
/proc/N/xmmregs in procfs.
 1.17.2.1 05-Dec-2001  thorpej file reg.h was added on branch sommerfeld_i386mp_1 on 2001-12-05 00:58:07 +0000
 1.18.92.1 19-Jan-2008  bouyer Sync with HEAD
 1.18.84.1 18-Feb-2008  mjf Sync with HEAD.
 1.18.78.1 23-Mar-2008  matt sync with HEAD
 1.18.16.1 21-Jan-2008  yamt sync with head
 1.19.82.1 21-Apr-2017  bouyer Sync with HEAD
 1.19.78.1 20-Mar-2017  pgoyette Sync with HEAD
 1.19.74.1 28-Aug-2017  skrll Sync with HEAD
 1.19.54.1 03-Dec-2017  jdolecek update from HEAD
 1.20.14.1 10-Jun-2019  christos Sync with HEAD
 1.1 03-Nov-2009  dyoung branches: 1.1.4; 1.1.8;
Add return_address(9) for reading the Nth return address from the call
stack.
 1.1.8.2 24-Oct-2010  jym Sync with HEAD
 1.1.8.1 03-Nov-2009  jym file return.h was added on branch jym-xensuspend on 2010-10-24 22:48:02 +0000
 1.1.4.2 11-Mar-2010  yamt sync with head
 1.1.4.1 03-Nov-2009  yamt file return.h was added on branch yamt-nfs-mp on 2010-03-11 15:02:29 +0000
 1.5 05-Feb-2003  nakayama Replace machine/rnd.h with more appropriate name to share it
with cycle counter based microtime in kern/kern_microtime.c.
 1.4 06-Dec-2001  sommerfeld branches: 1.4.2;
Use #if defined(FOO_CPU) instead of #if FOO_CPU just to be picky.
Spotted by Thomas Klausner.
 1.3 02-Jul-2000  sommerfeld branches: 1.3.4; 1.3.6; 1.3.8;
Return the full width of the counter here.
 1.2 06-Jun-2000  sommerfeld branches: 1.2.2; 1.2.4;
Replace "timestamp" with "counter" in previous change, to avoid any
possible confusion that it has anything to do with accurate
measurement of time.

New names:
__HAVE_CPU_COUNTER
cpu_counter()
cpu_hascounter()
 1.1 05-Jun-2000  sommerfeld Let rnd(4) know how to read the (pentium and higher) cycle counter:

If __HAVE_CPU_TIMESTAMP is defined, <machine/rnd.h> exists and defines
two functions:
1) u_int32_t cpu_timestamp(void);
returns the 32 low order bits of a reasonably high frequency counter.
2) int cpu_havetimestamp(void);
returns non-zero if cpu_timestamp() actually works.

The timestamp counter should run at a frequency greater than 1 MHz
(otherwise, microtime would be sufficient); other than that, the exact
frequency and origin of the counter are unspecified.
 1.2.4.2 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.2.4.1 06-Jun-2000  minoura file rnd.h was added on branch minoura-xpg4dl on 2000-06-22 17:00:34 +0000
 1.2.2.1 02-Jul-2000  sommerfeld Pull up fix from current: let cpu_counter() be wider than 32 bits on
platforms for which is the case; clip to 32 bits in rnd.c

Approved by thorpej
 1.3.8.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.3.6.1 08-Jan-2002  nathanw Catch up to -current.
 1.3.4.2 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.3.4.1 02-Jul-2000  bouyer file rnd.h was added on branch thorpej_scsipi on 2000-11-20 20:09:30 +0000
 1.4.2.2 06-Dec-2001  sommerfeld Use #if defined(FOO_CPU) instead of #if FOO_CPU just to be picky.
Spotted by Thomas Klausner.
 1.4.2.1 06-Dec-2001  sommerfeld file rnd.h was added on branch sommerfeld_i386mp_1 on 2001-12-06 01:56:20 +0000
 1.2 09-Feb-2007  ad branches: 1.2.4; 1.2.144;
Merge newlock2 to head.
 1.1 10-Sep-2006  ad branches: 1.1.2;
file rwlock.h was initially added on branch newlock2.
 1.1.2.3 29-Dec-2006  ad Checkpoint work in progress.
 1.1.2.2 24-Oct-2006  ad Compile fixes
 1.1.2.1 10-Sep-2006  ad Add updated locking primatives.
 1.2.144.2 29-Feb-2020  ad Sync with head.
 1.2.144.1 19-Jan-2020  ad empty these; remove later.
 1.2.4.2 26-Feb-2007  yamt sync with head.
 1.2.4.1 09-Feb-2007  yamt file rwlock.h was added on branch yamt-lazymbuf on 2007-02-26 09:07:02 +0000
 1.1 17-Mar-2002  thorpej branches: 1.1.2;
file rwlock_impl.h was initially added on branch newlock.
 1.1.2.2 22-Mar-2002  thorpej Add debug info structures if MUTEX_DEBUG or RWLOCK_DEBUG is
defined.

XXX Revisit, so that the structure doesn't change when debugging
is turned on; do it out-of-band?
 1.1.2.1 17-Mar-2002  thorpej Add first-cut mutex and rwlock implementation bits for the x86.
XXX Does not actually handle i386 CPUs yet, only i486 and later.
 1.70 18-May-2022  andvar fix typos in word "access" and it derivatives, mainly in comments.
 1.69 14-Jul-2020  yamaguchi Introduce per-cpu IDTs

This is realized by following modifications:
- Add IDT pages and its allocation maps for each cpu in "struct cpu_info"
- Load per-cpu IDTs at cpu_init_idt(struct cpu_info*)
- Copy the IDT entries for cpu0 to other CPUs at attach
- These are, for example, exceptions, db, system calls, etc.

And, added a kernel option named PCPU_IDT to enable the feature.
 1.68 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.67 23-Sep-2018  cherry Fix for i386, functionality intended in:
http://mail-index.netbsd.org/source-changes/2018/09/23/msg099357.html

This should fix the build for both GENERIC and XEN3PAE_DOM0

This has not been boot tested on native or xen3pae

Notes: pmap_changeprot_local() seems to be x86_64 only.
I was a bit surprised by this initially, but I suspect that the table
protections are enforced via ring0/ring1 fencing rather than page protections

the gdt registration code in i386 is still messy. I will leave it as is
for now - to avoid a rabbit hole.
 1.66 23-Sep-2018  cherry Summary: Remove older and now conflicting type declaration for global
variable 'idt'.

This should fix the i386 build failure now.
 1.65 23-Sep-2018  cherry Make XEN use the same api as native, for idt vector allocation
and registration.

lidt() placed in xenfunc() on maxv@ suggestion.

There should be no functional change due to this commit.

Tested on amd64 native and XEN.
 1.64 31-Dec-2017  maxv branches: 1.64.2; 1.64.4;
Fix a huge privilege separation vulnerability in Xen-amd64.

On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.

It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.

Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.63 04-Nov-2017  cherry In XEN PV, the idt vector table is not required to be altered at
runtime, since only entries for exceptions/traps are registered with
the hypervisor and interrupts are managed via a completely different
mechanism.

This change uses the idt_vec_reserve() mechanism nevertheless,
modifying it slightly to only do namespace management in XEN, while on
native it will continue to do idt entry init as before.

Rationale: Consistent API usage and potential future merging of
XEN/non-XEN code.

There are no functional changes in this commit.
 1.62 17-Sep-2017  maxv Remove the second argument from USERMODE and KERNELMODE, it is unused
now that we don't have vm86 anymore.
 1.61 12-Aug-2017  maxv Remove vm86.

Pass 4.
 1.60 02-Jul-2017  maxv Use a bitmap-based allocator for i386, same as amd64. Several functions
are now identical - or nearly identical - on both sides. I couldn't test
this change on xen, because I'm having some unrelated issues with my VM
and I've spent enough time not understanding what's wrong with it.
 1.59 08-Feb-2017  maxv branches: 1.59.6;
Localify, add a comment and merge some others.
 1.58 05-Feb-2017  maxv Rename ldt->ldtstore and gdt->gdtstore on i386. It reduces the diff with
amd64, and makes it easier to track down these variables on nxr - 'ldt'
and 'gdt' being common keywords.
 1.57 02-Sep-2016  maxv branches: 1.57.2;
KNF, and give the structure sizes.
 1.56 27-Aug-2016  maxv Remove idt_init.
 1.55 24-Jan-2016  christos branches: 1.55.2;
expose __vaddr_t for segments.h since it is a userland api.
 1.54 26-Apr-2011  joerg branches: 1.54.10; 1.54.14; 1.54.16; 1.54.24; 1.54.30; 1.54.32; 1.54.34; 1.54.38;
Remove Darwin, MACH and Mach-O support.
 1.53 17-May-2009  bouyer branches: 1.53.4; 1.53.6;
on Xen the GDT has to be updated though HYPERVISOR_update_descriptor().
Export i386/i386/gdt.c:update_descriptor() and use it in x86_set_sdbase(),
as a direct write to the GDT will cause a kernel trap.
Fix PR port-xen/41401.
 1.52 21-Mar-2009  ad A couple more comments.
 1.51 21-Mar-2009  ad Add a comment.
 1.50 26-Oct-2008  christos branches: 1.50.2; 1.50.4; 1.50.8;
use a macro to get to d_type.
 1.49 19-Apr-2008  cegger branches: 1.49.2; 1.49.8;
idt_* are not implemented for Xen. So don't provide the prototypes for Xen.
 1.48 11-Jan-2008  bouyer branches: 1.48.6; 1.48.8;
Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.47 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.46 26-Dec-2007  yamt - share idt entry allocation code among x86.
- introduce a function to reserve an idt entry and use it instead of
manipulating idt_allocmap directly.
- rename idt to xen_idt for amd64 xen. add missing #ifdef XEN.
 1.45 25-Dec-2007  perry Convert many of the uses of __attribute__ to equivalent
__packed, __unused and __dead macros from cdefs.h
 1.44 10-Nov-2007  ad branches: 1.44.2; 1.44.6;
- When computing the TSC frequency, call i8254_delay() and not DELAY().
- Use atomics to adjust the pmap reference count, instead of taking locks.
- Implement I386_{SET,GET}_{FS,GS}BASE, allowing %fs and %gs to be used
as per-thread registers. This is compatible with FreeBSD.
- Run patches after we have attached CPUs, since we then know if the
system is uniprocessor or not. Eliminates a lot of #ifdef MULTIPROCESSOR
and makes running MP kernels on UP systems cheaper.
- Patch out many of the 'lock' prefixes to nops if uniprocessor.
- Do a wbinvd after patching to ensure that the trace/instruction cache
is up to date.
 1.43 18-Oct-2007  yamt branches: 1.43.2;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.42 02-Mar-2007  ad branches: 1.42.2; 1.42.18; 1.42.20; 1.42.22; 1.42.24;
Shuffle the descriptor slots slightly to make the layout match what
sysenter/sysexit require. As far as I can tell this will not introduce
any incompatibility.
 1.41 05-Mar-2004  junyoung branches: 1.41.16; 1.41.54;
Drop trailing spaces.
 1.40 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.39 27-Oct-2003  junyoung Nuke __P().
 1.38 24-Aug-2003  chs add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

- pmap and trap-handler changes. these are all MD:
= alpha: we already track per-page execute permission with the (software)
PG_EXEC bit, so just have the trap handler pay attention to it.
= i386: use a new GDT segment for %cs for processes that have no
executable mappings above a certain threshold (currently the
bottom of the stack). track per-page execute permission with
the last unused PTE bit.
= powerpc/ibm4xx: just use the hardware exec bit.
= powerpc/oea: we already track per-page exec bits, but the hardware only
implements non-exec mappings at the segment level. so track the
number of executable mappings in each segment and turn on the no-exec
segment bit iff the count is 0. adjust the trap handler to deal.
= sparc (sun4m): fix our use of the hardware protection bits.
fix the trap handler to recognize text faults.
= sparc64: split the existing unified TSB into data and instruction TSBs,
and only load TTEs into the appropriate TSB(s) for the permissions.
fix the trap handler to check for execute permission.
= not yet implemented: amd64, hppa, sh5

- changes in all the emulations that put a signal trampoline on the stack.
instead, we now put the trampoline into a uvm_aobj and map that into
the process separately.

originally from openbsd, adapted for netbsd by me.
 1.37 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.36 03-Mar-2003  fvdl branches: 1.36.2;
The IDT only contains gate descriptors, so define it as such.
 1.35 05-Oct-2002  fvdl Change setgate() prototype.
Define GDT entries for DDB and double fault TSS.
 1.34 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.33 23-Jan-2002  rafal Re-arrange GDT entries somewhat so that: (1) I can reserve the 8th entry for
BIOS-bug-avoidance [fixes part of my own port-i386/11299], and (2) lets you
have APM and COMPAT_MACHO in the kernel at the same time. Also comments on
the special 8th entry and what else changing some of these values affects.

OK'ed by Frank.
 1.32 14-Jul-2001  christos Use global descriptor 7 for mach traps. Unfortunately this is already
used by apm 16 bit code segments so we cannot have both at the same time.
 1.31 30-May-2001  mrg branches: 1.31.2;
use _KERNEL_OPT
 1.30 12-Nov-1999  drochner branches: 1.30.2; 1.30.8;
add GDT segments for pnpbios use
 1.29 03-Oct-1998  christos branches: 1.29.12; 1.29.14; 1.29.18;
Add an LDT for Solaris-2.6 syscalls [from Frank]
 1.28 23-Jan-1998  mycroft Some rearrangement of the startup code:
* Move some of the memory bootstrapping and the DDB startup earlier.
* Always put the IDT and the initial GDT and LDT in a separate page.
* Various minor changes.
 1.27 15-Jan-1998  thorpej Generate dependencies on the VM86 option.
 1.26 13-Nov-1997  mycroft Some general cleanup:
* Call gdt_init() earlier on.
* Don't bother to check for TSS and LDT descriptors in verr_gdt().
* Nuke the sti special case for trace and breakpoint traps.
* Move some variable declarations into more appropriate locations.
 1.25 08-Sep-1996  jtk branches: 1.25.14;
change APM to use new almost-generalized BIOS trampoline:

/*
* void bioscall(int function, struct apmregs *regs):
* call the BIOS interrupt "function" from real mode with
* registers as specified in "regs"
* (for the flags, though, only these flags are passed to the BIOS;
* the remainder come from the flags register at the time of the call:
* (PSL_C|PSL_PF|PSL_AF|PSL_Z|PSL_N|PSL_D|PSL_V)
*
* Fills in *regs with registers as returned by BIOS.
*/

Thanks to Charles Hannum for complaining and inspiring me to hack this
together.
 1.24 25-Aug-1996  jtk add Advanced Power Management driver
Includes bootstrap support from FreeBSD (Tatsumi HOSOKAWA and <ukai>)
 1.23 01-Feb-1996  mycroft LOCORE -> _LOCORE
 1.22 20-Dec-1995  mycroft Use #pragma only for 2.0 <= GCC < 2.7.
 1.21 20-Dec-1995  mycroft Use alternate structure packing method added in GCC 2.7.
 1.20 12-Oct-1995  mycroft branches: 1.20.2;
Move the initialization of proc0's TSS and LDT to the end of cpu_startup(),
and switch to dynamically allocating the TSS.
 1.19 11-Oct-1995  mycroft Go back to statically allocating the GDT entries for proc0.
 1.18 11-Oct-1995  mycroft Remove reference to dead variable.
 1.17 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.16 10-Oct-1995  mycroft Add USERMODE() and KERNELMODE() macros, and use them.
 1.15 09-Oct-1995  mycroft Eliminate soft segment descriptors; instead use a functional interface for
creating segment descriptors. Add the duplicate system call gate used by
BSD/OS 2.0 executables. Prototype setsegment() and setgate(), and fix a bogon
caught by this.
 1.14 06-May-1995  mycroft Add a copy of the user code and data descriptors in the GDT.
 1.13 04-May-1995  mycroft Wrap NGDT and NLDT in parens.
 1.12 01-May-1995  mycroft Make this includable from locore. Remove unused GDT and LDT slots.
 1.11 01-May-1995  mycroft Expose idt[] here.
 1.10 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.9 08-Nov-1994  mycroft pcb.h requires segments.h now.
 1.8 05-Nov-1994  mycroft Fully prototype ssdtosd() and sdtossd().
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 03-Apr-1994  mycroft Clean this up a little.
 1.5 20-Dec-1993  mycroft branches: 1.5.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.4 26-Oct-1993  brezak Cleanup LDT/GDT defines
 1.3 22-May-1993  cgd branches: 1.3.4;
add rcsids to everything and clean up headers
 1.2 03-Apr-1993  cgd added changes from Steven Reiz <sreiz@aie.nl> (based on
those by Poul-Henning Kamp <phk@data.fls.dk>) to get the kernel
to compile properly when gcc2.* is cc. (should still work
when gcc1.39 is in use.)
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.4.1 26-Oct-1993  mycroft Merge changes from trunk.
 1.5.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.5.2.1 20-Dec-1993  mycroft file segments.h was added on branch magnum on 1993-12-20 05:25:44 +0000
 1.20.2.2 12-Oct-1995  mycroft Move the initialization of proc0's TSS and LDT to the end of cpu_startup(),
and switch to dynamically allocating the TSS.
 1.20.2.1 12-Oct-1995  mycroft file segments.h was added on branch netbsd-1-1 on 1995-10-12 17:57:02 +0000
 1.25.14.2 17-Oct-1998  cgd pull up rev 1.29 from trunk (christos)
 1.25.14.1 13-Nov-1997  mellon Pull rev 1.26 up from trunk (mycroft)
 1.29.18.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.29.14.1 15-Nov-1999  fvdl Sync with -current
 1.29.12.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.30.8.4 18-Oct-2002  nathanw Catch up to -current.
 1.30.8.3 28-Feb-2002  nathanw Catch up to -current.
 1.30.8.2 24-Aug-2001  nathanw Catch up with -current.
 1.30.8.1 21-Jun-2001  nathanw Catch up to -current.
 1.30.2.5 28-Jan-2002  sommerfeld Yet Another mergeup with -current.
 1.30.2.4 29-Dec-2001  sommerfeld Set up per-cpu GDT.
Use %fs for per-cpu data access.
 1.30.2.3 19-Jul-2001  sommerfeld catch up with -current
 1.30.2.2 18-Jun-2001  sommerfeld checkpoint merge-in-progress from mainline.
 1.30.2.1 20-Feb-2000  sommerfeld Include functions for allocation and freeing of IDT slots.
 1.31.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.31.2.2 11-Feb-2002  jdolecek Sync w/ -current.
 1.31.2.1 03-Aug-2001  lukem update to -current
 1.36.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.36.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.36.2.1 03-Aug-2004  skrll Sync with HEAD
 1.41.54.1 12-Mar-2007  rmind Sync with HEAD.
 1.41.16.4 21-Jan-2008  yamt sync with head
 1.41.16.3 15-Nov-2007  yamt sync with head.
 1.41.16.2 27-Oct-2007  yamt sync with head.
 1.41.16.1 03-Sep-2007  yamt sync with head.
 1.42.24.2 13-Nov-2007  bouyer Sync with HEAD
 1.42.24.1 25-Oct-2007  bouyer Sync with HEAD.
 1.42.22.1 18-Oct-2007  yamt reduce #ifdef.
 1.42.20.3 23-Mar-2008  matt sync with HEAD
 1.42.20.2 09-Jan-2008  matt sync with HEAD
 1.42.20.1 06-Nov-2007  matt sync with HEAD
 1.42.18.2 11-Nov-2007  joerg Sync with HEAD.
 1.42.18.1 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.42.2.2 03-Dec-2007  ad Sync with HEAD.
 1.42.2.1 23-Oct-2007  ad Sync with head.
 1.43.2.2 18-Feb-2008  mjf Sync with HEAD.
 1.43.2.1 19-Nov-2007  mjf Sync with HEAD.
 1.44.6.4 09-Jan-2008  bouyer Merge Xen support back to i386/i386/vector.S
 1.44.6.3 08-Jan-2008  bouyer Sync with HEAD
 1.44.6.2 07-Jan-2008  bouyer Move Xen support to i386/i386/machdep.c. two less files in xen/ :)
 1.44.6.1 02-Jan-2008  bouyer Sync with HEAD
 1.44.2.1 26-Dec-2007  ad Sync with head.
 1.48.8.1 18-May-2008  yamt sync with head.
 1.48.6.2 17-Jan-2009  mjf Sync with HEAD.
 1.48.6.1 02-Jun-2008  mjf Sync with HEAD.
 1.49.8.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.49.2.2 20-Jun-2009  yamt sync with head
 1.49.2.1 04-May-2009  yamt sync with head.
 1.50.8.4 02-May-2011  jym Sync with head.
 1.50.8.3 01-Nov-2009  jym Sync with HEAD.
 1.50.8.2 31-May-2009  jym Sync with HEAD.
 1.50.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.50.4.2 21-Mar-2012  jdc Apply patch (requested by bouyer in ticket #1738).

Do not special-case XEN and always use the proper selectors for %fs and %gs
in buildcontext() and setregs(). The consequence was that signal handlers
would have the wrong %fs/%gs. Found by running atf tests under Xen/i386.
 1.50.4.1 18-Nov-2008  snj Apply patch (requested by bouyer in ticket #65):
Add i386-specific COMPAT_30_PTHREAD option (enabled where COMPAT_30
is enabled), which restore binary compatibility with netbsd-3 libpthread.
 1.50.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.53.6.1 06-Jun-2011  jruoho Sync with HEAD.
 1.53.4.1 31-May-2011  rmind sync with head
 1.54.38.1 22-Jan-2018  snj Pull up following revision(s) (requested by maxv in ticket #1550):
sys/arch/amd64/amd64/machdep.c: revision 1.280 via patch
sys/arch/amd64/include/segments.h: revision 1.34 via patch
sys/arch/i386/i386/machdep.c: revision 1.800 via patch
sys/arch/i386/include/segments.h: revision 1.64 via patch
sys/arch/x86/x86/vm_machdep.c: revision 1.30 via patch
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.54.34.1 22-Jan-2018  snj Pull up following revision(s) (requested by maxv in ticket #1550):
sys/arch/amd64/amd64/machdep.c: revision 1.280 via patch
sys/arch/amd64/include/segments.h: revision 1.34 via patch
sys/arch/i386/i386/machdep.c: revision 1.800 via patch
sys/arch/i386/include/segments.h: revision 1.64 via patch
sys/arch/x86/x86/vm_machdep.c: revision 1.30 via patch
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.54.32.3 28-Aug-2017  skrll Sync with HEAD
 1.54.32.2 05-Oct-2016  skrll Sync with HEAD
 1.54.32.1 19-Mar-2016  skrll Sync with HEAD
 1.54.30.1 22-Jan-2018  snj Pull up following revision(s) (requested by maxv in ticket #1550):
sys/arch/amd64/amd64/machdep.c: revision 1.280 via patch
sys/arch/amd64/include/segments.h: revision 1.34 via patch
sys/arch/i386/i386/machdep.c: revision 1.800 via patch
sys/arch/i386/include/segments.h: revision 1.64 via patch
sys/arch/x86/x86/vm_machdep.c: revision 1.30 via patch
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.54.24.1 19-Feb-2018  snj Pull up following revision(s) (requested by maxv in ticket #1517):
sys/arch/amd64/amd64/machdep.c: 1.280 via patch
sys/arch/amd64/include/segments.h: 1.34 via patch
sys/arch/i386/i386/machdep.c: 1.800
sys/arch/i386/include/segments.h: 1.64
sys/arch/x86/x86/vm_machdep.c: 1.30
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.54.16.1 19-Feb-2018  snj Pull up following revision(s) (requested by maxv in ticket #1517):
sys/arch/amd64/amd64/machdep.c: 1.280 via patch
sys/arch/amd64/include/segments.h: 1.34 via patch
sys/arch/i386/i386/machdep.c: 1.800
sys/arch/i386/include/segments.h: 1.64
sys/arch/x86/x86/vm_machdep.c: 1.30
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.54.14.1 03-Dec-2017  jdolecek update from HEAD
 1.54.10.1 19-Feb-2018  snj Pull up following revision(s) (requested by maxv in ticket #1517):
sys/arch/amd64/amd64/machdep.c: 1.280 via patch
sys/arch/amd64/include/segments.h: 1.34 via patch
sys/arch/i386/i386/machdep.c: 1.800
sys/arch/i386/include/segments.h: 1.64
sys/arch/x86/x86/vm_machdep.c: 1.30
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.55.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.57.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.59.6.1 01-Jan-2018  snj Pull up following revision(s) (requested by maxv in ticket #477):
sys/arch/amd64/amd64/machdep.c: revision 1.280
sys/arch/amd64/include/segments.h: revision 1.34
sys/arch/i386/i386/machdep.c: revision 1.800
sys/arch/i386/include/segments.h: revision 1.64 via patch
sys/arch/x86/x86/vm_machdep.c: revision 1.30
Fix a huge privilege separation vulnerability in Xen-amd64.
On amd64 the kernel runs in ring3, like userland, and therefore SEL_KPL
equals SEL_UPL. While Xen can make a distinction between usermode and
kernelmode in %cs, it can't when it comes to iopl. Since we set SEL_KPL
in iopl, Xen sees SEL_UPL, and allows (unprivileged) userland processes
to read and write to the CPU ports.
It is easy, then, to completely escalate privileges; by reprogramming the
PIC, by reading the ATA disks, by intercepting the keyboard interrupts
(keylogger), etc.
Declare IOPL_KPL, set to 1 on Xen-amd64, which allows the kernel to use
the ports but not userland. I didn't test this change on i386, but it
seems fine enough.
 1.64.4.1 10-Jun-2019  christos Sync with HEAD
 1.64.2.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.2 14-Sep-1998  thorpej Need 13 longs for jmp_buf; signal mask is 128 bits now.

XXX Actually, libc appears to use only 7 of the previous 10, so increasing
the size isn't actually necessary! But there was a gap at the end before,
so we'll keep it.
 1.1 20-Dec-1994  cgd make the definition of _JBLEN mach. dep. header-dependent.
 1.31 29-Oct-2021  thorpej Define __HAVE_STRUCT_SIGCONTEXT regardless of its current visibility.
 1.30 26-Oct-2021  christos Merge all MD __sigaction14_sigtramp.c copies into one:
- sparc and sparc64 were not using version 0 sigcontext when there were
no arguments in the signal version. This was probably a bug.
- vax is using +1 the version numbers of the other archs.
- Only hppa was defining __LIBC12_SOURCE__ so it was getting a working
sigcontext before. all the other ports that supported sigcontext had
the compat code disabled.
[pointed out by thorpej, thanks!]
If we want to remove sigcontext support from userland at least now there
is less work to do so.
 1.29 19-Nov-2008  ad Make the emulations, exec formats, coredump, NFS, and the NFS server
into modules. By and large this commit:

- shuffles header files and ifdefs
- splits code out where necessary to be modular
- adds module glue for each of the components
- adds/replaces hooks for things that can be installed at runtime
 1.28 14-Nov-2008  ad Remove some compat ifdefs that aren't really needed.
 1.27 20-Jan-2005  drochner branches: 1.27.92; 1.27.96; 1.27.102; 1.27.104;
restrict visibility of struct sigcontext* as much
as possible; include the needed opt_compat_*.h for
kernel code
 1.26 10-May-2004  drochner branches: 1.26.4;
SIGTRAMP_VALID() should not pollute the user namespace
 1.25 26-Mar-2004  drochner nothing cares about __HAVE_SIGINFO anymore, so nuke it
 1.24 27-Sep-2003  christos add SIGTRAMP_VALID and gc old sigcontext <-> ucontext macros.
 1.23 12-Sep-2003  christos make sigcontext visible all the time instead of including opt_*.h from a
large number of files.
 1.22 11-Sep-2003  christos fix typo.
 1.21 11-Sep-2003  christos Bring back sigcontext to userland by popular demand.
 1.20 11-Sep-2003  christos XXX: vm86 for sigcontext comment is gone.
 1.19 10-Sep-2003  christos #ifdef struct sigframe_sigcontext and struct sigcontext, so that only code
that really needs them, get them.
XXX1: We need to fix the vm86 api.
XXX2: We need to fix the ibcs2 signal delivery mechanism.
 1.18 06-Sep-2003  christos SA_SIGINFO changes.
 1.17 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.16 28-Apr-2003  bjh21 branches: 1.16.2;
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.

This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
 1.15 17-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.14 14-Sep-1998  thorpej branches: 1.14.26;
oops, missed one.
 1.13 14-Sep-1998  thorpej sigset13_t -> int.
 1.12 13-Sep-1998  thorpej __LIBCxx_SOURCE__ refers to the library major number, not the NetBSD release
number.
 1.11 13-Sep-1998  thorpej Fix thinko in last thinko fix. We always have to store an old style
signal mask since a 1.3 binary may attempt to invoke sigreturn(2) directly
for an alternate exit from the signal handler. If we don't do this, it will
get a garbage signal mask if it tries to do that.
 1.10 12-Sep-1998  mycroft Fix thinko in previous.
 1.9 12-Sep-1998  mycroft Version sys_sigreturn, to avoid breaking programs that use it explicitly.
 1.8 11-Sep-1998  mycroft Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.7 25-May-1998  kleink If any of _ANSI_SOURCE, _POSIX_C_SOURCE or _XOPEN_SOURCE are defined, don't
provide any identifiers other than sig_atomic_t.
 1.6 08-Jan-1996  mycroft VM86 support, by John Kohl, touched up a bit by me.
 1.5 01-May-1995  mycroft Add sc_gs and sc_fs. Move sc_onstack and sc_mask to end.
 1.4 10-Jan-1995  jtc Only define sig_atomic_t when _ANSI_SOURCE is defined.
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 09-Oct-1994  mycroft Make reg, frame, and sigcontext more similar.
 1.1 19-Sep-1993  brezak branches: 1.1.2; 1.1.4;
Machine dependant signal.h. Defines sigcontext and sig_atomic_t for i386 port.
 1.1.4.1 11-Oct-1994  mycroft Update from trunk.
 1.1.2.2 19-Sep-1993  brezak Machine dependant signal.h. Defines sigcontext and sig_atomic_t for i386 port.
 1.1.2.1 19-Sep-1993  brezak file signal.h was added on branch magnum on 1993-09-19 18:57:49 +0000
 1.14.26.1 16-Jan-2003  thorpej * Include <sys/sigtypes.h> rather than <sys/signal.h> in <sys/ucontext.h>.
* Define _UCONTEXT_TO_SIGCONTEXT() and _SIGCONTEXT_TO_UCONTEXT()
macros for converting a ucontext -> sigcontext and back again.
These macros in turn use machine-dependent macros _MCONTEXT_TO_SIGCONTEXT()
and _SIGCONTEXT_TO_MCONTEXT() provided by <machine/signal.h>.

The conversion process is not 100% accurate, but should be close enough.

Also note that the mcontext conversion may not be enough for all platforms
(m68k is a good example of this). These macros should be used only if
you really know what you're doing.
 1.16.2.4 24-Jan-2005  skrll Sync with HEAD.
 1.16.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.16.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.16.2.1 03-Aug-2004  skrll Sync with HEAD
 1.26.4.1 29-Apr-2005  kent sync with -current
 1.27.104.1 19-Jan-2009  skrll Sync with HEAD.
 1.27.102.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.27.96.1 04-May-2009  yamt sync with head.
 1.27.92.1 17-Jan-2009  mjf Sync with HEAD.
 1.1 23-Jul-2014  alnsn branches: 1.1.2; 1.1.6;
Rename sljitarch.h to sljit_machdep.h.
 1.1.6.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.6.1 23-Jul-2014  tls file sljit_machdep.h was added on branch tls-maxphys on 2014-08-20 00:03:06 +0000
 1.1.2.2 10-Aug-2014  tls Rebase.
 1.1.2.1 23-Jul-2014  tls file sljit_machdep.h was added on branch tls-earlyentropy on 2014-08-10 06:53:59 +0000
 1.4 23-Jul-2014  alnsn Rename sljitarch.h to sljit_machdep.h.
 1.3 17-Nov-2013  alnsn branches: 1.3.2;
Always define SLJIT_CACHE_FLUSH(), start include guards with '_' and use _LP64 guard.
 1.2 18-Nov-2012  alnsn branches: 1.2.2; 1.2.4;
Disable generation of fastcall functions on i386.
 1.1 28-Oct-2012  alnsn branches: 1.1.2;
Build bpfjit on i386.
 1.1.2.4 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.2.3 16-Jan-2013  yamt sync with (a bit old) head
 1.1.2.2 30-Oct-2012  yamt sync with head
 1.1.2.1 28-Oct-2012  yamt file sljitarch.h was added on branch yamt-pagecache on 2012-10-30 17:19:50 +0000
 1.2.4.1 18-May-2014  rmind sync with head
 1.2.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.2.2 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.2.2.1 18-Nov-2012  tls file sljitarch.h was added on branch tls-maxphys on 2012-11-20 03:01:28 +0000
 1.3.2.1 10-Aug-2014  tls Rebase.
 1.29 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.28 05-Jan-2003  sommerfeld Add symbolic names for MSR's used by SYSENTER/EXIT.
(I was experimenting a while back, might as well commit this one file..)
 1.27 11-Dec-2002  joda cpuid feature bit 30 is set on IA-64 (in x86 mode)
 1.26 06-Dec-2002  junyoung Display the extended feature flags with non-Intel processors rather than
the standard flags. See also PR#19163.

Before:

cpu0: AMD Athlon XP 1800+ (686-class), 1532.11 MHz
cpu0: features 383f9ff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR>
cpu0: features 383f9ff<PGE,MCA,CMOV,FGPAT,PSE36,MMX>
cpu0: features 383f9ff<FXSR,SSE>

After:

cpu0: AMD Athlon XP 1800+ (686-class), 1532.11 MHz
cpu0: features c3cbf9ff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,SEP,MTRR>
cpu0: features c3cbf9ff<PGE,MCA,CMOV,PAT,PSE36,MPC,MMXX,MMX>
cpu0: features c3cbf9ff<FXSR,SSE,3DNOW2,3DNOW>

While I'm here, amd_cpuid_cpu_cacheinfo() is an info function rather
than a probe function.
 1.25 05-Dec-2002  junyoung - FGPAT -> PAT, as documented in Intel manual.
- Feature flag 31 is "Signal Break on FERR" (SBF).
 1.24 25-Oct-2002  fvdl Add macros for cpuid family/step, etc shifting. Moved here from
machdep.c.
 1.23 07-Jun-2002  gmcgarry branches: 1.23.2;
Add Athlon performance counters.
 1.22 07-Jun-2002  gmcgarry Add i586 performance counters.
 1.21 20-Mar-2002  joda branches: 1.21.6;
add HTT cpu flag, and further split message
 1.20 19-Sep-2001  thorpej Define the AMD K6 cache/write-combinding control register MSR.
 1.19 01-Aug-2001  thorpej branches: 1.19.4;
Add some more CPUID feature bits.
 1.18 22-Jul-2001  wiz seperate -> separate
 1.17 19-Jun-2001  wiz branches: 1.17.4;
`accessible' only has one `a'.
 1.16 19-Jun-2001  fvdl Add fxsr CR4 bits.
 1.15 21-Dec-2000  enami branches: 1.15.4;
Print cpu features line only when corresponding part of bits are set.
 1.14 20-Sep-2000  fvdl Fix typo.
 1.13 13-Sep-2000  thorpej Define some 586-class CESR MSR bits.
 1.12 13-Sep-2000  thorpej Add 686-class performance counter events.
 1.11 27-Mar-2000  thorpej Add/correct some MSRs, from Intel Architecture Software Developer's Manual,
Volume 3 (System Programming).
 1.10 24-Mar-2000  thorpej Add some Model Specific Register definitions. From FreeBSD.
 1.9 13-Dec-1999  sommerfeld Add new CPU feature flags (up through recent Pentium III and Celerons)
 1.8 05-Sep-1997  chuck branches: 1.8.18; 1.8.24;
add bits for %cr4 and cpu_feature [from freebsd and www.sandpile.org]
 1.7 27-Oct-1994  cgd branches: 1.7.16;
new RCS ID format.
 1.6 03-Aug-1994  deraadt document cyrix configuration registers
 1.5 24-May-1994  mycroft branches: 1.5.2;
Add some more constants.
 1.4 20-Dec-1993  mycroft branches: 1.4.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.3 22-May-1993  cgd branches: 1.3.4;
add rcsids to everything and clean up headers
 1.2 09-May-1993  deraadt npx patches from Bruce Evans. patchkit 10002
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.3.4.1 08-Nov-1993  mycroft Garbage collect some constants, and the entire 286 nonsense. (Like we even
get to start() on a 286? NOT!)
 1.4.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.4.2.1 20-Dec-1993  mycroft file specialreg.h was added on branch magnum on 1993-12-20 05:25:47 +0000
 1.5.2.1 03-Aug-1994  mycroft update from trunk
 1.7.16.1 06-Sep-1997  thorpej Update marc-pcmcia branch from trunk.
 1.8.24.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.8.18.2 05-Jan-2001  bouyer Sync with HEAD
 1.8.18.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.15.4.9 07-Jan-2003  thorpej Sync with HEAD.
 1.15.4.8 11-Dec-2002  thorpej Sync with HEAD.
 1.15.4.7 11-Dec-2002  thorpej Sync with HEAD.
 1.15.4.6 11-Nov-2002  nathanw Catch up to -current
 1.15.4.5 20-Jun-2002  nathanw Catch up to -current.
 1.15.4.4 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.15.4.3 21-Sep-2001  nathanw Catch up to -current.
 1.15.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.15.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.17.4.3 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.17.4.2 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.17.4.1 03-Aug-2001  lukem update to -current
 1.19.4.1 01-Oct-2001  fvdl Catch up with -current.
 1.21.6.1 14-Jul-2002  gehenna catch up with -current.
 1.23.2.2 07-Jun-2002  gmcgarry Add Athlon performance counters.
 1.23.2.1 07-Jun-2002  gmcgarry file specialreg.h was added on branch sommerfeld_i386mp_1 on 2002-06-07 04:03:50 +0000
 1.4 15-Apr-1998  drochner "spkr" is now mi. Keep this file for compatibility.
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 11-Jan-1994  mycroft branches: 1.2.2;
Gratuitous formatting changes.
 1.1 16-Jun-1993  brezak branches: 1.1.4;
Move spkr.h to include/machine so users can use it.
 1.1.4.2 14-Nov-1993  mycroft Missed something...
 1.1.4.1 14-Nov-1993  mycroft Clean up a bit.
 1.2.2.2 11-Jan-1994  mycroft Gratuitous formatting changes.
 1.2.2.1 11-Jan-1994  mycroft file spkr.h was added on branch magnum on 1994-01-11 13:30:41 +0000
 1.24 17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.23 18-Aug-2009  drochner use __builtin_va_start rather than __builtin_stdarg_start for gcc>=4.1,
I don't know why it was made that inconsistent at that time, but
the in-tree gcc-4.1 works with that, and gcc-4.4.1 removes builtin
support for old style varargs.
 1.22 21-Jun-2008  gmcgarry branches: 1.22.10;
Add stdargs support for pcc.
 1.21 07-Aug-2003  agc branches: 1.21.102; 1.21.106; 1.21.108; 1.21.110;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.20 28-Apr-2003  bjh21 branches: 1.20.2;
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.

This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
 1.19 05-May-2000  thorpej branches: 1.19.6;
Use __GNUC_PREREQ__().
 1.18 03-May-2000  thorpej Make varargs and stdarg work with GCC 2.96 and later.
 1.17 03-Feb-2000  kleink Add a C99-style va_copy macro.
 1.16 03-May-1999  christos branches: 1.16.2;
Define __builtin_*() for lint
 1.15 22-Jan-1999  mycroft branches: 1.15.4;
Use __builtin_next_arg(). Fixed PR 6862.
 1.14 26-Sep-1998  christos delint
 1.13 27-Jul-1998  mycroft Delint.
 1.12 25-Dec-1995  mycroft branches: 1.12.16;
Stylistic changes.
 1.11 25-Dec-1995  mycroft Stylistic changes.
 1.10 25-Dec-1995  mycroft Update for GCC 2.7, and fix bugs.
 1.9 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.8 28-Jan-1995  jtc ANSI says that <stdarg.h>'s va_end macro must expand to a void expression.
For consistancy, I'm changing <varargs.h> too.
 1.7 28-Dec-1994  cgd do the right thing with strange-sized varargs objects.
 1.6 27-Oct-1994  cgd new RCS ID format.
 1.5 15-Oct-1994  cgd make <stdarg.h> a symlink, and clean up ports' stdarg.h and varargs.h files.
 1.4 21-May-1994  cgd update from lite
 1.3 20-Dec-1993  mycroft branches: 1.3.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.3.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.3.2.1 20-Dec-1993  mycroft file stdarg.h was added on branch magnum on 1993-12-20 05:25:49 +0000
 1.12.16.1 01-Feb-1999  cgd pull up revs 1.13-1.15 from trunk (PR#6862). (mycroft)
 1.15.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.16.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.19.6.2 05-May-2000  thorpej Use __GNUC_PREREQ__().
 1.19.6.1 05-May-2000  thorpej file stdarg.h was added on branch sommerfeld_i386mp_1 on 2000-05-05 00:21:49 +0000
 1.20.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.20.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.20.2.1 03-Aug-2004  skrll Sync with HEAD
 1.21.110.1 27-Jun-2008  simonb Sync with head.
 1.21.108.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.21.106.2 19-Aug-2009  yamt sync with head.
 1.21.106.1 04-May-2009  yamt sync with head.
 1.21.102.1 29-Jun-2008  mjf Sync with HEAD.
 1.22.10.2 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.22.10.1 01-Nov-2009  jym Sync with HEAD.
 1.17 01-Aug-2017  maxv Remove svr4_machdep.h right away, no one should include it.
 1.16 28-Apr-2008  martin branches: 1.16.44; 1.16.64;
Remove clause 3 and 4 from TNF licenses
 1.15 27-Oct-2003  junyoung branches: 1.15.102; 1.15.104; 1.15.106;
Nuke __P().
 1.14 21-Dec-2001  jdolecek branches: 1.14.2; 1.14.18;
rename (incorrect) SVR4_TRAP_CLOCK_SETTIME to SVR4_TRAP_GETHRESTIME - this
is what Solaris8 calls it
implement SVR4_TRAP_GETHRESTIME, though obviously only with microsecond accuracy

now clock_gettime(CLOCK_REALTIME, tp) works on Solaris8/i386
 1.13 31-Oct-2001  jdolecek Add defines for the rest of fasttraps as defined on Solaris8/i386. For
documentation purposes only (though CLOCK_SETTIME a.k.a T_GETHRESTIME
shouldn't be too hard to implement).
 1.12 11-Dec-2000  mycroft branches: 1.12.4; 1.12.6; 1.12.10;
Introduce 2 new flags in types.h:
* __HAVE_SYSCALL_INTERN. If this is defined, e_syscall is replaced by
e_syscall_intern, which is called at key places in the kernel. This can be
used to set a MD syscall handler pointer. This obsoletes and replaces the
*_HAS_SEPARATED_SYSCALL flags.
* __HAVE_MINIMAL_EMUL. If this is defined, certain (deprecated) elements in
struct emul are omitted.
 1.11 09-Dec-2000  jdolecek prototype svr4_syscall() (only) in compat/svr4/svr4_exec.c
 1.10 09-Dec-2000  mycroft Add a separate svr4_syscall().
 1.9 21-Jan-1999  christos branches: 1.9.8;
Move prototypes to mi code; add MD constant for padding
 1.8 13-Dec-1998  christos Add defines for the fast trap vectors.
 1.7 11-Sep-1998  mycroft Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.6 05-Sep-1998  christos Assign copyright to TNF.
 1.5 31-Mar-1995  christos Reorganization of the signal frame and ucontext to make it shareable with
the sparc code. Added trap defines.
 1.4 01-Feb-1995  christos Added defines for svr4_sysarch()
 1.3 25-Jan-1995  christos Modify the floating point part of our context to reflect reality.
 1.2 09-Jan-1995  christos Added missing forward declaration
 1.1 08-Jan-1995  christos New file for signal handling and {g,s}etcontext().
 1.9.8.1 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.12.10.1 12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.12.6.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.12.4.2 08-Jan-2002  nathanw Catch up to -current.
 1.12.4.1 14-Nov-2001  nathanw Catch up to -current.
 1.14.18.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.14.18.2 18-Sep-2004  skrll Sync with HEAD.
 1.14.18.1 03-Aug-2004  skrll Sync with HEAD
 1.14.2.2 21-Dec-2001  jdolecek rename (incorrect) SVR4_TRAP_CLOCK_SETTIME to SVR4_TRAP_GETHRESTIME - this
is what Solaris8 calls it
implement SVR4_TRAP_GETHRESTIME, though obviously only with microsecond accuracy

now clock_gettime(CLOCK_REALTIME, tp) works on Solaris8/i386
 1.14.2.1 21-Dec-2001  jdolecek file svr4_machdep.h was added on branch sommerfeld_i386mp_1 on 2001-12-21 07:02:24 +0000
 1.15.106.1 16-May-2008  yamt sync with head.
 1.15.104.1 18-May-2008  yamt sync with head.
 1.15.102.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.64.1 28-Aug-2017  skrll Sync with HEAD
 1.16.44.1 03-Dec-2017  jdolecek update from HEAD
 1.18 16-Apr-2007  ad Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.17 12-Apr-2006  drochner branches: 1.17.14; 1.17.18; 1.17.20;
second step to retire the useless i386_set_ioperm/i386_get_ioperm
calls: remove declarations from public headers
(it still needs to be built for binary compatibility; one might consider
establishing a separate "compat" department as libc does, but these
little wrapper functions aren't worth the effort yet)
 1.16 26-Dec-2005  perry branches: 1.16.4; 1.16.6; 1.16.8; 1.16.10; 1.16.12;
u_intN_t -> uintN_t
 1.15 27-Oct-2003  junyoung branches: 1.15.16;
Nuke __P().
 1.14 11-Sep-2003  christos make vm86 use __gregset_t
 1.13 11-Sep-2003  kleink __{BEGIN,END}_DECLS-wrap prototypes.
 1.12 07-Jun-2002  gmcgarry branches: 1.12.2; 1.12.8;
Support Athlon performance counters.
 1.11 10-Sep-2001  fvdl branches: 1.11.12;
Add definitions for mtrr syscalls.
 1.10 13-Sep-2000  thorpej branches: 1.10.4; 1.10.6; 1.10.8;
Add support for using the 586- and 686-class performance
counters.
 1.9 25-Feb-1998  perry branches: 1.9.14;
change second parm of sysarch() from char * to void *
 1.8 08-Jan-1996  mycroft VM86 support, by John Kohl, touched up a bit by me.
 1.7 11-Oct-1995  mycroft Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.6 05-Jun-1995  pk Prototype sysarch(2) (Thorsten Lockert, PR#1096)
 1.5 06-May-1995  mycroft Define i386_[gs]et_ldt_args here.
 1.4 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.3 27-Oct-1994  cgd new RCS ID format.
 1.2 20-Dec-1993  mycroft branches: 1.2.2;
Cleanup and garbage collection; nothing significant. From magnum branch.
 1.1 19-Sep-1993  brezak branches: 1.1.2;
Defines architecure dependant syscalls.
 1.1.2.1 14-Nov-1993  mycroft Do the multiple-inclusion thang.
 1.2.2.2 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.2.2.1 20-Dec-1993  mycroft file sysarch.h was added on branch magnum on 1993-12-20 05:25:53 +0000
 1.9.14.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.10.8.1 01-Oct-2001  fvdl Catch up with -current.
 1.10.6.2 23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.10.6.1 13-Sep-2001  thorpej Update the kqueue branch to HEAD.
 1.10.4.2 20-Jun-2002  nathanw Catch up to -current.
 1.10.4.1 21-Sep-2001  nathanw Catch up to -current.
 1.11.12.1 14-Jul-2002  gehenna catch up with -current.
 1.12.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.12.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.12.8.1 03-Aug-2004  skrll Sync with HEAD
 1.12.2.2 07-Jun-2002  gmcgarry Support Athlon performance counters.
 1.12.2.1 07-Jun-2002  gmcgarry file sysarch.h was added on branch sommerfeld_i386mp_1 on 2002-06-07 04:04:48 +0000
 1.15.16.2 03-Sep-2007  yamt sync with head.
 1.15.16.1 21-Jun-2006  yamt sync with head.
 1.16.12.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.16.10.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.16.8.1 24-May-2006  yamt sync with head.
 1.16.6.1 22-Apr-2006  simonb Sync with head.
 1.16.4.1 09-Sep-2006  rpaulo sync with head
 1.17.20.1 11-Jul-2007  mjf Sync with head.
 1.17.18.1 27-May-2007  ad Sync with head.
 1.17.14.1 07-May-2007  yamt sync with head.
 1.5 17-Sep-2017  maxv Remove tlog.h - unused now. Note that it is not installed.
 1.4 13-Feb-2004  wiz branches: 1.4.150;
Uppercase CPU, plural is CPUs.
 1.3 11-Oct-2002  fvdl branches: 1.3.2; 1.3.8;
Add NetBSD RCS Id.
 1.2 01-Oct-2002  fvdl branches: 1.2.2;
Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.1 27-Apr-2002  sommerfeld branches: 1.1.2;
file tlog.h was initially added on branch sommerfeld_i386mp_1.
 1.1.2.1 27-Apr-2002  sommerfeld Add options TRAPLOG:

When enabled, each cpu gets a ring buffer; on every trap entry, we add
an entry to the trap log using the new locore "TLOG" macro. Somewhat
like a flight recorder, this may give some post-mortem clues as to
what was going on as we were spiralling in...

XXX currently depends on various intel MSR's to record the low order
32 bits of the cycle counter as well as last-branch from and to
addresses.
 1.2.2.2 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.2.2.1 01-Oct-2002  jdolecek file tlog.h was added on branch kqueue on 2002-10-10 18:33:30 +0000
 1.3.8.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.8.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.8.1 03-Aug-2004  skrll Sync with HEAD
 1.3.2.2 18-Oct-2002  nathanw Catch up to -current.
 1.3.2.1 11-Oct-2002  nathanw file tlog.h was added on branch nathanw_sa on 2002-10-18 02:37:58 +0000
 1.4.150.1 03-Dec-2017  jdolecek update from HEAD
 1.7 26-Feb-2003  fvdl Redirect some includes to x86/foo.h
 1.6 05-Oct-2002  fvdl Define some masks to be able to pass information about a trap
being a TSS trap down to things like DDB.

XXX a bit of a hack.
 1.5 17-Jun-2002  fvdl branches: 1.5.2;
Add XMM trap type.
 1.4 27-Oct-1994  cgd branches: 1.4.48; 1.4.50; 1.4.62;
new RCS ID format.
 1.3 19-Dec-1993  mycroft branches: 1.3.2;
Clean up trap handling and macroize interrupt entry and exit code. From
magnum branch.
 1.2 22-May-1993  cgd branches: 1.2.4;
add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.2.4.1 13-Nov-1993  mycroft Garbage collect unused traps.
 1.3.2.2 19-Dec-1993  mycroft Clean up trap handling and macroize interrupt entry and exit code. From
magnum branch.
 1.3.2.1 19-Dec-1993  mycroft file trap.h was added on branch magnum on 1993-12-19 06:58:28 +0000
 1.4.62.1 16-Jul-2002  gehenna catch up with -current.
 1.4.50.1 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.4.48.2 18-Oct-2002  nathanw Catch up to -current.
 1.4.48.1 20-Jun-2002  nathanw Catch up to -current.
 1.5.2.2 17-Jun-2002  fvdl Add XMM trap type.
 1.5.2.1 17-Jun-2002  fvdl file trap.h was added on branch sommerfeld_i386mp_1 on 2002-06-17 21:38:21 +0000
 1.12 07-Jul-2018  kamil Correct unportable signed integer left shift in i386/amd64 tss code

Change the type of IOMAP_INVALOFF to unsigned int.

sys/arch/amd64/amd64/machdep.c:518:42, left shift of 65535 by 16 places cannot be represented in type 'int'

Detected with Kernel Undefined Behavior Sanitizer.
 1.11 04-Jan-2018  maxv branches: 1.11.2; 1.11.4;
Declare IOMAP_VALIDOFF, not to use ci_tss pointers.
 1.10 05-Jan-2008  yamt move IOMAP_INVALOFF from cpu.h to tss.h
 1.9 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.8 07-Aug-2003  agc branches: 1.8.16; 1.8.78; 1.8.84; 1.8.92;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.7 05-Oct-2002  fvdl branches: 1.7.6;
Protect against multiple inclusion.
 1.6 11-Oct-1995  mycroft branches: 1.6.46;
Various changes from John Kohl and me:
Map kernel stacks only at unique addresses.
Use one TSS per process.
Add sysarch calls for modifying IOPL and the I/O permission bitmap.
Add a compacting GDT entry allocator, for TSS and LDT selectors.
Enable modifying %fs and %gs with PT_SETREGS.
Sanitize various bits of code.
 1.5 01-May-1995  mycroft Remove historical garbage.
 1.4 27-Oct-1994  cgd new RCS ID format.
 1.3 22-May-1993  cgd add rcsids to everything and clean up headers
 1.2 07-Apr-1993  deraadt /* ... /* ... */ problem in an include file
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.46.1 18-Oct-2002  nathanw Catch up to -current.
 1.7.6.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.7.6.2 18-Sep-2004  skrll Sync with HEAD.
 1.7.6.1 03-Aug-2004  skrll Sync with HEAD
 1.8.92.1 08-Jan-2008  bouyer Sync with HEAD
 1.8.84.1 18-Feb-2008  mjf Sync with HEAD.
 1.8.78.1 09-Jan-2008  matt sync with HEAD
 1.8.16.1 21-Jan-2008  yamt sync with head
 1.11.4.1 10-Jun-2019  christos Sync with HEAD
 1.11.2.1 28-Jul-2018  pgoyette Sync with HEAD
 1.95 08-May-2025  imil Rename BOOTCYCLETIME kernel option and subsequent files to BOOT_DURATION
 1.94 06-May-2025  imil Add BOOTCYCLETIME option to print kernel boot time

Introduce a new kernel option, BOOTCYCLETIME, which will print
the time taken for the kernel to boot on (for now) amd64 and i386
architectures.
 1.93 01-Apr-2021  simonb branches: 1.93.22;
Whitespace: #define<tab>
 1.92 01-Aug-2020  jdolecek branches: 1.92.2; 1.92.4;
move __HAVE_PCI_MSI_MSIX to <x86/pci_machdep_common.h>
 1.91 04-May-2020  jdolecek add support for using MSI for XenPV Dom0

use PHYSDEVOP_map_pirq to get the pirq/gsi for MSI/MSI-X, switch also INTx
to use it instead of PHYSDEVOP_alloc_irq_vector

MSI confirmed working with single-vector MSI for wm(4), ahcisata(4), bge(4)

XXX added some provision for MSI-X, but it doesn't actually work (no interrupts
delivered), needs some further investigation; disable MSI-X for XENPV
via flag in x86/pci/pci_machdep.c
 1.90 23-Sep-2019  kamil Disable __NO_STRICT_ALIGNMENT on amd64/i386 for UBSan builds

This change allows to pick code paths in the kernel that are tuned for
alignment sensitive (and stricted in C meaning) code paths. In particular
the IPv6 code uses this heavily and skips whenever possible the process
of aligning of networking data.

With this modification all ATF tests are executed on amd64 without
triggering any UBSan reports in dmesg.

In theory __NO_STRICT_ALIGNMENT could be tuned for vax and m68k, however
these machines are still unsupported in LLVM sanitizers and syzkaller.

sys/netinet6/scope6.c:404:6, member access within misaligned address 0xfffffaea81276086 for type 'struct in6_addr' which requires 4 byte alignment
Reported-by: syzbot+a86f58d17685317b3df9@syzkaller.appspotmail.com

sys/net/rtsock_shared.c:629:41, member access within misaligned address 0xffffddb5db3ff04c for type 'struct rt_msghdr50' which requires 8 byte alignment
Reported-by: syzbot+0a3a022bc9d2b8880c16@syzkaller.appspotmail.com
 1.89 06-Apr-2019  thorpej Overhaul the API used to fetch and store individual memory cells in
userspace. The old fetch(9) and store(9) APIs (fubyte(), fuword(),
subyte(), suword(), etc.) are retired and replaced with new ufetch(9)
and ustore(9) APIs that can return proper error codes, etc. and are
implemented consistently across all platforms. The interrupt-safe
variants are no longer supported (and several of the existing attempts
at fuswintr(), etc. were buggy and not actually interrupt-safe).

Also augmement the ucas(9) API, making it consistently available on
all plaforms, supporting uniprocessor and multiprocessor systems, even
those that do not have CAS or LL/SC primitives.

Welcome to NetBSD 8.99.37.
 1.88 12-Jul-2018  maxv Remove the kernel PMC code. Sent yesterday on tech-kern@.

This change:

* Removes "options PERFCTRS", the associated includes, and the associated
ifdefs. In doing so, it removes several XXXSMPs in the MI code, which is
good.

* Removes the PMC code of ARM XSCALE.

* Removes all the pmc.h files. They were all empty, except for ARM XSCALE.

* Reorders the x86 PMC code not to rely on the legacy pmc.h file. The
definitions are put in sysarch.h.

* Removes the kern/sys_pmc.c file, and along with it, the sys_pmc_control
and sys_pmc_get_info syscalls. They are marked as OBSOL in kern,
netbsd32 and rump.

* Removes the pmc_evid_t and pmc_ctr_t types.

* Removes all the associated man pages. The sets are marked as obsolete.
 1.87 27-Feb-2016  tls branches: 1.87.16; 1.87.18;
Add cpu_rng, a framework for simple on-CPU random number generators.
 1.86 24-Jan-2016  christos expose __vaddr_t for segments.h since it is a userland api.
 1.85 23-Jan-2016  christos expose the kernel types for standalone code.
 1.84 23-Jan-2016  christos Hide {p,v}{addr,size}_t and register_t (and a couple more types that
are machine-specific) from userland unless _KERNEL/_KMEMUSER and a
new _KERNTYPES variables is defined. The _KERNTYPES should be fixed
for many subsystems that should not be using it (rump)...
 1.83 27-Aug-2015  pooka Fix PTHREAD_FOO_INITIALIZER for C++ by not using volatile in the relevant
pthread types in C++ builds, attempt 2.

The problem with attempt 1 was making assumptions of what the MD
__cpu_simple_lock_t (declared volatile) looks like. To get a same type
except non-volatile, we change the MD type to __cpu_simple_lock_nv_t
and typedef __cpu_simple_lock_t as a volatile __cpu_simple_lock_nv_t.
IMO, __cpu_simple_lock_t should not be volatile at all, but changing it
now is too risky.

Fixes at least Rumprun w/ gcc 5.1/5.2. Furthermore, the mpd application
(and possibly others) will no longer require NetBSD-specific patches.

Tested: build.sh for i386, Rumprun for x86_64 w/ gcc 5.2.

Based on the patch from Christos in lib/49989.
 1.82 21-Aug-2015  pooka Make it possible to explicitly disable MSI/MSIX with NO_PCI_MSI_MSIX.

Some platforms, e.g. linux uio-pci-generic, do not support MSI at all.

XXX: does MSI being defined intentionally depend on _KERNEL_OPT on amd64
but not i386?
 1.81 27-Apr-2015  knakahara add x86 MD MSI/MSI-X support code.
 1.80 22-Apr-2015  pooka Revise rhetoric for why __HAVE_ATOMIC64_OPS is defined with _KERNEL even
though we don't know for sure that the target i386 CPU will support them.
 1.79 24-Apr-2014  christos branches: 1.79.4;
Explain what is going on with the 64 bit atomic ops, and restore them
for pure kernel use.
 1.78 22-Apr-2014  christos we don't really have 64 bit atomic ops.
 1.77 03-Apr-2014  christos branches: 1.77.2;
we have cpu_bootconf()
 1.76 01-Dec-2013  christos revert fpu/pcu changes until we figure out what's wrong; they cause random
freezes
 1.75 23-Oct-2013  drochner Use the MI "pcu" framework for bookkeeping of npx/fpu states on x86.
This reduces the amount of MD code enormously, and makes it easier
to implement support for newer CPU features which require more fpu
state, or for fpu usage by the kernel.
For access to FPU state across CPUs, an xcall kthread is used now
rather than a dedicated IPI.
No user visible changes intended.
 1.74 06-Jul-2011  dyoung branches: 1.74.2; 1.74.12; 1.74.16;
Implement bus_space_tag_create() and _destroy().

Factor bus_space_reserve(), bus_space_release(), et cetera out of
bus_space_alloc(), bus_space_map(), bus_space_free(), bus_space_unmap(),
et cetera.

For i386 and amd64, activate the use of <machine/bus_defs.h> and
<machine/bus_funcs.h> by #defining __HAVE_NEW_STYLE_BUS_H in
their respective types.h. While I'm here, remove unnecessary
__HAVE_DEVICE_REGISTER #defines.
 1.73 12-Jun-2011  rmind Welcome to 5.99.53! Merge rmind-uvmplock branch:

- Reorganize locking in UVM and provide extra serialisation for pmap(9).
New lock order: [vmpage-owner-lock] -> pmap-lock.

- Simplify locking in some pmap(9) modules by removing P->V locking.

- Use lock object on vmobjlock (and thus vnode_t::v_interlock) to share
the locks amongst UVM objects where necessary (tmpfs, layerfs, unionfs).

- Rewrite and optimise x86 TLB shootdown code, make it simpler and cleaner.
Add TLBSTATS option for x86 to collect statistics about TLB shootdowns.

- Unify /dev/mem et al in MI code and provide required locking (removes
kernel-lock on some ports). Also, avoid cache-aliasing issues.

Thanks to Andrew Doran and Joerg Sonnenberger, as their initial patches
formed the core changes of this branch.
 1.72 12-Mar-2011  joerg branches: 1.72.2;
Add TLS support for AMD64, i386 and SH3.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.71 24-Feb-2011  joerg Allow storing and receiving the LWP private pointer via ucontext_t
on all platforms except VAX and IA64. Add fast access via register for
AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace
the stack based pthread_self(). Implement skeleton support for Alpha,
HPPA, PowerPC, SPARC and SPARC64, but leave it disabled.

Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in
machine/types.h and a corresponding __lwp_getprivate_fast in
machine/mcontext.h.

This material is based upon work partially supported by
The NetBSD Foundation under a contract with Joerg Sonnenberger.
 1.70 22-Dec-2010  christos branches: 1.70.2; 1.70.4;
Make __HAVE_CPU_DATA_FIRST true
 1.69 14-Dec-2010  haad Revert change made in revision 1.66 by ad@ this is not true and 64bit
atomic ops should be enabled in libc by default.
 1.68 21-Sep-2010  jym Promote paddr_t to 64 bits for i386 userland (non PAE and PAE).

paddr_t has limited interest in userland, and should only be used by specific
code like kvm(3) (for VA => PA translations). To support non PAE and PAE
kernels simultaneously in kvm(3), promote paddr_t to 64 bits.

No objection on current-users@. See also:

http://mail-index.netbsd.org/current-users/2010/09/07/msg014249.html

Kernel remains untouched by this change. In-kernel 64 bits for paddr_t is for
a future commit (Yes, I do not forget about that :) )
 1.67 11-Dec-2009  matt branches: 1.67.2; 1.67.4;
Add PRIx{P,V}{ADDR,SIZE}, PRIu{P,V}SIZE, and PRIxREGISTER{,32,64} for all
(except where they will be added via merge). These should be used to print
{p,v}{addr,size}_t and register*_t as appropriate.
 1.66 28-Jun-2009  ad Define __HAVE_ATOMIC64_OPS only in kernel, since it doesn't work in
userspace on the i486.
 1.65 19-Apr-2009  ad cpuctl:

- Add interrupt shielding (direct hardware interrupts away from the
specified CPUs). Not documented just yet but will be soon.

- Redo /dev/cpu time_t compat so no kernel changes are needed.

x86:

- Make intr_establish, intr_disestablish safe to use when !cold.

- Distribute hardware interrupts among the CPUs, instead of directing
everything to the boot CPU.

- Add MD code for interrupt sheilding. This works in most cases but there is
a bug where delivery is not accepted by an LAPIC after redistribution. It
also needs re-balancing to make things fair after interrupts are turned
back on for a CPU.
 1.64 05-Apr-2009  tsutsui Use #define<tab> consistently.
 1.63 05-Apr-2009  tsutsui Remove __HAVE_UFS2_BOOT since it belongs to sysinst for now.
"Feel free to change it" by ad@.
 1.62 04-Apr-2009  ad +__HAVE_UFS2_BOOT
 1.61 29-Mar-2009  ad _lwp_setprivate: provide the value to MD code if a hook is present.

This will be used to support TLS. The MD method must match the ELF TLS spec
for that CPU architecture (if there is a spec).

At this time it is only implemented for i386, where it means setting the
per-thread base address for %gs. Please implement this for your platform!
 1.60 26-Oct-2008  mrg branches: 1.60.2; 1.60.8;
- use _I386_FOO_H for multi-include protection
- use <i386/foo.h> in a couple of places
 1.59 21-Feb-2008  ad branches: 1.59.2; 1.59.6; 1.59.12;
#define __HAVE_ATOMIC_AS_MEMBAR, indicating that:

- atomic_cas_ni() does an implicit membar_exit()
- all other atomic operations do an implicit membar_sync()

While this might seem kind of arbitrary it's the basis for some important
optimizations.
 1.58 23-Jan-2008  bouyer branches: 1.58.2;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.57 20-Jan-2008  joerg Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
 1.56 15-Jan-2008  joerg Introduce optional cpu_offline_md to execute MD actions at the end of
cpu_offline. Use this on amd64/i386 to force a FPU save. As this was
triggered by npxsave_cpu/fpusave_cpu not working for a different CPU,
remove the cpu_info argument and adjust npxsave_*/fpusave_* to use bool
for the save.

OK ad@
 1.55 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.54 04-Jan-2008  yamt i386:
- make tss per-cpu. this considerably speeds up context switch for,
at least, pentium4, where ltr instruction seems very slow.
i386, xen:
- kill cpu_maxproc.
kvm86:
- adapt to per-cpu tss.
- cleanup and simplify.
- move kvm86_mp_lock to more meaningful place.
- disable preemption during a call.
 1.53 20-Dec-2007  ad 64-bit atomic ops for i386.
 1.52 17-Oct-2007  garbled branches: 1.52.2; 1.52.4; 1.52.8;
Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.51 14-Jul-2007  ad branches: 1.51.10;
Generic soft interrupts are mandatory.
 1.50 09-Feb-2007  ad branches: 1.50.6; 1.50.14;
Merge newlock2 to head.
 1.49 03-Sep-2006  bjh21 branches: 1.49.2;
Nothing in the kernel now tests __HAVE_NWSCONS, so stop defining it everywhere.
 1.48 03-Sep-2006  gdamore Convert i386 to use common TODR code. Not tested, but Christos says he'll
test it for me right now. :-)
 1.47 07-Jun-2006  kardel convert to timecounters (from branch simonb-timecounters)
 1.46 24-Dec-2005  perry branches: 1.46.4; 1.46.6; 1.46.8; 1.46.14;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.45 18-Jan-2004  martin branches: 1.45.16;
Do not export __HAVE_RAS to userland. Applications are supposed to try
rasctl() and detect failure with EOPNOTSUPP.
 1.44 26-Sep-2003  nathanw Move __cpu_simple_lock_t and __SIMPLELOCK_{UN,}LOCKED to machine/types.h
so that they can be used in a namespace-friendly way.
 1.43 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.42 28-Apr-2003  bjh21 branches: 1.42.2;
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.

This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.

I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.

Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
 1.41 17-Dec-2002  gmcgarry Move to MI runqueue functions.
 1.40 16-Dec-2002  jdolecek use the __HAVE_CPU_MAXPROC hook to limit kern.maxproc to number
of available GDT slots
add code in init386() to force maxproc to be maximum cpu_maxproc()

this fixes port-i386/1635 by John Kohl
 1.39 01-Oct-2002  fvdl Merge Bill Sommerfeld's i386 MP branch. This code has some known
caveats, but works quite well in a lot of MP cases, and all
UP cases that I have tested. Parts of this will hopefully be
reworked in the not-too-distant future.
 1.38 23-Sep-2002  gmcgarry Back-out previous.
 1.37 22-Sep-2002  simonb Use "#define\t" instead of "#define ".
 1.36 22-Sep-2002  gmcgarry MD component of the new cpu_switch() interface. Introduces nextrunqueue(),
cpu_idle() and new cpu_switch() to replace the old cpu_switch()
which did the lot. Runs leaner without overly blocking interrupts.

Includes cleanup of the RAS code to make use of callee-saved registers.

Benchmarks on DX4 @ 100MHz reveal a slight performance improvement
but probably not statistically signficant. More TBD to verify this.

Changes passed a pounding on Athlon @ 1GHz too.
 1.35 22-Sep-2002  gmcgarry Add __HAVE_MD_RUNQUEUE flag for MD code to override MI run queue primitives.
 1.34 28-Aug-2002  gmcgarry RAS support for i386.
 1.33 07-Aug-2002  tron Redo last change. "pmc_evid_t" and "pmc_ctr_t" need to be visible for
userland because they are used in "sys/pmc.h".
 1.32 07-Aug-2002  tron Embed "pmc_evid_t" and "pmc_ctr_t" into "if defined(_KERNEL)" and use
"__uint64_t" from "int_types.h". This fixes "lint" errors while
building "libc".
 1.31 07-Aug-2002  briggs define pmc_evid_t, pmc_ctr_t.
 1.30 28-Feb-2002  simonb branches: 1.30.8;
Use "#define<tab>".
 1.29 28-Apr-2001  kleink branches: 1.29.2;
* Move definitions of exact-width integer types from <machine/types.h>
to <sys/types.h> and <sys/stdint.h>.
* Add a new C99 <stdint.h> header, which provides integer types of
explicit width, related limits and integer constant macros.
* Extend <inttypes.h> to provide <stdint.h> definitions and format
macros for printf() and scanf().
* Add C99 strtoimax() and strtoumax() functions.
* Use the latter within scanf().
* Add C99 %j, %t and %z printf()/scanf() conversions for
intmax_t, pointer-type and size_t arguments.
 1.28 14-Apr-2001  thorpej Generic soft interrupt implementation for NetBSD/i386. This could
probably be tuned somewhat, but this is a stop-gap measure to hold
us until Bill Sommerfeld's new interrupt code comes in from the
MP branch.
 1.27 07-Jan-2001  fvdl branches: 1.27.2;
Define __HAVE_OLD_DISKLABEL in <machine/types.h> for i386 (where the
other __HAVE_* defines are). Conditionalize definition of old
disklabel struct and ODIOC* definitions on it, allowing other ports
to bump the number of partitions in the label if they want to
(see comment in sys/disklabel.h).
 1.26 03-Jan-2001  takemura replace 'long long' with int64_t to compile stand alone program with
compiler other than GCC.
 1.25 11-Dec-2000  mycroft Introduce 2 new flags in types.h:
* __HAVE_SYSCALL_INTERN. If this is defined, e_syscall is replaced by
e_syscall_intern, which is called at key places in the kernel. This can be
used to set a MD syscall handler pointer. This obsoletes and replaces the
*_HAS_SEPARATED_SYSCALL flags.
* __HAVE_MINIMAL_EMUL. If this is defined, certain (deprecated) elements in
struct emul are omitted.
 1.24 06-Jun-2000  sommerfeld branches: 1.24.2; 1.24.4;
Replace "timestamp" with "counter" in previous change, to avoid any
possible confusion that it has anything to do with accurate
measurement of time.

New names:
__HAVE_CPU_COUNTER
cpu_counter()
cpu_hascounter()
 1.23 05-Jun-2000  sommerfeld Let rnd(4) know how to read the (pentium and higher) cycle counter:

If __HAVE_CPU_TIMESTAMP is defined, <machine/rnd.h> exists and defines
two functions:
1) u_int32_t cpu_timestamp(void);
returns the 32 low order bits of a reasonably high frequency counter.
2) int cpu_havetimestamp(void);
returns non-zero if cpu_timestamp() actually works.

The timestamp counter should run at a frequency greater than 1 MHz
(otherwise, microtime would be sufficient); other than that, the exact
frequency and origin of the counter are unspecified.
 1.22 05-Feb-2000  cgd branches: 1.22.4;
clean up (group, sort) __HAVE_* defines
 1.21 01-Feb-2000  danw #define __HAVE_DEVICE_REGISTER on ports that have it, and check for
that, rather than a list of architecture defines, in config_attach
 1.20 05-Feb-1999  thorpej branches: 1.20.8;
The x86 does not have strict alignment requirements, so define
__NO_STRICT_ALIGNMENT here.
 1.19 13-Aug-1998  thorpej Garbage-collect vm_offset_t and vm_size_t.
 1.18 13-Aug-1998  eeh Merge paddr_t changes into the main branch.
 1.17 14-Jun-1998  kleink branches: 1.17.2;
GC the unused `physadr' type, which was not able to hold a complete physical
address on 2 architectures anyhow. Also, move the definition of the `label_t'
type inside _KERNEL protection, since it is specific to the in-kernel
setjmp()/longjmp() implementations.
 1.16 22-Mar-1998  drochner tell drivers that this port knows about the new wscons code
(and generates the NWSCONS etc include files)
 1.15 22-Mar-1998  drochner switch to non-BROKEN_INDIRECT_CONFIG
 1.14 05-Nov-1997  thorpej Mark uses of long long with /* LONGLONG */ for lint. From
Chris Demetriou <cgd@pa.dec.com>.
 1.13 05-Dec-1996  cgd branches: 1.13.14;
First step inn removing config_scan() and the hacks that gave devices
on indirect-config busses a (permanent) softc that they could share
between 'match' and 'attach' routines:

Define __BROKEN_INDIRECT_CONFIG so that old autoconfiguration
interfaces are used, until drivers are converted to use the new
interfaces (actually, converted back to use the _older_ interfaces)
which prohibit indirect configuration devices from receiving a softc
in their match routine that they can share with their attach routine.
 1.12 24-Dec-1995  mycroft Enable paging of the user area.
 1.11 06-Jul-1995  cgd add <sys/cdefs.h> inclusions. namsspace-protect physadr, label_t
def'ns against _POSIX_SOURCE and _ANSI_SOURCE.
 1.10 28-Jun-1995  cgd remove unused cpu_exec() definitions. moved "broken swap" markers, for
ports that still need it, to types.h.
 1.9 20-Nov-1994  christos Included <sys/cdefs.h> since this file is now using __signed.
It broke non gnu compilers.
 1.8 27-Oct-1994  cgd new RCS ID format.
 1.7 20-Oct-1994  cgd update for new syscall args description mechanism
 1.6 20-Jul-1994  cgd define __BIT_TYPES_DEFINED__ for compatibility with things like BIND and nvi
 1.5 24-May-1994  cgd branches: 1.5.2;
use __signed instead of signed, per Lite
 1.4 23-May-1994  cgd can't use u_long
 1.3 14-Mar-1994  cgd add basic integral types (a la sparc port) that new nvi wants.
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.5.2.1 20-Jul-1994  cgd update from trunk.
 1.13.14.1 05-Nov-1997  thorpej Update from trunk: Mark usese of long long with /* LONGLONG */ for lint.
 1.17.2.2 12-Aug-1998  eeh Protect XOPEN and POSIX code from vm_offset_t, paddr_t, vaddr_t, vm_size_t, psize_t, and vsize_t.
 1.17.2.1 30-Jul-1998  eeh Split vm_offset_t and vm_size_t into paddr_t, psize_t, vaddr_t, and vsize_t.
 1.20.8.5 21-Apr-2001  bouyer Sync with HEAD
 1.20.8.4 18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.20.8.3 05-Jan-2001  bouyer Sync with HEAD
 1.20.8.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.20.8.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.22.4.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.24.4.7 31-Aug-2002  sommerfeld SMP branch resync. Mostly RAS support.
 1.24.4.6 19-Aug-2002  sommerfeld merged with -current as of today.
rearranged gdt init to deal with KVM86 changes; however, KVM86 has no
chance of working yet; good thing it's not part of GENERIC
 1.24.4.5 27-Apr-2002  sommerfeld Merge with current as of today
 1.24.4.4 30-Apr-2001  sommerfeld Merge sommerfeld_i386mp_1 branch with -current as of today.
GENERIC.MP kernel boots and runs multiuser on my ABIT BP6
 1.24.4.3 07-Jan-2001  sommerfeld Snapshot of merge-in-progress with -current.

[Not expected to build]. Catch up with the last N months worth of
changes to -current.
 1.24.4.2 07-Jan-2001  sommerfeld Partial merge with -current, largely to pick up __HAVE_OLD_DISKLABEL.
 1.24.4.1 06-Jun-2000  sommerfeld file types.h was added on branch sommerfeld_i386mp_1 on 2001-01-07 18:46:22 +0000
 1.24.2.1 01-May-2001  he Pull up revision 1.27 (via patch, requested by fvdl):
Increase the number of BSD disklabel partitions on i386 to 16.
 1.27.2.6 19-Dec-2002  thorpej Sync with HEAD.
 1.27.2.5 18-Oct-2002  nathanw Catch up to -current.
 1.27.2.4 17-Sep-2002  nathanw Catch up to -current.
 1.27.2.3 13-Aug-2002  nathanw Catch up to -current.
 1.27.2.2 01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.27.2.1 21-Jun-2001  nathanw Catch up to -current.
 1.29.2.3 10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.29.2.2 06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.29.2.1 16-Mar-2002  jdolecek Catch up with -current.
 1.30.8.1 31-Aug-2002  gehenna catch up with -current.
 1.42.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.42.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.42.2.1 03-Aug-2004  skrll Sync with HEAD
 1.45.16.9 27-Feb-2008  yamt sync with head.
 1.45.16.8 11-Feb-2008  yamt remove __HAVE_LAZY_MBUF for now.
 1.45.16.7 04-Feb-2008  yamt sync with head.
 1.45.16.6 21-Jan-2008  yamt sync with head
 1.45.16.5 03-Sep-2007  yamt sync with head.
 1.45.16.4 26-Feb-2007  yamt sync with head.
 1.45.16.3 30-Dec-2006  yamt sync with head.
 1.45.16.2 21-Jun-2006  yamt sync with head.
 1.45.16.1 07-Jul-2005  yamt define __HAVE_LAZY_MBUF for i386 and amd64.
 1.46.14.1 19-Jun-2006  chap Sync with head.
 1.46.8.3 14-Sep-2006  yamt sync with head.
 1.46.8.2 03-Sep-2006  yamt sync with head.
 1.46.8.1 26-Jun-2006  yamt sync with head.
 1.46.6.1 04-Feb-2006  simonb Define __HAVE_TIMECOUNTER.
 1.46.4.1 09-Sep-2006  rpaulo sync with head
 1.49.2.1 29-Dec-2006  ad Checkpoint work in progress.
 1.50.14.1 03-Oct-2007  garbled Sync with HEAD
 1.50.6.1 15-Jul-2007  ad Sync with head.
 1.51.10.3 23-Mar-2008  matt sync with HEAD
 1.51.10.2 09-Jan-2008  matt sync with HEAD
 1.51.10.1 06-Nov-2007  matt sync with HEAD
 1.52.8.7 23-Jan-2008  bouyer Sync with HEAD.
 1.52.8.6 19-Jan-2008  bouyer Sync with HEAD
 1.52.8.5 13-Jan-2008  bouyer Work in progress on xeni386 PAE support:
Make xeni386 build with a 64bit paddr_t. For this vaddr_t vs paddr_t vs
pointers usages had to be clarified.
If 'options PAE' is present in a Xen3 kernel, switch paddr_t, pd_entry_t
and pt_entry_t to 64bits, and add the PAE entry in the __xen_guest ELF section.
 1.52.8.4 11-Jan-2008  bouyer Xen has generic todr too
 1.52.8.3 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.52.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.52.8.1 02-Jan-2008  bouyer Sync with HEAD
 1.52.4.1 26-Dec-2007  ad Sync with head.
 1.52.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.58.2.1 24-Mar-2008  keiichi sync with head.
 1.59.12.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.59.6.4 09-Oct-2010  yamt sync with head
 1.59.6.3 11-Mar-2010  yamt sync with head
 1.59.6.2 18-Jul-2009  yamt sync with head.
 1.59.6.1 04-May-2009  yamt sync with head.
 1.59.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.59.2.1 21-Feb-2008  mjf file types.h was added on branch mjf-devfs2 on 2009-01-17 13:28:04 +0000
 1.60.8.6 27-Aug-2011  jym Sync with HEAD. Most notably: uvm/pmap work done by rmind@, and MP Xen
work of cherry@.

No regression observed on suspend/restore.
 1.60.8.5 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.60.8.4 28-Mar-2011  jym Sync with HEAD. TODO before merge:
- shortcut for suspend code in sysmon, when powerd(8) is not running.
Borrow ``xs_watch'' thread context?
- bug hunting in xbd + xennet resume. Rings are currently thrashed upon
resume, so current implementation force flush them on suspend. It's not
really needed.
 1.60.8.3 01-Nov-2009  jym Sync with HEAD.
 1.60.8.2 23-Jul-2009  jym Sync with HEAD.
 1.60.8.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.60.2.1 28-Apr-2009  skrll Sync with HEAD.
 1.67.4.3 21-Apr-2011  rmind sync with head
 1.67.4.2 05-Mar-2011  rmind sync with head
 1.67.4.1 18-Mar-2010  rmind Unify /dev/{mem,kmem,zero,null} implementations in MI code. Based on patch
from Joerg Sonnenberger, proposed on tech-kern@, in February 2008.

Work and depression still in progress.
 1.67.2.1 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.70.4.1 05-Mar-2011  bouyer Sync with HEAD
 1.70.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.72.2.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.74.16.1 18-May-2014  rmind sync with head
 1.74.12.2 03-Dec-2017  jdolecek update from HEAD
 1.74.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.74.2.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.77.2.1 10-Aug-2014  tls Rebase.
 1.79.4.3 19-Mar-2016  skrll Sync with HEAD
 1.79.4.2 22-Sep-2015  skrll Sync with HEAD
 1.79.4.1 06-Jun-2015  skrll Sync with HEAD
 1.87.18.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.87.18.1 10-Jun-2019  christos Sync with HEAD
 1.87.16.1 28-Jul-2018  pgoyette Sync with HEAD
 1.92.4.1 03-Apr-2021  thorpej Sync with HEAD.
 1.92.2.1 03-Apr-2021  thorpej Sync with HEAD.
 1.93.22.1 02-Aug-2025  perseant Sync with HEAD
 1.15 26-Jul-2018  maxv Rework dbregs, to switch the registers during context switches, and not on
each user->kernel transition via userret. Reloads of DR6/DR7 are expensive
on both native and xen.
 1.14 23-Feb-2017  kamil branches: 1.14.12; 1.14.14;
Introduce PT_GETDBREGS and PT_SETDBREGS in ptrace(2) on i386 and amd64

This interface is modeled after FreeBSD API with the usage.

This replaced previous watchpoint API. The previous one was introduced
recently in NetBSD-current and remove its spurs without any
backward-compatibility.

Design choices for Debug Register accessors:
- exec() (TRAP_EXEC event) must remove debug registers from LWP
- debug registers are only per-LWP, not per-process globally
- debug registers must not be inherited after (v)forking a process
- debug registers must not be inherited after forking a thread
- a debugger is responsible to set global watchpoints/breakpoints with the
debug registers, to achieve this PTRACE_LWP_CREATE/PTRACE_LWP_EXIT event
monitoring function is designed to be used
- debug register traps must generate SIGTRAP with si_code TRAP_DBREG
- debugger is responsible to retrieve debug register state to distinguish
the exact debug register trap (DR6 is Status Register on x86)
- kernel must not remove debug register traps after triggering a trap event
a debugger is responsible to detach this trap with appropriate PT_SETDBREGS
call (DR7 is Control Register on x86)
- debug registers must not be exposed in mcontext
- userland must not be allowed to set a trap on the kernel

Implementation notes on i386 and amd64:
- the initial state of debug register is retrieved on boot and this value is
stored in a local copy (initdbregs), this value is used to initialize dbreg
context after PT_GETDBREGS
- struct dbregs is stored in pcb as a pointer and by default not initialized
- reserved registers (DR4-DR5, DR9-DR15) are ignored

Further ideas:
- restrict this interface with securelevel

Tested on real hardware i386 (Intel Pentium IV) and amd64 (Intel i7).

This commit enables 390 debug register ATF tests in kernel/arch/x86.
All tests are passing.

This commit does not cover netbsd32 compat code. Currently other interface
PT_GET_SIGINFO/PT_SET_SIGINFO is required in netbsd32 compat code in order to
validate reliably PT_GETDBREGS/PT_SETDBREGS.

This implementation does not cover FreeBSD specific defines in their
<x86/reg.h>: DBREG_DR7_LOCAL_ENABLE, DBREG_DR7_GLOBAL_ENABLE, DBREG_DR7_LEN_1
etc. These values tend to be reinvented by each tracer on its own. GNU
Debugger (GDB) works with NetBSD debug registers after adding this patch:

--- gdb/amd64bsd-nat.c.orig 2016-02-10 03:19:39.000000000 +0000
+++ gdb/amd64bsd-nat.c
@@ -167,6 +167,10 @@ amd64bsd_target (void)

#ifdef HAVE_PT_GETDBREGS

+#ifndef DBREG_DRX
+#define DBREG_DRX(d,x) ((d)->dr[(x)])
+#endif
+
static unsigned long
amd64bsd_dr_get (ptid_t ptid, int regnum)
{


Another reason to stop introducing unpopular defines covering machine
specific register macros is that these value varies across generations of
the same CPU family.

GDB demo:
(gdb) c
Continuing.

Watchpoint 2: traceme

Old value = 0
New value = 16
main (argc=1, argv=0x7f7fff79fe30) at test.c:8
8 printf("traceme=%d\n", traceme);

(Currently the GDB interface is not reliable due to NetBSD support bugs)

Sponsored by <The NetBSD Foundation>
 1.13 16-Jan-2017  kamil Allow to mix single-step with hardware assisted watchpoints on i386

This case needs new handling in trap recognition.

Sponsored by <The NetBSD Foundation>
 1.12 15-Dec-2016  kamil branches: 1.12.2;
Add support for hardware assisted watchpoints/breakpoints API in ptrace(2)

Add new ptrace(2) calls:
- PT_COUNT_WATCHPOINTS - count the number of available hardware watchpoints
- PT_READ_WATCHPOINT - read struct ptrace_watchpoint from the kernel state
- PT_WRITE_WATCHPOINT - write new struct ptrace_watchpoint state, this
includes enabling and disabling watchpoints

The ptrace_watchpoint structure contains MI and MD parts:

typedef struct ptrace_watchpoint {
int pw_index; /* HW Watchpoint ID (count from 0) */
lwpid_t pw_lwpid; /* LWP described */
struct mdpw pw_md; /* MD fields */
} ptrace_watchpoint_t;

For example amd64 defines MD as follows:
struct mdpw {
void *md_address;
int md_condition;
int md_length;
};

These calls are protected with the __HAVE_PTRACE_WATCHPOINTS guard.

Tested on amd64, initial support added for i386 and XEN.

Sponsored by <The NetBSD Foundation>
 1.11 28-Apr-2008  martin branches: 1.11.44; 1.11.64; 1.11.68;
Remove clause 3 and 4 from TNF licenses
 1.10 09-Feb-2007  ad branches: 1.10.44; 1.10.46; 1.10.48;
Merge newlock2 to head.
 1.9 15-Apr-2006  simonb branches: 1.9.8;
Remove "register", ANSIfy.
 1.8 16-Feb-2006  perry branches: 1.8.2; 1.8.4; 1.8.6;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.7 24-Dec-2005  perry branches: 1.7.2; 1.7.4; 1.7.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6 31-Oct-2003  cl branches: 1.6.16;
Reduce code duplication by adding mi_userret() in sys/userret.h
containing signal posting, kernel-exit handling and sa_upcall processing.

XXX the pc532, sparc, sparc64 and vax ports should have their
XXX userret() code rearranged to use this.
 1.5 27-Oct-2003  junyoung Nuke __P().
 1.4 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.3 17-Jan-2003  thorpej branches: 1.3.2;
Merge the nathanw_sa branch.
 1.2 10-Dec-2000  mycroft branches: 1.2.2; 1.2.4; 1.2.6;
Introduce PROC_PC(), which is used to get a process's user PC. If this is
defined, call addupc_intr() directly from statclock() in the system time case,
using the same P_OWEUPC path if the copyin/copyout fails.
Use this in i386 to remove profiling code from the normal userret() path.
 1.1 09-Dec-2000  jdolecek put userret() into header file machine/userret.h and pull it where needed
 1.2.6.6 26-Sep-2002  nathanw Change "if (l->l_flag & L_SA_UPCALL)" to "while (l->l_flag & L_SA_UPCALL)"
in userret() functions or equivalent, to permit delivery of multiple upcalls
in a single kernel entry.

XXX It's getting crowded in here. Collapsing posting signals, upcalls, and
XXX kernel-exit handling into one mechanism would be nice.
 1.2.6.5 17-Dec-2001  nathanw Call sa_upcall_userret(), not cpu_upcall().
 1.2.6.4 17-Nov-2001  nathanw Check and obey user-return exit hook (replaces test for P_WEXIT).
 1.2.6.3 19-Jul-2001  nathanw Check for P_WEXIT after taking signals, in case we were stopped in CURSIG().
 1.2.6.2 09-Jul-2001  nathanw Move upcall processing to the point of userret() rather than invocation time.
 1.2.6.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.2.4.2 10-Dec-2000  mycroft Introduce PROC_PC(), which is used to get a process's user PC. If this is
defined, call addupc_intr() directly from statclock() in the system time case,
using the same P_OWEUPC path if the copyin/copyout fails.
Use this in i386 to remove profiling code from the normal userret() path.
 1.2.4.1 10-Dec-2000  mycroft file userret.h was added on branch sommerfeld_i386mp_1 on 2000-12-10 19:29:32 +0000
 1.2.2.2 13-Dec-2000  bouyer Sync with HEAD (for UBC fixes).
 1.2.2.1 10-Dec-2000  bouyer file userret.h was added on branch thorpej_scsipi on 2000-12-13 15:49:31 +0000
 1.3.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.3.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.3.2.1 03-Aug-2004  skrll Sync with HEAD
 1.6.16.2 26-Feb-2007  yamt sync with head.
 1.6.16.1 21-Jun-2006  yamt sync with head.
 1.7.6.1 22-Apr-2006  simonb Sync with head.
 1.7.4.1 09-Sep-2006  rpaulo sync with head
 1.7.2.1 18-Feb-2006  yamt sync with head.
 1.8.6.1 24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.8.4.1 19-Apr-2006  elad sync with head - hopefully this will work
 1.8.2.1 24-May-2006  yamt sync with head.
 1.9.8.1 20-Oct-2006  ad Do the priority adjustment in mi_userret().
 1.10.48.1 16-May-2008  yamt sync with head.
 1.10.46.1 18-May-2008  yamt sync with head.
 1.10.44.1 02-Jun-2008  mjf Sync with HEAD.
 1.11.68.2 20-Mar-2017  pgoyette Sync with HEAD
 1.11.68.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.11.64.2 28-Aug-2017  skrll Sync with HEAD
 1.11.64.1 05-Feb-2017  skrll Sync with HEAD
 1.11.44.1 03-Dec-2017  jdolecek update from HEAD
 1.12.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.14.14.1 10-Jun-2019  christos Sync with HEAD
 1.14.12.1 28-Jul-2018  pgoyette Sync with HEAD
 1.19 17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.18 07-Aug-2003  agc branches: 1.18.120;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.17 12-May-2000  thorpej branches: 1.17.6; 1.17.30;
Only use __builtin_va_alist_t if using GCC 2.96 or later. Fixes
pkg/10080, from Matthias Scheler.
 1.16 05-May-2000  thorpej Use __GNUC_PREREQ__().
 1.15 03-May-2000  thorpej Make varargs and stdarg work with GCC 2.96 and later.
 1.14 26-Dec-1995  mycroft branches: 1.14.30;
Make the type of __builtin_va_list a long.
 1.13 26-Dec-1995  mycroft Use __builtin_va_alist.
 1.12 25-Dec-1995  mycroft Stylistic changes.
 1.11 25-Dec-1995  mycroft Update for GCC 2.7, and fix bugs.
 1.10 28-Mar-1995  jtc KERNEL -> _KERNEL
 1.9 28-Jan-1995  jtc ANSI says that <stdarg.h>'s va_end macro must expand to a void expression.
For consistancy, I'm changing <varargs.h> too.
 1.8 28-Dec-1994  cgd do the right thing with strange-sized varargs objects.
 1.7 27-Oct-1994  cgd new RCS ID format.
 1.6 15-Oct-1994  cgd make <stdarg.h> a symlink, and clean up ports' stdarg.h and varargs.h files.
 1.5 09-Oct-1994  mycroft Make multiple-inclusion protection consistent.
 1.4 29-Jun-1994  deraadt branches: 1.4.2;
_MACHINE_VARGS_H_
 1.3 21-May-1994  cgd update from lite
 1.2 16-May-1994  cgd USL copyright foo
 1.1 27-Jan-1994  pk branches: 1.1.2;
move varargs stuff to arch/<machine>/include.
 1.1.2.2 27-Jan-1994  pk move varargs stuff to arch/<machine>/include.
 1.1.2.1 27-Jan-1994  pk file varargs.h was added on branch magnum on 1994-01-27 00:18:24 +0000
 1.4.2.1 11-Oct-1994  mycroft Update from trunk.
 1.14.30.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.17.30.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.17.30.2 18-Sep-2004  skrll Sync with HEAD.
 1.17.30.1 03-Aug-2004  skrll Sync with HEAD
 1.17.6.2 12-May-2000  thorpej Only use __builtin_va_alist_t if using GCC 2.96 or later. Fixes
pkg/10080, from Matthias Scheler.
 1.17.6.1 12-May-2000  thorpej file varargs.h was added on branch sommerfeld_i386mp_1 on 2000-05-12 23:49:13 +0000
 1.18.120.1 27-Aug-2011  jym Add/remove files, like in HEAD.
 1.20 12-Aug-2017  maxv Remove vm86.

Pass 4.
 1.19 21-Nov-2009  rmind branches: 1.19.22; 1.19.40;
Use lwp_getpcb() on x86 MD code, clean from struct user usage.
 1.18 16-Mar-2009  cegger ansify function definitions
 1.17 14-Nov-2008  ad branches: 1.17.4;
Remove some compat ifdefs that aren't really needed.
 1.16 28-Apr-2008  martin branches: 1.16.6; 1.16.8;
Remove clause 3 and 4 from TNF licenses
 1.15 16-Apr-2007  ad branches: 1.15.32; 1.15.34; 1.15.36;
Share the sysarch stuff between the x86 ports. PR kern/36046.
 1.14 16-Feb-2006  perry branches: 1.14.20; 1.14.24; 1.14.26;
Change "inline" back to "__inline" in .h files -- C99 is still too
new, and some apps compile things in C89 mode. C89 keywords stay.

As per core@.
 1.13 24-Dec-2005  perry branches: 1.13.2; 1.13.4; 1.13.6;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.12 27-Oct-2003  junyoung branches: 1.12.16;
Nuke __P().
 1.11 11-Sep-2003  christos make vm86 use __gregset_t
 1.10 17-Jan-2003  thorpej branches: 1.10.2;
Merge the nathanw_sa branch.
 1.9 09-Oct-1997  jtc branches: 1.9.30;
Fix tipo inherited from old version of TNF copyright template.
 1.8 03-May-1996  christos branches: 1.8.12;
Add missing prototypes.
 1.7 30-Apr-1996  mycroft Remove BIOSSEG.
Don't mess with the flags when entering a software interrupt.
Use IF, not VIF.
NOTE: These changes break dosemu, but are required for proper emulation.
 1.6 18-Apr-1996  mycroft Make some of the flag handling clearer. No functional change.
 1.5 12-Apr-1996  mycroft Use the flag mask in a somewhat more sane fashion.
 1.4 11-Apr-1996  mycroft Actually keep track of the naughty PSL bits.
Use VIF, rather than IF, by default, to be compatible with dosemu. XXXX
 1.3 11-Apr-1996  mycroft Export [gs]et_vflags(), and always use them when saving/restoring registers
in VM86 mode.
Allow changing of *all* PSL bits in VM86 mode; some applications don't work
right otherwise, and all the nasty bits are virtualized anyway.
Make sure PSL_VIF, PSL_VIP, and PSL_VM don't show up in the user's view of
the PSL.
 1.2 27-Feb-1996  jtc Copyright assigned to the NetBSD Foundation
 1.1 08-Jan-1996  mycroft VM86 support, by John Kohl, touched up a bit by me.
 1.8.12.1 14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.9.30.1 05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.10.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.10.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.10.2.1 03-Aug-2004  skrll Sync with HEAD
 1.12.16.1 03-Sep-2007  yamt sync with head.
 1.13.6.1 22-Apr-2006  simonb Sync with head.
 1.13.4.1 09-Sep-2006  rpaulo sync with head
 1.13.2.1 18-Feb-2006  yamt sync with head.
 1.14.26.1 11-Jul-2007  mjf Sync with head.
 1.14.24.1 27-May-2007  ad Sync with head.
 1.14.20.1 07-May-2007  yamt sync with head.
 1.15.36.3 11-Mar-2010  yamt sync with head
 1.15.36.2 04-May-2009  yamt sync with head.
 1.15.36.1 16-May-2008  yamt sync with head.
 1.15.34.1 18-May-2008  yamt sync with head.
 1.15.32.2 17-Jan-2009  mjf Sync with HEAD.
 1.15.32.1 02-Jun-2008  mjf Sync with HEAD.
 1.16.8.2 28-Apr-2009  skrll Sync with HEAD.
 1.16.8.1 19-Jan-2009  skrll Sync with HEAD.
 1.16.6.1 13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.17.4.3 28-Mar-2011  jym Cure sync hiccups. Code with compile errors is not really useful, heh.
 1.17.4.2 01-Nov-2009  jym Sync with HEAD.
 1.17.4.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.19.40.1 28-Aug-2017  skrll Sync with HEAD
 1.19.22.1 03-Dec-2017  jdolecek update from HEAD
 1.88 21-Aug-2022  riastradh i386/vmparam.h: Need some constants from i386/pte.h.

These are used by VM_MIN/MAX_KERNEL_ADDRESS. pte.h is small and
likely stable enough that it's not worthwhile to migrate them to
vmparam.h instead.
 1.87 20-Aug-2022  riastradh x86: Split most of pmap.h into pmap_private.h or vmparam.h.

This way pmap.h only contains the MD definition of the MI pmap(9)
API, which loads of things in the kernel rely on, so changing x86
pmap internals no longer requires recompiling the entire kernel every
time.

Callers needing these internals must now use machine/pmap_private.h.
Note: This is not x86/pmap_private.h because it contains three parts:

1. CPU-specific (different for i386/amd64) definitions used by...

2. common definitions, including Xenisms like xpmap_ptetomach,
further used by...

3. more CPU-specific inlines for pmap_pte_* operations

So {amd64,i386}/pmap_private.h defines 1, includes x86/pmap_private.h
for 2, and then defines 3. Maybe we should split that out into a new
pmap_pte.h to reduce this trouble.

No functional change intended, other than that some .c files must
include machine/pmap_private.h when previously uvm/uvm_pmap.h
polluted the namespace with pmap internals.

Note: This migrates part of i386/pmap.h into i386/vmparam.h --
specifically the parts that are needed for several constants defined
in vmparam.h:

VM_MAXUSER_ADDRESS
VM_MAX_ADDRESS
VM_MAX_KERNEL_ADDRESS
VM_MIN_KERNEL_ADDRESS

Since i386 needs PDP_SIZE in vmparam.h, I added it there on amd64
too, just to keep things parallel.
 1.86 11-Feb-2019  cherry We reorganise definitions for XEN source support as follows:

XEN - common sources required for baseline XEN support.
XENPV - sources required for support of XEN in PV mode.
XENPVHVM - sources required for support for XEN in HVM mode.
XENPVH - sources required for support for XEN in PVH mode.
 1.85 23-Jun-2017  joerg branches: 1.85.6;
Recommit exec_subr.c revision 1.79:
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.

Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.

Additionally, change VM_DEFAULT_ADDRESS_TOPDOWN to include
user_stack_guard_size in the size reservation.
 1.84 11-Feb-2017  maxv branches: 1.84.6;
Remove VM_MAX_KERNEL_BUF (unused). Looks like several other ports could
do the same.
 1.83 19-Nov-2016  maxv branches: 1.83.2;
Put a one-page redzone between userland and the PTE space on amd64 and
i386.

The PTE space is a critical region that maps the page tree, and bugs have
been found in both amd64 and i386 where the kernel would wrongly overflow
userland data on this area. This kind of bug is terrible, since it allows
userland to overwrite some entries of the page tree, which makes it easy
to patch the kernel text and get ring0 privileges.
 1.82 07-Aug-2016  dholland Remove unused <sys/tree.h>.
 1.81 24-Jul-2014  riastradh branches: 1.81.4; 1.81.8;
Add a FIRST1G page freelist to x86, for old graphics devices.
 1.80 12-Jun-2014  riastradh Tweak x86 page freelists and add x86_select_freelist.

- Add 4G freelist to i386 -- there may be higher addresses if PAE.
- Add 64G and 1T freelists to amd64.
- Simplify freelist setup code and condense it into a table.
- Add x86_select_freelist to get a freelist guaranteed to yield
addresses no greater than a prescribed maximum address.

x86_select_freelist takes a uint64_t, not a paddr_t or bus_addr_t, so
that you can pass in, e.g., a 36-bit maximum address without needing
to write conditionals for i386/PAE.

No objections on port-x86:

https://mail-index.netbsd.org/port-i386/2014/05/21/msg003277.html
https://mail-index.netbsd.org/port-amd64/2014/05/21/msg002062.html
 1.79 28-Jan-2014  christos branches: 1.79.2;
only limit bottom-up allocations, put back 3G limit on datasize.
 1.78 28-Jan-2014  christos Cut down MAXDSIZE from 3G to 2.5G otherwise bottomup allocation ends up
supplying an out of bounds hint for sigcode (c001e000 > bf000000). Makes
a.out binaries work again.
 1.77 25-Jan-2014  christos delete VM_DEFAULT_ADDRESS; some of those should be GC'ed because they match
the default definition.
 1.76 13-Nov-2012  chs branches: 1.76.2;
bump VM_PHYSSEG_MAX to 32, we've seen a system where 16 wasn't enough.
 1.75 15-Aug-2012  sborrill branches: 1.75.2;
Bump VM_PHYSSEG_MAX to 16 from 10. Modern IBM hardware requires
VM_PHYSSEG_MAX to be turned up to 11 to avoid an early panic.
 1.74 07-May-2012  joerg Raise per-image text size limit to 256MB. 64MB has seen already, so
provide some margin of grows.
 1.73 19-Feb-2012  cherry Removing remaining references to the alternate PTE space. Modify documentation appropriately
 1.72 14-Nov-2010  uebayasi branches: 1.72.8; 1.72.12; 1.72.14;
Move struct vm_page_md definition from vmparam.h to pmap.h, because
it's used only by pmap. vmparam.h has definitions for wider
audience.

All GENERIC kernels build tested, except ia64.

powerpc/include/booke/vmparam.h has one too, but it has no pmap.h,
so it's left as is.
 1.71 06-Nov-2010  uebayasi Remove incomplete, never worked dynamic run-time memory registration
(uvm_page_physload(9)). This functionality will be re-added later.
 1.70 06-Mar-2009  joerg branches: 1.70.2; 1.70.4;
Remove SHMMAXPGS from all kernel configs. Dynamically compute the
initial limit as 1/4 of the physical memory. Ensure the limit is at
least 1024 pages, the old default on most platforms.
 1.69 13-Dec-2008  pooka branches: 1.69.2;
_VMPARAM_H_ -> _$MACHINE_VMPARAM_H_
 1.68 23-Jan-2008  bouyer branches: 1.68.6; 1.68.10; 1.68.18;
Merge the bouyer-xeni386 branch. This brings in PAE support to NetBSD xeni386
(domU only). PAE support is enabled by 'options PAE', see the new XEN3PAE_DOMU
and INSTALL_XEN3PAE_DOMU kernel config files.

See the comments in arch/i386/include/{pte.h,pmap.h} to see how it works.
In short, we still handle it as a 2-level MMU, with the second level page
directory being 4 pages in size. pmap switching is done by switching the
L2 pages in the L3 entries, instead of loading %cr3. This is almost required
by Xen, which handle the last L2 page (the one mapping 0xc0000000 - 0xffffffff)
in a very special way. But this approach should also work for native PAE
support if ever supported (in fact, the pmap should almost suport native
PAE, what's missing is bootstrap code in locore.S).
 1.67 20-Jan-2008  yamt - rewrite P->V tracking.
- use a hash rather than SPLAY trees.
SPLAY tree is a wrong algorithm to use here.
will be revisited if it slows down anything other than
micro-benchmarks.
- optimize the single mapping case (it's a common case) by
embedding an entry into mdpage.
- don't keep a pmap pointer as it can be obtained from ptp.
(discussed on port-i386 some years ago.)
ideally, a single paddr_t should be enough to describe a pte.
but it needs some more thoughts as it can increase computational
costs.
- pmap_enter: simplify and fix races with pmap_sync_pv.
- don't bother to lock pm_obj[i] where i > 0, unless DIAGNOSTIC.
- kill mp_link to save space.
- add many KASSERTs.
 1.66 11-Jan-2008  bouyer Merge the bouyer-xeni386 branch to head, at tag bouyer-xeni386-merge1 (the
branch is still active and will see i386PAE support developement).
Sumary of changes:
- switch xeni386 to the x86/x86/pmap.c, and the xen/x86/x86_xpmap.c
pmap bootstrap.
- merge back most of xen/i386/ to i386/i386
- change the build to reduce diffs between i386 and amd64 in file locations
- remove include files that were identical to the i386/amd64 counterparts,
the build will find them via the xen-ma/machine link.
 1.65 06-Jan-2008  ad #include <sys/mutex.h>
 1.64 18-Oct-2007  yamt branches: 1.64.2; 1.64.8;
merge yamt-x86pmap branch.

- reduce differences between amd64 and i386. notably, share pmap.c
between them. it makes several i386 pmap improvements available to
amd64, including tlb shootdown reduction and bug fixes from Stephan Uphoff.
- implement deferred pmap switching for amd64.
- remove LARGEPAGES option. always use large pages if available.
also, make it work on amd64.
 1.63 17-Oct-2007  garbled Merge the ppcoea-renovation branch to HEAD.

This branch was a major cleanup and rototill of many of the various OEA
cpu based PPC ports that focused on sharing as much code as possible
between the various ports to eliminate near-identical copies of files in
every tree. Additionally there is a new PIC system that unifies the
interface to interrupt code for all different OEA ppc arches. The work
for this branch was done by a variety of people, too long to list here.

TODO:
bebox still needs work to complete the transition to -renovation.
ofppc still needs a bunch of work, which I will be looking at.
ev64260 still needs to be renovated
amigappc was not attempted.

NOTES:
pmppc was removed as an arch, and moved to a evbppc target.
 1.62 29-Aug-2007  ad branches: 1.62.2; 1.62.4;
Merge most x86 changes from the vmlocking branch, except the threaded soft
interrupt stuff. This is mostly comprised of changes to the pmap modules to
work on multiprocessor systems without kernel_lock, and changes to speed up
tlb shootdowns.
 1.61 27-Sep-2006  cube branches: 1.61.8; 1.61.16; 1.61.22; 1.61.26; 1.61.28;
This is again that time of the millenium where we have to crank up a few
static limits to meet modern bloat requirements.

VM_PHYSSEG_MAX needs it to run on Intel's D946GZIS motherboard, as reported
by rix on #NetBSD-code on freenode. This has a consequence on the initial
number of possible extent allocations for iomem_ex, so increase that value
too.

While there, clarify the action to be taken when VM_PHYSSEG_MAX is maxed
out.

Do that on both amd64 and i386 because the causes, the effects and the code
are mostly the same.
 1.60 20-Sep-2005  christos branches: 1.60.26; 1.60.28;
- Bump default data size from 128M to 256M, allows the java interpreter to
start up without unlimit.
- Bump max data size from 2G to 3G. The actual space we are allowed to allocate
is somewhere between 2G and 3G, so trying to allocate above that will fail.
- Bump max stack size from 32M to 64M.

Approved by fvdl
 1.59 17-Jul-2005  christos Increase the default datasize limit to 2GB.
 1.58 10-Jan-2005  mycroft branches: 1.58.10;
Now that countless UVM bugs have been fixed, enable "topdown" memory
allocation by default.
 1.57 12-May-2004  yamt add a comment on mp_attrs.
 1.56 23-Oct-2003  chs rename pv_next to pv_node. use SPLAY_RIGHT() instead of expanding it inline.
 1.55 23-Oct-2003  provos changed linked list in pmap_remove_pv to a splay tree; approved: fvdl@
 1.54 24-Aug-2003  chs add support for non-executable mappings (where the hardware allows this)
and make the stack and heap non-executable by default. the changes
fall into two basic catagories:

- pmap and trap-handler changes. these are all MD:
= alpha: we already track per-page execute permission with the (software)
PG_EXEC bit, so just have the trap handler pay attention to it.
= i386: use a new GDT segment for %cs for processes that have no
executable mappings above a certain threshold (currently the
bottom of the stack). track per-page execute permission with
the last unused PTE bit.
= powerpc/ibm4xx: just use the hardware exec bit.
= powerpc/oea: we already track per-page exec bits, but the hardware only
implements non-exec mappings at the segment level. so track the
number of executable mappings in each segment and turn on the no-exec
segment bit iff the count is 0. adjust the trap handler to deal.
= sparc (sun4m): fix our use of the hardware protection bits.
fix the trap handler to recognize text faults.
= sparc64: split the existing unified TSB into data and instruction TSBs,
and only load TTEs into the appropriate TSB(s) for the permissions.
fix the trap handler to check for execute permission.
= not yet implemented: amd64, hppa, sh5

- changes in all the emulations that put a signal trampoline on the stack.
instead, we now put the trampoline into a uvm_aobj and map that into
the process separately.

originally from openbsd, adapted for netbsd by me.
 1.53 07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.52 22-Jul-2003  yamt move pv_head and page attributes into md part of vm_page structure
instead of having separate arrays for them.
(i.e. use __HAVE_VM_PAGE_MD instead of __HAVE_PMAP_PHYSSEG.)
 1.51 02-Apr-2003  thorpej branches: 1.51.2;
Use PAGE_SIZE rather than NBPG.
 1.50 16-Mar-2003  cjep kernal -> kernel
 1.49 23-Feb-2003  atatat #include opt_uvm.h in machine/vmparam.h (for those ports offering the
topdown option) so that including it directly before including
uvm/uvm_param.h (or uvm/uvm_extern.h which includes uvm/uvm_param.h)
and attempting to use topdown won't result in a compiler error.

Problem noted in private email.
 1.48 20-Feb-2003  atatat Introduce "top down" memory management for mmap()ed allocations. This
means that the dynamic linker gets mapped in at the top of available
user virtual memory (typically just below the stack), shared libraries
get mapped downwards from that point, and calls to mmap() that don't
specify a preferred address will get mapped in below those.

This means that the heap and the mmap()ed allocations will grow
towards each other, allowing one or the other to grow larger than
before. Previously, the heap was limited to MAXDSIZ by the placement
of the dynamic linker (and the process's rlimits) and the space
available to mmap was hobbled by this reservation.

This is currently only enabled via an *option* for the i386 platform
(though other platforms are expected to follow). Add "options
USE_TOPDOWN_VM" to your kernel config file, rerun config, and rebuild
your kernel to take advantage of this.

Note that the pmap_prefer() interface has not yet been modified to
play nicely with this, so those platforms require a bit more work
(most notably the sparc) before they can use this new memory
arrangement.

This change also introduces a VM_DEFAULT_ADDRESS() macro that picks
the appropriate default address based on the size of the allocation or
the size of the process's text segment accordingly. Several drivers
and the SYSV SHM address assignment were changed to use this instead
of each one picking their own "default".
 1.47 29-Jan-2003  drochner give some VM which was reserved for the UAREA but not used anymore back
to the user and adjust some comments (which were not accurate anyway
since NOREDZONE)
binary compatibility note: changing VM_MAXUSER_ADDRESS might influence
some sanity check in kvm_proc, where arguments on the stack are dealt
with, but it was a variable anyway and noone did care...
 1.46 10-Dec-2002  thorpej Use __LDPGSZ (which must be == USRTEXT) as the text address for a.out
executables, and eliminate the USRTEXT constant, which was only used
by the a.out exec code.
 1.45 15-Nov-2001  soren branches: 1.45.2;
MAXSLP is defined to be a machine-independent scheduling parameter,
so move it into sys/param.h.
 1.44 20-Oct-2001  fvdl Until early last year, the i386 port had 256M of kvm, and the max.
amount of kvm used for buffers was set at 70%, some 188M. Then
the total amount of kvm became 1G, and the amount for buffers
thus became some 716M. This is really too much, and some
device drivers want to map quite a bit of kvm these days.

So, cap it at 384M, which gives each buffer a little over 8k (the
default FFS blocksize) physical in an 1G physram configuration.
 1.43 25-Jun-2001  thorpej branches: 1.43.4;
Compute the VM_* constants directly, rather than hard-coding
them (with the formulas in comments).
 1.42 01-May-2001  thorpej Per discussion w/ chuck and chuck, restructure the md page stuff
to use a structure called "vm_page_md", and use __HAVE_VM_PAGE_MD
and __HAVE_PMAP_PHYSSEG.
 1.41 29-Apr-2001  thorpej Add a VM_MDPAGE_MEMBERS macro that defines pmap-specific data for
each vm_page structure. Add a VM_MDPAGE_INIT() macro to init this
data when pages are initialized by UVM. These macros are mandatory,
but ports may #define them to nothing if they are not needed/used.

This deprecates struct pmap_physseg. As a transitional measure,
allow a port to #define PMAP_PHYSSEG so that it can continue to
use it until its pmap is converted to use VM_MDPAGE_MEMBERS.

Use all this stuff to eliminate a lot of extra work in the Alpha
pmap module (it's smaller and faster now). Changes to other pmap
modules will follow.
 1.40 03-Jan-2001  fvdl branches: 1.40.4;
Bump shm max pages value to a more realistic one.
 1.39 14-Nov-2000  thorpej The i386 page size is fixed -- override PAGE_SIZE, et al, so that they
are compile-time constants.
 1.38 09-Nov-2000  kim BIOS memory loading messages can be enabled with DEBUG_MEMLOAD.
Increase VM_PHYSSEG_MAX from 3 to 5 to avoid a panic. Suggest
increasing VM_PHYSSEG_MAX in the panic message.
 1.37 18-Jun-2000  castor branches: 1.37.2;
Fix integer overflow in calculation of VM_MAX_KERNEL_BUF.
 1.36 11-Feb-2000  thorpej branches: 1.36.4;
Update for the NKMEMPAGES changes.
 1.35 11-Feb-2000  thorpej Move KERNBASE to 0xc0000000, giving the kernel a more-or-less full 1G
of virtual address space, leaving userland with 3G, and update comments
to match the new reality.

We knew we were going to have to bite this bullet eventually, and there
are a couple of outstanding PRs related to this issue (9389 and 9313).
Complete solution to those PRs is going to involve some sort of run-time
decision on how large kmem_map should be, as well as changing some data
structure allocation strategies in UVM. However, this change will at
least allow the PR submitter to simply throw resources at the problem.
 1.34 26-Jan-2000  tsutsui Remove obsoleted macros.
 1.33 04-Dec-1999  ragge CL* discarding.
 1.32 17-Jun-1999  thorpej branches: 1.32.2; 1.32.8;
PMAP_NEW is no longer optional on the i386; the old pmap's page table
allocation strategy no longer works at all. Move pmap.new.* to pmap.*.

To read the revision history of PMAP_NEW up until this merge, use cvs
rlog of the old pmap.new.* files.
 1.31 26-Apr-1999  thorpej Garbage-collect the VM_MBUF_SIZE constant. Instead, use the size
(nmbclusters * mclbytes), so that the right amount of KVA space is
allocated if those variables are patched.
 1.30 16-Jan-1999  chuck branches: 1.30.2; 1.30.4;
remove non MNN code
 1.29 13-Aug-1998  thorpej vm_offset_t -> {vaddr_t,paddr_t}, vm_size_t -> vsize_t
 1.28 08-Jul-1998  thorpej Define 2 free lists: a default, and a "first16", which is where the first
16M of RAM goes (in an effort to protect ISA DMA-safe memory).
 1.27 04-May-1998  thorpej Whitespace.
 1.26 10-Feb-1998  mrg - add defopt's for UVM, UVMHIST and PMAP_NEW.
- remove unnecessary UVMHIST_DECL's.
 1.25 06-Feb-1998  mrg add the i386 MD portions for UVM.
 1.24 15-Jan-1998  thorpej Just commit to using MACHINE_NEW_NONCONTIG.
 1.23 13-Jan-1998  mrg this is the i386 MD portion of the MACHINE_NEW_NONCONTIG code, as
written by chuck cranor. thanks to mycroft for helping me find the
one little line of code i accidentally deleted while merging it.

this is not enabled by default. `options MACHINE_NEW_NONCONTIG'
will use this code. eventually, this should go into <machine/vmparam.h>
insteaed of MACHINE_NONCONTIG.
 1.22 20-Oct-1997  fvdl Fix typo in VM_MAX_ADDRESS.
 1.21 20-Oct-1997  fvdl Change various constants that depend on the kernel VM base address. Lower
it to 0xf0000000 to give it more breathing space.
 1.20 12-Jul-1997  perry update comment from 1981 on memory and disk prices -- pr-2754 from Curt Sampson
 1.19 12-Jun-1997  mrg bring mrg-vm-swap2 onto mainilne.
 1.18 05-Mar-1997  fvdl branches: 1.18.2;
Bring limits up to 'modern' standards.
 1.17 09-Dec-1996  fvdl branches: 1.17.4; 1.17.6;
Include VM_MAX_KERNEL_BUF constant to put a cap on buffer cache KVM usage.
Override via config file possible.

XXX this is a stopgap measure.
 1.16 15-Nov-1996  fvdl Add MACHINE_NONCONTIG as a define.
 1.15 27-Oct-1994  cgd new RCS ID format.
 1.14 16-Jan-1994  cgd branches: 1.14.2;
SHMMAXPGS now pegged at 1024, where it belongs
 1.13 05-Jan-1994  mycroft Move kernel to 0xf8000000.
 1.12 04-Jan-1994  mycroft Fix VM_{MIN,MAX}_KERNEL_ADDRESS.
 1.11 03-Jan-1994  mycroft Garbage collection.
 1.10 22-Dec-1993  cgd bump MAXSSIZ back down to 8M (from 256M, where charles put it).
execve() currently allocated MAXSSIZ of address space (AND PAGE TABLES)
for the stack. until that's changed, and the stack-handling code is
updated to match, MAXSSIZ==256M will make execve() significantly slower
than MAXSSIZ==8M.
 1.9 20-Dec-1993  mycroft Cleanup and garbage collection; nothing significant. From magnum branch.
 1.8 15-Nov-1993  cgd cut down SHMMAXPGS (temporary)
 1.7 14-Nov-1993  cgd Add the System V message queue and semaphore facilities. Implemented
by Daniel Boulet <danny@BouletFermat.ab.ca>
 1.6 04-Sep-1993  cgd branches: 1.6.2;
change maximum stack size to 8M.
 1.5 04-Sep-1993  cgd decouple MAXDSIZ and MAXSSIZ. MAXSSIZ now is 2M; shouldn't need more,
and saves time in exec.
 1.4 13-Jul-1993  cgd up default data size limit to 16M, like on freefall, so everything will
compile properly with gcc2.
 1.3 18-Jun-1993  cgd convert magic numbers to network byte order, and attendent changes
 1.2 22-May-1993  cgd add rcsids to everything and clean up headers
 1.1 21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.1 21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.6.2.4 26-Oct-1993  mycroft Add a default SHMMAXPGS.
 1.6.2.3 15-Oct-1993  mycroft I386_CR3PAT could not justify its existence.
 1.6.2.2 15-Oct-1993  mycroft Major cleanup of include files and constants.
 1.6.2.1 10-Oct-1993  mycroft Remove old and non-working macros.
 1.14.2.2 16-Jan-1994  cgd SHMMAXPGS now pegged at 1024, where it belongs
 1.14.2.1 16-Jan-1994  cgd file vmparam.h was added on branch magnum on 1994-01-16 01:36:08 +0000
 1.17.6.1 12-Mar-1997  is Merge in Changes from The Trunk.
 1.17.4.1 12-Feb-1997  mrg initial work for dynamic swap additions.
 1.18.2.1 04-May-1997  mrg re-merge mrg-vm-swap into -current, and call it mrg-vm-swap2.
 1.30.4.2 04-Jul-1999  chs add UBC parameters.
 1.30.4.1 21-Jun-1999  thorpej Sync w/ -current.
 1.30.2.1 19-Feb-2000  he Apply patch (requested by thorpej):
Move KERNBASE to 0xc0000000, giving the kernel a more-or-less
full 1GB of virtual address space, leaving userland with 3GB,
and update comments to match the new reality.
 1.32.8.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.32.2.3 05-Jan-2001  bouyer Sync with HEAD
 1.32.2.2 22-Nov-2000  bouyer Sync with HEAD.
 1.32.2.1 20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
A i386 GENERIC kernel compiles without the siop, ahc and bha drivers
(will be updated later). i386 IDE/ATAPI and ncr work, as well as
sparc/esp_sbus. alpha should work as well (untested yet).
siop, ahc and bha will be updated once I've updated the branch to current
-current, as well as machine-dependant code.
 1.36.4.1 22-Jun-2000  minoura Sync w/ netbsd-1-5-base.
 1.37.2.1 30-Mar-2001  he Pull up revision 1.40 (requested by fvdl):
Add some required Linux emulation bits to support the Linux
version of VMware.
 1.40.4.5 11-Dec-2002  thorpej Sync with HEAD.
 1.40.4.4 08-Jan-2002  nathanw Catch up to -current.
 1.40.4.3 22-Oct-2001  nathanw Catch up to -current.
 1.40.4.2 24-Aug-2001  nathanw Catch up with -current.
 1.40.4.1 21-Jun-2001  nathanw Catch up to -current.
 1.43.4.1 10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.45.2.2 15-Nov-2001  soren MAXSLP is defined to be a machine-independent scheduling parameter,
so move it into sys/param.h.
 1.45.2.1 15-Nov-2001  soren file vmparam.h was added on branch sommerfeld_i386mp_1 on 2001-11-15 18:06:15 +0000
 1.51.2.5 10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.51.2.4 17-Jan-2005  skrll Sync with HEAD.
 1.51.2.3 21-Sep-2004  skrll Fix the sync with head I botched.
 1.51.2.2 18-Sep-2004  skrll Sync with HEAD.
 1.51.2.1 03-Aug-2004  skrll Sync with HEAD
 1.58.10.6 04-Feb-2008  yamt sync with head.
 1.58.10.5 21-Jan-2008  yamt sync with head
 1.58.10.4 27-Oct-2007  yamt sync with head.
 1.58.10.3 03-Sep-2007  yamt sync with head.
 1.58.10.2 30-Dec-2006  yamt sync with head.
 1.58.10.1 21-Jun-2006  yamt sync with head.
 1.60.28.1 22-Oct-2006  yamt sync with head
 1.60.26.1 18-Nov-2006  ad Sync with head.
 1.61.28.3 23-Mar-2008  matt sync with HEAD
 1.61.28.2 09-Jan-2008  matt sync with HEAD
 1.61.28.1 06-Nov-2007  matt sync with HEAD
 1.61.26.2 26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.61.26.1 03-Sep-2007  jmcneill Sync with HEAD.
 1.61.22.1 03-Sep-2007  skrll Sync with HEAD.
 1.61.16.1 03-Oct-2007  garbled Sync with HEAD
 1.61.8.3 23-Oct-2007  ad Sync with head.
 1.61.8.2 05-Apr-2007  ad Fix the pmap locking.
 1.61.8.1 13-Mar-2007  ad Pull in the initial set of changes for the vmlocking branch.
 1.62.4.1 25-Oct-2007  bouyer Sync with HEAD.
 1.62.2.1 23-Sep-2007  yamt - sync with amd64.
- pmap_alloc_level: remove fast call special case.
- tweak some printf to work for both of LP64 and LP32.
- remove machdep.nkpde sysctl.
- remove automatic adjustment of nkpde for now. will revisit later.
 1.64.8.5 20-Jan-2008  bouyer Sync with HEAD
 1.64.8.4 13-Jan-2008  bouyer Reorganize so that there are less #ifdef XEN
 1.64.8.3 10-Jan-2008  bouyer Change xeni386 build to match xenamd64:
- machine/ points to xen/include/i386
- remove includes that were identical to the i386/include/ ones; the build
will find them though the xen-ma/machine link.
- include xen files using xen/ not machine/
 1.64.8.2 08-Jan-2008  bouyer Sync with HEAD
 1.64.8.1 11-Dec-2007  bouyer Switch i386 to x86/x86/pmap.c
 1.64.2.1 18-Feb-2008  mjf Sync with HEAD.
 1.68.18.2 28-Apr-2009  skrll Sync with HEAD.
 1.68.18.1 19-Jan-2009  skrll Sync with HEAD.
 1.68.10.1 04-May-2009  yamt sync with head.
 1.68.6.1 17-Jan-2009  mjf Sync with HEAD.
 1.69.2.3 10-Jan-2011  jym Sync with HEAD
 1.69.2.2 01-Nov-2009  jym Sync with HEAD.
 1.69.2.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.70.4.1 05-Mar-2011  rmind sync with head
 1.70.2.3 16-Nov-2010  uebayasi Sync with HEAD.
 1.70.2.2 26-Apr-2010  uebayasi Remove the unfinished code to add a memory segment after uvm_page_init().
It doesn't even compile.

(In the future, we should allocate struct vm_page [] on the added memory
segment for NUMA's sake.)
 1.70.2.1 23-Feb-2010  uebayasi Convert all VM_MDPAGE_INIT()'s to take struct vm_page_md * and paddr_t.
 1.72.14.1 15-Aug-2012  riz Pull up following revision(s) (requested by sborrill in ticket #501):
sys/arch/amd64/include/vmparam.h: revision 1.31
sys/arch/i386/include/vmparam.h: revision 1.75
Bump VM_PHYSSEG_MAX to 16 from 10. Modern IBM hardware requires
VM_PHYSSEG_MAX to be turned up to 11 to avoid an early panic.
Bump VM_PHYSSEG_MAX to 16 from 10. Modern IBM hardware requires
VM_PHYSSEG_MAX to be turned up to 11 to avoid an early panic.
 1.72.12.2 02-Jun-2012  mrg sync to latest -current.
 1.72.12.1 24-Feb-2012  mrg sync to -current.
 1.72.8.5 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.72.8.4 16-Jan-2013  yamt sync with (a bit old) head
 1.72.8.3 30-Oct-2012  yamt sync with head
 1.72.8.2 23-May-2012  yamt sync with head.
 1.72.8.1 17-Apr-2012  yamt sync with head
 1.75.2.3 03-Dec-2017  jdolecek update from HEAD
 1.75.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.75.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.76.2.1 18-May-2014  rmind sync with head
 1.79.2.1 10-Aug-2014  tls Rebase.
 1.81.8.2 20-Mar-2017  pgoyette Sync with HEAD
 1.81.8.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.81.4.3 28-Aug-2017  skrll Sync with HEAD
 1.81.4.2 05-Dec-2016  skrll Sync with HEAD
 1.81.4.1 05-Oct-2016  skrll Sync with HEAD
 1.83.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.84.6.1 31-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #234):
sys/arch/amd64/include/vmparam.h: revision 1.43
sys/kern/exec_subr.c: revision 1.79
lib/libpthread/pthread_int.h: revision 1.94
sys/arch/mips/include/vmparam.h: revision 1.58
sys/arch/mips/include/vmparam.h: revision 1.59
lib/libpthread/TODO: revision 1.19
sys/arch/powerpc/include/vmparam.h: revision 1.20
sys/arch/riscv/include/vmparam.h: revision 1.2
sys/arch/riscv/include/vmparam.h: revision 1.3
sys/arch/i386/include/vmparam.h: revision 1.85
tests/lib/libpthread/t_join.c: revision 1.9
sys/uvm/uvm_meter.c: revision 1.66
sys/uvm/uvm_param.h: revision 1.36
sys/kern/exec_subr.c: revision 1.80
sys/uvm/uvm_param.h: revision 1.37
sys/kern/exec_subr.c: revision 1.81
sys/kern/exec_subr.c: revision 1.82
lib/libpthread/pthread_attr_getguardsize.3: revision 1.4
lib/libpthread/pthread.c: revision 1.148
lib/libpthread/pthread_attr.c: revision 1.17
sys/arch/amd64/include/vmparam.h: revision 1.42
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Revert for the moment, creates problems on i386.
Recommit exec_subr.c revision 1.79:
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Additionally, change VM_DEFAULT_ADDRESS_TOPDOWN to include
user_stack_guard_size in the size reservation.
Update VM_DEFAULT_ADDRESS32_TOPDOWN to include guard area.
Export the guard size of the main thread via vm.guard_size. Add a
complementary writable sysctl for the initial guard size of threads
created via pthread_create. Let the existing attribut accessors do the
right thing. Raise the default guard size for threads to 64KB.
 1.85.6.1 10-Jun-2019  christos Sync with HEAD
 1.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.1 08-May-2004  kleink branches: 1.1.2; 1.1.98; 1.1.100; 1.1.102;
Factor out W{CHAR,INT}_{MAX,MIN} into their own header file.
 1.1.102.1 16-May-2008  yamt sync with head.
 1.1.100.1 18-May-2008  yamt sync with head.
 1.1.98.1 02-Jun-2008  mjf Sync with HEAD.
 1.1.2.4 21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.2.3 18-Sep-2004  skrll Sync with HEAD.
 1.1.2.2 03-Aug-2004  skrll Sync with HEAD
 1.1.2.1 08-May-2004  skrll file wchar_limits.h was added on branch ktrace-lwp on 2004-08-03 10:36:05 +0000
 1.4 18-Nov-2011  jmcneill remove Xbox support
 1.3 07-Jan-2007  jmcneill branches: 1.3.2; 1.3.6; 1.3.86;
Remove nForce ethernet hack from machdep and instead call xbox_startup from
cpu_startup, which applies the patch.
 1.2 06-Jan-2007  jmcneill Use the pic16lc@iic driver for setting the system LED, rebooting, and
powering off the machine instead of the assembly code in pic16l.S
 1.1 04-Jan-2007  jmcneill Microsoft Xbox support, from Andrew Gillham.

Still requires some bug fixes in the nfe(4) driver; works with USB ethernet.
Requires Xromwell / Cromwell 2.41dev or above to boot. Tested both CD boot
and etherboot.

xboxfb(4) currently does not work properly with component video cables.
 1.3.86.1 17-Apr-2012  yamt sync with head
 1.3.6.2 26-Feb-2007  yamt sync with head.
 1.3.6.1 07-Jan-2007  yamt file xbox.h was added on branch yamt-lazymbuf on 2007-02-26 09:07:03 +0000
 1.3.2.2 12-Jan-2007  ad Sync with head.
 1.3.2.1 07-Jan-2007  ad file xbox.h was added on branch newlock2 on 2007-01-12 01:00:50 +0000
 1.2 25-Apr-2020  bouyer Merge the bouyer-xenpvh branch, bringing in Xen PV drivers support under HVM
guests in GENERIC.
Xen support can be disabled at runtime with
boot -c
disable hypervisor
 1.1 16-Apr-2020  bouyer branches: 1.1.2;
file hypercalls.h was initially added on branch bouyer-xenpvh.
 1.1.2.2 25-Apr-2020  bouyer Include changes in sys/arch/xen/include/ between bouyer-xenpvh-base1 and
bouyer-xenpvh-base2.
 1.1.2.1 16-Apr-2020  bouyer Reorganise sources to make it possible to include Xen PVHVM support in
native kernels. Among others:
- move xen/include/amd64/hypercall.h to amd64/include/xen and
xen/include/i386/hypercall.h to i386/include/xen
- exclude some native files from the build for xenpv
- add xen to "machine" config statement for amd64 and i386
- split arch/xen/conf/files.xen to arch/xen/conf/files.xen (for pv drivers)
and arch/xen/conf/files.xen.pv (for full pv support)
- add GENERIC_XENHVM kernel config which includes GENERIC and add Xen PV
drivers.

RSS XML Feed